Skip to content

Commit 56d0cf1

Browse files
nahguameddumelendezkiview
authored
Check admin endpoint instead of metrics for Pulsar WaitStrategy. (#5514)
Fixes #5513 Co-authored-by: Eddú Meléndez Gonzales <[email protected]> Co-authored-by: Kevin Wittek <[email protected]>
1 parent c0eb042 commit 56d0cf1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ public class PulsarContainer extends GenericContainer<PulsarContainer> {
1717

1818
public static final int BROKER_HTTP_PORT = 8080;
1919

20+
/**
21+
* @deprecated The metrics endpoint is no longer being used for the WaitStrategy.
22+
*/
23+
@Deprecated
2024
public static final String METRICS_ENDPOINT = "/metrics";
2125

26+
private static final String ADMIN_CLUSTERS_ENDPOINT = "/admin/v2/clusters";
27+
2228
/**
2329
* See <a href="https://github.com/apache/pulsar/blob/master/pulsar-common/src/main/java/org/apache/pulsar/common/naming/SystemTopicNames.java">SystemTopicNames</a>.
2430
*/
@@ -92,7 +98,12 @@ protected void setupCommandAndEnv() {
9298

9399
List<WaitStrategy> waitStrategies = new ArrayList<>();
94100
waitStrategies.add(Wait.defaultWaitStrategy());
95-
waitStrategies.add(Wait.forHttp(METRICS_ENDPOINT).forStatusCode(200).forPort(BROKER_HTTP_PORT));
101+
waitStrategies.add(
102+
Wait
103+
.forHttp(ADMIN_CLUSTERS_ENDPOINT)
104+
.forPort(BROKER_HTTP_PORT)
105+
.forResponsePredicate("[\"standalone\"]"::equals)
106+
);
96107
if (transactionsEnabled) {
97108
withEnv("PULSAR_PREFIX_transactionCoordinatorEnabled", "true");
98109
waitStrategies.add(Wait.forHttp(TRANSACTION_TOPIC_ENDPOINT).forStatusCode(200).forPort(BROKER_HTTP_PORT));

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

+11
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ public void testTransactionsAndFunctionsWorker() throws Exception {
122122
}
123123
}
124124

125+
@Test
126+
public void testClusterFullyInitialized() throws Exception {
127+
try (PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE)) {
128+
pulsar.start();
129+
130+
try (PulsarAdmin pulsarAdmin = PulsarAdmin.builder().serviceHttpUrl(pulsar.getHttpServiceUrl()).build()) {
131+
assertThat(pulsarAdmin.clusters().getClusters()).hasSize(1).contains("standalone");
132+
}
133+
}
134+
}
135+
125136
protected void testPulsarFunctionality(String pulsarBrokerUrl) throws Exception {
126137
try (
127138
PulsarClient client = PulsarClient.builder().serviceUrl(pulsarBrokerUrl).build();

0 commit comments

Comments
 (0)