Skip to content

Commit

Permalink
maxPoolSize setting for MySQL config must by > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
geomagilles committed Dec 28, 2023
1 parent df94d29 commit cf195e0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ data class MySQL(
val user: String = "root",
val password: Secret? = null,
val database: String = "infinitic",
val maxPoolSize: Int = -1
val maxPoolSize: Int? = null
) {
init {
maxPoolSize?.let {
require(it > 0) { "maxPoolSize must by strictly positive" }
}
}

companion object {
val pools = ConcurrentHashMap<MySQL, HikariDataSource>()

Expand All @@ -58,9 +64,8 @@ data class MySQL(
driverClassName = "com.mysql.cj.jdbc.Driver"
username = user
password = this@MySQL.password?.value
maximumPoolSize = maxPoolSize
maxPoolSize?.let { maximumPoolSize = it }
},
)
.also { Runtime.getRuntime().addShutdownHook(Thread { it.close() }) }
).also { Runtime.getRuntime().addShutdownHook(Thread { it.close() }) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,65 +31,75 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain

class StorageConfigTests :
StringSpec({
"default storage should be inMemory" {
val config = loadConfigFromYaml<StorageConfigImpl>("nothing:")
StringSpec(
{
"default storage should be inMemory" {
val config = loadConfigFromYaml<StorageConfigImpl>("nothing:")

config shouldBe StorageConfigImpl(storage = Storage(inMemory = InMemory()))
}
config shouldBe StorageConfigImpl(storage = Storage(inMemory = InMemory()))
}

"default storage should not be compressed" {
val config = loadConfigFromYaml<StorageConfigImpl>("nothing:")
"default storage should not be compressed" {
val config = loadConfigFromYaml<StorageConfigImpl>("nothing:")

config shouldBe StorageConfigImpl(storage = Storage(compression = null))
}
config shouldBe StorageConfigImpl(storage = Storage(compression = null))
}

"storage without type should default" {
val default1 = loadConfigFromYaml<StorageConfigImpl>("nothing:")
val default2 = loadConfigFromYaml<StorageConfigImpl>("storage:")
"storage without type should default" {
val default1 = loadConfigFromYaml<StorageConfigImpl>("nothing:")
val default2 = loadConfigFromYaml<StorageConfigImpl>("storage:")

default1 shouldBe default2
}
default1 shouldBe default2
}

"can choose inMemory storage" {
val config = loadConfigFromYaml<StorageConfigImpl>("""
"can choose inMemory storage" {
val config = loadConfigFromYaml<StorageConfigImpl>(
"""
storage:
inMemory:
""")
""",
)

config shouldBe StorageConfigImpl(storage = Storage(inMemory = InMemory()))
}
config shouldBe StorageConfigImpl(storage = Storage(inMemory = InMemory()))
}

"can choose Redis storage" {
val config = loadConfigFromYaml<StorageConfigImpl>("""
"can choose Redis storage" {
val config = loadConfigFromYaml<StorageConfigImpl>(
"""
storage:
redis:
""")
""",
)

config shouldBe StorageConfigImpl(storage = Storage(redis = Redis()))
}
config shouldBe StorageConfigImpl(storage = Storage(redis = Redis()))
}

"can choose MySQL storage" {
val config = loadConfigFromYaml<StorageConfigImpl>("""
"can choose MySQL storage" {
val config = loadConfigFromYaml<StorageConfigImpl>(
"""
storage:
mysql:
""")
""",
)

config shouldBe StorageConfigImpl(storage = Storage(mysql = MySQL()))
}
config shouldBe StorageConfigImpl(storage = Storage(mysql = MySQL()))
}

"can not have multiple definition in storage" {
val e =
shouldThrow<ConfigException> {
loadConfigFromYaml<StorageConfigImpl>("""
"can not have multiple definition in storage" {
val e =
shouldThrow<ConfigException> {
loadConfigFromYaml<StorageConfigImpl>(
"""
storage:
redis:
mysql:
""")
}
e.message shouldContain ("Multiple definitions for storage")
}
})
""",
)
}
e.message shouldContain ("Multiple definitions for storage")
}
},
)

private inline fun <reified T : Any> loadConfigFromYaml(yaml: String): T =
ConfigLoaderBuilder.default()
Expand Down

0 comments on commit cf195e0

Please sign in to comment.