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 6a792be
Showing 1 changed file with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@ 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,
private val database: Database.Internal,
private val jdbcAwareClassLoader: ClassLoader,
) : JdbcDatabaseContainer<GenericDatabaseContainer>(DockerImageName.parse(image.name)) {
private val image: Image,
private val database: Database.Internal,
private val jdbcAwareClassLoader: ClassLoader,
) : JdbcDatabaseContainer<GenericDatabaseContainer>(
image.let {
failFastAlways.set(false)
DockerImageName.parse(it.name)
}
) {

private val driverLoadLock = ReentrantLock()
private var driver: Driver? = null
Expand Down Expand Up @@ -67,4 +77,18 @@ class GenericDatabaseContainer(
else -> throw e
}
}

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

0 comments on commit 6a792be

Please sign in to comment.