From 2174928a5d2ac6e117643c12300171a03f8de7f8 Mon Sep 17 00:00:00 2001 From: Kevin Wittek Date: Thu, 14 Oct 2021 13:44:14 +0200 Subject: [PATCH] Remove unused `@ClassRule` container in `KafkaContainerTest` and use `cp-kafka:6.2.1` as default (#4564) --- docs/modules/kafka.md | 4 +-- .../containers/KafkaContainerTest.java | 34 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/docs/modules/kafka.md b/docs/modules/kafka.md index b0cd1742f6b..58f447d412e 100644 --- a/docs/modules/kafka.md +++ b/docs/modules/kafka.md @@ -10,9 +10,9 @@ More precisely Testcontainers uses the official Docker images for [Confluent OSS ## Example -The following field in your JUnit test class will prepare a container running Kafka: +Create a `KafkaContainer` to use it in your tests: -[JUnit Rule](../../modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java) inside_block:junitRule +[Creating a KafkaContainer](../../modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java) inside_block:constructorWithVersion The correspondence between Confluent Platform versions and Kafka versions can be seen [in Confluent documentation](https://docs.confluent.io/current/installation/versions-interoperability.html#cp-and-apache-kafka-compatibility) diff --git a/modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java b/modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java index e16081d16d9..f0ef0db2067 100644 --- a/modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java +++ b/modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java @@ -1,14 +1,6 @@ package org.testcontainers.containers; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.tuple; - import com.google.common.collect.ImmutableMap; -import java.time.Duration; -import java.util.Collection; -import java.util.UUID; -import java.util.concurrent.TimeUnit; import org.apache.kafka.clients.admin.AdminClient; import org.apache.kafka.clients.admin.AdminClientConfig; import org.apache.kafka.clients.admin.NewTopic; @@ -21,22 +13,25 @@ import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.common.serialization.StringDeserializer; import org.apache.kafka.common.serialization.StringSerializer; -import org.junit.ClassRule; import org.junit.Test; import org.rnorth.ducttape.unreliables.Unreliables; import org.testcontainers.Testcontainers; import org.testcontainers.utility.DockerImageName; +import java.time.Duration; +import java.util.Collection; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + public class KafkaContainerTest { - private static final DockerImageName KAFKA_TEST_IMAGE = DockerImageName.parse("confluentinc/cp-kafka:5.4.3"); + private static final DockerImageName KAFKA_TEST_IMAGE = DockerImageName.parse("confluentinc/cp-kafka:6.2.1"); private static final DockerImageName ZOOKEEPER_TEST_IMAGE = DockerImageName.parse("confluentinc/cp-zookeeper:4.0.0"); - // junitRule { - @ClassRule - public static KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3")); - // } - @Test public void testUsage() throws Exception { try (KafkaContainer kafka = new KafkaContainer(KAFKA_TEST_IMAGE)) { @@ -50,7 +45,7 @@ public void testUsage() throws Exception { public void testUsageWithSpecificImage() throws Exception { try ( // constructorWithVersion { - KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3")) + KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1")) // } ) { kafka.start(); @@ -62,11 +57,10 @@ public void testUsageWithSpecificImage() throws Exception { } } - @Test public void testUsageWithVersion() throws Exception { try ( - KafkaContainer kafka = new KafkaContainer("5.5.1") + KafkaContainer kafka = new KafkaContainer("6.2.1") ) { kafka.start(); testKafkaFunctionality(kafka.getBootstrapServers()); @@ -105,9 +99,9 @@ public void testExternalZookeeperWithExternalNetwork() throws Exception { } @Test - public void testConfluentPlatformVersion6() throws Exception { + public void testConfluentPlatformVersion5() throws Exception { try ( - KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.0.0")) + KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3")) ) { kafka.start(); testKafkaFunctionality(kafka.getBootstrapServers());