Skip to content

Remove deprecated implicit network in KafkaContainer #2932

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2020
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 @@ -29,16 +29,13 @@ public class KafkaContainer extends GenericContainer<KafkaContainer> {

private int port = PORT_NOT_ASSIGNED;

private boolean useImplicitNetwork = true;

public KafkaContainer() {
this("5.2.1");
}

public KafkaContainer(String confluentPlatformVersion) {
super(TestcontainersConfiguration.getInstance().getKafkaImage() + ":" + confluentPlatformVersion);

super.withNetwork(Network.SHARED);
withExposedPorts(KAFKA_PORT);

// Use two listeners with different names, it will force Kafka to communicate with itself via internal
Expand All @@ -54,26 +51,6 @@ public KafkaContainer(String confluentPlatformVersion) {
withEnv("KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS", "0");
}

@Override
public KafkaContainer withNetwork(Network network) {
useImplicitNetwork = false;
return super.withNetwork(network);
}

@Override
public Network getNetwork() {
if (useImplicitNetwork) {
// TODO Only for backward compatibility, to be removed soon
logger().warn(
"Deprecation warning! " +
"KafkaContainer#getNetwork without an explicitly set network. " +
"Consider using KafkaContainer#withNetwork",
new Exception("Deprecated method")
);
}
return super.getNetwork();
}

public KafkaContainer withEmbeddedZookeeper() {
externalZookeeperConnect = null;
return self();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,6 @@ public void testUsage() throws Exception {
}
}

/**
* @deprecated the {@link Network} should be set explicitly with {@link KafkaContainer#withNetwork(Network)}.
*/
@Test
@Deprecated
public void testExternalZookeeperWithKafkaNetwork() throws Exception {
try (
KafkaContainer kafka = new KafkaContainer()
.withExternalZookeeper("zookeeper:2181");

GenericContainer zookeeper = new GenericContainer("confluentinc/cp-zookeeper:4.0.0")
.withNetwork(kafka.getNetwork())
.withNetworkAliases("zookeeper")
.withEnv("ZOOKEEPER_CLIENT_PORT", "2181");
) {
zookeeper.start();
kafka.start();

testKafkaFunctionality(kafka.getBootstrapServers());
}
}

@Test
public void testExternalZookeeperWithExternalNetwork() throws Exception {
try (
Expand Down