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
8 changes: 8 additions & 0 deletions modules/kafka/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ description = "Testcontainers :: Kafka"
dependencies {
api project(':testcontainers')

testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'

testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.13.4'
testImplementation 'org.apache.kafka:kafka-clients:3.8.0'
testImplementation 'org.assertj:assertj-core:3.27.4'
testImplementation 'com.google.guava:guava:23.0'
testImplementation 'org.awaitility:awaitility:4.3.0'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.apache.kafka.common.errors.SaslAuthenticationException;
import org.apache.kafka.common.errors.TopicAuthorizationException;
import org.awaitility.Awaitility;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.testcontainers.AbstractKafka;
import org.testcontainers.Testcontainers;
import org.testcontainers.images.builder.Transferable;
Expand All @@ -24,7 +24,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class KafkaContainerTest extends AbstractKafka {
class KafkaContainerTest extends AbstractKafka {

private static final DockerImageName KAFKA_TEST_IMAGE = DockerImageName.parse("confluentinc/cp-kafka:6.2.1");

Expand All @@ -35,15 +35,15 @@ public class KafkaContainerTest extends AbstractKafka {
);

@Test
public void testUsage() throws Exception {
void testUsage() throws Exception {
try (KafkaContainer kafka = new KafkaContainer(KAFKA_TEST_IMAGE)) {
kafka.start();
testKafkaFunctionality(kafka.getBootstrapServers());
}
}

@Test
public void testUsageWithSpecificImage() throws Exception {
void testUsageWithSpecificImage() throws Exception {
try (
// constructorWithVersion {
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1"))
Expand All @@ -59,15 +59,15 @@ public void testUsageWithSpecificImage() throws Exception {
}

@Test
public void testUsageWithVersion() throws Exception {
void testUsageWithVersion() throws Exception {
try (KafkaContainer kafka = new KafkaContainer("6.2.1")) {
kafka.start();
testKafkaFunctionality(kafka.getBootstrapServers());
}
}

@Test
public void testExternalZookeeperWithExternalNetwork() throws Exception {
void testExternalZookeeperWithExternalNetwork() throws Exception {
try (
Network network = Network.newNetwork();
// withExternalZookeeper {
Expand All @@ -89,23 +89,23 @@ public void testExternalZookeeperWithExternalNetwork() throws Exception {
}

@Test
public void testConfluentPlatformVersion7() throws Exception {
void testConfluentPlatformVersion7() throws Exception {
try (KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.2.2"))) {
kafka.start();
testKafkaFunctionality(kafka.getBootstrapServers());
}
}

@Test
public void testConfluentPlatformVersion5() throws Exception {
void testConfluentPlatformVersion5() throws Exception {
try (KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3"))) {
kafka.start();
testKafkaFunctionality(kafka.getBootstrapServers());
}
}

@Test
public void testWithHostExposedPort() throws Exception {
void testWithHostExposedPort() throws Exception {
Testcontainers.exposeHostPorts(12345);
try (KafkaContainer kafka = new KafkaContainer(KAFKA_TEST_IMAGE)) {
kafka.start();
Expand All @@ -114,7 +114,7 @@ public void testWithHostExposedPort() throws Exception {
}

@Test
public void testWithHostExposedPortAndExternalNetwork() throws Exception {
void testWithHostExposedPortAndExternalNetwork() throws Exception {
Testcontainers.exposeHostPorts(12345);
try (KafkaContainer kafka = new KafkaContainer(KAFKA_TEST_IMAGE).withNetwork(Network.newNetwork())) {
kafka.start();
Expand All @@ -123,7 +123,7 @@ public void testWithHostExposedPortAndExternalNetwork() throws Exception {
}

@Test
public void testUsageKraftBeforeConfluentPlatformVersion74() throws Exception {
void testUsageKraftBeforeConfluentPlatformVersion74() throws Exception {
try (
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.0.1")).withKraft()
) {
Expand All @@ -133,7 +133,7 @@ public void testUsageKraftBeforeConfluentPlatformVersion74() throws Exception {
}

@Test
public void testUsageKraftAfterConfluentPlatformVersion74() throws Exception {
void testUsageKraftAfterConfluentPlatformVersion74() throws Exception {
try (
// withKraftMode {
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.4.0")).withKraft()
Expand All @@ -145,7 +145,7 @@ public void testUsageKraftAfterConfluentPlatformVersion74() throws Exception {
}

@Test
public void testNotSupportedKraftVersion() {
void testNotSupportedKraftVersion() {
try (
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1")).withKraft()
) {} catch (IllegalArgumentException e) {
Expand All @@ -157,7 +157,7 @@ public void testNotSupportedKraftVersion() {
}

@Test
public void testKraftZookeeperMutualExclusion() {
void testKraftZookeeperMutualExclusion() {
try (
KafkaContainer kafka = new KafkaContainer(KAFKA_KRAFT_TEST_IMAGE).withKraft().withExternalZookeeper("")
) {} catch (IllegalStateException e) {
Expand All @@ -178,15 +178,15 @@ public void testKraftZookeeperMutualExclusion() {
}

@Test
public void testKraftPrecedenceOverEmbeddedZookeeper() throws Exception {
void testKraftPrecedenceOverEmbeddedZookeeper() throws Exception {
try (KafkaContainer kafka = new KafkaContainer(KAFKA_KRAFT_TEST_IMAGE).withEmbeddedZookeeper().withKraft()) {
kafka.start();
testKafkaFunctionality(kafka.getBootstrapServers());
}
}

@Test
public void testUsageWithListener() throws Exception {
void testUsageWithListener() throws Exception {
try (
Network network = Network.newNetwork();
KafkaContainer kafka = new KafkaContainer(KAFKA_KRAFT_TEST_IMAGE)
Expand Down Expand Up @@ -216,7 +216,7 @@ public void testUsageWithListener() throws Exception {

@SneakyThrows
@Test
public void shouldConfigureAuthenticationWithSaslUsingJaas() {
void shouldConfigureAuthenticationWithSaslUsingJaas() {
try (
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1"))
.withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "PLAINTEXT:SASL_PLAINTEXT,BROKER:SASL_PLAINTEXT")
Expand All @@ -234,7 +234,7 @@ public void shouldConfigureAuthenticationWithSaslUsingJaas() {

@SneakyThrows
@Test
public void shouldConfigureAuthenticationWithSaslScramUsingJaas() {
void shouldConfigureAuthenticationWithSaslScramUsingJaas() {
try (
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.7.0")) {
protected String commandKraft() {
Expand Down Expand Up @@ -265,7 +265,7 @@ protected String commandKraft() {

@SneakyThrows
@Test
public void enableSaslWithUnsuccessfulTopicCreation() {
void enableSaslWithUnsuccessfulTopicCreation() {
try (
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1"))
.withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "PLAINTEXT:SASL_PLAINTEXT,BROKER:SASL_PLAINTEXT")
Expand Down Expand Up @@ -306,7 +306,7 @@ public void enableSaslWithUnsuccessfulTopicCreation() {

@SneakyThrows
@Test
public void enableSaslAndWithAuthenticationError() {
void enableSaslAndWithAuthenticationError() {
String jaasConfig = getJaasConfig();
try (
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package org.testcontainers.kafka;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.testcontainers.AbstractKafka;

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

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

@Parameterized.Parameter
public String imageName;

@Test
public void testUsage() throws Exception {
try (KafkaContainer kafka = new KafkaContainer(this.imageName)) {
@ParameterizedTest
@MethodSource("params")
public void testUsage(String imageName) throws Exception {
try (KafkaContainer kafka = new KafkaContainer(imageName)) {
kafka.start();
testKafkaFunctionality(kafka.getBootstrapServers());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.github.dockerjava.api.command.InspectContainerResponse;
import lombok.SneakyThrows;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.testcontainers.AbstractKafka;
import org.testcontainers.KCatContainer;
import org.testcontainers.containers.Network;
Expand All @@ -11,10 +11,10 @@

import static org.assertj.core.api.Assertions.assertThat;

public class ConfluentKafkaContainerTest extends AbstractKafka {
class ConfluentKafkaContainerTest extends AbstractKafka {

@Test
public void testUsage() throws Exception {
void testUsage() throws Exception {
try ( // constructorWithVersion {
ConfluentKafkaContainer kafka = new ConfluentKafkaContainer("confluentinc/cp-kafka:7.4.0")
// }
Expand All @@ -25,7 +25,7 @@ public void testUsage() throws Exception {
}

@Test
public void testUsageWithListener() throws Exception {
void testUsageWithListener() throws Exception {
try (
Network network = Network.newNetwork();
// registerListener {
Expand All @@ -48,7 +48,7 @@ public void testUsageWithListener() throws Exception {
}

@Test
public void testUsageWithListenerFromProxy() throws Exception {
void testUsageWithListenerFromProxy() throws Exception {
try (
Network network = Network.newNetwork();
// registerListenerFromProxy {
Expand All @@ -68,7 +68,7 @@ public void testUsageWithListenerFromProxy() throws Exception {

@SneakyThrows
@Test
public void shouldConfigureAuthenticationWithSaslUsingJaas() {
void shouldConfigureAuthenticationWithSaslUsingJaas() {
try (
ConfluentKafkaContainer kafka = new ConfluentKafkaContainer("confluentinc/cp-kafka:7.7.0")
.withEnv(
Expand All @@ -89,7 +89,7 @@ public void shouldConfigureAuthenticationWithSaslUsingJaas() {

@SneakyThrows
@Test
public void shouldConfigureAuthenticationWithSaslScramUsingJaas() {
void shouldConfigureAuthenticationWithSaslScramUsingJaas() {
try (
ConfluentKafkaContainer kafka = new ConfluentKafkaContainer("confluentinc/cp-kafka:7.7.0") {
@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.testcontainers.kafka;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.testcontainers.AbstractKafka;
import org.testcontainers.KCatContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.SocatContainer;

import static org.assertj.core.api.Assertions.assertThat;

public class KafkaContainerTest extends AbstractKafka {
class KafkaContainerTest extends AbstractKafka {

@Test
public void testUsage() throws Exception {
void testUsage() throws Exception {
try ( // constructorWithVersion {
KafkaContainer kafka = new KafkaContainer("apache/kafka-native:3.8.0")
// }
Expand All @@ -22,7 +22,7 @@ public void testUsage() throws Exception {
}

@Test
public void testUsageWithListener() throws Exception {
void testUsageWithListener() throws Exception {
try (
Network network = Network.newNetwork();
// registerListener {
Expand All @@ -45,7 +45,7 @@ public void testUsageWithListener() throws Exception {
}

@Test
public void testUsageWithListenerFromProxy() throws Exception {
void testUsageWithListenerFromProxy() throws Exception {
try (
Network network = Network.newNetwork();
SocatContainer socat = new SocatContainer().withNetwork(network).withTarget(2000, "kafka", 19092);
Expand Down
Loading