I am trying to execute the following containers, but I am finding an error because kafkaConnect is being started befor kafka, when kafka:9092 and when the kafka:9092 url is reached during the kafkaConnect execution no response is obtained since kafka is not running yet.
@Container
private final KafkaContainer kafka = new KafkaContainer()
.withNetwork(network)
.withNetworkAliases("kafka");
@Container
private final GenericContainer kafkaConnect = new GenericContainer("confluentinc/cp-kafka-connect:latest")
.withEnv("CONNECT_BOOTSTRAP_SERVERS", "kafka:9092")
.withEnv("CONNECT_REST_PORT", KAFKA_CONNECT_EXPOSED_PORT.toString())
.withEnv("CONNECT_GROUP_ID", "quickstart-avro")
.withEnv("CONNECT_CONFIG_STORAGE_TOPIC", "quickstart-avro-config")
.withEnv("CONNECT_OFFSET_STORAGE_TOPIC", "quickstart-avro-offsets")
.withEnv("CONNECT_STATUS_STORAGE_TOPIC", "quickstart-avro-status")
.withEnv("CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR", "1")
.withEnv("CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR", "1")
.withEnv("CONNECT_STATUS_STORAGE_REPLICATION_FACTOR", "1")
.withEnv("CONNECT_KEY_CONVERTER", "io.confluent.connect.avro.AvroConverter")
.withEnv("CONNECT_VALUE_CONVERTER", "io.confluent.connect.avro.AvroConverter")
.withEnv("CONNECT_KEY_CONVERTER_SCHEMA_REGISTRY_URL", "http://registry:8081/")
.withEnv("CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL", "http://registry:8081/")
.withEnv("CONNECT_INTERNAL_KEY_CONVERTER", "org.apache.kafka.connect.json.JsonConverter")
.withEnv("CONNECT_INTERNAL_VALUE_CONVERTER", "org.apache.kafka.connect.json.JsonConverter")
.withEnv("CONNECT_LOG4J_ROOT_LOGLEVEL", "INFO")
.withEnv("CONNECT_LOG4J_LOGGERS", "org.reflections=INFO,io.debezium.connector.mysql=INFO,io.debezium.connector.mysql.BinlogReader=INFO,io.debezium.relational.history=INFO")
.withEnv("CONNECT_PLUGIN_PATH", "/usr/share/java,/etc/kafka-connect/jars")
.withClasspathResourceMapping("dbzp/", "/etc/kafka-connect/jars/dbz", BindMode.READ_ONLY)
.withExposedPorts(KAFKA_CONNECT_EXPOSED_PORT)
.withNetwork(network)
// .withStartupTimeout(Duration.of(240, SECONDS))
;
I have tried to postponing the kafkaConnect starting using startupTimeout, but I couldn't because after reading documentation I understood this method just increases the period to check if the container is started.
I have found two temporal workarounds.
- Remove
@Container of kafkaConect, which allows to @TestContainer annotation to start kafka. Once kafka is running, this forces each test to execute kafkaConect.start(), which is a pain.
- Use compose. This would be a perfect solution but I found a little issue here. Kafka can not be used with a random bound port, as testContainer/issue-184.
Question
How can I ensure kafka will be executed before kafkaConnect?
I am using Java 8, JUnit:5.3.2 and Jupiter TestContainer:1.11.1
I am trying to execute the following containers, but I am finding an error because
kafkaConnectis being started beforkafka, whenkafka:9092and when thekafka:9092url is reached during thekafkaConnectexecution no response is obtained sincekafkais not running yet.I have tried to postponing the
kafkaConnectstarting usingstartupTimeout, but I couldn't because after reading documentation I understood this method just increases the period to check if the container is started.I have found two temporal workarounds.
@ContainerofkafkaConect, which allows to@TestContainerannotation to startkafka. Oncekafkais running, this forces each test to executekafkaConect.start(), which is a pain.Question
How can I ensure
kafkawill be executed beforekafkaConnect?I am using
Java 8,JUnit:5.3.2andJupiter TestContainer:1.11.1