Skip to content

Commit ae46d10

Browse files
authored
Support Confluent Platform 6 in Kafka (#3293)
* Support Confluent Platform 6 in Kafka * remove `KafkaContainer#startZookeeper`
1 parent 17b4f6c commit ae46d10

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

modules/kafka/src/main/java/org/testcontainers/containers/KafkaContainer.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package org.testcontainers.containers;
22

3-
import com.github.dockerjava.api.command.ExecCreateCmdResponse;
43
import com.github.dockerjava.api.command.InspectContainerResponse;
54
import lombok.SneakyThrows;
65
import org.testcontainers.images.builder.Transferable;
76
import org.testcontainers.utility.DockerImageName;
87
import org.testcontainers.utility.TestcontainersConfiguration;
98

109
import java.nio.charset.StandardCharsets;
11-
import java.util.concurrent.TimeUnit;
1210
import java.util.stream.Collectors;
1311
import java.util.stream.Stream;
1412

@@ -108,14 +106,18 @@ protected void containerIsStarting(InspectContainerResponse containerInfo, boole
108106
return;
109107
}
110108

109+
String command = "#!/bin/bash\n";
111110
final String zookeeperConnect;
112111
if (externalZookeeperConnect != null) {
113112
zookeeperConnect = externalZookeeperConnect;
114113
} else {
115-
zookeeperConnect = startZookeeper();
114+
zookeeperConnect = "localhost:" + ZOOKEEPER_PORT;
115+
command += "echo 'clientPort=" + ZOOKEEPER_PORT + "' > zookeeper.properties\n";
116+
command += "echo 'dataDir=/var/lib/zookeeper/data' >> zookeeper.properties\n";
117+
command += "echo 'dataLogDir=/var/lib/zookeeper/log' >> zookeeper.properties\n";
118+
command += "zookeeper-server-start zookeeper.properties &\n";
116119
}
117120

118-
String command = "#!/bin/bash \n";
119121
command += "export KAFKA_ZOOKEEPER_CONNECT='" + zookeeperConnect + "'\n";
120122
command += "export KAFKA_ADVERTISED_LISTENERS='" + Stream
121123
.concat(
@@ -130,22 +132,8 @@ protected void containerIsStarting(InspectContainerResponse containerInfo, boole
130132
command += "/etc/confluent/docker/launch \n";
131133

132134
copyFileToContainer(
133-
Transferable.of(command.getBytes(StandardCharsets.UTF_8), 700),
135+
Transferable.of(command.getBytes(StandardCharsets.UTF_8), 0777),
134136
STARTER_SCRIPT
135137
);
136138
}
137-
138-
@SneakyThrows(InterruptedException.class)
139-
private String startZookeeper() {
140-
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(getContainerId())
141-
.withCmd("sh", "-c", "" +
142-
"printf 'clientPort=" + ZOOKEEPER_PORT + "\ndataDir=/var/lib/zookeeper/data\ndataLogDir=/var/lib/zookeeper/log' > /zookeeper.properties\n" +
143-
"zookeeper-server-start /zookeeper.properties\n"
144-
)
145-
.exec();
146-
147-
dockerClient.execStartCmd(execCreateCmdResponse.getId()).start().awaitStarted(10, TimeUnit.SECONDS);
148-
149-
return "localhost:" + ZOOKEEPER_PORT;
150-
}
151139
}

modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ public void testExternalZookeeperWithExternalNetwork() throws Exception {
9999
}
100100
}
101101

102+
@Test
103+
public void testConfluentPlatformVersion6() throws Exception {
104+
try (
105+
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.0.0"))
106+
) {
107+
kafka.start();
108+
testKafkaFunctionality(kafka.getBootstrapServers());
109+
}
110+
}
111+
102112
protected void testKafkaFunctionality(String bootstrapServers) throws Exception {
103113
try (
104114
KafkaProducer<String, String> producer = new KafkaProducer<>(

0 commit comments

Comments
 (0)