Skip to content

Commit 1419cf2

Browse files
authored
Improve Pulsar's wait strategy to rely on clusterName (#5613)
`PulsarContainer` allow to override configuration using env vars, using `PULSAR_PREFIX_clusterName" will override the default's value "standalone". The endpoint response should adapt accordingly.
1 parent fca585d commit 1419cf2

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

modules/pulsar/src/main/java/org/testcontainers/containers/PulsarContainer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ protected void setupCommandAndEnv() {
9696

9797
withCommand("/bin/bash", "-c", standaloneBaseCommand);
9898

99+
final String clusterName = getEnvMap().getOrDefault("PULSAR_PREFIX_clusterName", "standalone");
100+
final String response = String.format("[\"%s\"]", clusterName);
101+
99102
List<WaitStrategy> waitStrategies = new ArrayList<>();
100103
waitStrategies.add(Wait.defaultWaitStrategy());
101104
waitStrategies.add(
102-
Wait
103-
.forHttp(ADMIN_CLUSTERS_ENDPOINT)
104-
.forPort(BROKER_HTTP_PORT)
105-
.forResponsePredicate("[\"standalone\"]"::equals)
105+
Wait.forHttp(ADMIN_CLUSTERS_ENDPOINT).forPort(BROKER_HTTP_PORT).forResponsePredicate(response::equals)
106106
);
107107
if (transactionsEnabled) {
108108
withEnv("PULSAR_PREFIX_transactionCoordinatorEnabled", "true");

modules/pulsar/src/test/java/org/testcontainers/containers/PulsarContainerTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ public void envVarsUsage() throws Exception {
5454
}
5555
}
5656

57+
@Test
58+
public void customClusterName() throws Exception {
59+
try (
60+
PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE)
61+
.withEnv("PULSAR_PREFIX_clusterName", "tc-cluster");
62+
) {
63+
pulsar.start();
64+
testPulsarFunctionality(pulsar.getPulsarBrokerUrl());
65+
}
66+
}
67+
5768
@Test
5869
public void shouldNotEnableFunctionsWorkerByDefault() throws Exception {
5970
try (PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE)) {

0 commit comments

Comments
 (0)