diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index e336cbe56..000000000
--- a/.travis.yml
+++ /dev/null
@@ -1,41 +0,0 @@
-dist: trusty
-language: java
-install: true
-sudo: required
-
-services:
- - docker
-
-jdk:
- - oraclejdk8
-
-before_cache:
- - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
-
-cache:
- directories:
- - $HOME/.gradle/caches/
- - $HOME/.gradle/wrapper/
-
-stages:
-- name: build
-- name: release
- if: branch IN (release) AND type = push
-
-jobs:
- include:
- - stage: build
- script:
- # - ./gradlew build -Pnetty_version=4.0.56.Final
- # - ./gradlew clean build -x test
- # - ./gradlew :mysq-async:test --tests com.github.jasync.sql.db.mysql.QueryTimeoutSpec --info
- - ./resources/run-docker-memsql.sh
- - ./gradlew clean build
- - ./resources/detect-leak.sh mysql-async/target/mysql-async-tests.log
- - ./resources/detect-leak.sh postgresql-async/target/postgresql-async-tests.log
- - ./gradlew codeCoverageReport
- after_success:
- - bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN
- - stage: release
- script: ./gradlew clean build publishToSonatype closeAndReleaseSonatypeStagingRepository -no-daemon --no-parallel -x test
diff --git a/README.md b/README.md
index 743dec73d..0eee53ab5 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-
+
[](https://gitter.im/jasync-sql/support) [](https://search.maven.org/search?q=g:%22com.github.jasync-sql%22%20AND%20a:%22jasync-common%22)  [](https://github.com/jasync-sql/jasync-sql/blob/master/LICENSE) [](https://codecov.io/gh/jasync-sql/jasync-sql) [](https://github.com/KotlinBy/awesome-kotlin#libraries-frameworks-database)
@@ -39,14 +39,14 @@ For docs and info see the [wiki](https://github.com/jasync-sql/jasync-sql/wiki).
com.github.jasync-sql
jasync-mysql
- 2.1.16
+ 2.2.4
com.github.jasync-sql
jasync-postgresql
- 2.1.16
+ 2.2.4
```
@@ -56,9 +56,9 @@ For docs and info see the [wiki](https://github.com/jasync-sql/jasync-sql/wiki).
```gradle
dependencies {
// mysql
- compile 'com.github.jasync-sql:jasync-mysql:2.1.16'
+ compile 'com.github.jasync-sql:jasync-mysql:2.2.4'
// postgresql
- compile 'com.github.jasync-sql:jasync-postgresql:2.1.16'
+ compile 'com.github.jasync-sql:jasync-postgresql:2.2.4'
}
```
diff --git a/build.gradle.kts b/build.gradle.kts
index b351a901b..19635393e 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -24,7 +24,7 @@ apply(plugin = "io.github.gradle-nexus.publish-plugin")
allprojects {
group = "com.github.jasync-sql"
- version = "2.1.25"
+ version = "2.2.5"
apply(plugin = "kotlin")
apply(plugin = "maven-publish")
@@ -91,10 +91,6 @@ subprojects {
withJavadocJar()
}
- sourceSets.main {
- java.srcDirs("src/main/java")
- }
-
val varintName = when (project.name) {
"db-async-common" -> "jasync-common"
"pool-async" -> "jasync-pool"
diff --git a/db-async-common/build.gradle.kts b/db-async-common/build.gradle.kts
index a80ece15a..b1887e834 100644
--- a/db-async-common/build.gradle.kts
+++ b/db-async-common/build.gradle.kts
@@ -11,15 +11,15 @@ val LOGBACK_VERSION: String by project
val AWAITILITY_VERSION: String by project
dependencies {
- compile(project(":pool-async"))
+ api(project(":pool-async"))
api("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION")
- compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINES_VERSION")
+ api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINES_VERSION")
implementation("org.slf4j:slf4j-api:$SL4J_VERSION")
implementation("io.netty:netty-transport:$NETTY_VERSION")
implementation("io.netty:netty-handler:$NETTY_VERSION")
compileOnly("io.netty:netty-transport-native-epoll:$NETTY_VERSION:linux-x86_64")
compileOnly("io.netty:netty-transport-native-kqueue:$NETTY_VERSION:osx-x86_64")
- implementation("io.github.microutils:kotlin-logging:$KOTLIN_LOGGING_VERSION")
+ implementation("io.github.oshai:kotlin-logging-jvm:$KOTLIN_LOGGING_VERSION")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$KOTLIN_COROUTINES_VERSION")
testImplementation("junit:junit:$JUNIT_VERSION")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION")
diff --git a/db-async-common/src/main/java/com/github/jasync/sql/db/ConcreteConnectionBase.kt b/db-async-common/src/main/java/com/github/jasync/sql/db/ConcreteConnectionBase.kt
index 6467eb4a0..c522a71a3 100644
--- a/db-async-common/src/main/java/com/github/jasync/sql/db/ConcreteConnectionBase.kt
+++ b/db-async-common/src/main/java/com/github/jasync/sql/db/ConcreteConnectionBase.kt
@@ -24,10 +24,11 @@ abstract class ConcreteConnectionBase(
val p = CompletableFuture()
f(this).onCompleteAsync(configuration.executionContext) { ty1 ->
sendQuery(if (ty1.isFailure) "ROLLBACK" else "COMMIT").onCompleteAsync(configuration.executionContext) { ty2 ->
- if (ty2.isFailure && ty1.isSuccess)
+ if (ty2.isFailure && ty1.isSuccess) {
p.failed((ty2 as Failure).exception)
- else
+ } else {
p.complete(ty1)
+ }
}
}
p
diff --git a/db-async-common/src/main/java/com/github/jasync/sql/db/Configuration.kt b/db-async-common/src/main/java/com/github/jasync/sql/db/Configuration.kt
index e23661a67..0ebc9e174 100644
--- a/db-async-common/src/main/java/com/github/jasync/sql/db/Configuration.kt
+++ b/db-async-common/src/main/java/com/github/jasync/sql/db/Configuration.kt
@@ -3,12 +3,12 @@ package com.github.jasync.sql.db
import com.github.jasync.sql.db.interceptor.QueryInterceptor
import com.github.jasync.sql.db.util.ExecutorServiceUtils
import com.github.jasync.sql.db.util.NettyUtils
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.PooledByteBufAllocator
import io.netty.channel.EventLoopGroup
import io.netty.channel.nio.NioEventLoopGroup
import io.netty.util.CharsetUtil
-import mu.KotlinLogging
import java.nio.charset.Charset
import java.nio.file.Path
import java.time.Duration
@@ -66,7 +66,7 @@ class Configuration @JvmOverloads constructor(
val currentSchema: String? = null,
val socketPath: String? = null,
val credentialsProvider: CredentialsProvider? = null,
- val rsaPublicKey: Path? = null,
+ val rsaPublicKey: Path? = null
) {
init {
if (socketPath != null && eventLoopGroup is NioEventLoopGroup) {
@@ -99,7 +99,7 @@ class Configuration @JvmOverloads constructor(
currentSchema: String? = null,
socketPath: String? = null,
credentialsProvider: CredentialsProvider? = null,
- rsaPublicKey: Path? = null,
+ rsaPublicKey: Path? = null
): Configuration {
return Configuration(
username = username ?: this.username,
@@ -120,14 +120,14 @@ class Configuration @JvmOverloads constructor(
currentSchema = currentSchema ?: this.currentSchema,
socketPath = socketPath ?: this.socketPath,
credentialsProvider = credentialsProvider ?: this.credentialsProvider,
- rsaPublicKey = rsaPublicKey ?: this.rsaPublicKey,
+ rsaPublicKey = rsaPublicKey ?: this.rsaPublicKey
)
}
@Deprecated(
"backward compatibility for https://github.com/jasync-sql/jasync-sql/issues/359",
ReplaceWith("copy()"),
- DeprecationLevel.ERROR,
+ DeprecationLevel.ERROR
)
fun copy(
username: String? = null,
@@ -146,7 +146,7 @@ class Configuration @JvmOverloads constructor(
eventLoopGroup: EventLoopGroup? = null,
executionContext: Executor? = null,
currentSchema: String? = null,
- socketPath: String? = null,
+ socketPath: String? = null
): Configuration {
return Configuration(
username = username ?: this.username,
@@ -167,7 +167,7 @@ class Configuration @JvmOverloads constructor(
currentSchema = currentSchema ?: this.currentSchema,
socketPath = socketPath ?: this.socketPath,
credentialsProvider = this.credentialsProvider,
- rsaPublicKey = this.rsaPublicKey,
+ rsaPublicKey = this.rsaPublicKey
)
}
diff --git a/db-async-common/src/main/java/com/github/jasync/sql/db/ConnectionPoolConfiguration.kt b/db-async-common/src/main/java/com/github/jasync/sql/db/ConnectionPoolConfiguration.kt
index 5518d107f..1b8f0894a 100644
--- a/db-async-common/src/main/java/com/github/jasync/sql/db/ConnectionPoolConfiguration.kt
+++ b/db-async-common/src/main/java/com/github/jasync/sql/db/ConnectionPoolConfiguration.kt
@@ -79,7 +79,7 @@ class ConnectionPoolConfiguration @JvmOverloads constructor(
val currentSchema: String? = null,
val socketPath: String? = null,
val credentialsProvider: CredentialsProvider? = null,
- val minIdleConnections: Int? = null,
+ val minIdleConnections: Int? = null
) {
init {
require(port > 0) { "port should be positive: $port" }
@@ -130,7 +130,7 @@ class ConnectionPoolConfiguration @JvmOverloads constructor(
testTimeout = connectionTestTimeout,
queryTimeout = queryTimeout,
coroutineDispatcher = coroutineDispatcher,
- minIdleObjects = minIdleConnections,
+ minIdleObjects = minIdleConnections
)
override fun toString() = """ConnectionPoolConfiguration(host=$host, port=REDACTED,
@@ -151,7 +151,8 @@ class ConnectionPoolConfiguration @JvmOverloads constructor(
|interceptors=$interceptors,
|maxConnectionTtl=$maxConnectionTtl
|minIdleConnections=$minIdleConnections)""${'"'}.trimMargin()
-|)""".trimMargin()
+|)
+ """.trimMargin()
@JvmOverloads
fun copy(
@@ -180,7 +181,7 @@ class ConnectionPoolConfiguration @JvmOverloads constructor(
currentSchema: String? = null,
socketPath: String? = null,
credentialsProvider: CredentialsProvider? = null,
- minIdleConnections: Int? = null,
+ minIdleConnections: Int? = null
): ConnectionPoolConfiguration {
return ConnectionPoolConfiguration(
username = username ?: this.username,
@@ -341,6 +342,6 @@ data class ConnectionPoolConfigurationBuilder @JvmOverloads constructor(
currentSchema = currentSchema,
socketPath = socketPath,
credentialsProvider = credentialsProvider,
- minIdleConnections = minIdleConnections,
+ minIdleConnections = minIdleConnections
)
}
diff --git a/db-async-common/src/main/java/com/github/jasync/sql/db/exceptions/InsufficientParametersException.kt b/db-async-common/src/main/java/com/github/jasync/sql/db/exceptions/InsufficientParametersException.kt
index 6465c1e34..5acb93708 100644
--- a/db-async-common/src/main/java/com/github/jasync/sql/db/exceptions/InsufficientParametersException.kt
+++ b/db-async-common/src/main/java/com/github/jasync/sql/db/exceptions/InsufficientParametersException.kt
@@ -10,8 +10,11 @@ package com.github.jasync.sql.db.exceptions
* @param given the collection given
*/
@Suppress("RedundantVisibilityModifier")
-public class InsufficientParametersException(expected: Int, given: List) : DatabaseException(
- "The query contains %s parameters but you gave it %s (%s)".format(
- expected, given.size, given.joinToString(",")
+public class InsufficientParametersException(query: String, expected: Int, given: List) : DatabaseException(
+ "The query contains %s parameters but you gave it %s (%s):${System.lineSeparator()}%s".format(
+ expected,
+ given.size,
+ given.joinToString(","),
+ query
)
)
diff --git a/db-async-common/src/main/java/com/github/jasync/sql/db/interceptor/Interceptors.kt b/db-async-common/src/main/java/com/github/jasync/sql/db/interceptor/Interceptors.kt
index 7e88c7e55..28205080a 100644
--- a/db-async-common/src/main/java/com/github/jasync/sql/db/interceptor/Interceptors.kt
+++ b/db-async-common/src/main/java/com/github/jasync/sql/db/interceptor/Interceptors.kt
@@ -2,7 +2,7 @@ package com.github.jasync.sql.db.interceptor
import com.github.jasync.sql.db.QueryResult
import com.github.jasync.sql.db.util.mapTry
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import org.slf4j.MDC
import java.util.concurrent.CompletableFuture
import java.util.function.Supplier
diff --git a/db-async-common/src/main/java/com/github/jasync/sql/db/pool/ConnectionFactory.kt b/db-async-common/src/main/java/com/github/jasync/sql/db/pool/ConnectionFactory.kt
index ec606b2d0..070b6c85c 100644
--- a/db-async-common/src/main/java/com/github/jasync/sql/db/pool/ConnectionFactory.kt
+++ b/db-async-common/src/main/java/com/github/jasync/sql/db/pool/ConnectionFactory.kt
@@ -8,7 +8,7 @@ import com.github.jasync.sql.db.interceptor.PreparedStatementParams
import com.github.jasync.sql.db.util.FP
import com.github.jasync.sql.db.util.Try
import com.github.jasync.sql.db.util.map
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import java.util.concurrent.CompletableFuture
private val logger = KotlinLogging.logger {}
diff --git a/db-async-common/src/main/java/com/github/jasync/sql/db/pool/ConnectionPool.kt b/db-async-common/src/main/java/com/github/jasync/sql/db/pool/ConnectionPool.kt
index 77d24b44f..0a1c209cf 100644
--- a/db-async-common/src/main/java/com/github/jasync/sql/db/pool/ConnectionPool.kt
+++ b/db-async-common/src/main/java/com/github/jasync/sql/db/pool/ConnectionPool.kt
@@ -9,7 +9,7 @@ import com.github.jasync.sql.db.interceptor.wrapPreparedStatementWithInterceptor
import com.github.jasync.sql.db.interceptor.wrapQueryWithInterceptors
import com.github.jasync.sql.db.util.FP
import com.github.jasync.sql.db.util.mapAsync
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import java.util.concurrent.CompletableFuture
private val logger = KotlinLogging.logger {}
@@ -69,7 +69,6 @@ class ConnectionPool(
values: List,
release: Boolean
): CompletableFuture {
-
return wrapPreparedStatementWithInterceptors(
PreparedStatementParams(query, values, release),
configuration.interceptors
@@ -131,6 +130,8 @@ class ConnectionPool(
fun giveBack(item: T): CompletableFuture> = objectPool.giveBack(item)
+ fun softEvictConnections(): CompletableFuture> = objectPool.softEvict()
+
/**
*
* Closes the pool
diff --git a/db-async-common/src/main/java/com/github/jasync/sql/db/pool/TimeoutScheduler.kt b/db-async-common/src/main/java/com/github/jasync/sql/db/pool/TimeoutScheduler.kt
index 59835d8bd..d4e784ef0 100644
--- a/db-async-common/src/main/java/com/github/jasync/sql/db/pool/TimeoutScheduler.kt
+++ b/db-async-common/src/main/java/com/github/jasync/sql/db/pool/TimeoutScheduler.kt
@@ -3,8 +3,8 @@ package com.github.jasync.sql.db.pool
import com.github.jasync.sql.db.util.nullableMap
import com.github.jasync.sql.db.util.onCompleteAsync
import com.github.jasync.sql.db.util.tryFailure
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.channel.EventLoopGroup
-import mu.KotlinLogging
import java.time.Duration
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Executor
diff --git a/db-async-common/src/main/java/com/github/jasync/sql/db/util/AbstractURIParser.kt b/db-async-common/src/main/java/com/github/jasync/sql/db/util/AbstractURIParser.kt
index df087a82d..e036122c5 100644
--- a/db-async-common/src/main/java/com/github/jasync/sql/db/util/AbstractURIParser.kt
+++ b/db-async-common/src/main/java/com/github/jasync/sql/db/util/AbstractURIParser.kt
@@ -3,7 +3,7 @@ package com.github.jasync.sql.db.util
import com.github.jasync.sql.db.Configuration
import com.github.jasync.sql.db.SSLConfiguration
import com.github.jasync.sql.db.exceptions.UnableToParseURLException
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import java.net.URI
import java.net.URISyntaxException
import java.net.URLDecoder
@@ -140,7 +140,9 @@ abstract class AbstractURIParser {
protected fun unwrapIpv6address(server: String): String {
return if (server.startsWith("<")) {
server.substring(1, server.length - 1)
- } else server
+ } else {
+ server
+ }
}
companion object {
diff --git a/db-async-common/src/main/java/com/github/jasync/sql/db/util/NettyUtils.kt b/db-async-common/src/main/java/com/github/jasync/sql/db/util/NettyUtils.kt
index 15c24bb92..af8662009 100644
--- a/db-async-common/src/main/java/com/github/jasync/sql/db/util/NettyUtils.kt
+++ b/db-async-common/src/main/java/com/github/jasync/sql/db/util/NettyUtils.kt
@@ -2,6 +2,7 @@ package com.github.jasync.sql.db.util
import com.github.jasync.sql.db.Configuration
import com.github.jasync.sql.db.SSLConfiguration
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.channel.Channel
import io.netty.channel.EventLoopGroup
import io.netty.channel.epoll.Epoll
@@ -20,7 +21,6 @@ import io.netty.handler.ssl.SslContextBuilder
import io.netty.handler.ssl.util.InsecureTrustManagerFactory
import io.netty.util.internal.logging.InternalLoggerFactory
import io.netty.util.internal.logging.Slf4JLoggerFactory
-import mu.KotlinLogging
import java.io.FileInputStream
import java.net.InetSocketAddress
import java.net.SocketAddress
diff --git a/db-async-common/src/main/java/com/github/jasync/sql/db/util/PrintUtils.kt b/db-async-common/src/main/java/com/github/jasync/sql/db/util/PrintUtils.kt
index 791659061..e0b86faad 100644
--- a/db-async-common/src/main/java/com/github/jasync/sql/db/util/PrintUtils.kt
+++ b/db-async-common/src/main/java/com/github/jasync/sql/db/util/PrintUtils.kt
@@ -2,8 +2,8 @@
package com.github.jasync.sql.db.util
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
-import mu.KotlinLogging
object PrintUtils {
diff --git a/db-async-common/src/test/java/com/github/jasync/sql/db/ConnectionPoolConfigurationTest.kt b/db-async-common/src/test/java/com/github/jasync/sql/db/ConnectionPoolConfigurationTest.kt
index ad37c2dc2..b67504e3c 100644
--- a/db-async-common/src/test/java/com/github/jasync/sql/db/ConnectionPoolConfigurationTest.kt
+++ b/db-async-common/src/test/java/com/github/jasync/sql/db/ConnectionPoolConfigurationTest.kt
@@ -30,7 +30,7 @@ class ConnectionPoolConfigurationTest {
maximumMessageSize = 17,
applicationName = "applicationName",
maxConnectionTtl = 18,
- minIdleConnections = 5,
+ minIdleConnections = 5
).build()
assertThat(configuration.host).isEqualTo("host")
assertThat(configuration.connectionConfiguration.host).isEqualTo("host")
diff --git a/db-async-common/src/test/java/com/github/jasync/sql/db/util/HexCodecSpec.kt b/db-async-common/src/test/java/com/github/jasync/sql/db/util/HexCodecSpec.kt
index f8368587d..a6800318f 100644
--- a/db-async-common/src/test/java/com/github/jasync/sql/db/util/HexCodecSpec.kt
+++ b/db-async-common/src/test/java/com/github/jasync/sql/db/util/HexCodecSpec.kt
@@ -52,7 +52,6 @@ class HexCodecSpec {
@Test
fun `correctly generate a byte array from the PG output`() {
-
val input = "\\x53617920"
val bytes = byteArrayOf(83, 97, 121, 32)
assertEquals(HexCodec.decode(input, 2).toList(), bytes.toList())
diff --git a/db-async-common/src/test/java/com/github/jasync/sql/db/util/VersionSpec.kt b/db-async-common/src/test/java/com/github/jasync/sql/db/util/VersionSpec.kt
index 6fd151312..68db4625c 100644
--- a/db-async-common/src/test/java/com/github/jasync/sql/db/util/VersionSpec.kt
+++ b/db-async-common/src/test/java/com/github/jasync/sql/db/util/VersionSpec.kt
@@ -23,7 +23,6 @@ class VersionSpec {
@Test
fun `correctly compare between major different versions 1`() {
-
val version1 = parseVersion("8.2.0")
val version2 = parseVersion("9.2.0")
@@ -32,7 +31,6 @@ class VersionSpec {
@Test
fun `correctly compare between major different versions 2`() {
-
val version1 = parseVersion("8.2.0")
val version2 = parseVersion("8.2.0")
@@ -41,7 +39,6 @@ class VersionSpec {
@Test
fun `correctly compare between major different versions 3`() {
-
val version1 = parseVersion("8.2.8")
val version2 = parseVersion("8.2.87")
@@ -50,7 +47,6 @@ class VersionSpec {
@Test
fun `correctly compare two different versions`() {
-
val version1 = parseVersion("9.1.2")
val version2 = parseVersion("9.2.0")
diff --git a/gradle.properties b/gradle.properties
index a04036877..165b663d2 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,21 +1,22 @@
-KOTLIN_VERSION=1.6.21
-KTLINT_VERSION=11.0.0
+KOTLIN_VERSION=1.8.21
+KTLINT_VERSION=11.3.1
JACOCO_VERSION=0.8.8
-KOTLIN_COROUTINES_VERSION=1.6.1
-SL4J_VERSION=1.7.25
-JODA_VERSION=2.11.2
-JODA_CONVERT_VERSION=2.2.2
-NETTY_VERSION=4.1.86.Final
-KOTLIN_LOGGING_VERSION=2.1.21
+KOTLIN_COROUTINES_VERSION=1.7.1
+SL4J_VERSION=2.0.7
+JODA_VERSION=2.12.5
+JODA_CONVERT_VERSION=2.2.3
+NETTY_VERSION=4.1.93.Final
+KOTLIN_LOGGING_VERSION=5.0.0
SCRAM_CLIENT_VERSION=2.1
R2DBC_SPI_VERSION=1.0.0.RELEASE
-REACTOR_CORE_VERSION=3.4.23
+REACTOR_CORE_VERSION=3.5.7
+REACTOR_KOTLIN_EXTENSION=1.2.2
JUNIT_VERSION=4.13.2
ASSERTJ_VERSION=3.23.1
MOCKK_VERSION=1.9
-LOGBACK_VERSION=1.1.8
+LOGBACK_VERSION=1.3.8
TEST_CONTAINERS_VERSION=1.17.6
MYSQL_CONNECTOR_VERSION=5.1.47
AWAITILITY_VERSION=3.1.5
-THREETEN_EXTRA=1.6.0
+THREETEN_EXTRA=1.7.2
JTS_VERSION=1.19.0
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index f11982043..d4aebfed0 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
diff --git a/mysql-async/build.gradle.kts b/mysql-async/build.gradle.kts
index 6b18449f0..0c1924828 100644
--- a/mysql-async/build.gradle.kts
+++ b/mysql-async/build.gradle.kts
@@ -13,15 +13,15 @@ val MYSQL_CONNECTOR_VERSION: String by project
val AWAITILITY_VERSION: String by project
dependencies {
- compile(project(":pool-async"))
- compile(project(":db-async-common"))
- compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION")
- compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINES_VERSION")
- compile("org.slf4j:slf4j-api:$SL4J_VERSION")
- compile("io.netty:netty-transport:$NETTY_VERSION")
- compile("io.netty:netty-handler:$NETTY_VERSION")
+ api(project(":pool-async"))
+ api(project(":db-async-common"))
+ api("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION")
+ api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINES_VERSION")
+ api("org.slf4j:slf4j-api:$SL4J_VERSION")
+ api("io.netty:netty-transport:$NETTY_VERSION")
+ api("io.netty:netty-handler:$NETTY_VERSION")
testImplementation("io.netty:netty-transport-native-epoll:$NETTY_VERSION:linux-x86_64")
- compile("io.github.microutils:kotlin-logging:$KOTLIN_LOGGING_VERSION")
+ api("io.github.oshai:kotlin-logging-jvm:$KOTLIN_LOGGING_VERSION")
testImplementation("junit:junit:$JUNIT_VERSION")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION")
testImplementation("org.assertj:assertj-core:$ASSERTJ_VERSION")
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/MySQLConnection.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/MySQLConnection.kt
index 34f633ef8..2591acf12 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/MySQLConnection.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/MySQLConnection.kt
@@ -43,9 +43,9 @@ import com.github.jasync.sql.db.util.onFailureAsync
import com.github.jasync.sql.db.util.parseVersion
import com.github.jasync.sql.db.util.success
import com.github.jasync.sql.db.util.toCompletableFuture
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.ssl.SslHandler
-import mu.KotlinLogging
import java.time.Duration
import java.util.Optional
import java.util.concurrent.CancellationException
@@ -315,7 +315,7 @@ class MySQLConnection @JvmOverloads constructor(
password = configuration.password,
appName = configuration.applicationName,
sslConfiguration = configuration.ssl,
- rsaPublicKey = configuration.rsaPublicKey,
+ rsaPublicKey = configuration.rsaPublicKey
)
if (!switchToSsl) {
@@ -394,8 +394,11 @@ class MySQLConnection @JvmOverloads constructor(
sendQuery(query)
}.mapTry { queryResult, throwable ->
// Cancellation exception will be ignored so that the following transaction clean up can be executed
- if (throwable is CancellationException) QueryResult(rowsAffected = 0L, statusMessage = null)
- else queryResult
+ if (throwable is CancellationException) {
+ QueryResult(rowsAffected = 0L, statusMessage = null)
+ } else {
+ queryResult
+ }
}
}
@@ -465,7 +468,7 @@ class MySQLConnection @JvmOverloads constructor(
this.validateIsReadyForQuery()
val totalParameters = params.query.count { it == '?' }
if (params.values.length != totalParameters) {
- throw InsufficientParametersException(totalParameters, params.values)
+ throw InsufficientParametersException(params.query, totalParameters, params.values)
}
val promise = CompletableFuture()
this.setQueryPromise(promise)
@@ -503,8 +506,9 @@ class MySQLConnection @JvmOverloads constructor(
private fun queryPromise(): Optional> = queryPromiseReference.get()
private fun setQueryPromise(promise: CompletableFuture) {
- if (!this.queryPromiseReference.compareAndSet(Optional.empty(), Optional.of(promise)))
+ if (!this.queryPromiseReference.compareAndSet(Optional.empty(), Optional.of(promise))) {
throw ConnectionStillRunningQueryException(this.id, true)
+ }
}
private fun clearQueryPromise(): Optional> {
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/BinaryRowDecoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/BinaryRowDecoder.kt
index 7fd4f6d41..63464318d 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/BinaryRowDecoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/BinaryRowDecoder.kt
@@ -4,15 +4,14 @@ import com.github.jasync.sql.db.exceptions.BufferNotFullyConsumedException
import com.github.jasync.sql.db.mysql.message.server.ColumnDefinitionMessage
import com.github.jasync.sql.db.util.BufferDumper
import com.github.jasync.sql.db.util.PrintUtils
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
-import mu.KotlinLogging
private val logger = KotlinLogging.logger {}
class BinaryRowDecoder {
fun decode(buffer: ByteBuf, columns: List): Array {
-
logger.trace { "columns are ${buffer.readableBytes()} - $columns" }
logger.trace { "decoding row\n${BufferDumper.dumpAsHex(buffer)}" }
PrintUtils.printArray("bitmap", buffer)
@@ -31,7 +30,6 @@ class BinaryRowDecoder {
val result = if ((nullBitMask[nullMaskPos].toInt() and bit) != 0) {
null
} else {
-
val column = columns[it]
logger.trace { "${buffer.readableBytes()}" }
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/BinaryRowEncoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/BinaryRowEncoder.kt
index 7a661a138..aeb478891 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/BinaryRowEncoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/BinaryRowEncoder.kt
@@ -71,7 +71,6 @@ class BinaryRowEncoder(charset: Charset) {
)
fun encoderFor(v: Any): BinaryEncoder {
-
return this.encoders.getOrElse(v::class.java) {
return when (v) {
is CharSequence -> this.stringEncoder
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/decoder/TimeDecoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/decoder/TimeDecoder.kt
index 1619a7edd..57996a844 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/decoder/TimeDecoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/decoder/TimeDecoder.kt
@@ -12,12 +12,10 @@ import java.time.Duration
object TimeDecoder : BinaryDecoder {
override fun decode(buffer: ByteBuf): Duration {
-
val unsignedByte = buffer.readUnsignedByte()
return when (unsignedByte) {
0.toShort() -> 0.seconds
8.toShort() -> {
-
val isNegative = buffer.readUnsignedByte() == 1.toShort()
val duration = buffer.readUnsignedInt().days +
@@ -32,7 +30,6 @@ object TimeDecoder : BinaryDecoder {
}
}
12.toShort() -> {
-
val isNegative = buffer.readUnsignedByte() == 1.toShort()
val duration = buffer.readUnsignedInt().days +
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/decoder/TimestampDecoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/decoder/TimestampDecoder.kt
index db6704703..50be9f593 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/decoder/TimestampDecoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/binary/decoder/TimestampDecoder.kt
@@ -1,7 +1,7 @@
package com.github.jasync.sql.db.mysql.binary.decoder
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
-import mu.KotlinLogging
import java.time.LocalDateTime
private val logger = KotlinLogging.logger {}
@@ -16,7 +16,10 @@ object TimestampDecoder : BinaryDecoder {
buffer.readUnsignedShort(),
buffer.readUnsignedByte().toInt(),
buffer.readUnsignedByte().toInt(),
- 0, 0, 0, 0
+ 0,
+ 0,
+ 0,
+ 0
)
7.toShort() -> LocalDateTime.of(
buffer.readUnsignedShort(),
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/DecoderRegistry.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/DecoderRegistry.kt
index e7aae1a9e..720935cd9 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/DecoderRegistry.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/DecoderRegistry.kt
@@ -38,7 +38,6 @@ class DecoderRegistry(charset: Charset) {
private val stringDecoder = StringDecoder(charset)
fun binaryDecoderFor(columnType: Int, charsetCode: Int): BinaryDecoder {
-
return when (columnType) {
ColumnTypes.FIELD_TYPE_VARCHAR,
ColumnTypes.FIELD_TYPE_JSON,
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLConnectionHandler.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLConnectionHandler.kt
index d8ded74d9..f6b3c54c0 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLConnectionHandler.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLConnectionHandler.kt
@@ -38,6 +38,7 @@ import com.github.jasync.sql.db.util.length
import com.github.jasync.sql.db.util.onFailure
import com.github.jasync.sql.db.util.tail
import com.github.jasync.sql.db.util.toCompletableFuture
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.bootstrap.Bootstrap
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
@@ -49,7 +50,6 @@ import io.netty.channel.ChannelOption
import io.netty.channel.EventLoopGroup
import io.netty.channel.SimpleChannelInboundHandler
import io.netty.handler.codec.CodecException
-import mu.KotlinLogging
import java.nio.ByteBuffer
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Executor
@@ -215,6 +215,12 @@ class MySQLConnectionHandler(
}
@Suppress("OverridingDeprecatedMember")
+ // /**
+ // * Calls {@link ChannelHandlerContext#fireExceptionCaught(Throwable)} to forward
+ // * to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
+ // *
+ // * Sub-classes may override this method to change behavior.
+ // */
override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) {
// unwrap CodecException if needed
when (cause) {
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLFrameDecoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLFrameDecoder.kt
index 1c92570fe..9e0cc2f09 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLFrameDecoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLFrameDecoder.kt
@@ -25,10 +25,10 @@ import com.github.jasync.sql.db.mysql.message.server.ServerMessage
import com.github.jasync.sql.db.util.BufferDumper
import com.github.jasync.sql.db.util.ByteBufferUtils.read3BytesInt
import com.github.jasync.sql.db.util.readBinaryLength
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.ByteToMessageDecoder
-import mu.KotlinLogging
import java.nio.charset.Charset
import java.util.concurrent.atomic.AtomicInteger
@@ -65,7 +65,6 @@ class MySQLFrameDecoder(val charset: Charset, private val connectionId: String)
override fun decode(ctx: ChannelHandlerContext, buffer: ByteBuf, out: MutableList) {
if (buffer.readableBytes() > 4) {
-
buffer.markReaderIndex()
val size = read3BytesInt(buffer)
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLOneToOneEncoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLOneToOneEncoder.kt
index bff1fc7c7..0deb61c5b 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLOneToOneEncoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/MySQLOneToOneEncoder.kt
@@ -14,10 +14,10 @@ import com.github.jasync.sql.db.mysql.message.client.ClientMessage
import com.github.jasync.sql.db.mysql.util.CharsetMapper
import com.github.jasync.sql.db.util.BufferDumper
import com.github.jasync.sql.db.util.ByteBufferUtils
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.MessageToMessageEncoder
-import mu.KotlinLogging
import java.nio.charset.Charset
class MySQLOneToOneEncoder(charset: Charset, charsetMapper: CharsetMapper) :
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/SendLongDataEncoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/SendLongDataEncoder.kt
index 8f043ec71..ac18ced6c 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/SendLongDataEncoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/codec/SendLongDataEncoder.kt
@@ -3,10 +3,10 @@ package com.github.jasync.sql.db.mysql.codec
import com.github.jasync.sql.db.mysql.message.client.ClientMessage
import com.github.jasync.sql.db.mysql.message.client.SendLongDataMessage
import com.github.jasync.sql.db.util.ByteBufferUtils
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.Unpooled
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.MessageToMessageEncoder
-import mu.KotlinLogging
private val logger = KotlinLogging.logger {}
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/column/TimeDecoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/column/TimeDecoder.kt
index a09812d84..0fc62ec49 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/column/TimeDecoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/column/TimeDecoder.kt
@@ -11,7 +11,6 @@ import java.time.Duration
object TimeDecoder : ColumnDecoder {
override fun decode(value: String): Duration {
-
val pieces = value.split(':')
val secondsAndMillis = pieces[2].split('.')
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/AuthMoreDataDecoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/AuthMoreDataDecoder.kt
index 32c069e7f..5a7911264 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/AuthMoreDataDecoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/AuthMoreDataDecoder.kt
@@ -7,7 +7,7 @@ import io.netty.buffer.ByteBuf
class AuthMoreDataDecoder : MessageDecoder {
override fun decode(buffer: ByteBuf): ServerMessage {
return AuthMoreDataMessage(
- data = buffer.readByte(),
+ data = buffer.readByte()
)
}
}
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/AuthenticationSwitchRequestDecoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/AuthenticationSwitchRequestDecoder.kt
index 97c0840e7..3f8561fd2 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/AuthenticationSwitchRequestDecoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/AuthenticationSwitchRequestDecoder.kt
@@ -12,11 +12,15 @@ class AuthenticationSwitchRequestDecoder(val charset: Charset) : MessageDecoder
val method = buffer.readCString(charset)
val bytes: Int = buffer.readableBytes()
val terminal = 0.toByte()
- val seed = if (bytes > 0 && buffer.getByte(buffer.writerIndex() - 1) == terminal) ByteBufUtil.getBytes(
- buffer,
- buffer.readerIndex(),
- bytes - 1
- ) else ByteBufUtil.getBytes(buffer)
+ val seed = if (bytes > 0 && buffer.getByte(buffer.writerIndex() - 1) == terminal) {
+ ByteBufUtil.getBytes(
+ buffer,
+ buffer.readerIndex(),
+ bytes - 1
+ )
+ } else {
+ ByteBufUtil.getBytes(buffer)
+ }
buffer.skipBytes(bytes)
return AuthenticationSwitchRequest(method, seed)
}
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/ColumnDefinitionDecoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/ColumnDefinitionDecoder.kt
index e53fba2df..0d6605d51 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/ColumnDefinitionDecoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/ColumnDefinitionDecoder.kt
@@ -10,7 +10,6 @@ import java.nio.charset.Charset
class ColumnDefinitionDecoder(val charset: Charset, val registry: DecoderRegistry) : MessageDecoder {
override fun decode(buffer: ByteBuf): ColumnDefinitionMessage {
-
val catalog = buffer.readLengthEncodedString(charset)
val schema = buffer.readLengthEncodedString(charset)
val table = buffer.readLengthEncodedString(charset)
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/ErrorDecoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/ErrorDecoder.kt
index a7670fe77..ed549622c 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/ErrorDecoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/ErrorDecoder.kt
@@ -10,7 +10,6 @@ import java.nio.charset.Charset
class ErrorDecoder(val charset: Charset) : MessageDecoder {
override fun decode(buffer: ByteBuf): ServerMessage {
-
return ErrorMessage(
buffer.readShort().toInt(),
buffer.readFixedString(6, charset),
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/HandshakeV10Decoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/HandshakeV10Decoder.kt
index 73a2fa77d..b8d57b09a 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/HandshakeV10Decoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/HandshakeV10Decoder.kt
@@ -7,9 +7,9 @@ import com.github.jasync.sql.db.mysql.util.CapabilityFlag.CLIENT_PLUGIN_AUTH
import com.github.jasync.sql.db.mysql.util.CapabilityFlag.CLIENT_SECURE_CONNECTION
import com.github.jasync.sql.db.util.readCString
import com.github.jasync.sql.db.util.readUntilEOF
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
import io.netty.util.CharsetUtil
-import mu.KotlinLogging
import kotlin.experimental.and
private val logger = KotlinLogging.logger {}
@@ -24,7 +24,6 @@ class HandshakeV10Decoder : MessageDecoder {
}
override fun decode(buffer: ByteBuf): ServerMessage {
-
val serverVersion = buffer.readCString(ASCII)
val connectionId = buffer.readUnsignedInt()
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/OkDecoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/OkDecoder.kt
index f8112ee4c..c30655cfa 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/OkDecoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/OkDecoder.kt
@@ -10,7 +10,6 @@ import java.nio.charset.Charset
class OkDecoder(val charset: Charset) : MessageDecoder {
override fun decode(buffer: ByteBuf): ServerMessage {
-
return OkMessage(
affectedRows = buffer.readBinaryLength(),
lastInsertId = buffer.readBinaryLength(),
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/PreparedStatementPrepareResponseDecoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/PreparedStatementPrepareResponseDecoder.kt
index d0cf037e3..40d9a6381 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/PreparedStatementPrepareResponseDecoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/decoder/PreparedStatementPrepareResponseDecoder.kt
@@ -3,15 +3,14 @@ package com.github.jasync.sql.db.mysql.decoder
import com.github.jasync.sql.db.mysql.message.server.PreparedStatementPrepareResponse
import com.github.jasync.sql.db.mysql.message.server.ServerMessage
import com.github.jasync.sql.db.util.BufferDumper.dumpAsHex
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
-import mu.KotlinLogging
private val logger = KotlinLogging.logger {}
class PreparedStatementPrepareResponseDecoder : MessageDecoder {
override fun decode(buffer: ByteBuf): ServerMessage {
-
logger.trace { "prepared statement response dump is \n${dumpAsHex(buffer)}" }
val statementId = ByteArray(4) { buffer.readByte() }
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/AuthenticationSwitchResponseEncoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/AuthenticationSwitchResponseEncoder.kt
index f470d99b8..ffdcda4fb 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/AuthenticationSwitchResponseEncoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/AuthenticationSwitchResponseEncoder.kt
@@ -25,7 +25,7 @@ class AuthenticationSwitchResponseEncoder(val charset: Charset) : MessageEncoder
switch.password,
switch.request.seed,
switch.sslConfiguration,
- switch.rsaPublicKey,
+ switch.rsaPublicKey
)
buffer.writeBytes(bytes)
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/HandshakeResponseEncoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/HandshakeResponseEncoder.kt
index 6054ef52d..e7646d1cf 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/HandshakeResponseEncoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/HandshakeResponseEncoder.kt
@@ -47,7 +47,7 @@ class HandshakeResponseEncoder(private val charset: Charset, private val headerE
if (m.appName != null) {
// CONNECTION_ATTRS
val byteWidthEvaluator = {
- value: Int ->
+ value: Int ->
when {
value < 251 -> 1
value < (1 shl 16) -> 3
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/PreparedStatementExecuteEncoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/PreparedStatementExecuteEncoder.kt
index 8859bfe78..e3bef1d81 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/PreparedStatementExecuteEncoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/PreparedStatementExecuteEncoder.kt
@@ -61,7 +61,8 @@ class PreparedStatementExecuteEncoder(private val rowEncoder: BinaryRowEncoder)
fun encodeValue(parameterTypesBuffer: ByteBuf, parameterValuesBuffer: ByteBuf, value: Any, includeValue: Boolean) {
val encoder = rowEncoder.encoderFor(value)
parameterTypesBuffer.writeShort(encoder.encodesTo())
- if (includeValue)
+ if (includeValue) {
encoder.encode(value, parameterValuesBuffer)
+ }
}
}
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/QueryMessageEncoder.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/QueryMessageEncoder.kt
index ee84a8b77..672f32060 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/QueryMessageEncoder.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/QueryMessageEncoder.kt
@@ -9,7 +9,6 @@ import java.nio.charset.Charset
class QueryMessageEncoder(val charset: Charset) : MessageEncoder {
override fun encode(message: ClientMessage): ByteBuf {
-
val m = message as QueryMessage
val encodedQuery = m.query.toByteArray(charset)
val buffer = ByteBufferUtils.packetBuffer(4 + 1 + encodedQuery.size)
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/AuthenticationMethod.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/AuthenticationMethod.kt
index 3ba84cfab..c7b9e0db9 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/AuthenticationMethod.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/AuthenticationMethod.kt
@@ -11,7 +11,7 @@ interface AuthenticationMethod {
password: String?,
seed: ByteArray,
sslConfiguration: SSLConfiguration,
- rsaPublicKey: Path?,
+ rsaPublicKey: Path?
): ByteArray
companion object {
@@ -24,7 +24,7 @@ interface AuthenticationMethod {
CachingSha2 to CachingSha2PasswordAuthentication,
Native to MySQLNativePasswordAuthentication,
Old to OldPasswordAuthentication,
- Sha256 to Sha256PasswordAuthentication,
+ Sha256 to Sha256PasswordAuthentication
)
}
}
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/AuthenticationScrambler.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/AuthenticationScrambler.kt
index a43132ca4..33675104b 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/AuthenticationScrambler.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/AuthenticationScrambler.kt
@@ -11,7 +11,7 @@ object AuthenticationScrambler {
password: String,
charset: Charset,
seed: ByteArray,
- seedFirst: Boolean,
+ seedFirst: Boolean
): ByteArray {
val messageDigest = MessageDigest.getInstance(algorithm)
val initialDigest = messageDigest.digest(password.toByteArray(charset))
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/CachingSha2PasswordAuthentication.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/CachingSha2PasswordAuthentication.kt
index dcacae2c1..d47d71062 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/CachingSha2PasswordAuthentication.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/CachingSha2PasswordAuthentication.kt
@@ -13,7 +13,7 @@ object CachingSha2PasswordAuthentication : AuthenticationMethod {
password: String?,
seed: ByteArray,
sslConfiguration: SSLConfiguration,
- rsaPublicKey: Path?,
+ rsaPublicKey: Path?
): ByteArray {
return if (password != null) {
AuthenticationScrambler.scramble411("SHA-256", password, charset, seed, false)
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/MySQLNativePasswordAuthentication.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/MySQLNativePasswordAuthentication.kt
index 6101c6b8b..7efa9c59b 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/MySQLNativePasswordAuthentication.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/MySQLNativePasswordAuthentication.kt
@@ -13,7 +13,7 @@ object MySQLNativePasswordAuthentication : AuthenticationMethod {
password: String?,
seed: ByteArray,
sslConfiguration: SSLConfiguration,
- rsaPublicKey: Path?,
+ rsaPublicKey: Path?
): ByteArray {
return if (password != null) {
AuthenticationScrambler.scramble411("SHA-1", password, charset, seed, true)
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/OldPasswordAuthentication.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/OldPasswordAuthentication.kt
index 199c7e98d..638865e9f 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/OldPasswordAuthentication.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/OldPasswordAuthentication.kt
@@ -16,7 +16,7 @@ object OldPasswordAuthentication : AuthenticationMethod {
password: String?,
seed: ByteArray,
sslConfiguration: SSLConfiguration,
- rsaPublicKey: Path?,
+ rsaPublicKey: Path?
): ByteArray {
return when {
!password.isNullOrEmpty() -> {
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/Sha256PasswordAuthentication.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/Sha256PasswordAuthentication.kt
index a9c618ca6..efd6d55a1 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/Sha256PasswordAuthentication.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/encoder/auth/Sha256PasswordAuthentication.kt
@@ -2,7 +2,7 @@ package com.github.jasync.sql.db.mysql.encoder.auth
import com.github.jasync.sql.db.SSLConfiguration
import com.github.jasync.sql.db.util.length
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import java.nio.charset.Charset
import java.nio.file.Files
import java.nio.file.Path
@@ -25,7 +25,7 @@ object Sha256PasswordAuthentication : AuthenticationMethod {
password: String?,
seed: ByteArray,
sslConfiguration: SSLConfiguration,
- rsaPublicKey: Path?,
+ rsaPublicKey: Path?
): ByteArray {
if (password == null) {
return EmptyArray
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/client/AuthenticationSwitchResponse.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/client/AuthenticationSwitchResponse.kt
index ffd6d222c..0ff1ab5c8 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/client/AuthenticationSwitchResponse.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/client/AuthenticationSwitchResponse.kt
@@ -8,5 +8,5 @@ data class AuthenticationSwitchResponse(
val password: String?,
val sslConfiguration: SSLConfiguration,
val rsaPublicKey: Path?,
- val request: AuthenticationSwitchRequest,
+ val request: AuthenticationSwitchRequest
) : ClientMessage(AuthSwitchResponse)
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/client/HandshakeResponseMessage.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/client/HandshakeResponseMessage.kt
index 291f23262..76badacab 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/client/HandshakeResponseMessage.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/client/HandshakeResponseMessage.kt
@@ -15,5 +15,5 @@ data class HandshakeResponseMessage(
val database: String? = null,
val appName: String? = null,
val sslConfiguration: SSLConfiguration,
- val rsaPublicKey: Path? = null,
+ val rsaPublicKey: Path? = null
) : ClientMessage(ClientProtocolVersion)
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/server/AuthMoreDataMessage.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/server/AuthMoreDataMessage.kt
index dfeaa4de7..b40ffb1a8 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/server/AuthMoreDataMessage.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/server/AuthMoreDataMessage.kt
@@ -1,7 +1,7 @@
package com.github.jasync.sql.db.mysql.message.server
data class AuthMoreDataMessage(
- val data: Byte,
+ val data: Byte
) : ServerMessage(AuthMoreData) {
fun isSuccess(): Boolean {
return data == 3.toByte()
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/server/AuthenticationSwitchRequest.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/server/AuthenticationSwitchRequest.kt
index 33dfe8371..1ce19004f 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/server/AuthenticationSwitchRequest.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/message/server/AuthenticationSwitchRequest.kt
@@ -2,5 +2,5 @@ package com.github.jasync.sql.db.mysql.message.server
data class AuthenticationSwitchRequest(
val method: String,
- val seed: ByteArray,
+ val seed: ByteArray
) : ServerMessage(ServerMessage.EOF)
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/pool/MySQLConnectionFactory.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/pool/MySQLConnectionFactory.kt
index 00fd3f798..851a1df59 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/pool/MySQLConnectionFactory.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/pool/MySQLConnectionFactory.kt
@@ -3,7 +3,7 @@ package com.github.jasync.sql.db.mysql.pool
import com.github.jasync.sql.db.Configuration
import com.github.jasync.sql.db.mysql.MySQLConnection
import com.github.jasync.sql.db.pool.ConnectionFactory
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import java.util.concurrent.CompletableFuture
private val logger = KotlinLogging.logger {}
diff --git a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/util/CapabilityFlag.kt b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/util/CapabilityFlag.kt
index 61a9e669c..2c66d44b7 100644
--- a/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/util/CapabilityFlag.kt
+++ b/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/util/CapabilityFlag.kt
@@ -11,5 +11,5 @@ enum class CapabilityFlag(val value: Int) {
CLIENT_PLUGIN_AUTH(0x00080000),
CLIENT_SECURE_CONNECTION(0x00008000),
CLIENT_CONNECT_ATTRS(0x00100000),
- CLIENT_SSL(0x00000800),
+ CLIENT_SSL(0x00000800)
}
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/AuthenticationSpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/AuthenticationSpec.kt
index 4e57f8cb1..cef8aaa66 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/AuthenticationSpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/AuthenticationSpec.kt
@@ -158,14 +158,14 @@ class AuthenticationSpec {
password: String,
sslConfiguration: SSLConfiguration = SSLConfiguration(Mode.Disable),
rsaPublicKey: Path? = null,
- fn: (MySQLConnection) -> T,
+ fn: (MySQLConnection) -> T
): T {
val configuration = Configuration(
username = username,
password = password,
port = container.firstMappedPort,
ssl = sslConfiguration,
- rsaPublicKey = rsaPublicKey,
+ rsaPublicKey = rsaPublicKey
)
val connection = MySQLConnection(configuration)
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/BinaryColumnsSpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/BinaryColumnsSpec.kt
index e70c98f40..88818c8ef 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/BinaryColumnsSpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/BinaryColumnsSpec.kt
@@ -14,7 +14,6 @@ class BinaryColumnsSpec : ConnectionHelper() {
@Test
fun `correctly load fields as byte arrays`() {
-
val create = """CREATE TEMPORARY TABLE t (
id BIGINT NOT NULL AUTO_INCREMENT,
uuid BINARY(36) NOT NULL,
@@ -51,7 +50,6 @@ class BinaryColumnsSpec : ConnectionHelper() {
@Test
fun `support BINARY type`() {
-
val create =
"""CREATE TEMPORARY TABLE POSTS (
id INT NOT NULL AUTO_INCREMENT,
@@ -76,7 +74,6 @@ class BinaryColumnsSpec : ConnectionHelper() {
@Test
fun `support VARBINARY type`() {
-
val create = """CREATE TEMPORARY TABLE POSTS (
id INT NOT NULL AUTO_INCREMENT,
varbinary_column VARBINARY(20),
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/BitSpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/BitSpec.kt
index 0b704a5ed..dc1c440ee 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/BitSpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/BitSpec.kt
@@ -8,7 +8,6 @@ class BitSpec : ConnectionHelper() {
@Test
fun `result in binary data`() {
-
withConnection { connection ->
val create = """CREATE TEMPORARY TABLE binary_test
(
@@ -36,7 +35,6 @@ class BitSpec : ConnectionHelper() {
@Test
fun `result in binary data in BIT(2) column`() {
-
withConnection { connection ->
val create = """CREATE TEMPORARY TABLE binary_test
(
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ConcurrentlyRunTest.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ConcurrentlyRunTest.kt
index 9dffdd847..432e6d2a3 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ConcurrentlyRunTest.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ConcurrentlyRunTest.kt
@@ -1,7 +1,7 @@
package com.github.jasync.sql.db.mysql
import com.github.jasync.sql.db.RowData
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import java.util.concurrent.atomic.AtomicInteger
private val logger = KotlinLogging.logger {}
@@ -13,7 +13,6 @@ object ConcurrentlyRunTest : ConnectionHelper(), Runnable {
@JvmStatic
fun main(args: Array) {
-
logger.info("Starting executing code")
val threads = 1.until(10).map { Thread(this) }
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ConnectionHelper.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ConnectionHelper.kt
index 0e382fafb..8228bc94f 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ConnectionHelper.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ConnectionHelper.kt
@@ -98,7 +98,6 @@ open class ConnectionHelper : ContainerHelper() {
}
fun withConfigurablePool(configuration: Configuration, f: (ConnectionPool) -> T): T {
-
val poolConfiguration = ConnectionPoolConfiguration(
host = configuration.host,
port = configuration.port,
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ExecuteManyQueriesSpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ExecuteManyQueriesSpec.kt
index 933766977..63f4bf5a5 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ExecuteManyQueriesSpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ExecuteManyQueriesSpec.kt
@@ -8,7 +8,6 @@ class ExecuteManyQueriesSpec : ConnectionHelper() {
@Test
fun `execute many queries one after the other`() {
-
withConnection { connection ->
(1..500).forEach { _ ->
val rows = assertNotNull(executeQuery(connection, "SELECT 6578, 'this is some text'").rows)
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/MySQLConnectionSpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/MySQLConnectionSpec.kt
index cec6f4684..7e25e94f5 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/MySQLConnectionSpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/MySQLConnectionSpec.kt
@@ -16,7 +16,6 @@ class MySQLConnectionSpec : ConnectionHelper() {
@Test
fun `connect should return with timeout exception after create timeout`() {
-
class MySQLSlowConnectionDelegate(
private val delegate: MySQLHandlerDelegate,
private val onOkSlowdownInMillis: Int
@@ -82,7 +81,6 @@ class MySQLConnectionSpec : ConnectionHelper() {
@Test
fun `connect to a MySQL instance without a database`() {
-
val configurationWithoutDatabase = Configuration(
"mysql_async_nopw",
"localhost",
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/PreparedStatementsSpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/PreparedStatementsSpec.kt
index 7f0dde158..70b5169ec 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/PreparedStatementsSpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/PreparedStatementsSpec.kt
@@ -21,7 +21,6 @@ class PreparedStatementsSpec : ConnectionHelper() {
@Test
fun `be able to execute prepared statements`() {
-
withConnection { connection ->
val result = assertNotNull(executePreparedStatement(connection, "select 1 as id , 'joe' as name").rows)
assertEquals(1, result.size)
@@ -37,7 +36,6 @@ class PreparedStatementsSpec : ConnectionHelper() {
@Test
fun `be able to detect a null value()a prepared statement`() {
-
withConnection { connection ->
val result = assertNotNull(
executePreparedStatement(
@@ -54,7 +52,6 @@ class PreparedStatementsSpec : ConnectionHelper() {
@Test
fun `be able to select numbers and process them`() {
-
withConnection { connection ->
executeQuery(connection, createTableNumericColumns)
executeQuery(connection, insertTableNumericColumns)
@@ -74,7 +71,6 @@ class PreparedStatementsSpec : ConnectionHelper() {
@Test
fun `be able to select from a table with timestamps`() {
-
withConnection { connection ->
executeQuery(connection, createTableTimeColumns)
executeQuery(connection, insertTableTimeColumns)
@@ -116,7 +112,6 @@ class PreparedStatementsSpec : ConnectionHelper() {
@Test
fun `it should be able to bind statement values to the prepared statement`() {
-
withConnection { connection ->
val insert =
"""
@@ -181,7 +176,6 @@ class PreparedStatementsSpec : ConnectionHelper() {
@Test
fun `bind parameters on a prepared statement`() {
-
val create = """CREATE TEMPORARY TABLE posts (
id INT NOT NULL AUTO_INCREMENT,
some_text TEXT not null,
@@ -207,7 +201,6 @@ class PreparedStatementsSpec : ConnectionHelper() {
@Test
fun `bind timestamp parameters to a table`() {
-
val insert =
"""
insert into posts (created_at_date, created_at_datetime, created_at_timestamp, created_at_time, created_at_year)
@@ -244,7 +237,6 @@ class PreparedStatementsSpec : ConnectionHelper() {
@Test
fun `read a timestamp with microseconds`() {
-
val create =
"""CREATE TEMPORARY TABLE posts (
id INT NOT NULL AUTO_INCREMENT,
@@ -284,7 +276,6 @@ class PreparedStatementsSpec : ConnectionHelper() {
@Test
fun `support prepared statement with a big string`() {
-
val bigString: String
val builder = StringBuilder()
(0..400).map { builder.append("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789") }
@@ -363,7 +354,6 @@ class PreparedStatementsSpec : ConnectionHelper() {
@Test
fun `bind parameters on a prepared statement with limit`() {
-
val create = """CREATE TEMPORARY TABLE posts (
id INT NOT NULL AUTO_INCREMENT,
some_text TEXT not null,
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/QuerySpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/QuerySpec.kt
index 569e7f563..34c40f476 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/QuerySpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/QuerySpec.kt
@@ -53,7 +53,6 @@ class QuerySpec : ConnectionHelper() {
@Test
fun `connection should be able to select from a table`() {
-
withConnection { connection ->
assertThat(executeQuery(connection, this.createTable).rowsAffected).isEqualTo(0)
assertThat(executeQuery(connection, this.insert).rowsAffected).isEqualTo(1)
@@ -83,7 +82,6 @@ class QuerySpec : ConnectionHelper() {
@Test
fun `connection should be able to select from a table - validate columnNames()`() {
-
withConnection { connection ->
assertThat(executeQuery(connection, this.createTable).rowsAffected).isEqualTo(0)
assertThat(executeQuery(connection, this.insert).rowsAffected).isEqualTo(1)
@@ -95,7 +93,6 @@ class QuerySpec : ConnectionHelper() {
@Test
fun `connection should be able to select from a table with timestamps`() {
-
withConnection { connection ->
executeQuery(connection, createTableTimeColumns)
executeQuery(connection, insertTableTimeColumns)
@@ -139,7 +136,6 @@ class QuerySpec : ConnectionHelper() {
@Test
fun `connection should be able to select from a table with the various numeric types`() {
-
withConnection { connection ->
executeQuery(connection, createTableNumericColumns)
executeQuery(connection, insertTableNumericColumns)
@@ -178,7 +174,6 @@ class QuerySpec : ConnectionHelper() {
@Test
fun `connection should have column names on result set`() {
-
val create = """CREATE TEMPORARY TABLE posts (
| id INT NOT NULL AUTO_INCREMENT,
| some_bytes BLOB not null,
@@ -219,7 +214,6 @@ class QuerySpec : ConnectionHelper() {
@Test
fun `connection should support BIT type`() {
-
val create =
"""CREATE TEMPORARY TABLE POSTS (
| id INT NOT NULL AUTO_INCREMENT,
@@ -244,12 +238,12 @@ class QuerySpec : ConnectionHelper() {
@Test
fun `connection should fail if number of args required is different than the number of provided parameters`() {
-
withConnection { connection ->
- verifyException(InsufficientParametersException::class.java) {
+ val query = "select * from some_table where c = ? and b = ?"
+ verifyException(InsufficientParametersException::class.java, containedInMessage = query) {
executePreparedStatement(
connection,
- "select * from some_table where c = ? and b = ?",
+ query,
listOf("one", "two", "three")
)
}
@@ -277,7 +271,6 @@ class QuerySpec : ConnectionHelper() {
@Test
fun `connection should select from an empty table with many columns`() {
-
withConnection { connection ->
val create = """create temporary table test_10 (
@@ -297,7 +290,6 @@ class QuerySpec : ConnectionHelper() {
@Test
fun `connection should select from a json column`() {
-
val create = "create temporary table jsons (id char(4), data json)"
val insert = """ insert jsons values
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/TransactionSpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/TransactionSpec.kt
index 258f30447..4f0d23925 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/TransactionSpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/TransactionSpec.kt
@@ -53,7 +53,6 @@ class TransactionSpec : ConnectionHelper() {
@Test
fun `connection in transaction should correctly rollback changes if the transaction raises an exception`() {
-
withConnection { connection ->
executeQuery(connection, this.createTable)
executeQuery(connection, this.insert)
@@ -78,7 +77,6 @@ class TransactionSpec : ConnectionHelper() {
@Test
fun `connection in transaction should should make a connection invalid and not return it to the pool if it raises an exception`() {
-
withPool { pool ->
executeQuery(pool, this.createTable)
@@ -99,7 +97,6 @@ class TransactionSpec : ConnectionHelper() {
@Test
fun `connection in transaction should runs commands for a transaction in a single connection`() {
-
val id = UUID.randomUUID().toString()
withPool { pool ->
@@ -125,7 +122,6 @@ class TransactionSpec : ConnectionHelper() {
@Test
fun `check auto-commit and in transaction flag`() {
-
withConnection { connection ->
assertThat(connection.isAutoCommit()).isTrue()
awaitFuture(connection.sendQuery("SET AUTOCOMMIT=0"))
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/Utils.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/Utils.kt
index a24a4ed54..2e991788c 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/Utils.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/Utils.kt
@@ -5,6 +5,7 @@ import org.assertj.core.api.Assertions
fun verifyException(
exType: Class,
causeType: Class? = null,
+ containedInMessage: String? = null,
body: () -> Unit
): Throwable {
try {
@@ -13,6 +14,7 @@ fun verifyException(
} catch (e: Exception) {
// e.printStackTrace()
Assertions.assertThat(e::class.java).isEqualTo(exType)
+ containedInMessage?.let { Assertions.assertThat(e.message).contains(it) }
causeType?.let { Assertions.assertThat(e.cause!!::class.java).isEqualTo(it) }
return e.cause ?: e
}
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ZeroDatesSpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ZeroDatesSpec.kt
index 6ebd6a5bf..ccf1b1df0 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ZeroDatesSpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/ZeroDatesSpec.kt
@@ -34,7 +34,6 @@ class ZeroDatesSpec : ConnectionHelper() {
@Test
fun `correctly parse the MySQL zeroed dates as NULL values in text protocol`() {
-
withConnection { connection ->
executeQuery(
connection,
@@ -48,7 +47,6 @@ class ZeroDatesSpec : ConnectionHelper() {
@Test
fun `correctly parse the MySQL zeroed dates as NULL values in binary protocol`() {
-
withConnection { connection ->
executeQuery(
connection,
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/binary/BinaryRowDecoderSpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/binary/BinaryRowDecoderSpec.kt
index 858bbec20..c67d6f180 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/binary/BinaryRowDecoderSpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/binary/BinaryRowDecoderSpec.kt
@@ -32,7 +32,6 @@ class BinaryRowDecoderSpec {
@Test
fun `decoder a long and a string from the byte array`() {
-
@Suppress("DEPRECATION")
val buffer = Unpooled.wrappedBuffer(idAndName).order(ByteOrder.LITTLE_ENDIAN)
val result = decoder.decode(buffer, idAndNameColumns)
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/codec/MySQLFrameDecoderSpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/codec/MySQLFrameDecoderSpec.kt
index 9e8257279..3750de787 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/codec/MySQLFrameDecoderSpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/codec/MySQLFrameDecoderSpec.kt
@@ -74,7 +74,6 @@ class MySQLFrameDecoderSpec {
@Test
fun `on query process it should correctly send an error`() {
-
val decoder = MySQLFrameDecoder(charset, "[mysql-connection]")
decoder.hasDoneHandshake = true
val embedder = EmbeddedChannel(decoder)
@@ -97,7 +96,6 @@ class MySQLFrameDecoderSpec {
@Test
fun `on query process it should correctly handle a result set`() {
-
val decoder = MySQLFrameDecoder(charset, "[mysql-connection]")
decoder.hasDoneHandshake = true
val embedder = EmbeddedChannel(decoder)
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/column/TimeDecoderSpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/column/TimeDecoderSpec.kt
index 82e0cba97..ad0c8bec8 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/column/TimeDecoderSpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/column/TimeDecoderSpec.kt
@@ -8,7 +8,6 @@ class TimeDecoderSpec {
@Test
fun `handle a time`() {
-
val time = "120:10:07"
val duration = Duration.ofHours(120) + Duration.ofMinutes(10) + Duration.ofSeconds(7)
assertEquals(duration, TimeDecoder.decode(time))
@@ -16,7 +15,6 @@ class TimeDecoderSpec {
@Test
fun `handle a time with millis`() {
-
val time = "120:10:07.00098"
val duration = Duration.ofHours(120) + Duration.ofMinutes(10) + Duration.ofSeconds(7) + Duration.ofMillis(98)
assertEquals(duration, TimeDecoder.decode(time))
diff --git a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/pool/MySQLConnectionFactorySpec.kt b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/pool/MySQLConnectionFactorySpec.kt
index 8390126df..a3558218a 100644
--- a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/pool/MySQLConnectionFactorySpec.kt
+++ b/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/pool/MySQLConnectionFactorySpec.kt
@@ -86,7 +86,6 @@ class MySQLConnectionFactorySpec : ConnectionHelper() {
@Test
fun `test a valid connection and say it is ok`() {
-
val connection = factory.create().get()
val future = factory.test(connection)
diff --git a/pool-async/build.gradle.kts b/pool-async/build.gradle.kts
index b663a12dd..29ad74728 100644
--- a/pool-async/build.gradle.kts
+++ b/pool-async/build.gradle.kts
@@ -12,9 +12,9 @@ val AWAITILITY_VERSION: String by project
dependencies {
api("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION")
api("org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION")
- compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINES_VERSION")
+ api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINES_VERSION")
implementation("org.slf4j:slf4j-api:$SL4J_VERSION")
- implementation("io.github.microutils:kotlin-logging:$KOTLIN_LOGGING_VERSION")
+ implementation("io.github.oshai:kotlin-logging-jvm:$KOTLIN_LOGGING_VERSION")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$KOTLIN_COROUTINES_VERSION")
testImplementation("junit:junit:$JUNIT_VERSION")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION")
diff --git a/pool-async/src/main/java/com/github/jasync/sql/db/pool/ActorBasedObjectPool.kt b/pool-async/src/main/java/com/github/jasync/sql/db/pool/ActorBasedObjectPool.kt
index 971ddd51f..794cd1a5b 100644
--- a/pool-async/src/main/java/com/github/jasync/sql/db/pool/ActorBasedObjectPool.kt
+++ b/pool-async/src/main/java/com/github/jasync/sql/db/pool/ActorBasedObjectPool.kt
@@ -8,13 +8,13 @@ import com.github.jasync.sql.db.util.failed
import com.github.jasync.sql.db.util.map
import com.github.jasync.sql.db.util.mapTry
import com.github.jasync.sql.db.util.onComplete
+import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.channels.actor
-import mu.KotlinLogging
import java.util.LinkedList
import java.util.Queue
import java.util.WeakHashMap
@@ -91,6 +91,15 @@ internal constructor(
return future
}
+ override fun softEvict(): CompletableFuture> {
+ val future = CompletableFuture()
+ val offered = actor.trySend(SoftEvictAll(future)).isSuccess
+ if (!offered) {
+ future.completeExceptionally(Exception("could not offer to actor"))
+ }
+ return future.map { this }
+ }
+
override fun giveBack(item: T): CompletableFuture> {
val future = CompletableFuture()
val offered = actor.trySend(GiveBack(item, future)).isSuccess
@@ -166,6 +175,7 @@ private sealed class ActorObjectPoolMessage {
}
private class Take(val future: CompletableFuture) : ActorObjectPoolMessage()
+private class SoftEvictAll(val future: CompletableFuture) : ActorObjectPoolMessage()
private class GiveBack(
val returnedItem: T,
val future: CompletableFuture,
@@ -174,16 +184,19 @@ private class GiveBack(
) : ActorObjectPoolMessage() {
override fun toString(): String {
return "GiveBack: ${returnedItem.id} hasError=" +
- if (exception != null)
+ if (exception != null) {
"${exception.javaClass.simpleName} - ${exception.message}"
- else "false"
+ } else {
+ "false"
+ }
}
}
private class Created(
val itemCreateId: Int,
val item: Try,
- val takeAskFuture: CompletableFuture?
+ val takeAskFuture: CompletableFuture?,
+ val objectHolder: ObjectHolder>
) : ActorObjectPoolMessage() {
override fun toString(): String {
val id = when (item) {
@@ -227,6 +240,7 @@ private class ObjectPoolActor(
when (message) {
is Take -> handleTake(message)
is GiveBack -> handleGiveBack(message)
+ is SoftEvictAll -> handleSoftEvictAll(message)
is Created -> handleCreated(message)
is TestPoolItems -> handleTestPoolItems()
is Close -> handleClose(message)
@@ -235,6 +249,19 @@ private class ObjectPoolActor(
scheduleNewItemsIfNeeded()
}
+ private fun handleSoftEvictAll(message: SoftEvictAll) {
+ evictAvailableItems()
+ inUseItems.values.forEach { it.markForEviction = true }
+ inCreateItems.entries.forEach { it.value.markForEviction = true }
+ logger.trace { "handleSoftEvictAll - done" }
+ message.future.complete(Unit)
+ }
+
+ private fun evictAvailableItems() {
+ availableItems.forEach { it.item.destroy() }
+ availableItems.clear()
+ }
+
private fun scheduleNewItemsIfNeeded() {
logger.trace { "scheduleNewItemsIfNeeded - $poolStatusString" }
// deal with inconsistency in case we have items but also waiting futures
@@ -247,7 +274,7 @@ private class ObjectPoolActor(
return
}
}
- // deal with inconsistency in case we have waiting futures, and but we can create new items for them
+ // deal with inconsistency in case we have waiting futures, but we can create new items for them
while (availableItems.isEmpty() &&
waitingQueue.isNotEmpty() &&
totalItems < configuration.maxObjects &&
@@ -273,8 +300,7 @@ private class ObjectPoolActor(
try {
closed = true
channel.close()
- availableItems.forEach { it.item.destroy() }
- availableItems.clear()
+ evictAvailableItems()
inUseItems.forEach {
it.value.cleanedByPool = true
it.key.destroy()
@@ -368,10 +394,12 @@ private class ObjectPoolActor(
logger.trace { "releasing idle item ${item.id}" }
item.destroy()
}
+
configuration.maxObjectTtl != null && System.currentTimeMillis() - item.creationTime > configuration.maxObjectTtl -> {
logger.trace { "releasing item past ttl ${item.id}" }
item.destroy()
}
+
else -> {
val test = objectFactory.test(item)
inUseItems[item] = ItemInUseHolder(item.id, isInTest = true, testFuture = test)
@@ -411,7 +439,7 @@ private class ObjectPoolActor(
is Failure -> future.completeExceptionally(message.item.exception)
is Success -> {
try {
- message.item.value.borrowTo(future)
+ message.item.value.borrowTo(future, markForEviction = message.objectHolder.markForEviction)
} catch (e: Exception) {
future.completeExceptionally(e)
}
@@ -420,11 +448,11 @@ private class ObjectPoolActor(
}
}
- private fun T.borrowTo(future: CompletableFuture, validate: Boolean = true) {
+ private fun T.borrowTo(future: CompletableFuture, validate: Boolean = true, markForEviction: Boolean = false) {
if (validate) {
validate(this)
}
- inUseItems[this] = ItemInUseHolder(this.id, isInTest = false)
+ inUseItems[this] = ItemInUseHolder(this.id, isInTest = false, markForEviction = markForEviction)
logger.trace { "borrowed: ${this.id} ; $poolStatusString" }
future.complete(this)
}
@@ -450,6 +478,11 @@ private class ObjectPoolActor(
}
validate(message.returnedItem)
message.future.complete(Unit)
+ if (removed.markForEviction) {
+ logger.trace { "GiveBack got item ${message.returnedItem.id} marked for eviction, so destroying it" }
+ message.returnedItem.destroy()
+ return
+ }
if (waitingQueue.isEmpty()) {
if (availableItems.any { holder -> message.returnedItem === holder.item }) {
logger.warn { "trying to give back an item to the pool twice ${message.returnedItem.id}, will ignore that" }
@@ -482,8 +515,9 @@ private class ObjectPoolActor(
while (availableItems.isNotEmpty()) {
val future = message.future
val wasBorrowed = borrowFirstAvailableItem(future)
- if (wasBorrowed)
+ if (wasBorrowed) {
return
+ }
}
// available is empty
createNewItemPutInWaitQueue(message)
@@ -533,10 +567,11 @@ private class ObjectPoolActor(
val created = objectFactory.create()
val itemCreateId = createIndex
createIndex++
- inCreateItems[itemCreateId] = ObjectHolder(created)
+ val objectHolder = ObjectHolder(created)
+ inCreateItems[itemCreateId] = objectHolder
logger.trace { "createObject createRequest=$itemCreateId" }
created.onComplete { tried ->
- offerOrLog(Created(itemCreateId, tried, future)) {
+ offerOrLog(Created(itemCreateId, tried, future, objectHolder)) {
"failed to offer on created item $itemCreateId"
}
}
@@ -558,9 +593,11 @@ private open class PoolObjectHolder(
val timeElapsed: Long get() = System.currentTimeMillis() - time
}
-private class ObjectHolder(val item: T) {
+private class ObjectHolder(
+ val item: T,
+ var markForEviction: Boolean = false
+) {
val time = System.currentTimeMillis()
-
val timeElapsed: Long get() = System.currentTimeMillis() - time
}
@@ -569,12 +606,13 @@ private data class ItemInUseHolder(
val isInTest: Boolean,
val testFuture: CompletableFuture? = null,
val time: Long = System.currentTimeMillis(),
- var cleanedByPool: Boolean = false
+ var cleanedByPool: Boolean = false,
+ var markForEviction: Boolean = false
) {
val timeElapsed: Long get() = System.currentTimeMillis() - time
- @Suppress("unused", "ProtectedInFinal")
+ @Suppress("unused")
protected fun finalize() {
if (!cleanedByPool) {
logger.warn { "LEAK DETECTED for item $this - $timeElapsed ms since in use" }
diff --git a/pool-async/src/main/java/com/github/jasync/sql/db/pool/AsyncObjectPool.kt b/pool-async/src/main/java/com/github/jasync/sql/db/pool/AsyncObjectPool.kt
index cd1510ff5..e62ca2e26 100644
--- a/pool-async/src/main/java/com/github/jasync/sql/db/pool/AsyncObjectPool.kt
+++ b/pool-async/src/main/java/com/github/jasync/sql/db/pool/AsyncObjectPool.kt
@@ -40,6 +40,11 @@ interface AsyncObjectPool {
fun giveBack(item: T): CompletableFuture>
+ /**
+ * Mark all objects in the pool as invalid. Objects will be evicted when not in use.
+ */
+ fun softEvict(): CompletableFuture>
+
/**
*
* Closes this pool and future calls to **take** will cause the Future to raise an
diff --git a/pool-async/src/test/java/com/github/jasync/sql/db/pool/AbstractAsyncObjectPoolSpec.kt b/pool-async/src/test/java/com/github/jasync/sql/db/pool/AbstractAsyncObjectPoolSpec.kt
index cbedbc8da..fa60d42fe 100644
--- a/pool-async/src/test/java/com/github/jasync/sql/db/pool/AbstractAsyncObjectPoolSpec.kt
+++ b/pool-async/src/test/java/com/github/jasync/sql/db/pool/AbstractAsyncObjectPoolSpec.kt
@@ -227,9 +227,10 @@ class TestWidgetFactory :
override fun destroy(item: Widget) {}
override fun validate(item: Widget): Try = Try {
- if (item.factory == this)
+ if (item.factory == this) {
item
- else
+ } else {
throw IllegalArgumentException("Not our item")
+ }
}
}
diff --git a/pool-async/src/test/java/com/github/jasync/sql/db/pool/ActorBasedObjectPoolTest.kt b/pool-async/src/test/java/com/github/jasync/sql/db/pool/ActorBasedObjectPoolTest.kt
index d3671d751..843d578f5 100644
--- a/pool-async/src/test/java/com/github/jasync/sql/db/pool/ActorBasedObjectPoolTest.kt
+++ b/pool-async/src/test/java/com/github/jasync/sql/db/pool/ActorBasedObjectPoolTest.kt
@@ -17,8 +17,10 @@ class ActorBasedObjectPoolTest {
private val factory = ForTestingMyFactory()
private val configuration = PoolConfiguration(
- maxObjects = 10, maxQueueSize = Int.MAX_VALUE,
- validationInterval = Long.MAX_VALUE, maxIdle = Long.MAX_VALUE,
+ maxObjects = 10,
+ maxQueueSize = Int.MAX_VALUE,
+ validationInterval = Long.MAX_VALUE,
+ maxIdle = Long.MAX_VALUE,
maxObjectTtl = null
)
private lateinit var tested: ActorBasedObjectPool
@@ -58,7 +60,9 @@ class ActorBasedObjectPoolTest {
@Test
fun `basic take operation - when create is stuck should be timeout`() {
tested = ActorBasedObjectPool(
- factory, configuration.copy(createTimeout = 10), false
+ factory,
+ configuration.copy(createTimeout = 10),
+ false
)
factory.creationStuck = true
val result = tested.take()
@@ -70,7 +74,9 @@ class ActorBasedObjectPoolTest {
@Test
fun `take operation that is waiting in queue - when create is stuck should be timeout`() {
tested = ActorBasedObjectPool(
- factory, configuration.copy(maxObjects = 1, queryTimeout = 10), false
+ factory,
+ configuration.copy(maxObjects = 1, queryTimeout = 10),
+ false
)
// first item is canceled when the create fails
tested.take()
@@ -90,7 +96,9 @@ class ActorBasedObjectPoolTest {
@Test
fun `basic take operation - when create is little stuck should not be timeout (create timeout is 5 sec)`() {
tested = ActorBasedObjectPool(
- factory, configuration.copy(createTimeout = 5000), false
+ factory,
+ configuration.copy(createTimeout = 5000),
+ false
)
factory.creationStuckTime = 10
val result = tested.take()
@@ -150,6 +158,41 @@ class ActorBasedObjectPoolTest {
assertThat(factory.validated).isEqualTo(listOf(result, result, result))
}
+ @Test
+ fun `softEviction - basic take-evict-return pool should be empty`() {
+ tested = createDefaultPool()
+ val result = tested.take().get()
+ tested.softEvict().get()
+ tested.giveBack(result).get()
+ assertThat(tested.availableItems).isEmpty()
+ }
+
+ @Test
+ fun `softEviction - minimum number of objects is maintained, but objects are replaced`() {
+ tested = ActorBasedObjectPool(
+ factory,
+ configuration.copy(minIdleObjects = 3),
+ false
+ )
+ tested.take().get()
+ await.untilCallTo { tested.availableItemsSize } matches { it == 3 }
+ val availableItems = tested.availableItems
+ tested.softEvict().get()
+ await.untilCallTo { tested.availableItemsSize } matches { it == 3 }
+ assertThat(tested.availableItems.toSet().intersect(availableItems.toSet())).isEmpty()
+ }
+
+ @Test
+ fun `test for objects in create eviction in case of softEviction`() {
+ factory.creationStuckTime = 10
+ tested = createDefaultPool()
+ val itemPromise = tested.take()
+ tested.softEvict().get()
+ val item = itemPromise.get()
+ tested.giveBack(item).get()
+ assertThat(tested.availableItemsSize).isEqualTo(0)
+ }
+
@Test
fun `take2-return2-take first not validated second is ok should be returned`() {
tested = createDefaultPool()
diff --git a/postgis-jasync/build.gradle.kts b/postgis-jasync/build.gradle.kts
index b2e9887b1..79b504f85 100644
--- a/postgis-jasync/build.gradle.kts
+++ b/postgis-jasync/build.gradle.kts
@@ -16,18 +16,18 @@ val AWAITILITY_VERSION: String by project
val JTS_VERSION: String by project
dependencies {
- compile(project(":db-async-common"))
- compile(project(":pool-async"))
- compile(project(":postgresql-async"))
- compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION")
- compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINES_VERSION")
- compile("org.slf4j:slf4j-api:$SL4J_VERSION")
- compile("joda-time:joda-time:$JODA_VERSION")
- compile("io.netty:netty-transport:$NETTY_VERSION")
- compile("io.netty:netty-handler:$NETTY_VERSION")
- compile("io.github.microutils:kotlin-logging:$KOTLIN_LOGGING_VERSION")
- compile("com.ongres.scram:client:$SCRAM_CLIENT_VERSION")
- compile("org.threeten:threeten-extra:$THREETEN_EXTRA")
+ api(project(":db-async-common"))
+ api(project(":pool-async"))
+ api(project(":postgresql-async"))
+ api("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION")
+ api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINES_VERSION")
+ api("org.slf4j:slf4j-api:$SL4J_VERSION")
+ api("joda-time:joda-time:$JODA_VERSION")
+ api("io.netty:netty-transport:$NETTY_VERSION")
+ api("io.netty:netty-handler:$NETTY_VERSION")
+ api("io.github.oshai:kotlin-logging-jvm:$KOTLIN_LOGGING_VERSION")
+ api("com.ongres.scram:client:$SCRAM_CLIENT_VERSION")
+ api("org.threeten:threeten-extra:$THREETEN_EXTRA")
testImplementation("junit:junit:$JUNIT_VERSION")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION")
@@ -37,5 +37,5 @@ dependencies {
testImplementation("ch.qos.logback:logback-classic:$LOGBACK_VERSION")
testImplementation("org.testcontainers:postgresql:$TEST_CONTAINERS_VERSION")
testImplementation("org.awaitility:awaitility-kotlin:$AWAITILITY_VERSION")
- compile("org.locationtech.jts:jts-core:$JTS_VERSION")
+ api("org.locationtech.jts:jts-core:$JTS_VERSION")
}
diff --git a/postgis-jasync/src/main/java/com/github/jasync/sql/db/postgis/BinaryParser.kt b/postgis-jasync/src/main/java/com/github/jasync/sql/db/postgis/BinaryParser.kt
index 70d9573a6..a2eb0435a 100644
--- a/postgis-jasync/src/main/java/com/github/jasync/sql/db/postgis/BinaryParser.kt
+++ b/postgis-jasync/src/main/java/com/github/jasync/sql/db/postgis/BinaryParser.kt
@@ -256,8 +256,13 @@ object Geom {
val ALLTYPES = arrayOf(
"", // internally used LinearRing does not have any text in front of
// it
- "POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING",
- "MULTIPOLYGON", "GEOMETRYCOLLECTION"
+ "POINT",
+ "LINESTRING",
+ "POLYGON",
+ "MULTIPOINT",
+ "MULTILINESTRING",
+ "MULTIPOLYGON",
+ "GEOMETRYCOLLECTION"
)
/**
diff --git a/postgis-jasync/src/main/java/com/github/jasync/sql/db/postgis/JasyncPostgisRegister.kt b/postgis-jasync/src/main/java/com/github/jasync/sql/db/postgis/JasyncPostgisRegister.kt
index efdb56769..16732fe14 100644
--- a/postgis-jasync/src/main/java/com/github/jasync/sql/db/postgis/JasyncPostgisRegister.kt
+++ b/postgis-jasync/src/main/java/com/github/jasync/sql/db/postgis/JasyncPostgisRegister.kt
@@ -4,7 +4,7 @@ import com.github.jasync.sql.db.Connection
import com.github.jasync.sql.db.postgresql.column.PostgreSQLColumnDecoderRegistry
import com.github.jasync.sql.db.util.FP
import com.github.jasync.sql.db.util.map
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import java.util.concurrent.CompletableFuture
import java.util.concurrent.atomic.AtomicBoolean
@@ -19,6 +19,7 @@ private val logger = KotlinLogging.logger {}
object JasyncPostgisRegister {
val geometryRegistered = AtomicBoolean(false)
+
@JvmStatic
fun init(connection: Connection): CompletableFuture {
if (geometryRegistered.get()) {
diff --git a/postgis-jasync/src/test/java/ContainerHelper.kt b/postgis-jasync/src/test/java/ContainerHelper.kt
index 7825d390b..b5cd89a7f 100644
--- a/postgis-jasync/src/test/java/ContainerHelper.kt
+++ b/postgis-jasync/src/test/java/ContainerHelper.kt
@@ -2,7 +2,7 @@ package com.github.aysnc.sql.db.integration
import com.github.jasync.sql.db.Configuration
import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import org.testcontainers.containers.BindMode
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.utility.DockerImageName
diff --git a/postgis-jasync/src/test/java/DatabaseTestHelper.kt b/postgis-jasync/src/test/java/DatabaseTestHelper.kt
index 2c24b834f..8e8688b10 100644
--- a/postgis-jasync/src/test/java/DatabaseTestHelper.kt
+++ b/postgis-jasync/src/test/java/DatabaseTestHelper.kt
@@ -38,7 +38,6 @@ open class DatabaseTestHelper {
}
fun withHandler(configuration: Configuration, fn: (PostgreSQLConnection) -> T): T {
-
val handler = PostgreSQLConnection(configuration)
try {
@@ -65,7 +64,6 @@ open class DatabaseTestHelper {
try {
return fn()
} catch (e: TimeoutException) {
-
throw IllegalStateException("Timeout executing call from handler -> %s".format(handler))
}
}
diff --git a/postgresql-async/build.gradle.kts b/postgresql-async/build.gradle.kts
index e2e133be0..1e2f5dd51 100644
--- a/postgresql-async/build.gradle.kts
+++ b/postgresql-async/build.gradle.kts
@@ -15,17 +15,17 @@ val TEST_CONTAINERS_VERSION: String by project
val AWAITILITY_VERSION: String by project
dependencies {
- compile(project(":db-async-common"))
- compile(project(":pool-async"))
- compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION")
- compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINES_VERSION")
- compile("org.slf4j:slf4j-api:$SL4J_VERSION")
- compile("joda-time:joda-time:$JODA_VERSION")
- compile("io.netty:netty-transport:$NETTY_VERSION")
- compile("io.netty:netty-handler:$NETTY_VERSION")
- compile("io.github.microutils:kotlin-logging:$KOTLIN_LOGGING_VERSION")
- compile("com.ongres.scram:client:$SCRAM_CLIENT_VERSION")
- compile("org.threeten:threeten-extra:$THREETEN_EXTRA")
+ api(project(":db-async-common"))
+ api(project(":pool-async"))
+ api("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION")
+ api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINES_VERSION")
+ api("org.slf4j:slf4j-api:$SL4J_VERSION")
+ api("joda-time:joda-time:$JODA_VERSION")
+ api("io.netty:netty-transport:$NETTY_VERSION")
+ api("io.netty:netty-handler:$NETTY_VERSION")
+ api("io.github.oshai:kotlin-logging-jvm:$KOTLIN_LOGGING_VERSION")
+ api("com.ongres.scram:client:$SCRAM_CLIENT_VERSION")
+ api("org.threeten:threeten-extra:$THREETEN_EXTRA")
testImplementation("junit:junit:$JUNIT_VERSION")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION")
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/PostgreSQLConnection.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/PostgreSQLConnection.kt
index 3f6ba18ab..b7145eb67 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/PostgreSQLConnection.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/PostgreSQLConnection.kt
@@ -61,7 +61,7 @@ import com.ongres.scram.client.ScramClient
import com.ongres.scram.client.ScramSession
import com.ongres.scram.common.exception.ScramException
import com.ongres.scram.common.stringprep.StringPreparations
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import java.time.Duration
import java.util.Collections
import java.util.Optional
@@ -190,20 +190,20 @@ class PostgreSQLConnection @JvmOverloads constructor(
if (holder.paramsCount != params.values.length) {
this.clearQueryPromise()
- throw InsufficientParametersException(holder.paramsCount, params.values)
+ throw InsufficientParametersException(params.query, holder.paramsCount, params.values)
}
this.currentPreparedStatement = Optional.of(holder)
this.currentQuery = Optional.of(MutableResultSet(holder.columnDatas))
write(
- if (holder.prepared)
+ if (holder.prepared) {
PreparedStatementExecuteMessage(
holder.statementId,
holder.realQuery,
params.values,
this.encoderRegistry
)
- else {
+ } else {
holder.prepared = true
PreparedStatementOpeningMessage(
holder.statementId,
@@ -382,8 +382,9 @@ class PostgreSQLConnection @JvmOverloads constructor(
}
fun validateIfItIsReadyForQuery(errorMessage: String) {
- if (this.queryPromise().isPresent)
+ if (this.queryPromise().isPresent) {
notReadyForQueryError(errorMessage, false)
+ }
}
private fun validateQuery(query: String) {
@@ -400,8 +401,9 @@ class PostgreSQLConnection @JvmOverloads constructor(
private fun queryPromise(): Optional> = queryPromiseReference.get()
private fun setQueryPromise(promise: CompletableFuture) {
- if (!this.queryPromiseReference.compareAndSet(Optional.empty(), Optional.of(promise)))
+ if (!this.queryPromiseReference.compareAndSet(Optional.empty(), Optional.of(promise))) {
notReadyForQueryError("Can't run query due to a race , another started query", true)
+ }
}
private fun clearQueryPromise(): Optional> {
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/MessageDecoder.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/MessageDecoder.kt
index 7c43104df..0531fa0ac 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/MessageDecoder.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/MessageDecoder.kt
@@ -7,10 +7,10 @@ import com.github.jasync.sql.db.postgresql.messages.backend.ServerMessage
import com.github.jasync.sql.db.postgresql.parsers.AuthenticationStartupParser
import com.github.jasync.sql.db.postgresql.parsers.MessageParsersRegistry
import com.github.jasync.sql.db.util.BufferDumper
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.ByteToMessageDecoder
-import mu.KotlinLogging
import java.nio.charset.Charset
private val logger = KotlinLogging.logger {}
@@ -27,14 +27,12 @@ class MessageDecoder(
private var sslChecked = false
public override fun decode(ctx: ChannelHandlerContext, b: ByteBuf, out: MutableList) {
-
if (sslEnabled && !sslChecked) {
val code = b.readByte()
logger.trace { "Received buffer ${code.toChar()}($code)\n${BufferDumper.dumpAsHex(b)}" }
sslChecked = true
out.add(SSLResponseMessage(code.toChar() == 'S'))
} else if (b.readableBytes() >= 5) {
-
b.markReaderIndex()
val code = b.readByte()
@@ -50,7 +48,6 @@ class MessageDecoder(
}
if (b.readableBytes() >= length) {
-
logger.trace { "Received buffer ${code.toChar()}($code)\n${BufferDumper.dumpAsHex(b)}" }
val result = when (code.toInt()) {
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/MessageEncoder.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/MessageEncoder.kt
index 93bf0d491..505f1edbb 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/MessageEncoder.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/MessageEncoder.kt
@@ -15,9 +15,9 @@ import com.github.jasync.sql.db.postgresql.messages.frontend.ClientMessage
import com.github.jasync.sql.db.postgresql.messages.frontend.SSLRequestMessage
import com.github.jasync.sql.db.postgresql.messages.frontend.StartupMessage
import com.github.jasync.sql.db.util.BufferDumper
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.MessageToMessageEncoder
-import mu.KotlinLogging
import java.nio.charset.Charset
private val logger = KotlinLogging.logger {}
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/PostgreSQLConnectionHandler.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/PostgreSQLConnectionHandler.kt
index cd1be3041..bd8f77fed 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/PostgreSQLConnectionHandler.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/codec/PostgreSQLConnectionHandler.kt
@@ -27,6 +27,7 @@ import com.github.jasync.sql.db.util.onCompleteAsync
import com.github.jasync.sql.db.util.onFailure
import com.github.jasync.sql.db.util.success
import com.github.jasync.sql.db.util.toCompletableFuture
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.bootstrap.Bootstrap
import io.netty.channel.Channel
import io.netty.channel.ChannelHandlerContext
@@ -36,7 +37,6 @@ import io.netty.channel.EventLoopGroup
import io.netty.channel.SimpleChannelInboundHandler
import io.netty.handler.codec.CodecException
import io.netty.handler.ssl.SslHandler
-import mu.KotlinLogging
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Executor
@@ -127,10 +127,11 @@ class PostgreSQLConnectionHandler(
@Suppress("RedundantUnitReturnType")
override fun channelActive(ctx: ChannelHandlerContext) {
- if (configuration.ssl.mode == SSLConfiguration.Mode.Disable)
+ if (configuration.ssl.mode == SSLConfiguration.Mode.Disable) {
ctx.writeAndFlush(StartupMessage(this.properties))
- else
+ } else {
ctx.writeAndFlush(SSLRequestMessage)
+ }
}
override fun channelRead0(ctx: ChannelHandlerContext?, message: Any) {
@@ -221,6 +222,12 @@ class PostgreSQLConnectionHandler(
}
@Suppress("OverridingDeprecatedMember")
+ // /**
+ // * Calls {@link ChannelHandlerContext#fireExceptionCaught(Throwable)} to forward
+ // * to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
+ // *
+ // * Sub-classes may override this method to change behavior.
+ // */
override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) {
// unwrap CodecException if needed
when (cause) {
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ArrayDecoder.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ArrayDecoder.kt
index adc7b9d6b..b90cfd1a9 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ArrayDecoder.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ArrayDecoder.kt
@@ -13,7 +13,6 @@ import java.nio.charset.Charset
class ArrayDecoder(private val decoder: ColumnDecoder) : ColumnDecoder {
override fun decode(kind: ColumnData, value: ByteBuf, charset: Charset): List? {
-
val bytes = ByteArray(value.readableBytes())
value.readBytes(bytes)
val valueString = String(bytes, charset)
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ByteArrayEncoderDecoder.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ByteArrayEncoderDecoder.kt
index 67ea9c857..2c04fc795 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ByteArrayEncoderDecoder.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ByteArrayEncoderDecoder.kt
@@ -12,7 +12,6 @@ object ByteArrayEncoderDecoder : ColumnEncoderDecoder {
private val HexStartChars = HexStart.toCharArray()
override fun decode(value: String): ByteArray {
-
return if (value.startsWith(HexStart)) {
HexCodec.decode(value, 2)
} else {
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ColumnTypes.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ColumnTypes.kt
index eba24cb1d..e01b44272 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ColumnTypes.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/ColumnTypes.kt
@@ -12,6 +12,7 @@ object ColumnTypes {
const val Integer = 23
const val IntegerArray = 1007
const val Numeric = 1700
+
// Decimal is the same as Numeric on PostgreSQL
const val NumericArray = 1231
const val Real = 700
@@ -22,6 +23,7 @@ object ColumnTypes {
const val Bpchar = 1042
const val BpcharArray = 1014
const val Varchar = 1043
+
// Char is the same as Varchar on PostgreSQL
const val VarcharArray = 1015
const val Text = 25
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLColumnDecoderRegistry.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLColumnDecoderRegistry.kt
index 85e795e4d..39f05f14d 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLColumnDecoderRegistry.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLColumnDecoderRegistry.kt
@@ -15,9 +15,9 @@ import com.github.jasync.sql.db.column.TimeEncoderDecoder
import com.github.jasync.sql.db.column.TimeWithTimezoneEncoderDecoder
import com.github.jasync.sql.db.column.UUIDEncoderDecoder
import com.github.jasync.sql.db.general.ColumnData
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
import io.netty.util.CharsetUtil
-import mu.KotlinLogging
import java.nio.charset.Charset
private val logger = KotlinLogging.logger {}
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLColumnEncoderRegistry.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLColumnEncoderRegistry.kt
index 41edd0c7e..ef715e592 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLColumnEncoderRegistry.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLColumnEncoderRegistry.kt
@@ -16,8 +16,8 @@ import com.github.jasync.sql.db.column.TimeEncoderDecoder
import com.github.jasync.sql.db.column.TimestampEncoderDecoder
import com.github.jasync.sql.db.column.TimestampWithTimezoneEncoderDecoder
import com.github.jasync.sql.db.column.UUIDEncoderDecoder
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
-import mu.KotlinLogging
import org.threeten.extra.PeriodDuration
import java.math.BigDecimal
import java.nio.ByteBuffer
@@ -115,7 +115,6 @@ class PostgreSQLColumnEncoderRegistry : ColumnEncoderRegistry {
* Used to encode a value that is not null and not an Option.
*/
private fun encodeValue(value: Any): String {
-
val encoder = this.classes[value.javaClass]
return if (encoder != null) {
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLIntervalEncoderDecoder.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLIntervalEncoderDecoder.kt
index 826e6329b..80658d575 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLIntervalEncoderDecoder.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/column/PostgreSQLIntervalEncoderDecoder.kt
@@ -79,27 +79,33 @@ object PostgreSQLIntervalEncoderDecoder : ColumnEncoderDecoder {
PeriodDuration.parse(value)
} else {
val format = (
- if (value.startsWith("@ "))
+ if (value.startsWith("@ ")) {
postgres_verboseParser
- else {
+ } else {
/* try to guess based on what comes after the first number */
val i = value.indexOfFirst { !it.isDigit() }.let { if ("-+".contains(value[0])) 1 else 0 }
- if (i < 0 || ":.".contains(value[i])) /* simple HMS (to support group negation) */
+ if (i < 0 || ":.".contains(value[i])) {
+ /* simple HMS (to support group negation) */
hmsParser
- else if (value[i] == '-') /* sql_standard: Y-M */
+ } else if (value[i] == '-') {
+ /* sql_standard: Y-M */
sqlParser
- else if (value[i] == ' ' && i + 1 < value.length && value[i + 1].isDigit()) /* sql_standard: D H:M:S */
+ } else if (value[i] == ' ' && i + 1 < value.length && value[i + 1].isDigit()) {
+ /* sql_standard: D H:M:S */
sqlDTParser
- else
+ } else {
postgresParser
+ }
}
)
- val jodaPeriod = if ((format == hmsParser) && value.startsWith('-'))
+ val jodaPeriod = if ((format == hmsParser) && value.startsWith('-')) {
format.parsePeriod(value.substring(1)).negated()
- else if (value.endsWith(" ago")) /* only really applies to postgres_verbose, but shouldn't hurt */
+ } else if (value.endsWith(" ago")) {
+ /* only really applies to postgres_verbose, but shouldn't hurt */
format.parsePeriod(value.removeSuffix(" ago")).negated()
- else
+ } else {
format.parsePeriod(value)
+ }
PeriodDuration.of(
Period.of(jodaPeriod.years, jodaPeriod.months, jodaPeriod.days),
Duration.ofHours(jodaPeriod.hours.toLong()).plusMinutes(jodaPeriod.minutes.toLong())
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/CloseStatementEncoder.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/CloseStatementEncoder.kt
index f29b11c83..099f3aa51 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/CloseStatementEncoder.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/CloseStatementEncoder.kt
@@ -2,8 +2,8 @@ package com.github.jasync.sql.db.postgresql.encoders
import com.github.jasync.sql.db.postgresql.messages.frontend.ClientMessage
import com.github.jasync.sql.db.postgresql.messages.frontend.PreparedStatementCloseMessage
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
-import mu.KotlinLogging
import java.nio.charset.Charset
private val logger = KotlinLogging.logger {}
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/ExecutePreparedStatementEncoder.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/ExecutePreparedStatementEncoder.kt
index 531f49caf..f27770f9d 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/ExecutePreparedStatementEncoder.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/ExecutePreparedStatementEncoder.kt
@@ -11,7 +11,6 @@ class ExecutePreparedStatementEncoder(val charset: Charset, val encoder: ColumnE
PreparedStatementEncoderHelper {
override fun encode(message: ClientMessage): ByteBuf {
-
val m = message as PreparedStatementExecuteMessage
val statementIdBytes = m.statementId.toString().toByteArray(charset)
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/PreparedStatementEncoderHelper.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/PreparedStatementEncoderHelper.kt
index fedec5898..a2ebff94f 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/PreparedStatementEncoderHelper.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/PreparedStatementEncoderHelper.kt
@@ -4,9 +4,9 @@ import com.github.jasync.sql.db.column.ColumnEncoderRegistry
import com.github.jasync.sql.db.postgresql.messages.backend.ServerMessage
import com.github.jasync.sql.db.util.ByteBufferUtils
import com.github.jasync.sql.db.util.length
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
-import mu.KotlinLogging
import java.nio.charset.Charset
private val logger = KotlinLogging.logger {}
@@ -26,7 +26,6 @@ interface PreparedStatementEncoderHelper {
charset: Charset,
writeDescribe: Boolean = false
): ByteBuf {
-
logger.debug { "Preparing execute portal to statement ($query) - values (${values.joinToString(", ")}) - $charset" }
val bindBuffer = Unpooled.buffer(1024)
@@ -89,6 +88,7 @@ interface PreparedStatementEncoderHelper {
if (writeDescribe) {
val describeLength = 1 + 4 + 1 + statementIdBytes.length + 1
+
@Suppress("UnnecessaryVariable")
val describeBuffer = bindBuffer
describeBuffer.writeByte(ServerMessage.Describe)
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/PreparedStatementOpeningEncoder.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/PreparedStatementOpeningEncoder.kt
index 48242ecb1..edae08327 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/PreparedStatementOpeningEncoder.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/PreparedStatementOpeningEncoder.kt
@@ -5,9 +5,9 @@ import com.github.jasync.sql.db.postgresql.messages.backend.ServerMessage
import com.github.jasync.sql.db.postgresql.messages.frontend.ClientMessage
import com.github.jasync.sql.db.postgresql.messages.frontend.PreparedStatementOpeningMessage
import com.github.jasync.sql.db.util.ByteBufferUtils
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
-import mu.KotlinLogging
import java.nio.charset.Charset
private val logger = KotlinLogging.logger {}
@@ -15,7 +15,6 @@ private val logger = KotlinLogging.logger {}
class PreparedStatementOpeningEncoder(val charset: Charset, val encoder: ColumnEncoderRegistry) : Encoder, PreparedStatementEncoderHelper {
override fun encode(message: ClientMessage): ByteBuf {
-
val m = message as PreparedStatementOpeningMessage
val statementIdBytes = m.statementId.toString().toByteArray(charset)
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/QueryMessageEncoder.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/QueryMessageEncoder.kt
index f4f937a34..22b9f8b1a 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/QueryMessageEncoder.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/QueryMessageEncoder.kt
@@ -4,9 +4,9 @@ import com.github.jasync.sql.db.postgresql.messages.backend.ServerMessage
import com.github.jasync.sql.db.postgresql.messages.frontend.ClientMessage
import com.github.jasync.sql.db.postgresql.messages.frontend.QueryMessage
import com.github.jasync.sql.db.util.ByteBufferUtils
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
-import mu.KotlinLogging
import java.nio.charset.Charset
private val logger = KotlinLogging.logger {}
@@ -14,7 +14,6 @@ private val logger = KotlinLogging.logger {}
class QueryMessageEncoder(val charset: Charset) : Encoder {
override fun encode(message: ClientMessage): ByteBuf {
-
val m = message as QueryMessage
logger.debug("Executing direct query ({})", m.query)
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/StartupMessageEncoder.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/StartupMessageEncoder.kt
index 13bfe204b..9af48af49 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/StartupMessageEncoder.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/encoders/StartupMessageEncoder.kt
@@ -2,9 +2,9 @@ package com.github.jasync.sql.db.postgresql.encoders
import com.github.jasync.sql.db.postgresql.messages.frontend.StartupMessage
import com.github.jasync.sql.db.util.ByteBufferUtils
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
-import mu.KotlinLogging
import java.nio.charset.Charset
private val logger = KotlinLogging.logger {}
@@ -12,7 +12,6 @@ private val logger = KotlinLogging.logger {}
class StartupMessageEncoder(val charset: Charset) {
fun encode(startup: StartupMessage): ByteBuf {
-
val buffer = Unpooled.buffer()
buffer.writeInt(0)
buffer.writeShort(3)
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/parsers/InformationParser.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/parsers/InformationParser.kt
index 9ca119ed0..f48a68c68 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/parsers/InformationParser.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/parsers/InformationParser.kt
@@ -8,7 +8,6 @@ import java.nio.charset.Charset
abstract class InformationParser(val charset: Charset) : MessageParser {
override fun parseMessage(buffer: ByteBuf): ServerMessage {
-
val fields = mutableMapOf()
while (buffer.isReadable) {
val kind = buffer.readByte()
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/parsers/RowDescriptionParser.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/parsers/RowDescriptionParser.kt
index 46da872b3..311debe93 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/parsers/RowDescriptionParser.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/parsers/RowDescriptionParser.kt
@@ -47,7 +47,6 @@ The format code being used for the field. Currently will be zero (text) or one (
class RowDescriptionParser(val charset: Charset) : MessageParser {
override fun parseMessage(buffer: ByteBuf): ServerMessage {
-
val columnsCount = buffer.readShort()
val columns = mutableListOf()
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/pool/PostgreSQLConnectionFactory.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/pool/PostgreSQLConnectionFactory.kt
index 83c623a02..8d0778a27 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/pool/PostgreSQLConnectionFactory.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/pool/PostgreSQLConnectionFactory.kt
@@ -3,7 +3,7 @@ package com.github.jasync.sql.db.postgresql.pool
import com.github.jasync.sql.db.Configuration
import com.github.jasync.sql.db.pool.ConnectionFactory
import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import java.util.concurrent.CompletableFuture
private val logger = KotlinLogging.logger {}
diff --git a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/util/ArrayStreamingParser.kt b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/util/ArrayStreamingParser.kt
index 60249a8f0..5f6c25f81 100644
--- a/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/util/ArrayStreamingParser.kt
+++ b/postgresql-async/src/main/java/com/github/jasync/sql/db/postgresql/util/ArrayStreamingParser.kt
@@ -6,7 +6,6 @@ import com.github.jasync.sql.db.util.size
object ArrayStreamingParser {
fun parse(content: String, delegate: ArrayStreamingParserDelegate) {
-
var index = 0
var escaping = false
var quoted = false
@@ -71,7 +70,6 @@ object ArrayStreamingParser {
}
fun sendElementEvent(builder: StringBuilder?, quoted: Boolean, delegate: ArrayStreamingParserDelegate) {
-
val value = builder.toString()
if (!quoted && "NULL".equals(value, ignoreCase = true)) {
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/Utils.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/Utils.kt
index bc7d16d62..cafea1ba4 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/Utils.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/Utils.kt
@@ -5,6 +5,7 @@ import org.assertj.core.api.Assertions
fun verifyException(
exType: Class,
causeType: Class? = null,
+ containedInMessage: String? = null,
body: () -> Unit
): Throwable {
try {
@@ -12,6 +13,7 @@ fun verifyException(
throw Exception("Expected exception was not thrown: ${exType.simpleName}->${causeType?.simpleName}")
} catch (e: Exception) {
Assertions.assertThat(e::class.java).isEqualTo(exType)
+ containedInMessage?.let { Assertions.assertThat(e.message).contains(it) }
causeType?.let { Assertions.assertThat(e.cause!!::class.java).isEqualTo(it) }
return e.cause ?: e
}
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/general/MutableResultSetSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/general/MutableResultSetSpec.kt
index 2c999a51b..4f7c14213 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/general/MutableResultSetSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/general/MutableResultSetSpec.kt
@@ -22,7 +22,6 @@ class MutableResultSetSpec {
@Test
fun `result set should correctly map column data to fields`() {
-
val columns = listOf(
create(
name = "id",
@@ -59,7 +58,6 @@ class MutableResultSetSpec {
@Test
fun `result set should return the same order as the one given by columns`() {
-
val columns = listOf(
create("id", ColumnTypes.Integer),
create("name", ColumnTypes.Varchar),
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ArrayTypesSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ArrayTypesSpec.kt
index 2e11f5138..a5128e647 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ArrayTypesSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ArrayTypesSpec.kt
@@ -46,7 +46,6 @@ class ArrayTypesSpec : DatabaseTestHelper() {
@Test
fun `connection should correctly parse the array type`() {
-
withHandler { handler ->
try {
executeDdl(handler, simpleCreate("cptat"))
@@ -82,7 +81,6 @@ class ArrayTypesSpec : DatabaseTestHelper() {
@Test
fun `connection should correctly send arrays using prepared statements`() {
-
val timestamps = listOf(
TimestampWithTimezoneEncoderDecoder.decode("2013-04-06 01:15:10.528-03"),
TimestampWithTimezoneEncoderDecoder.decode("2013-04-06 01:15:08.528-03")
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/BitSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/BitSpec.kt
index b1e4c5240..de77405dd 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/BitSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/BitSpec.kt
@@ -8,7 +8,6 @@ class BitSpec : DatabaseTestHelper() {
@Test
fun `when processing bit columns should result in binary data`() {
-
withHandler { handler ->
val create = """CREATE TEMP TABLE binary_test
(
@@ -35,7 +34,6 @@ class BitSpec : DatabaseTestHelper() {
@Test
fun `when processing bit columns should result in binary data in BIT(2) column`() {
-
withHandler { handler ->
val create = """CREATE TEMP TABLE binary_test
(
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ContainerHelper.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ContainerHelper.kt
index 1f2b583e2..a34e31c04 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ContainerHelper.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ContainerHelper.kt
@@ -2,7 +2,7 @@ package com.github.aysnc.sql.db.integration
import com.github.jasync.sql.db.Configuration
import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import org.testcontainers.containers.BindMode
import org.testcontainers.containers.PostgreSQLContainer
import java.util.concurrent.TimeUnit
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/DatabaseTestHelper.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/DatabaseTestHelper.kt
index 2c24b834f..8e8688b10 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/DatabaseTestHelper.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/DatabaseTestHelper.kt
@@ -38,7 +38,6 @@ open class DatabaseTestHelper {
}
fun withHandler(configuration: Configuration, fn: (PostgreSQLConnection) -> T): T {
-
val handler = PostgreSQLConnection(configuration)
try {
@@ -65,7 +64,6 @@ open class DatabaseTestHelper {
try {
return fn()
} catch (e: TimeoutException) {
-
throw IllegalStateException("Timeout executing call from handler -> %s".format(handler))
}
}
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ListenNotifySpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ListenNotifySpec.kt
index 7972af4ef..4d5fceaf0 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ListenNotifySpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/ListenNotifySpec.kt
@@ -11,7 +11,6 @@ class ListenNotifySpec : DatabaseTestHelper() {
@Test
fun `connection should be able to receive a notification if listening`() {
-
withHandler { connection ->
val queue = generateQueueName()
@@ -39,7 +38,6 @@ class ListenNotifySpec : DatabaseTestHelper() {
@Test
fun `connection should be able to receive a notification from a pg_notify call`() {
-
withHandler { connection ->
val queue = generateQueueName()
@@ -64,7 +62,6 @@ class ListenNotifySpec : DatabaseTestHelper() {
@Test
fun `connection should not receive any notification if not registered to the correct channel`() {
-
withHandler { connection ->
val queue = generateQueueName()
@@ -91,7 +88,6 @@ class ListenNotifySpec : DatabaseTestHelper() {
@Test
fun `connection should not receive notifications if cleared the collection`() {
-
withHandler { connection ->
val queue = generateQueueName()
@@ -118,7 +114,6 @@ class ListenNotifySpec : DatabaseTestHelper() {
@Test
fun `connection should not receive notification if listener was removed`() {
-
withHandler { connection ->
val queue = generateQueueName()
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/NumericSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/NumericSpec.kt
index cbdb7d98f..27ae1be51 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/NumericSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/NumericSpec.kt
@@ -9,7 +9,6 @@ class NumericSpec : DatabaseTestHelper() {
@Test
fun `when processing numeric columns should support first update of num column with floating`() {
-
withHandler { handler ->
executeDdl(handler, "CREATE TEMP TABLE numeric_test (id BIGSERIAL, numcol NUMERIC)")
@@ -28,7 +27,6 @@ class NumericSpec : DatabaseTestHelper() {
@Ignore("this test fail since always, see https://github.com/jasync-sql/jasync-sql/issues/15 and https://github.com/mauricio/postgresql-async/blob/b96aaf163e6ce757e722e95763a9dbc6f90211d5/postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/NumericSpec.scala")
@Test
fun `when processing numeric columns should support first update of num column with integer`() {
-
withHandler { handler ->
executeDdl(handler, "CREATE TEMP TABLE numeric_test (id BIGSERIAL, numcol NUMERIC)")
@@ -45,7 +43,6 @@ class NumericSpec : DatabaseTestHelper() {
@Test
fun `when processing numeric columns should support using first update with queries instead of prepared statements`() {
-
withHandler { handler ->
executeDdl(handler, "CREATE TEMP TABLE numeric_test (id BIGSERIAL, numcol NUMERIC)")
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PostgreSQLConnectionSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PostgreSQLConnectionSpec.kt
index 13c0e78af..a181f2e94 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PostgreSQLConnectionSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PostgreSQLConnectionSpec.kt
@@ -128,7 +128,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `connect should return with timeout exception after create timeout`() {
-
class PostgreSQLSlowConnectionDelegate(
private val delegate: PostgreSQLConnectionDelegate,
private val onReadyForQuerySlowdownInMillis: Int
@@ -157,7 +156,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should connect to the database`() {
-
withHandler { handler ->
assertThat(handler.isReadyForQuery()).isTrue()
}
@@ -165,7 +163,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should create a table in the database`() {
-
withHandler { handler ->
assertThat(executeDdl(handler, this.create)).isEqualTo(0)
}
@@ -173,7 +170,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should insert a row in the database`() {
-
withHandler { handler ->
executeDdl(handler, this.create)
assertThat(executeDdl(handler, this.insert, 1)).isEqualTo(1)
@@ -182,7 +178,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should select rows in the database`() {
-
withHandler { handler ->
executeDdl(handler, this.create)
executeDdl(handler, this.insert, 1)
@@ -208,7 +203,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should select rows that has duplicate column names`() {
-
withHandler { handler ->
val result = executeQuery(handler, "SELECT 1 COL, 2 COL")
@@ -221,7 +215,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should execute a prepared statement`() {
-
withHandler { handler ->
executeDdl(handler, this.preparedStatementCreate)
executeDdl(handler, this.preparedStatementInsert, 1)
@@ -236,7 +229,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should execute a prepared statement , parameters`() {
-
withHandler { handler ->
executeDdl(handler, this.preparedStatementCreate)
executeDdl(handler, this.preparedStatementInsert, 1)
@@ -261,7 +253,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should transaction and flatmap example`() {
-
val handler: Connection = PostgreSQLConnection(defaultConfiguration)
val result: CompletableFuture = handler.connect()
.mapAsync(ExecutorServiceUtils.CommonPool) { handler }
@@ -278,7 +269,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should use RETURNING in an insert statement`() {
-
withHandler { connection ->
executeDdl(connection, this.preparedStatementCreate)
val result = executeQuery(connection, this.preparedStatementInsertReturning)
@@ -288,7 +278,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should execute a prepared statement , limit`() {
-
withHandler { handler ->
executeDdl(handler, this.preparedStatementCreate)
executeDdl(handler, this.preparedStatementInsert, 1)
@@ -304,10 +293,8 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should execute an empty query`() {
-
withHandler { handler ->
verifyException(QueryMustNotBeNullOrEmptyException::class.java) {
-
assertThat(executeQuery(handler, "").rows).isNull()
}
}
@@ -315,7 +302,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should execute an whitespace query`() {
-
withHandler { handler ->
verifyException(ExecutionException::class.java, QueryMustNotBeNullOrEmptyException::class.java) {
assertThat(executeQuery(handler, " ").rows).isNull()
@@ -335,7 +321,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should load data from a bytea column`() {
-
val create = """create temp table file_samples (
id bigserial not null,
content bytea not null,
@@ -384,7 +369,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should insert a LocalDateTime`() {
-
withHandler { handler ->
executePreparedStatement(handler, "CREATE TEMP TABLE test(t TIMESTAMP)")
val date1 = LocalDateTime.now()
@@ -397,7 +381,6 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
@Test
fun `handler should insert ,out return after select`() {
-
withHandler { handler ->
executeDdl(handler, this.preparedStatementCreate)
executeDdl(handler, this.preparedStatementInsert, 1)
@@ -419,7 +402,7 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
applicationName = "jasync_test"
)
withHandler(configuration) {
- handler ->
+ handler ->
val result = executeQuery(handler, "SELECT application_name FROM pg_stat_activity WHERE pid = pg_backend_pid()")
val name = result.rows[0].getString(0)
assertThat(name).isEqualTo("jasync_test")
@@ -440,7 +423,7 @@ class PostgreSQLConnectionSpec : DatabaseTestHelper() {
interceptors = listOf(Supplier { interceptor }, mdcInterceptor)
)
withHandler(configuration) {
- handler ->
+ handler ->
handler.sendQuery("SELECT application_name FROM pg_stat_activity WHERE pid = pg_backend_pid()")
.map { assertThat(MDC.get("a")).isEqualTo("b") }
.get(5, TimeUnit.SECONDS)
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PostgreSQLPoolConfigurationSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PostgreSQLPoolConfigurationSpec.kt
index 2e87c3694..fe9cb6171 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PostgreSQLPoolConfigurationSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PostgreSQLPoolConfigurationSpec.kt
@@ -28,7 +28,6 @@ class PostgreSQLPoolConfigurationSpec : DatabaseTestHelper() {
@Test
fun `handler should create a table in the database with connection pool`() {
-
withPoolConfigurationConnectionConnection { handler ->
assertThat(executeDdl(handler, this.create)).isEqualTo(0)
}
@@ -54,7 +53,6 @@ class PostgreSQLPoolConfigurationSpec : DatabaseTestHelper() {
@Test
fun `handler should create a table in the database with connection pool builder`() {
-
withPoolConfigurationConnectionBuilderConnection { handler ->
assertThat(executeDdl(handler, this.create)).isEqualTo(0)
}
@@ -78,7 +76,6 @@ class PostgreSQLPoolConfigurationSpec : DatabaseTestHelper() {
@Test
fun `handler should create a table in the database with connection pool parsed from url`() {
-
withPoolUrlConfigurationConnection { handler ->
assertThat(executeDdl(handler, this.create)).isEqualTo(0)
}
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PreparedStatementSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PreparedStatementSpec.kt
index 966074a85..051b6933b 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PreparedStatementSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/PreparedStatementSpec.kt
@@ -66,7 +66,6 @@ class PreparedStatementSpec : DatabaseTestHelper() {
@Test
fun `prepared statements should execute a prepared statement without any parameters multiple times`() {
-
withHandler { handler ->
executeDdl(handler, this.messagesCreate)
executePreparedStatement(handler, "UPDATE messages SET content = content")
@@ -76,10 +75,9 @@ class PreparedStatementSpec : DatabaseTestHelper() {
@Test
fun `prepared statements should raise an exception if the parameter count is different from the given parameters count`() {
-
withHandler { handler ->
executeDdl(handler, this.messagesCreate)
- verifyException(InsufficientParametersException::class.java) {
+ verifyException(InsufficientParametersException::class.java, containedInMessage = this.messagesSelectOne) {
executePreparedStatement(handler, this.messagesSelectOne)
}
}
@@ -87,7 +85,6 @@ class PreparedStatementSpec : DatabaseTestHelper() {
@Test
fun `prepared statements should run two different prepared statements in sequence and get the right values`() {
-
val create = """CREATE TEMP TABLE other_messages
(
id bigserial NOT NULL,
@@ -212,7 +209,6 @@ class PreparedStatementSpec : DatabaseTestHelper() {
@Test
fun `prepared statements should support handling of enum types`() {
-
withHandler { handler ->
val create = """CREATE TEMP TABLE messages
|(
@@ -237,7 +233,6 @@ class PreparedStatementSpec : DatabaseTestHelper() {
@Test
fun `prepared statements should support handling JSON type`() {
-
withHandler { handler ->
val create = """create temp table people
|(
@@ -273,9 +268,10 @@ class PreparedStatementSpec : DatabaseTestHelper() {
fun `prepared statements should fail if prepared statement has more variables than it was given`() {
withHandler { handler ->
executeDdl(handler, messagesCreate)
- verifyException(InsufficientParametersException::class.java) {
+ val query = "SELECT * FROM messages WHERE content = ? AND moment = ?"
+ verifyException(InsufficientParametersException::class.java, containedInMessage = query) {
handler.sendPreparedStatement(
- "SELECT * FROM messages WHERE content = ? AND moment = ?",
+ query,
listOf("some content")
)
}
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/TimeAndDateSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/TimeAndDateSpec.kt
index 9d37e81a2..ea8d4f260 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/TimeAndDateSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/TimeAndDateSpec.kt
@@ -20,7 +20,6 @@ class TimeAndDateSpec : DatabaseTestHelper() {
@Test
fun `when processing times and dates should support a time object`() {
-
withHandler { handler ->
val create = """CREATE TEMP TABLE messages
(
@@ -44,7 +43,6 @@ class TimeAndDateSpec : DatabaseTestHelper() {
@Test
fun `when processing times and dates should support a time object, microseconds`() {
-
withHandler { handler ->
val create = """CREATE TEMP TABLE messages
(
@@ -74,7 +72,6 @@ class TimeAndDateSpec : DatabaseTestHelper() {
@Ignore("need to find a way to implement this")
@Test
fun `when processing times and dates should support a time with timezone object`() {
-
withHandler { handler ->
val create = """CREATE TEMP TABLE messages
(
@@ -123,7 +120,6 @@ class TimeAndDateSpec : DatabaseTestHelper() {
@Test
fun `when processing times and dates should support timestamp with timezone and microseconds`() {
-
(1 until 6).forEach { index ->
withHandler { handler ->
@@ -183,7 +179,6 @@ class TimeAndDateSpec : DatabaseTestHelper() {
@Test
fun `when processing times and dates should handle sending a time with timezone and return a LocalDateTime for a timestamp without timezone column`() {
-
withHandler { conn ->
val date = OffsetDateTime.ofInstant(Instant.ofEpochMilli(2190319), ZoneOffset.UTC)
@@ -197,7 +192,6 @@ class TimeAndDateSpec : DatabaseTestHelper() {
@Test
fun `when processing times and dates should supports sending a local date and later a date time object for the same field`() {
-
withHandler { conn ->
val date = OffsetDateTime.of(2016, 3, 5, 0, 0, 0, 0, ZoneOffset.UTC)
@@ -214,7 +208,6 @@ class TimeAndDateSpec : DatabaseTestHelper() {
@Test
fun `when processing times and dates should handle sending a LocalDateTime and return a LocalDateTime for a timestamp without timezone column`() {
-
withHandler { conn ->
val date1 = LocalDateTime.ofInstant(Instant.ofEpochMilli(2190319), ZoneOffset.UTC)
@@ -229,7 +222,6 @@ class TimeAndDateSpec : DatabaseTestHelper() {
@Test
fun `when processing times and dates should handle sending a date with timezone and retrieving the date , the same time zone`() {
-
withHandler { conn ->
val date1 = OffsetDateTime.ofInstant(Instant.ofEpochMilli(2190319), ZoneOffset.UTC)
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/ActorAsyncObjectPoolSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/ActorAsyncObjectPoolSpec.kt
index 92b62fd46..b0d8abe3e 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/ActorAsyncObjectPoolSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/ActorAsyncObjectPoolSpec.kt
@@ -24,7 +24,6 @@ class ActorAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should give me a valid object when I ask for one`() {
-
withPool { pool ->
val connection = get(pool)
val result = executeTest(connection)
@@ -35,7 +34,6 @@ class ActorAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should enqueue an action if the pool is full`() {
-
withPool(1, 3) { pool ->
val connection = get(pool)
@@ -76,7 +74,6 @@ class ActorAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should exhaust the pool`() {
-
withPool(1, 1) { pool ->
(1..2).forEach { _ ->
pool.take()
@@ -89,7 +86,6 @@ class ActorAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should it should remove idle connections once the time limit has been reached`() {
-
withPool(validationInterval = 1000) { pool ->
val connections = (1..5).map { _ ->
val connection = get(pool)
@@ -109,7 +105,6 @@ class ActorAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should it should remove aged out connections once the time limit has been reached`() {
-
withPool(validationInterval = 1000, maxTtl = 1000) { pool ->
val connections = (1..5).map { _ ->
val connection = get(pool)
@@ -128,7 +123,6 @@ class ActorAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should it should validate returned connections before sending them back to the pool`() {
-
withPool { pool ->
val connection = get(pool)
awaitFuture(connection.disconnect())
@@ -146,7 +140,6 @@ class ActorAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should it should not accept returned connections that aren't ready for query`() {
-
withPool { pool ->
val connection = get(pool)
connection.sendPreparedStatement("SELECT pg_sleep(3)")
@@ -167,7 +160,6 @@ class ActorAsyncObjectPoolSpec : DatabaseTestHelper() {
maxTtl: Long = -1,
fn: (ActorBasedObjectPool) -> T
): T {
-
val poolConfiguration = PoolConfiguration(
maxIdle = maxTtl,
maxObjects = maxObjects,
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/NextGenConnectionPoolSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/NextGenConnectionPoolSpec.kt
index aa04c0486..1effcf5a4 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/NextGenConnectionPoolSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/NextGenConnectionPoolSpec.kt
@@ -17,7 +17,6 @@ class NextGenConnectionPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should give you a connection when sending statements`() {
-
withPool { pool ->
assertThat(executeQuery(pool, "SELECT 8").rows.get(0)(0)).isEqualTo(8)
Thread.sleep(1000)
@@ -43,7 +42,6 @@ class NextGenConnectionPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should runs commands for a transaction in a single connection`() {
-
val id = UUID.randomUUID().toString()
withPool { pool ->
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/PoolHelper.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/PoolHelper.kt
index 2db11a890..e27bee9fe 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/PoolHelper.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/PoolHelper.kt
@@ -31,7 +31,6 @@ fun withPool(
validationInterval: Long = 3000,
fn: (ConnectionPool) -> T
): T {
-
val poolConfiguration = ConnectionPoolConfiguration(
host = ContainerHelper.defaultConfiguration.host,
port = ContainerHelper.defaultConfiguration.port,
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/SingleThreadedAsyncObjectPoolSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/SingleThreadedAsyncObjectPoolSpec.kt
index d9827bbd1..b51b016a9 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/SingleThreadedAsyncObjectPoolSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/integration/pool/SingleThreadedAsyncObjectPoolSpec.kt
@@ -22,7 +22,6 @@ class SingleThreadedAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should give me a valid object when I ask for one`() {
-
withPool { pool ->
val connection = get(pool)
val result = executeTest(connection)
@@ -33,7 +32,6 @@ class SingleThreadedAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should enqueue an action if the pool is full`() {
-
withPool(1, 3) { pool ->
val connection = get(pool)
@@ -77,7 +75,6 @@ class SingleThreadedAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should exhaust the pool`() {
-
withPool(1, 1) { pool ->
(1..2).forEach { _ ->
pool.take()
@@ -90,7 +87,6 @@ class SingleThreadedAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should it should remove idle connections once the time limit has been reached`() {
-
withPool(validationInterval = 1000) { pool ->
val connections = (1..5).map { _ ->
val connection = get(pool)
@@ -110,7 +106,6 @@ class SingleThreadedAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should it should validate returned connections before sending them back to the pool`() {
-
withPool { pool ->
val connection = get(pool)
awaitFuture(connection.disconnect())
@@ -128,7 +123,6 @@ class SingleThreadedAsyncObjectPoolSpec : DatabaseTestHelper() {
@Test
fun `pool should it should not accept returned connections that aren't ready for query`() {
-
withPool { pool ->
val connection = get(pool)
connection.sendPreparedStatement("SELECT pg_sleep(3)")
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/MessageDecoderSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/MessageDecoderSpec.kt
index 42133ce6a..6c803b58f 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/MessageDecoderSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/MessageDecoderSpec.kt
@@ -19,7 +19,6 @@ class MessageDecoderSpec {
@Test
fun `message decoder should not try to decode if there is not enough data available`() {
-
val buffer = Unpooled.buffer()
buffer.writeByte('R'.toInt())
@@ -33,7 +32,6 @@ class MessageDecoderSpec {
@Test
fun `should not try to decode if there is a type and length but it is not long enough`() {
-
val buffer = Unpooled.buffer()
buffer.writeByte('R'.toInt())
@@ -47,7 +45,6 @@ class MessageDecoderSpec {
@Test
fun `should correctly decode a message`() {
-
val buffer = Unpooled.buffer()
val text = "This is an error message"
val textBytes = text.toByteArray(CharsetUtil.UTF_8)
@@ -77,7 +74,6 @@ class MessageDecoderSpec {
@Test(expected = MessageTooLongException::class)
fun `should raise an exception if the length is too big`() {
-
val buffer = Unpooled.buffer()
buffer.writeByte(ServerMessage.Close)
buffer.writeInt(MessageDecoder_DefaultMaximumSize + 10)
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/PostgreSQLColumnEncoderRegistrySpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/PostgreSQLColumnEncoderRegistrySpec.kt
index cb229f122..c43a8230e 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/PostgreSQLColumnEncoderRegistrySpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/PostgreSQLColumnEncoderRegistrySpec.kt
@@ -10,7 +10,6 @@ class PostgreSQLColumnEncoderRegistrySpec {
@Test
fun `column encoder registry should encode Some(value) like value`() {
-
val actual = encoder.encode(1L)
val expected = encoder.encode(1L)
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/column/ArrayDecoderSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/column/ArrayDecoderSpec.kt
index 3757cecee..e885fea9b 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/column/ArrayDecoderSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/column/ArrayDecoderSpec.kt
@@ -18,7 +18,6 @@ class ArrayDecoderSpec {
@Test
fun `encoder decoder should parse an array of numbers`() {
-
assertThat(execute("{1,2,3}")).isEqualTo(listOf(1, 2, 3))
}
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/column/ByteArrayDecoderSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/column/ByteArrayDecoderSpec.kt
index 18f43ddfe..b820145c0 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/column/ByteArrayDecoderSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/column/ByteArrayDecoderSpec.kt
@@ -41,7 +41,6 @@ class ByteArrayDecoderSpec {
@Test
fun `decoder should parse escape data`() {
-
assertThat(ByteArrayEncoderDecoder.decode(escapeTestData)).isEqualTo(originalData)
}
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/encoders/ExecutePreparedStatementEncoderSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/encoders/ExecutePreparedStatementEncoderSpec.kt
index 9a8a2d279..67cf8725e 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/encoders/ExecutePreparedStatementEncoderSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/encoders/ExecutePreparedStatementEncoderSpec.kt
@@ -200,7 +200,6 @@ class ExecutePreparedStatementEncoderSpec {
@Test
fun `encoder should correctly handle the case where an encoder returns null`() {
-
val uuid = UUID.fromString("3edfe88f-f0d0-46bc-8580-053b9e8af6c5")
val message = PreparedStatementExecuteMessage(uuid, "select * from users", listOf(null), registry)
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserESpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserESpec.kt
index 06becd6ba..85e6456db 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserESpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserESpec.kt
@@ -12,7 +12,6 @@ class ParserESpec {
@Test
fun `ErrorParser should correctly parse an error message`() {
-
val content = "this is my error message"
val error = content.toByteArray(CharsetUtil.UTF_8)
val buffer = Unpooled.buffer()
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserKSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserKSpec.kt
index d6b6ff7cc..d60801685 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserKSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserKSpec.kt
@@ -13,7 +13,6 @@ class ParserKSpec {
@Test
fun `parserk should correctly parse the message`() {
-
val buffer = Unpooled.buffer()
buffer.writeInt(10)
buffer.writeInt(20)
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserSSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserSSpec.kt
index 33774a8c0..b95e9b4b6 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserSSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/parsers/ParserSSpec.kt
@@ -15,7 +15,6 @@ class ParserSSpec {
@Test
fun `ParameterStatusParser should correctly parse a config pair`() {
-
val key = "application-name"
val value = "my-cool-application"
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/util/ArrayStreamingParserSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/util/ArrayStreamingParserSpec.kt
index f312ef419..d95a96cfe 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/util/ArrayStreamingParserSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/util/ArrayStreamingParserSpec.kt
@@ -11,7 +11,6 @@ class ArrayStreamingParserSpec {
@Test
fun `parser should generate the events correctly`() {
-
val content = "{{1,2,3},{4,5,6}}"
val delegate = LoggingDelegate()
diff --git a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/util/PasswordHelperSpec.kt b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/util/PasswordHelperSpec.kt
index 1ab8b536e..05d86e897 100644
--- a/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/util/PasswordHelperSpec.kt
+++ b/postgresql-async/src/test/java/com/github/aysnc/sql/db/postgresql/util/PasswordHelperSpec.kt
@@ -52,7 +52,6 @@ class PasswordHelperSpec {
@Test
fun `helper should generate the same value as the PostgreSQL code`() {
-
val username = "jasync"
val password = "example"
diff --git a/r2dbc-mysql/build.gradle.kts b/r2dbc-mysql/build.gradle.kts
index edd62ff2b..2ee44e9e9 100644
--- a/r2dbc-mysql/build.gradle.kts
+++ b/r2dbc-mysql/build.gradle.kts
@@ -15,26 +15,27 @@ val LOGBACK_VERSION: String by project
val TEST_CONTAINERS_VERSION: String by project
val MYSQL_CONNECTOR_VERSION: String by project
val AWAITILITY_VERSION: String by project
+val REACTOR_KOTLIN_EXTENSION: String by project
repositories {
mavenCentral()
}
dependencies {
- compile(project(":db-async-common"))
- compile(project(":pool-async"))
- compile(project(":mysql-async"))
- compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION")
- compile("org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION")
- compile("io.r2dbc:r2dbc-spi:$R2DBC_SPI_VERSION")
+ api(project(":db-async-common"))
+ api(project(":pool-async"))
+ api(project(":mysql-async"))
+ api("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION")
+ api("org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION")
+ api("io.r2dbc:r2dbc-spi:$R2DBC_SPI_VERSION")
implementation("io.projectreactor:reactor-core:$REACTOR_CORE_VERSION")
- implementation("io.projectreactor.kotlin:reactor-kotlin-extensions:1.1.7")
- compile("org.slf4j:slf4j-api:$SL4J_VERSION")
- compile("joda-time:joda-time:$JODA_VERSION")
- compile("org.joda:joda-convert:$JODA_CONVERT_VERSION")
- compile("io.netty:netty-transport:$NETTY_VERSION")
- compile("io.netty:netty-handler:$NETTY_VERSION")
- compile("io.github.microutils:kotlin-logging:$KOTLIN_LOGGING_VERSION")
+ implementation("io.projectreactor.kotlin:reactor-kotlin-extensions:$REACTOR_KOTLIN_EXTENSION")
+ api("org.slf4j:slf4j-api:$SL4J_VERSION")
+ api("joda-time:joda-time:$JODA_VERSION")
+ api("org.joda:joda-convert:$JODA_CONVERT_VERSION")
+ api("io.netty:netty-transport:$NETTY_VERSION")
+ api("io.netty:netty-handler:$NETTY_VERSION")
+ api("io.github.oshai:kotlin-logging-jvm:$KOTLIN_LOGGING_VERSION")
testImplementation("org.springframework.data:spring-data-r2dbc:1.5.6")
testImplementation("io.r2dbc:r2dbc-pool:1.0.0.RELEASE")
testImplementation("junit:junit:$JUNIT_VERSION")
diff --git a/r2dbc-mysql/src/main/java/JasyncClientConnection.kt b/r2dbc-mysql/src/main/java/JasyncClientConnection.kt
index 112a2342e..901821e5a 100644
--- a/r2dbc-mysql/src/main/java/JasyncClientConnection.kt
+++ b/r2dbc-mysql/src/main/java/JasyncClientConnection.kt
@@ -43,8 +43,6 @@ class JasyncClientConnection(
override fun beginTransaction(definition: TransactionDefinition): Publisher {
return Mono.defer {
- val setAutoCommit = Mono.from(setAutoCommit(false))
-
val setLockWaitTimeout = Mono.justOrEmpty(definition.getAttribute(TransactionDefinition.LOCK_WAIT_TIMEOUT))
.flatMap { timeout -> Mono.from(setLockWaitTimeout(timeout)) }
@@ -53,8 +51,7 @@ class JasyncClientConnection(
val startTransaction = Mono.from(beginTransaction())
- return@defer Mono.from(setAutoCommit)
- .then(setLockWaitTimeout)
+ return@defer Mono.from(setLockWaitTimeout)
.then(changeIsolationLevel)
.then(startTransaction)
.then()
@@ -104,7 +101,7 @@ class JasyncClientConnection(
Mono.defer { (jasyncConnection as MySQLConnection).sendQueryAfterCurrent(query).toMono().then() }
override fun setTransactionIsolationLevel(isolationLevel: IsolationLevel): Publisher {
- return executeVoidAfterCurrent("SET TRANSACTION ISOLATION LEVEL ${isolationLevel.asSql()}")
+ return executeVoidAfterCurrent("SET SESSION TRANSACTION ISOLATION LEVEL ${isolationLevel.asSql()}")
.doOnSuccess { this.isolationLevel = isolationLevel }
}
diff --git a/r2dbc-mysql/src/main/java/JasyncMetadata.kt b/r2dbc-mysql/src/main/java/JasyncMetadata.kt
index e941474bd..3f6e5b25c 100644
--- a/r2dbc-mysql/src/main/java/JasyncMetadata.kt
+++ b/r2dbc-mysql/src/main/java/JasyncMetadata.kt
@@ -15,7 +15,8 @@ class JasyncMetadata(rows: ResultSet) : RowMetadata {
throw ArrayIndexOutOfBoundsException(
String
.format(
- "Column index %d is larger than the number of columns %d", index,
+ "Column index %d is larger than the number of columns %d",
+ index,
columnNames
.size
)
diff --git a/r2dbc-mysql/src/main/java/JasyncRow.kt b/r2dbc-mysql/src/main/java/JasyncRow.kt
index d272c9c0c..ba74c74a3 100644
--- a/r2dbc-mysql/src/main/java/JasyncRow.kt
+++ b/r2dbc-mysql/src/main/java/JasyncRow.kt
@@ -30,6 +30,14 @@ class JasyncRow(private val rowData: RowData, private val metadata: JasyncMetada
return when {
requestedType == Object::class.java -> value
requestedType == String::class.java -> value?.toString()
+ requestedType == java.lang.Boolean::class.java -> {
+ when (value) {
+ is Number -> value.toInt() != 0
+ is String -> value.toBoolean()
+ is Boolean -> value
+ else -> throw IllegalStateException("Cannot convert ${value?.javaClass?.simpleName} to Boolean")
+ }
+ }
value is Number -> {
when (requestedType) {
java.lang.Long::class.java -> value.toLong()
@@ -54,6 +62,12 @@ class JasyncRow(private val rowData: RowData, private val metadata: JasyncMetada
else -> throw IllegalStateException("unmatched requested type ${requestedType.simpleName}")
}
}
+ value is Boolean && requestedType.isPrimitive -> {
+ when (requestedType.name) {
+ "boolean" -> value
+ else -> throw IllegalStateException("Cannot convert Boolean to ${requestedType.name}")
+ }
+ }
value is LocalDateTime -> {
when (requestedType) {
LocalDate::class.java -> value.toLocalDate()
diff --git a/r2dbc-mysql/src/main/java/JasyncStatement.kt b/r2dbc-mysql/src/main/java/JasyncStatement.kt
index 647eb5c04..3e4074334 100644
--- a/r2dbc-mysql/src/main/java/JasyncStatement.kt
+++ b/r2dbc-mysql/src/main/java/JasyncStatement.kt
@@ -5,15 +5,17 @@ import com.github.jasync.sql.db.exceptions.InsufficientParametersException
import com.github.jasync.sql.db.mysql.MySQLQueryResult
import com.github.jasync.sql.db.mysql.exceptions.MySQLException
import com.github.jasync.sql.db.mysql.exceptions.MysqlErrors
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.r2dbc.spi.Parameter
import io.r2dbc.spi.R2dbcBadGrammarException
import io.r2dbc.spi.R2dbcDataIntegrityViolationException
+import io.r2dbc.spi.R2dbcNonTransientResourceException
import io.r2dbc.spi.R2dbcPermissionDeniedException
import io.r2dbc.spi.R2dbcRollbackException
import io.r2dbc.spi.R2dbcTimeoutException
+import io.r2dbc.spi.R2dbcTransientResourceException
import io.r2dbc.spi.Result
import io.r2dbc.spi.Statement
-import mu.KotlinLogging
import org.reactivestreams.Publisher
import reactor.core.publisher.Mono
import reactor.kotlin.core.publisher.onErrorMap
@@ -137,50 +139,117 @@ internal class JasyncStatement(private val clientSupplier: Supplier throwable
is MySQLException -> {
val errorMessage = throwable.errorMessage
- when {
- errorMessage.errorCode == MysqlErrors.ER_DBACCESS_DENIED_ERROR -> R2dbcPermissionDeniedException(
+ when (errorMessage.errorCode) {
+ MysqlErrors.ER_DBACCESS_DENIED_ERROR,
+ MysqlErrors.ER_ACCESS_DENIED_ERROR,
+ MysqlErrors.ER_KILL_DENIED_ERROR,
+ MysqlErrors.ER_TABLEACCESS_DENIED_ERROR,
+ MysqlErrors.ER_COLUMNACCESS_DENIED_ERROR,
+ MysqlErrors.ER_SPECIFIC_ACCESS_DENIED_ERROR,
+ MysqlErrors.ER_PROCACCESS_DENIED_ERROR,
+ MysqlErrors.ER_ACCESS_DENIED_NO_PASSWORD_ERROR,
+ MysqlErrors.ER_ACCESS_DENIED_CHANGE_USER_ERROR -> R2dbcPermissionDeniedException(
errorMessage.errorMessage,
errorMessage.sqlState,
errorMessage.errorCode,
throwable
)
-
- errorMessage.errorCode == MysqlErrors.ER_ACCESS_DENIED_ERROR -> R2dbcPermissionDeniedException(
+ MysqlErrors.ER_DUP_KEY,
+ MysqlErrors.ER_BAD_NULL_ERROR,
+ MysqlErrors.ER_DUP_ENTRY,
+ MysqlErrors.ER_DUP_UNIQUE,
+ MysqlErrors.ER_CANNOT_ADD_FOREIGN,
+ MysqlErrors.ER_NO_REFERENCED_ROW,
+ MysqlErrors.ER_ROW_IS_REFERENCED,
+ MysqlErrors.ER_NO_DEFAULT_FOR_FIELD,
+ MysqlErrors.ER_ROW_IS_REFERENCED_2,
+ MysqlErrors.ER_NO_REFERENCED_ROW_2,
+ MysqlErrors.ER_FOREIGN_DUPLICATE_KEY,
+ MysqlErrors.ER_DUP_UNKNOWN_IN_INDEX
+ -> R2dbcDataIntegrityViolationException(
errorMessage.errorMessage,
errorMessage.sqlState,
errorMessage.errorCode,
throwable
)
-
- errorMessage.errorCode == MysqlErrors.ER_DUP_ENTRY -> R2dbcDataIntegrityViolationException(
+ MysqlErrors.ER_TABLE_EXISTS_ERROR,
+ MysqlErrors.ER_BAD_TABLE_ERROR,
+ MysqlErrors.ER_BAD_FIELD_ERROR,
+ MysqlErrors.ER_PARSE_ERROR,
+ MysqlErrors.ER_ILLEGAL_REFERENCE,
+ MysqlErrors.ER_NO_SUCH_TABLE,
+ MysqlErrors.ER_SP_ALREADY_EXISTS,
+ MysqlErrors.ER_SP_DOES_NOT_EXIST,
+ MysqlErrors.ER_FUNC_INEXISTENT_NAME_COLLISION
+ -> R2dbcBadGrammarException(
errorMessage.errorMessage,
errorMessage.sqlState,
errorMessage.errorCode,
+ sql,
throwable
)
-
- errorMessage.errorCode == MysqlErrors.ER_PARSE_ERROR -> R2dbcBadGrammarException(
+ MysqlErrors.ER_LOCK_WAIT_TIMEOUT,
+ MysqlErrors.ER_QUERY_TIMEOUT,
+ 3024 -> R2dbcTimeoutException(
errorMessage.errorMessage,
errorMessage.sqlState,
errorMessage.errorCode,
- sql,
throwable
)
-
- errorMessage.errorCode == 3024 || errorMessage.errorCode == MysqlErrors.ER_QUERY_TIMEOUT -> R2dbcTimeoutException(
- errorMessage.errorMessage, errorMessage.sqlState, errorMessage.errorCode, throwable
- )
-
- errorMessage.errorCode == MysqlErrors.ER_XA_RBROLLBACK -> R2dbcRollbackException(
- errorMessage.errorMessage, errorMessage.sqlState, errorMessage.errorCode, throwable
+ MysqlErrors.ER_XA_RBROLLBACK,
+ MysqlErrors.ER_XA_RBTIMEOUT -> R2dbcRollbackException(
+ errorMessage.errorMessage,
+ errorMessage.sqlState,
+ errorMessage.errorCode,
+ throwable
)
-
- else -> JasyncDatabaseException(
+ MysqlErrors.ER_NET_READ_INTERRUPTED,
+ MysqlErrors.ER_NET_WRITE_INTERRUPTED,
+ MysqlErrors.ER_LOCK_DEADLOCK,
+ MysqlErrors.ER_QUERY_INTERRUPTED -> R2dbcTransientResourceException(
errorMessage.errorMessage,
errorMessage.sqlState,
errorMessage.errorCode,
throwable
)
+ else -> when (errorMessage.sqlState.take(2)) {
+ "0A", "22", "26", "2F", "20", "42", "XA" -> R2dbcBadGrammarException(
+ errorMessage.errorMessage,
+ errorMessage.sqlState,
+ errorMessage.errorCode,
+ throwable
+ )
+ "25", "28" -> R2dbcPermissionDeniedException(
+ errorMessage.errorMessage,
+ errorMessage.sqlState,
+ errorMessage.errorCode,
+ throwable
+ )
+ "21", "23" -> R2dbcDataIntegrityViolationException(
+ errorMessage.errorMessage,
+ errorMessage.sqlState,
+ errorMessage.errorCode,
+ throwable
+ )
+ "H1", "08" -> R2dbcNonTransientResourceException(
+ errorMessage.errorMessage,
+ errorMessage.sqlState,
+ errorMessage.errorCode,
+ throwable
+ )
+ "40" -> R2dbcRollbackException(
+ errorMessage.errorMessage,
+ errorMessage.sqlState,
+ errorMessage.errorCode,
+ throwable
+ )
+ else -> JasyncDatabaseException(
+ errorMessage.errorMessage,
+ errorMessage.sqlState,
+ errorMessage.errorCode,
+ throwable
+ )
+ }
}
}
diff --git a/r2dbc-mysql/src/main/java/MysqlConnectionFactoryProvider.kt b/r2dbc-mysql/src/main/java/MysqlConnectionFactoryProvider.kt
index 4c15da6ee..67f3a07fc 100644
--- a/r2dbc-mysql/src/main/java/MysqlConnectionFactoryProvider.kt
+++ b/r2dbc-mysql/src/main/java/MysqlConnectionFactoryProvider.kt
@@ -3,6 +3,7 @@ package com.github.jasync.r2dbc.mysql
import com.github.jasync.sql.db.Configuration
import com.github.jasync.sql.db.mysql.MySQLConnection.Companion.CLIENT_FOUND_ROWS_PROP_NAME
import com.github.jasync.sql.db.mysql.pool.MySQLConnectionFactory
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.r2dbc.spi.ConnectionFactoryOptions
import io.r2dbc.spi.ConnectionFactoryOptions.CONNECT_TIMEOUT
import io.r2dbc.spi.ConnectionFactoryOptions.DATABASE
@@ -14,7 +15,7 @@ import io.r2dbc.spi.ConnectionFactoryOptions.STATEMENT_TIMEOUT
import io.r2dbc.spi.ConnectionFactoryOptions.USER
import io.r2dbc.spi.ConnectionFactoryProvider
import io.r2dbc.spi.Option
-import mu.KotlinLogging
+import java.nio.file.Paths
import java.time.Duration
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
@@ -30,11 +31,19 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
@JvmField
val APPLICATION_NAME: Option = Option.valueOf("applicationName")
+ /**
+ * Server rsa public key file.
+ */
+ @JvmField
+ val SERVER_RSA_PUBLIC_KEY_FILE: Option = Option.valueOf("serverRSAPublicKeyFile")
+
/**
* Driver option value.
*/
const val MYSQL_DRIVER = "mysql"
+ const val MYSQL_DEFAULT_PORT = 3306
+
var CLIENT_FOUND_ROWS: Boolean by ClientFoundRowsDelegate()
init {
@@ -63,14 +72,15 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
override fun create(connectionFactoryOptions: ConnectionFactoryOptions): JasyncConnectionFactory {
val configuration = Configuration(
host = connectionFactoryOptions.getValue(HOST) as String? ?: throw IllegalArgumentException("HOST is missing"),
- port = connectionFactoryOptions.getValue(PORT) as Int? ?: throw IllegalArgumentException("PORT is missing"),
+ port = connectionFactoryOptions.getValue(PORT) as Int? ?: MYSQL_DEFAULT_PORT,
username = connectionFactoryOptions.getValue(USER) as String? ?: throw IllegalArgumentException("USER is missing"),
password = connectionFactoryOptions.getValue(PASSWORD)?.toString(),
database = connectionFactoryOptions.getValue(DATABASE) as String?,
applicationName = connectionFactoryOptions.getValue(APPLICATION_NAME) as String?,
- connectionTimeout = (connectionFactoryOptions.getValue(CONNECT_TIMEOUT) as Duration?)?.toMillis()?.toInt() ?: 5000,
- queryTimeout = connectionFactoryOptions.getValue(STATEMENT_TIMEOUT) as Duration?,
- ssl = MysqlSSLConfigurationFactory.create(connectionFactoryOptions)
+ connectionTimeout = connectionFactoryOptions.getValue(CONNECT_TIMEOUT)?.parseDuration()?.toMillis()?.toInt() ?: 5000,
+ queryTimeout = connectionFactoryOptions.getValue(STATEMENT_TIMEOUT)?.parseDuration(),
+ ssl = MysqlSSLConfigurationFactory.create(connectionFactoryOptions),
+ rsaPublicKey = (connectionFactoryOptions.getValue(SERVER_RSA_PUBLIC_KEY_FILE) as String?)?.let { Paths.get(it) }
)
return JasyncConnectionFactory(MySQLConnectionFactory(configuration))
}
@@ -80,7 +90,6 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
return when {
driver == null || driver != MYSQL_DRIVER -> false
!connectionFactoryOptions.hasOption(HOST) -> false
- !connectionFactoryOptions.hasOption(PORT) -> false
!connectionFactoryOptions.hasOption(USER) -> false
else -> true
}
@@ -88,3 +97,15 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
override fun getDriver(): String = MYSQL_DRIVER
}
+
+private fun Any.parseDuration(): Duration {
+ return when (this) {
+ is Duration -> {
+ this
+ }
+ is String -> {
+ Duration.parse(this)
+ }
+ else -> throw Exception("cant parse $this to Duration")
+ }
+}
diff --git a/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/JasyncRowTest.kt b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/JasyncRowTest.kt
new file mode 100644
index 000000000..44ecad31b
--- /dev/null
+++ b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/JasyncRowTest.kt
@@ -0,0 +1,55 @@
+package com.github.jasync.r2dbc.mysql
+
+import com.github.jasync.sql.db.RowData
+import io.mockk.every
+import io.mockk.mockk
+import org.junit.Test
+import kotlin.test.assertFalse
+import kotlin.test.assertTrue
+
+/**
+ * Unit tests for [JasyncRow].
+ */
+internal class JasyncRowTest {
+
+ @Test
+ fun testBooleanConversion() {
+ // Mock dependencies
+ val rowData = mockk()
+ val metadata = mockk()
+
+ // Setup mock values for different types of data
+ every { rowData["boolTrue"] } returns true
+ every { rowData["boolFalse"] } returns false
+ every { rowData["numZero"] } returns 0
+ every { rowData["numOne"] } returns 1
+ every { rowData["stringTrue"] } returns "true"
+ every { rowData["stringFalse"] } returns "false"
+ every { rowData[0] } returns true
+ every { rowData[1] } returns 0
+ every { rowData[2] } returns "true"
+
+ val row = JasyncRow(rowData, metadata)
+
+ // Test conversion from Boolean to Boolean
+ assertTrue(row.get("boolTrue", java.lang.Boolean::class.java) as Boolean)
+ assertFalse(row.get("boolFalse", java.lang.Boolean::class.java) as Boolean)
+
+ // Test conversion from Number to Boolean
+ assertFalse(row.get("numZero", java.lang.Boolean::class.java) as Boolean)
+ assertTrue(row.get("numOne", java.lang.Boolean::class.java) as Boolean)
+
+ // Test conversion from String to Boolean
+ assertTrue(row.get("stringTrue", java.lang.Boolean::class.java) as Boolean)
+ assertFalse(row.get("stringFalse", java.lang.Boolean::class.java) as Boolean)
+
+ // Test conversion from various types using index
+ assertTrue(row.get(0, java.lang.Boolean::class.java) as Boolean)
+ assertFalse(row.get(1, java.lang.Boolean::class.java) as Boolean)
+ assertTrue(row.get(2, java.lang.Boolean::class.java) as Boolean)
+
+ // Test conversion to primitive boolean - using Boolean class in Kotlin
+ assertTrue(row.get("boolTrue", java.lang.Boolean::class.java) as Boolean)
+ assertFalse(row.get("boolFalse", java.lang.Boolean::class.java) as Boolean)
+ }
+}
diff --git a/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/MysqlConnectionFactoryProviderTest.kt b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/MysqlConnectionFactoryProviderTest.kt
index f44e3dc1b..63753f6a1 100644
--- a/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/MysqlConnectionFactoryProviderTest.kt
+++ b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/MysqlConnectionFactoryProviderTest.kt
@@ -4,6 +4,7 @@ import com.github.jasync.sql.db.SSLConfiguration
import io.r2dbc.spi.ConnectionFactoryOptions
import org.junit.Assert.assertEquals
import org.junit.Test
+import java.time.Duration
class MysqlConnectionFactoryProviderTest {
@@ -11,9 +12,7 @@ class MysqlConnectionFactoryProviderTest {
@Test
fun shouldCreateMysqlConnectionWithMysqlSSLConfigurationFactory() {
-
- val options =
- ConnectionFactoryOptions.parse("r2dbc:mysql://user@host:443/")
+ val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host:443/")
// when
val result = provider.create(options)
@@ -21,4 +20,59 @@ class MysqlConnectionFactoryProviderTest {
// then
assertEquals(SSLConfiguration(), result.mySQLConnectionFactory.configuration.ssl)
}
+
+ @Test
+ fun shouldUseDefaultPortWhenPortIsNotSpecified() {
+ val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host/")
+
+ // when
+ val result = provider.create(options)
+
+ // then
+ assertEquals(3306, result.mySQLConnectionFactory.configuration.port)
+ }
+
+ @Test
+ fun shouldUseSpecifiedPort() {
+ val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host:3307/")
+
+ // when
+ val result = provider.create(options)
+
+ // then
+ assertEquals(3307, result.mySQLConnectionFactory.configuration.port)
+ }
+
+ @Test
+ fun shouldNotUseWhenRsaPublicKeyIsNotSpecified() {
+ val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host/")
+
+ // when
+ val result = provider.create(options)
+
+ // then
+ assertEquals(null, result.mySQLConnectionFactory.configuration.rsaPublicKey)
+ }
+
+ @Test
+ fun shouldUseSpecifiedRsaPublicKey() {
+ val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host/db?serverRSAPublicKeyFile=rsa.pem")
+
+ // when
+ val result = provider.create(options)
+
+ // then
+ assertEquals("rsa.pem", result.mySQLConnectionFactory.configuration.rsaPublicKey.toString())
+ }
+
+ @Test
+ fun shouldUseTimeoutAsString() {
+ val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host/db?connectTimeout=PT3S")
+
+ // when
+ val result = provider.create(options)
+
+ // then
+ assertEquals(Duration.parse("PT3S").toMillis().toInt(), result.mySQLConnectionFactory.configuration.connectionTimeout)
+ }
}
diff --git a/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/MysqlSSLConfigurationFactoryTest.kt b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/MysqlSSLConfigurationFactoryTest.kt
index 52d9cb747..af5a2b980 100644
--- a/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/MysqlSSLConfigurationFactoryTest.kt
+++ b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/MysqlSSLConfigurationFactoryTest.kt
@@ -95,7 +95,7 @@ internal class MysqlSSLConfigurationFactoryTest(
.build(),
expected = SSLConfiguration(mode = VerifyFull),
message = "sslMode should be 'verify_identity'"
- ),
+ )
)
private fun createTestParams(
diff --git a/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/JasyncR2dbcIntegTest.kt b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/JasyncR2dbcIntegTest.kt
index d591377aa..8a4dc7831 100644
--- a/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/JasyncR2dbcIntegTest.kt
+++ b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/JasyncR2dbcIntegTest.kt
@@ -4,12 +4,12 @@ import com.github.jasync.r2dbc.mysql.JasyncConnectionFactory
import com.github.jasync.sql.db.mysql.MySQLConnection
import com.github.jasync.sql.db.mysql.pool.MySQLConnectionFactory
import com.github.jasync.sql.db.util.FP
+import io.github.oshai.kotlinlogging.KotlinLogging
import io.mockk.mockk
import io.r2dbc.pool.ConnectionPoolConfiguration
import io.r2dbc.spi.Parameter
import io.r2dbc.spi.Result
import io.r2dbc.spi.Type
-import mu.KotlinLogging
import org.assertj.core.api.Assertions.assertThat
import org.awaitility.kotlin.await
import org.hamcrest.core.IsEqual
@@ -188,7 +188,7 @@ class JasyncR2dbcIntegTest : R2dbcConnectionHelper() {
"name",
"id",
"title",
- "user_id",
+ "user_id"
)
)
}
diff --git a/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/R2dbcConnectionHelper.kt b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/R2dbcConnectionHelper.kt
index 919edfdc3..3d2ae7905 100644
--- a/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/R2dbcConnectionHelper.kt
+++ b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/R2dbcConnectionHelper.kt
@@ -107,7 +107,6 @@ open class R2dbcConnectionHelper : R2dbcContainerHelper() {
}
fun withConfigurablePool(configuration: Configuration, f: (ConnectionPool) -> T): T {
-
val poolConfiguration = ConnectionPoolConfiguration(
host = configuration.host,
port = configuration.port,
diff --git a/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/R2dbcTransactionIntegrationTest.kt b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/R2dbcTransactionIntegrationTest.kt
index 62c4d81f1..08b19d898 100644
--- a/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/R2dbcTransactionIntegrationTest.kt
+++ b/r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/integ/R2dbcTransactionIntegrationTest.kt
@@ -179,7 +179,9 @@ class R2dbcTransactionIntegrationTest : R2dbcConnectionHelper() {
}
return if (TransactionDefinition.LOCK_WAIT_TIMEOUT == option && !this.lockWaitTimeout.isZero) {
this.lockWaitTimeout
- } else null
+ } else {
+ null
+ }
}
}
}
diff --git a/samples/ktor/build.gradle b/samples/ktor/build.gradle
index 3fbbe8587..2e0148f97 100644
--- a/samples/ktor/build.gradle
+++ b/samples/ktor/build.gradle
@@ -36,7 +36,7 @@ dependencies {
implementation "io.ktor:ktor-server-core:$ktor_version"
implementation "io.ktor:ktor-server-host-common:$ktor_version"
implementation "io.ktor:ktor-gson:$ktor_version"
- implementation "io.github.microutils:kotlin-logging:1.6.10"
+ implementation "io.github.oshai:kotlin-logging-jvm:1.6.10"
implementation 'com.github.jasync-sql:jasync-mysql:0.9.23'
testImplementation "io.ktor:ktor-server-tests:$ktor_version"
testImplementation "io.ktor:ktor-server-core:$ktor_version"
diff --git a/samples/ktor/src/application.kt b/samples/ktor/src/application.kt
index 3a89b97ab..fc0b4ba44 100644
--- a/samples/ktor/src/application.kt
+++ b/samples/ktor/src/application.kt
@@ -15,7 +15,7 @@ import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.ktor.util.pipeline.PipelineContext
import kotlinx.coroutines.future.await
-import mu.KotlinLogging
+import io.github.oshai.kotlinlogging.KotlinLogging
import java.util.concurrent.TimeUnit
diff --git a/samples/spring-kotlin/README.md b/samples/spring-kotlin/README.md
index d33398874..a599471a5 100644
--- a/samples/spring-kotlin/README.md
+++ b/samples/spring-kotlin/README.md
@@ -1,2 +1,2 @@
# spring-kotlin-jasync-sql
-reactive applcation base on Spring + Kotlin + [Jasync-sql](https://github.com/jasync-sql/jasync-sql)
+reactive application base on Spring + Kotlin + [Jasync-sql](https://github.com/jasync-sql/jasync-sql)
diff --git a/samples/spring-kotlin/build.gradle.kts b/samples/spring-kotlin/build.gradle.kts
index 365ca8791..852c3b94d 100644
--- a/samples/spring-kotlin/build.gradle.kts
+++ b/samples/spring-kotlin/build.gradle.kts
@@ -5,25 +5,30 @@ version = "1.0-SNAPSHOT"
plugins {
application
- kotlin("jvm") version "1.6.10"
- kotlin("plugin.spring") version "1.6.10"
- id("org.springframework.boot") version "2.6.3"
+ kotlin("jvm") version "1.9.25"
+ kotlin("plugin.spring") version "1.9.25"
+ id("org.springframework.boot") version "3.3.4"
+ id("io.spring.dependency-management") version "1.1.6"
}
-apply(plugin = "io.spring.dependency-management")
+java {
+ sourceCompatibility = JavaVersion.VERSION_17
+
+ toolchain {
+ languageVersion.set(JavaLanguageVersion.of(17))
+ }
+}
repositories {
mavenCentral()
}
dependencies {
- implementation(kotlin("stdlib-jdk8"))
- implementation(kotlin("reflect"))
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
implementation("org.springframework.boot:spring-boot-starter-webflux")
testImplementation("org.springframework.boot:spring-boot-starter-test")
- runtimeOnly("com.github.jasync-sql:jasync-r2dbc-mysql:2.0.6")
+ runtimeOnly("com.github.jasync-sql:jasync-r2dbc-mysql:2.2.4")
}
tasks.test {
@@ -32,7 +37,6 @@ tasks.test {
tasks.withType {
kotlinOptions {
- jvmTarget = "1.8"
+ jvmTarget = "17"
}
}
-
diff --git a/samples/spring-kotlin/gradle/wrapper/gradle-wrapper.properties b/samples/spring-kotlin/gradle/wrapper/gradle-wrapper.properties
index cc321e658..d26953aba 100644
--- a/samples/spring-kotlin/gradle/wrapper/gradle-wrapper.properties
+++ b/samples/spring-kotlin/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
diff --git a/samples/spring-kotlin/src/main/resources/schema.sql b/samples/spring-kotlin/src/main/resources/schema.sql
new file mode 100644
index 000000000..109fd860b
--- /dev/null
+++ b/samples/spring-kotlin/src/main/resources/schema.sql
@@ -0,0 +1,8 @@
+CREATE TABLE IF NOT EXISTS `user` (
+ `username` VARCHAR(20) NOT NULL,
+ `password` VARCHAR(100) NULL,
+ PRIMARY KEY (`username`)
+);
+
+INSERT INTO `user` (username, password) VALUES ('Bob', 'password1');
+INSERT INTO `user` (username, password) VALUES ('Alice', 'password2');