Utility for integration tests to wait for ZK
Utility to allow an integration test to wait for zookeeper to come up
before proceeding.
@@ -75,6 +75,26 @@ public class PulsarClusterUtils {
return false;
}
+ public static boolean waitZooKeeperUp(DockerClient docker, String cluster, int timeout, TimeUnit timeoutUnit)
+ throws Exception {
+ Optional<String> zookeeper = zookeeperSet(docker, cluster).stream().findAny();
+ if (zookeeper.isPresent()) {
+ long timeoutMillis = timeoutUnit.toMillis(timeout);
+ long pollMillis = 1000;
+ while (timeoutMillis > 0) {
+ if (zookeeperRunning(docker, zookeeper.get())) {
+ return true;
+ }
+ Thread.sleep(pollMillis);
+ timeoutMillis -= pollMillis;
+ }
+ return false;
+ } else {
+ LOG.warn("No zookeeper containers found");
+ return false;
+ }
+ }
+
public static boolean runOnAnyBroker(DockerClient docker, String cluster, String... cmds) throws Exception {
Optional<String> broker = DockerUtils.cubeIdsWithLabels(
docker,ImmutableMap.of("service", "pulsar-broker", "cluster", cluster)).stream().findAny();
@@ -266,4 +286,9 @@ public class PulsarClusterUtils {
return DockerUtils.cubeIdsWithLabels(docker, ImmutableMap.of("service", "pulsar-proxy",
"cluster", cluster));
}
+
+ public static Set<String> zookeeperSet(DockerClient docker, String cluster) {
+ return DockerUtils.cubeIdsWithLabels(docker, ImmutableMap.of("service", "zookeeper",
+ "cluster", cluster));
+ }
}
