incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/2] git commit: Fixing a race condition in the ZK minicluster.
Date Sun, 16 Feb 2014 13:46:29 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/apache-blur-0.2 9d2c296f7 -> c47af820e


Fixing a race condition in the ZK minicluster.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/a7311fc4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/a7311fc4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/a7311fc4

Branch: refs/heads/apache-blur-0.2
Commit: a7311fc400f86b9547026650510ecf4394a68b8e
Parents: 9d2c296
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Sun Feb 16 08:44:33 2014 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Sun Feb 16 08:44:33 2014 -0500

----------------------------------------------------------------------
 .../org/apache/blur/zookeeper/ZkMiniCluster.java     | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a7311fc4/blur-util/src/test/java/org/apache/blur/zookeeper/ZkMiniCluster.java
----------------------------------------------------------------------
diff --git a/blur-util/src/test/java/org/apache/blur/zookeeper/ZkMiniCluster.java b/blur-util/src/test/java/org/apache/blur/zookeeper/ZkMiniCluster.java
index 0dd0d3c..6dbbd93 100644
--- a/blur-util/src/test/java/org/apache/blur/zookeeper/ZkMiniCluster.java
+++ b/blur-util/src/test/java/org/apache/blur/zookeeper/ZkMiniCluster.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.lang.reflect.Field;
 import java.net.InetSocketAddress;
 import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.blur.log.Log;
 import org.apache.blur.log.LogFactory;
@@ -38,9 +39,21 @@ public class ZkMiniCluster {
 
   private static Log LOG = LogFactory.getLog(ZkMiniCluster.class);
   private Thread serverThread;
-  private ZooKeeperServerMainEmbedded zooKeeperServerMain;
+  private volatile ZooKeeperServerMainEmbedded zooKeeperServerMain;
 
   public String getZkConnectionString() {
+    long s = System.nanoTime();
+    while (zooKeeperServerMain == null) {
+      long now = System.nanoTime();
+      if (s + TimeUnit.SECONDS.toNanos(60) < now) {
+        throw new RuntimeException("ZooKeeper server did not start.");
+      }
+      try {
+        Thread.sleep(100);
+      } catch (InterruptedException e) {
+        throw new RuntimeException(e);
+      }
+    }
     return zooKeeperServerMain.getConnectionString();
   }
 


Mime
View raw message