Skip to content

Commit 405ddb7

Browse files
author
Dave Maughan
authored
Allow Pulsar default WaitStrategy to honour startup timeout (#5674)
1 parent f54a29a commit 405ddb7

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
import org.testcontainers.containers.wait.strategy.Wait;
44
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
5-
import org.testcontainers.containers.wait.strategy.WaitStrategy;
65
import org.testcontainers.utility.DockerImageName;
76

8-
import java.util.ArrayList;
9-
import java.util.List;
10-
117
/**
128
* This container wraps Apache Pulsar running in standalone mode
139
*/
@@ -36,6 +32,8 @@ public class PulsarContainer extends GenericContainer<PulsarContainer> {
3632
@Deprecated
3733
private static final String DEFAULT_TAG = "2.10.0";
3834

35+
private final WaitAllStrategy waitAllStrategy = new WaitAllStrategy();
36+
3937
private boolean functionsWorkerEnabled = false;
4038

4139
private boolean transactionsEnabled = false;
@@ -60,6 +58,7 @@ public PulsarContainer(final DockerImageName dockerImageName) {
6058
super(dockerImageName);
6159
dockerImageName.assertCompatibleWith(DockerImageName.parse("apachepulsar/pulsar"));
6260
withExposedPorts(BROKER_PORT, BROKER_HTTP_PORT);
61+
setWaitStrategy(waitAllStrategy);
6362
}
6463

6564
@Override
@@ -98,21 +97,18 @@ protected void setupCommandAndEnv() {
9897

9998
final String clusterName = getEnvMap().getOrDefault("PULSAR_PREFIX_clusterName", "standalone");
10099
final String response = String.format("[\"%s\"]", clusterName);
101-
102-
List<WaitStrategy> waitStrategies = new ArrayList<>();
103-
waitStrategies.add(Wait.defaultWaitStrategy());
104-
waitStrategies.add(
100+
waitAllStrategy.withStrategy(
105101
Wait.forHttp(ADMIN_CLUSTERS_ENDPOINT).forPort(BROKER_HTTP_PORT).forResponsePredicate(response::equals)
106102
);
103+
107104
if (transactionsEnabled) {
108105
withEnv("PULSAR_PREFIX_transactionCoordinatorEnabled", "true");
109-
waitStrategies.add(Wait.forHttp(TRANSACTION_TOPIC_ENDPOINT).forStatusCode(200).forPort(BROKER_HTTP_PORT));
106+
waitAllStrategy.withStrategy(
107+
Wait.forHttp(TRANSACTION_TOPIC_ENDPOINT).forStatusCode(200).forPort(BROKER_HTTP_PORT)
108+
);
110109
}
111110
if (functionsWorkerEnabled) {
112-
waitStrategies.add(Wait.forLogMessage(".*Function worker service started.*", 1));
111+
waitAllStrategy.withStrategy(Wait.forLogMessage(".*Function worker service started.*", 1));
113112
}
114-
final WaitAllStrategy compoundedWaitStrategy = new WaitAllStrategy();
115-
waitStrategies.forEach(compoundedWaitStrategy::withStrategy);
116-
waitingFor(compoundedWaitStrategy);
117113
}
118114
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.junit.Test;
1313
import org.testcontainers.utility.DockerImageName;
1414

15+
import java.time.Duration;
1516
import java.util.concurrent.CompletableFuture;
1617
import java.util.concurrent.TimeUnit;
1718

@@ -144,6 +145,14 @@ public void testClusterFullyInitialized() throws Exception {
144145
}
145146
}
146147

148+
@Test
149+
public void testStartupTimeoutIsHonored() {
150+
try (PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE).withStartupTimeout(Duration.ZERO)) {
151+
assertThatThrownBy(pulsar::start)
152+
.hasRootCauseMessage("Precondition failed: timeout must be greater than zero");
153+
}
154+
}
155+
147156
protected void testPulsarFunctionality(String pulsarBrokerUrl) throws Exception {
148157
try (
149158
PulsarClient client = PulsarClient.builder().serviceUrl(pulsarBrokerUrl).build();

0 commit comments

Comments
 (0)