You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running a basic code to use test container for postgres I am getting an error constructing Hikari datasource. Looks like the code breaks on the second .configure() attempt here
packagecom.devraccoon.dataaccessimportcom.zaxxer.hikari.HikariDataSourceimportio.kotest.core.extensions.MountableExtensionimportio.kotest.core.extensions.installimportio.kotest.core.spec.style.DescribeSpecimportio.kotest.extensions.testcontainers.JdbcDatabaseContainerExtensionimportio.kotest.extensions.testcontainers.toDataSourceimportio.kotest.matchers.shouldBeimportorg.testcontainers.containers.JdbcDatabaseContainerimportorg.testcontainers.containers.PostgreSQLContainerimportjava.sql.SQLExceptionclassDatabaseAccessContainer : DescribeSpec({
val postgresSqlContainer = PostgreSQLContainer<Nothing>("postgres:15.3").apply {
withDatabaseName("test_db")
withUsername("sa")
withPassword("sa")
}
val ds = install(JdbcDatabaseContainerExtension(postgresSqlContainer)) {
poolName = "connection_pool_for_tests"
maximumPoolSize = 8
idleTimeout = 3000
}
describe("database access") {
it("should run a postgres test container") {
try {
val conn = ds.connection
val statement = conn.createStatement()
val resultSet = statement.executeQuery("SELECT 1 as DB;")
while (resultSet.next()) {
resultSet.getInt("DB") shouldBe 1
}
} catch (ex: SQLException) {
ex.printStackTrace()
}
}
}
})
The code works as expected if I use a custom extension class without the second .configure() call:
class NoSecondConfigureJdbcDatabaseContainerExtension(private val container: JdbcDatabaseContainer<*>) : MountableExtension<HikariDataSource, HikariDataSource> {
private var dataSource: HikariDataSource? = null
override fun mount(configure: HikariDataSource.() -> Unit): HikariDataSource {
if (!container.isRunning) {
container.start()
dataSource = container.toDataSource()
}
// dataSource?.configure()
return dataSource ?: error("Datasource not initialized")
}
}
...
val ds = install(NoSecondConfigureJdbcDatabaseContainerExtension(postgresSqlContainer)) {
poolName = "connection_pool_for_tests"
maximumPoolSize = 8
idleTimeout = 3000
}
...
Caused by: java.lang.IllegalStateException: The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes.
at com.zaxxer.hikari.HikariConfig.checkIfSealed(HikariConfig.java:1095)
at com.zaxxer.hikari.HikariConfig.setPoolName(HikariConfig.java:803)
at com.devraccoon.dataaccess.DatabaseAccessContainer$1$ds$1.invoke(DatabaseAccessContainer.kt:23)
at com.devraccoon.dataaccess.DatabaseAccessContainer$1$ds$1.invoke(DatabaseAccessContainer.kt:22)
at io.kotest.extensions.testcontainers.JdbcDatabaseContainerExtension.mount(JdbcDatabaseContainerExtension.kt:91)
at io.kotest.extensions.testcontainers.JdbcDatabaseContainerExtension.mount(JdbcDatabaseContainerExtension.kt:53)
at io.kotest.core.extensions.MountableExtensionKt.install(MountableExtension.kt:69)
at com.devraccoon.dataaccess.DatabaseAccessContainer$1.invoke(DatabaseAccessContainer.kt:22)
at com.devraccoon.dataaccess.DatabaseAccessContainer$1.invoke(DatabaseAccessContainer.kt:14)
at io.kotest.core.spec.style.DescribeSpec.<init>(describeSpec.kt:25)
at com.devraccoon.dataaccess.DatabaseAccessContainer.<init>(DatabaseAccessContainer.kt:14)
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
... 111 more
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Running a basic code to use test container for postgres I am getting an error constructing Hikari datasource. Looks like the code breaks on the second
.configure()
attempt hereThe code works as expected if I use a custom extension class without the second
.configure()
call:versions:
Error:
The text was updated successfully, but these errors were encountered: