Skip to content

Add support for Apache Kafka native image #8993

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -12,14 +12,16 @@
/**
* Testcontainers implementation for Apache Kafka.
* <p>
* Supported image: {@code apache/kafka}
* Supported image: {@code apache/kafka}, {@code apache/kafka-native}
* <p>
* Exposed ports: 9092
*/
public class KafkaContainer extends GenericContainer<KafkaContainer> {

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("apache/kafka");

private static final DockerImageName APACHE_KAFKA_NATIVE_IMAGE_NAME = DockerImageName.parse("apache/kafka-native");

private static final int KAFKA_PORT = 9092;

private static final String DEFAULT_INTERNAL_TOPIC_RF = "1";
@@ -34,7 +36,7 @@ public KafkaContainer(String imageName) {

public KafkaContainer(DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, APACHE_KAFKA_NATIVE_IMAGE_NAME);

withExposedPorts(KAFKA_PORT);
withEnv("CLUSTER_ID", DEFAULT_CLUSTER_ID);
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package org.testcontainers.kafka;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.testcontainers.AbstractKafka;

@RunWith(Parameterized.class)
public class KafkaContainerTest extends AbstractKafka {

@Parameterized.Parameters(name = "{0}")
public static String[] params() {
return new String[] { "apache/kafka:3.7.0", "apache/kafka-native:3.8.0-rc3" };
}

@Parameterized.Parameter
public String imageName;

@Test
public void testUsage() throws Exception {
try (KafkaContainer kafka = new KafkaContainer("apache/kafka:3.7.0")) {
try (KafkaContainer kafka = new KafkaContainer(imageName)) {
kafka.start();
testKafkaFunctionality(kafka.getBootstrapServers());
}
Loading