Added some additional tests to validate NamespaceWatcher identity
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/dce3146c Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/dce3146c Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/dce3146c Branch: refs/heads/CURATOR-3.0 Commit: dce3146c32d982dc84608d4db14d043464f9d188 Parents: b521b2e Author: randgalt <[email protected]> Authored: Wed Feb 10 09:29:37 2016 -0500 Committer: randgalt <[email protected]> Committed: Wed Feb 10 09:29:37 2016 -0500 ---------------------------------------------------------------------- .../framework/imps/TestWatcherIdentity.java | 65 +++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/dce3146c/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java index 2a37052..0686347 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java @@ -55,12 +55,75 @@ public class TestWatcherIdentity extends BaseClassForTests @Override public void process(WatchedEvent event) { - System.out.println("count=" + count); count.incrementAndGet(); } } @Test + public void testSameWatcherPerZKDocs() throws Exception + { + CountZKWatcher actualWatcher = new CountZKWatcher(); + Timing timing = new Timing(); + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); + try + { + client.start(); + client.create().forPath("/test"); + + // per ZK docs, this watcher should only trigger once + client.checkExists().usingWatcher(actualWatcher).forPath("/test"); + client.getData().usingWatcher(actualWatcher).forPath("/test"); + + client.setData().forPath("/test", "foo".getBytes()); + client.delete().forPath("/test"); + timing.sleepABit(); + Assert.assertEquals(actualWatcher.count.getAndSet(0), 1); + + client.create().forPath("/test"); + client.checkExists().usingWatcher(actualWatcher).forPath("/test"); + client.delete().forPath("/test"); + timing.sleepABit(); + Assert.assertEquals(actualWatcher.count.get(), 1); + } + finally + { + CloseableUtils.closeQuietly(client); + } + } + + @Test + public void testSameCuratorWatcherPerZKDocs() throws Exception + { + CountCuratorWatcher actualWatcher = new CountCuratorWatcher(); + Timing timing = new Timing(); + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); + try + { + client.start(); + client.create().forPath("/test"); + + // per ZK docs, this watcher should only trigger once + client.checkExists().usingWatcher(actualWatcher).forPath("/test"); + client.getData().usingWatcher(actualWatcher).forPath("/test"); + + client.setData().forPath("/test", "foo".getBytes()); + client.delete().forPath("/test"); + timing.sleepABit(); + Assert.assertEquals(actualWatcher.count.getAndSet(0), 1); + + client.create().forPath("/test"); + client.checkExists().usingWatcher(actualWatcher).forPath("/test"); + client.delete().forPath("/test"); + timing.sleepABit(); + Assert.assertEquals(actualWatcher.count.get(), 1); + } + finally + { + CloseableUtils.closeQuietly(client); + } + } + + @Test public void testSetAddition() { Watcher watcher = new Watcher()
