Skip to content

Commit

Permalink
fix: add a workaround for testcontainers/testcontainers-java#6441
Browse files Browse the repository at this point in the history
  • Loading branch information
monosoul committed Oct 20, 2023
1 parent 3146995 commit 4a926c7
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import org.slf4j.LoggerFactory
import org.testcontainers.containers.JdbcDatabaseContainer
import org.testcontainers.containers.output.Slf4jLogConsumer
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy
import org.testcontainers.dockerclient.DockerClientProviderStrategy
import org.testcontainers.utility.DockerImageName
import java.sql.Driver
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.withLock
import kotlin.reflect.KCallable
import kotlin.reflect.full.declaredMembers
import kotlin.reflect.jvm.isAccessible

class GenericDatabaseContainer(
private val image: Image,
Expand All @@ -20,6 +25,19 @@ class GenericDatabaseContainer(
private val driverLoadLock = ReentrantLock()
private var driver: Driver? = null

/**
* Workaround for https://github.com/testcontainers/testcontainers-java/issues/6441
*/
private val failFastAlways = DockerClientProviderStrategy::class.declaredMembers
.single { it.name == "FAIL_FAST_ALWAYS" }
.apply { isAccessible = true }
.let {
@Suppress("UNCHECKED_CAST")
it as KCallable<AtomicBoolean>
}
.call()


init {
withLogConsumer(
Slf4jLogConsumer(
Expand Down Expand Up @@ -56,6 +74,11 @@ class GenericDatabaseContainer(
return driver!!
}

override fun start() {
failFastAlways.set(false)
super.start()
}

private fun getNewJdbcDriverInstance() = try {
@Suppress("DEPRECATION")
jdbcAwareClassLoader.loadClass(driverClassName).newInstance() as Driver
Expand Down

0 comments on commit 4a926c7

Please sign in to comment.