You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by dl...@apache.org on 2021/02/10 12:31:01 UTC

[accumulo] branch main updated: fixes #1909 - test broken by changes in commit 954a55395 (#1915)

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

dlmarion pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new a75dad4  fixes #1909 - test broken by changes in commit 954a55395 (#1915)
a75dad4 is described below

commit a75dad45d4a6e1e78f5e22f19eacaafa7f7c430e
Author: Dave Marion <dl...@apache.org>
AuthorDate: Wed Feb 10 07:30:52 2021 -0500

    fixes #1909 - test broken by changes in commit 954a55395 (#1915)
---
 .../apache/accumulo/fate/zookeeper/ZooLock.java    | 13 +++++++++
 .../accumulo/test/fate/zookeeper/ZooLockIT.java    | 33 +++++++++++++++++-----
 2 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
index f5e476e..0a92c7b 100644
--- a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
+++ b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
@@ -107,6 +107,19 @@ public class ZooLock implements Watcher {
     }
   }
 
+  protected ZooLock(ZooKeeper zookeeper, String path, UUID uuid) {
+    this.zooKeeper = zookeeper;
+    this.path = path;
+    try {
+      zooKeeper.exists(path, this);
+      watchingParent = true;
+      this.vmLockPrefix = new Prefix(ZLOCK_PREFIX + uuid.toString() + "#");
+    } catch (Exception ex) {
+      LOG.error("Error setting initial watch", ex);
+      throw new RuntimeException(ex);
+    }
+  }
+
   private static class LockWatcherWrapper implements AccumuloLockWatcher {
 
     boolean acquiredLock = false;
diff --git a/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ZooLockIT.java b/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ZooLockIT.java
index 243b5f1..f65bff3 100644
--- a/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ZooLockIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ZooLockIT.java
@@ -92,6 +92,14 @@ public class ZooLockIT extends SharedMiniClusterBase {
 
   }
 
+  private static class ZooLockWrapper extends ZooLock {
+
+    protected ZooLockWrapper(ZooKeeper zookeeper, String path, UUID uuid) {
+      super(zookeeper, path, uuid);
+    }
+
+  }
+
   static class RetryLockWatcher implements AccumuloLockWatcher {
 
     private boolean lockHeld = false;
@@ -181,7 +189,10 @@ public class ZooLockIT extends SharedMiniClusterBase {
     props.put(Property.INSTANCE_ZK_TIMEOUT.toString(), "30000");
     props.put(Property.INSTANCE_SECRET.toString(), "secret");
     return new ZooLock(new ConfigurationCopy(props), parent, uuid);
+  }
 
+  private static ZooLock getZooLock(ZooKeeperWrapper zkw, String parent, UUID uuid) {
+    return new ZooLockWrapper(zkw, parent, uuid);
   }
 
   @Test(timeout = 10000)
@@ -381,14 +392,20 @@ public class ZooLockIT extends SharedMiniClusterBase {
   public void testLockSerial() throws Exception {
     String parent = "/zlretryLockSerial";
 
-    ConnectedWatcher watcher = new ConnectedWatcher();
-    try (ZooKeeperWrapper zk1 = new ZooKeeperWrapper(getCluster().getZooKeepers(), 30000, watcher);
-        ZooKeeperWrapper zk2 = new ZooKeeperWrapper(getCluster().getZooKeepers(), 30000, watcher)) {
+    ConnectedWatcher watcher1 = new ConnectedWatcher();
+    ConnectedWatcher watcher2 = new ConnectedWatcher();
+    try (ZooKeeperWrapper zk1 = new ZooKeeperWrapper(getCluster().getZooKeepers(), 30000, watcher1);
+        ZooKeeperWrapper zk2 =
+            new ZooKeeperWrapper(getCluster().getZooKeepers(), 30000, watcher2)) {
 
       zk1.addAuthInfo("digest", "accumulo:secret".getBytes(UTF_8));
       zk2.addAuthInfo("digest", "accumulo:secret".getBytes(UTF_8));
 
-      while (!watcher.isConnected()) {
+      while (!watcher1.isConnected()) {
+        Thread.sleep(200);
+      }
+
+      while (!watcher2.isConnected()) {
         Thread.sleep(200);
       }
 
@@ -396,7 +413,8 @@ public class ZooLockIT extends SharedMiniClusterBase {
       zk1.createOnce(parent, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
 
       final RetryLockWatcher zlw1 = new RetryLockWatcher();
-      ZooLock zl1 = getZooLock(parent, UUID.fromString("00000000-0000-0000-0000-aaaaaaaaaaaa"));
+      ZooLock zl1 =
+          getZooLock(zk1, parent, UUID.fromString("00000000-0000-0000-0000-aaaaaaaaaaaa"));
       zl1.lock(zlw1, "test1".getBytes(UTF_8));
       // The call above creates two nodes in ZK because of the overridden create method in
       // ZooKeeperWrapper.
@@ -410,7 +428,8 @@ public class ZooLockIT extends SharedMiniClusterBase {
       // zl1 assumes that it has the lock.
 
       final RetryLockWatcher zlw2 = new RetryLockWatcher();
-      ZooLock zl2 = getZooLock(parent, UUID.fromString("00000000-0000-0000-0000-bbbbbbbbbbbb"));
+      ZooLock zl2 =
+          getZooLock(zk2, parent, UUID.fromString("00000000-0000-0000-0000-bbbbbbbbbbbb"));
       zl2.lock(zlw2, "test1".getBytes(UTF_8));
       // The call above creates two nodes in ZK because of the overridden create method in
       // ZooKeeperWrapper.
@@ -495,7 +514,7 @@ public class ZooLockIT extends SharedMiniClusterBase {
           while (!watcher.isConnected()) {
             Thread.sleep(50);
           }
-          ZooLock zl = getZooLock(parent, uuid);
+          ZooLock zl = getZooLock(zk, parent, uuid);
           getLockLatch.countDown(); // signal we are done
           getLockLatch.await(); // wait for others to finish
           zl.lock(lockWatcher, "test1".getBytes(UTF_8)); // race to the lock