Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9CE5B11238 for ; Tue, 24 Jun 2014 01:25:59 +0000 (UTC) Received: (qmail 83120 invoked by uid 500); 24 Jun 2014 01:25:59 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 83017 invoked by uid 500); 24 Jun 2014 01:25:59 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 82783 invoked by uid 99); 24 Jun 2014 01:25:59 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jun 2014 01:25:59 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 29AC090F0F7; Tue, 24 Jun 2014 01:25:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: elserj@apache.org To: commits@accumulo.apache.org Date: Tue, 24 Jun 2014 01:26:04 -0000 Message-Id: <81438e1db9e8421d9492edfa18209e7d@git.apache.org> In-Reply-To: <7ce9c3ae68b84b0f8a23ea8131b7c377@git.apache.org> References: <7ce9c3ae68b84b0f8a23ea8131b7c377@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [7/7] git commit: Merge branch '1.5.2-SNAPSHOT' Merge branch '1.5.2-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/f785903c Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/f785903c Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/f785903c Branch: refs/heads/master Commit: f785903c5ba33a9127e6cebdb7981f340fe407b5 Parents: 5026b13 65782b5 Author: Josh Elser Authored: Mon Jun 23 20:29:09 2014 -0400 Committer: Josh Elser Committed: Mon Jun 23 20:29: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/f785903c/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))); }