testcontainers-scala
testcontainers-scala copied to clipboard
Kafka container not waiting for full startup
Minimal test to reproduce the issue:
import com.dimafeng.testcontainers.{ForAllTestContainer, KafkaContainer}
import org.scalatest.flatspec.AnyFlatSpec
class KafkaExampleTest extends AnyFlatSpec with ForAllTestContainer {
override def container: KafkaContainer = KafkaContainer()
"Kafka container" should "be started" in {
container.bootstrapServers
}
}
This code throws
java.lang.IllegalStateException: You should start Kafka container first
at org.testcontainers.containers.KafkaContainer.getBootstrapServers(KafkaContainer.java:89)
at com.dimafeng.testcontainers.KafkaContainer.bootstrapServers(KafkaContainer.scala:25)
at links.kafka.KafkaExampleTest.$anonfun$new$1(KafkaExampleTest.scala:10)
It happens only with ForAllTestContainer trait. When using new TestContainerForAll from experimental API it works as expected. Tested on Ubuntu 18.04 and Docker Toolbox for Windows using testcontainsers-scala v0.38.4, same results.
Had a similar issue with Postgresql as linked by Mithunatri.
In my case changing override def container = PostgreSQLContainer() by an override val solved the problem (actually the examples use a val but IntelliJ overrides with a def by default).