You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2014/06/24 03:26:03 UTC

[6/7] git commit: Merge branch '1.5.2-SNAPSHOT' into 1.6.1-SNAPSHOT

Merge branch '1.5.2-SNAPSHOT' into 1.6.1-SNAPSHOT

Conflicts:
	test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java


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

Branch: refs/heads/1.6.1-SNAPSHOT
Commit: fd080f03f663579c8de6058f1ed14acb38638618
Parents: 3583409 65782b5
Author: Josh Elser <el...@apache.org>
Authored: Mon Jun 23 19:46:09 2014 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Mon Jun 23 19:46:09 2014 -0400

----------------------------------------------------------------------
 .../accumulo/fate/zookeeper/ZooLockTest.java    | 54 +++++++++++++++-----
 1 file changed, 40 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/fd080f03/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
----------------------------------------------------------------------
diff --cc test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
index e902818,717bf0a..d19320d
--- a/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
+++ b/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
@@@ -39,13 -41,30 +42,30 @@@ import org.junit.rules.TemporaryFolder
   * 
   */
  public class ZooLockTest {
 -  
 -  public static TemporaryFolder folder = new TemporaryFolder();
 -  
 +
 +  public static TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
 +
    private static MiniAccumuloCluster accumulo;
  
+   static class ConnectedWatcher implements Watcher {
+     volatile boolean connected = false;
+ 
+     @Override
+     public synchronized void process(WatchedEvent event) {
+       if (event.getState() == KeeperState.SyncConnected) { // For ZK >3.4.... || event.getState() == KeeperState.ConnectedReadOnly) {
+         connected = true;
+       } else {
+         connected = false;
+       }
+     }
+ 
+     public synchronized boolean isConnected() {
+       return connected;
+     }
+   }
+ 
    static class TestALW implements AsyncLockWatcher {
 -    
 +
      LockLossReason reason = null;
      boolean locked = false;
      Exception exception = null;
@@@ -84,129 -103,121 +104,121 @@@
        this.notifyAll();
      }
    }
 -  
 +
    @BeforeClass
    public static void setupMiniCluster() throws Exception {
 -    
 +
      folder.create();
 -    
 +
      Logger.getLogger("org.apache.zookeeper").setLevel(Level.ERROR);
 -    
 +
      accumulo = new MiniAccumuloCluster(folder.getRoot(), "superSecret");
 -    
 +
      accumulo.start();
 -    
 +
    }
 -  
 +
    private static int pdCount = 0;
 -  
 +
    @Test(timeout = 10000)
    public void testDeleteParent() throws Exception {
-     accumulo.getZooKeepers();
- 
      String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
 -    
 +
      ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
 -    
 +
      Assert.assertFalse(zl.isLocked());
 -    
 +
      ZooReaderWriter zk = ZooReaderWriter.getInstance(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes());
 -    
 +
      // intentionally created parent after lock
      zk.mkdirs(parent);
 -    
 +
      zk.delete(parent, -1);
 -    
 +
      zk.mkdirs(parent);
 -    
 +
      TestALW lw = new TestALW();
 -    
 +
      zl.lockAsync(lw, "test1".getBytes());
 -    
 +
      lw.waitForChanges(1);
 -    
 +
      Assert.assertTrue(lw.locked);
      Assert.assertTrue(zl.isLocked());
      Assert.assertNull(lw.exception);
      Assert.assertNull(lw.reason);
 -    
 +
      zl.unlock();
    }
 -  
 +
    @Test(timeout = 10000)
    public void testNoParent() throws Exception {
-     accumulo.getZooKeepers();
- 
      String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
 -    
 +
      ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
 -    
 +
      Assert.assertFalse(zl.isLocked());
 -    
 +
      TestALW lw = new TestALW();
 -    
 +
      zl.lockAsync(lw, "test1".getBytes());
 -    
 +
      lw.waitForChanges(1);
 -    
 +
      Assert.assertFalse(lw.locked);
      Assert.assertFalse(zl.isLocked());
      Assert.assertNotNull(lw.exception);
      Assert.assertNull(lw.reason);
    }
 -  
 +
    @Test(timeout = 10000)
    public void testDeleteLock() throws Exception {
-     accumulo.getZooKeepers();
- 
      String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
 -    
 +
      ZooReaderWriter zk = ZooReaderWriter.getInstance(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes());
      zk.mkdirs(parent);
 -    
 +
      ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
 -    
 +
      Assert.assertFalse(zl.isLocked());
 -    
 +
      TestALW lw = new TestALW();
 -    
 +
      zl.lockAsync(lw, "test1".getBytes());
 -    
 +
      lw.waitForChanges(1);
 -    
 +
      Assert.assertTrue(lw.locked);
      Assert.assertTrue(zl.isLocked());
      Assert.assertNull(lw.exception);
      Assert.assertNull(lw.reason);
 -    
 +
      zk.delete(zl.getLockPath(), -1);
 -    
 +
      lw.waitForChanges(2);
 -    
 +
      Assert.assertEquals(LockLossReason.LOCK_DELETED, lw.reason);
      Assert.assertNull(lw.exception);
 -    
 +
    }
 -  
 +
    @Test(timeout = 10000)
    public void testDeleteWaiting() throws Exception {
-     accumulo.getZooKeepers();
- 
      String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
 -    
 +
      ZooReaderWriter zk = ZooReaderWriter.getInstance(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes());
      zk.mkdirs(parent);
 -    
 +
      ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
 -    
 +
      Assert.assertFalse(zl.isLocked());
 -    
 +
      TestALW lw = new TestALW();
 -    
 +
      zl.lockAsync(lw, "test1".getBytes());
 -    
 +
      lw.waitForChanges(1);
 -    
 +
      Assert.assertTrue(lw.locked);
      Assert.assertTrue(zl.isLocked());
      Assert.assertNull(lw.exception);
@@@ -251,35 -262,38 +263,38 @@@
      Assert.assertTrue(zl3.isLocked());
      Assert.assertNull(lw3.exception);
      Assert.assertNull(lw3.reason);
 -    
 +
      zl3.unlock();
 -    
 +
    }
 -  
 +
    @Test(timeout = 10000)
    public void testUnexpectedEvent() throws Exception {
-     accumulo.getZooKeepers();
- 
      String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
  
-     ZooKeeper zk = new ZooKeeper(accumulo.getZooKeepers(), 30000, null);
+     ConnectedWatcher watcher = new ConnectedWatcher();
+     ZooKeeper zk = new ZooKeeper(accumulo.getZooKeepers(), 30000, watcher);
      zk.addAuthInfo("digest", "secret".getBytes());
  
+     while (!watcher.isConnected()) {
+       Thread.sleep(200);
+     }
+     
      zk.create(parent, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
 -    
 +
      ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
 -    
 +
      Assert.assertFalse(zl.isLocked());
 -    
 +
      // would not expect data to be set on this node, but it should not cause problems.....
      zk.setData(parent, "foo".getBytes(), -1);
 -    
 +
      TestALW lw = new TestALW();
 -    
 +
      zl.lockAsync(lw, "test1".getBytes());
 -    
 +
      lw.waitForChanges(1);
 -    
 +
      Assert.assertTrue(lw.locked);
      Assert.assertTrue(zl.isLocked());
      Assert.assertNull(lw.exception);
@@@ -300,12 -314,17 +315,17 @@@
    @Test(timeout = 10000)
    public void testTryLock() throws Exception {
      String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
 -    
 +
      ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 1000, "digest", "secret".getBytes(), parent);
- 
-     ZooKeeper zk = new ZooKeeper(accumulo.getZooKeepers(), 1000, null);
+     
+     ConnectedWatcher watcher = new ConnectedWatcher();
+     ZooKeeper zk = new ZooKeeper(accumulo.getZooKeepers(), 1000, watcher);
      zk.addAuthInfo("digest", "secret".getBytes());
  
+     while (!watcher.isConnected()) {
+       Thread.sleep(200);
+     }
+     
      for (int i = 0; i < 10; i++) {
        zk.create(parent, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zk.delete(parent, -1);
@@@ -332,17 -351,23 +352,23 @@@
    @Test(timeout = 10000)
    public void testChangeData() throws Exception {
      String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-     ZooKeeper zk = new ZooKeeper(accumulo.getZooKeepers(), 1000, null);
+     ConnectedWatcher watcher = new ConnectedWatcher();
+     ZooKeeper zk = new ZooKeeper(accumulo.getZooKeepers(), 1000, watcher);
      zk.addAuthInfo("digest", "secret".getBytes());
+ 
+     while (!watcher.isConnected()) {
+       Thread.sleep(200);
+     }
+     
      zk.create(parent, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
 -    
 +
      ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 1000, "digest", "secret".getBytes(), parent);
 -    
 +
      TestALW lw = new TestALW();
 -    
 +
      zl.lockAsync(lw, "test1".getBytes());
      Assert.assertEquals("test1", new String(zk.getData(zl.getLockPath(), null, null)));
 -    
 +
      zl.replaceLockData("test2".getBytes());
      Assert.assertEquals("test2", new String(zk.getData(zl.getLockPath(), null, null)));
    }