Open loicgreffier opened 1 month ago
I think an easier way to reproduce it is to simply do this in a few lines.
var container = new KafkaContainer(DockerImageName
.parse("confluentinc/cp-kafka:7.6.1"))
.withKraft();
container.start();
container.stop();
container.start();
This is enough to reproduce the issue. I fixed it temporarily like this by removing CONTROLLER://0.0.0.0:9094
before start. But that's flimsy
var container = new KafkaContainer(DockerImageName
.parse("confluentinc/cp-kafka:7.6.1"))
.withKraft();
container.start();
container.stop();
container.withEnv("KAFKA_LISTENERS", "PLAINTEXT://0.0.0.0:9093,BROKER://0.0.0.0:9092");
container.start();
Module
Kafka
Testcontainers version
1.19.8
Using the latest Testcontainers version?
Yes
Host OS
Windows (WSL2)
Host Arch
x64
Docker version
What happened?
Declare a Kraft Kafka container in an abstract class
Declare at least two classes implementing
KraftIntegrationTest
so theKafkaContainer
runs at least twiceThe second container will not start and fail on
KAFKA_LISTENERS
containing multiple listeners with the same name.Relevant log output
Additional Information
The second container fails to start because:
java.lang.IllegalArgumentException: requirement failed: Each listener must have a different name, listeners: CONTROLLER://0.0.0.0:9094,PLAINTEXT://0.0.0.0:9093,BROKER://0.0.0.0:9092,CONTROLLER://0.0.0.0:9094
Not sure this can be described as an actual bug as it happens when the container is explicitly declared
static
in a parent class. It does not happen when the container is not static, or static but not running in Kraft mode.However, this is disrupting when the container has to be static, for example, when using it with Spring Boot Dynamic Property Sources which is a common use-case.
I think the issue is coming from there: https://github.com/testcontainers/testcontainers-java/blob/1f291eb5eca5f7ad3cd8461bfbac2605afd45585/modules/kafka/src/main/java/org/testcontainers/containers/KafkaContainer.java#L332 where current env vars are concatenated with
CONTROLLER://0.0.0.0:9094
each time a container starts.Maybe this could be improved by checking the content of the
KAFKA_LISTENERS
var env before concatenating.A code sample is available at https://github.com/loicgreffier/testcontainers-kraft-bug.