Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -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";
Expand All @@ -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);
Expand Down
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());
}
Expand Down