This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ceedee  Utility for integration tests to wait for ZK (#1561)
9ceedee is described below

commit 9ceedee8064a0820afba2cc9de27bdfd7189eac6
Author: Ivan Kelly <iv...@apache.org>
AuthorDate: Thu Apr 12 20:49:38 2018 +0200

    Utility for integration tests to wait for ZK (#1561)
    
    Utility to allow an integration test to wait for zookeeper to come up
    before proceeding.
---
 .../apache/pulsar/tests/PulsarClusterUtils.java    | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)

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 c5b8e70..f7771dd 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 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));
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
si...@apache.org.

Reply via email to