sijie closed pull request #1561: Utility for integration tests to wait for ZK
URL: https://github.com/apache/incubator-pulsar/pull/1561
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/tests/integration-tests-utils/src/main/java/org/apache/pulsar/tests/PulsarClusterUtils.java
 
b/tests/integration-tests-utils/src/main/java/org/apache/pulsar/tests/PulsarClusterUtils.java
index c5b8e7019d..f7771ddf81 100644
--- 
a/tests/integration-tests-utils/src/main/java/org/apache/pulsar/tests/PulsarClusterUtils.java
+++ 
b/tests/integration-tests-utils/src/main/java/org/apache/pulsar/tests/PulsarClusterUtils.java
@@ -75,6 +75,26 @@ public static boolean zookeeperRunning(DockerClient docker, 
String containerId)
         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 static void stopAllProxies(DockerClient docker, 
String cluster) {
         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));
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to