List of usage examples for org.apache.zookeeper Watcher Watcher
Watcher
From source file:org.apache.curator.framework.imps.TestWatcherRemovalManager.java
License:Apache License
@Test public void testSameWatcherDifferentPaths1Triggered() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); try {//from www . j a v a2 s. c o m client.start(); WatcherRemovalFacade removerClient = (WatcherRemovalFacade) client.newWatcherRemoveCuratorFramework(); final CountDownLatch latch = new CountDownLatch(1); Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { latch.countDown(); } }; removerClient.checkExists().usingWatcher(watcher).forPath("/a/b/c"); removerClient.checkExists().usingWatcher(watcher).forPath("/d/e/f"); removerClient.create().creatingParentsIfNeeded().forPath("/d/e/f"); Timing timing = new Timing(); Assert.assertTrue(timing.awaitLatch(latch)); timing.sleepABit(); removerClient.removeWatchers(); } finally { TestCleanState.closeAndTestClean(client); } }
From source file:org.apache.curator.framework.imps.TestWatcherRemovalManager.java
License:Apache License
@Test public void testSameWatcherDifferentPaths() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); try {/*ww w .j a va2 s. co m*/ client.start(); WatcherRemovalFacade removerClient = (WatcherRemovalFacade) client.newWatcherRemoveCuratorFramework(); Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { // NOP } }; removerClient.checkExists().usingWatcher(watcher).forPath("/a/b/c"); removerClient.checkExists().usingWatcher(watcher).forPath("/d/e/f"); Assert.assertEquals(removerClient.getWatcherRemovalManager().getEntries().size(), 2); removerClient.removeWatchers(); } finally { TestCleanState.closeAndTestClean(client); } }
From source file:org.apache.curator.framework.imps.TestWatcherRemovalManager.java
License:Apache License
@Test public void testSameWatcherDifferentKinds1Triggered() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); try {//from www. java2 s . com client.start(); WatcherRemovalFacade removerClient = (WatcherRemovalFacade) client.newWatcherRemoveCuratorFramework(); final CountDownLatch latch = new CountDownLatch(1); Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { latch.countDown(); } }; removerClient.create().creatingParentsIfNeeded().forPath("/a/b/c"); removerClient.checkExists().usingWatcher(watcher).forPath("/a/b/c"); removerClient.getData().usingWatcher(watcher).forPath("/a/b/c"); removerClient.setData().forPath("/a/b/c", "new".getBytes()); Timing timing = new Timing(); Assert.assertTrue(timing.awaitLatch(latch)); timing.sleepABit(); removerClient.removeWatchers(); } finally { TestCleanState.closeAndTestClean(client); } }
From source file:org.apache.curator.framework.imps.TestWatcherRemovalManager.java
License:Apache License
@Test public void testSameWatcherDifferentKinds() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); try {// ww w.j a va 2s . c o m client.start(); WatcherRemovalFacade removerClient = (WatcherRemovalFacade) client.newWatcherRemoveCuratorFramework(); Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { // NOP } }; removerClient.create().creatingParentsIfNeeded().forPath("/a/b/c"); removerClient.checkExists().usingWatcher(watcher).forPath("/a/b/c"); removerClient.getData().usingWatcher(watcher).forPath("/a/b/c"); removerClient.removeWatchers(); } finally { TestCleanState.closeAndTestClean(client); } }
From source file:org.apache.curator.framework.imps.TestWatcherRemovalManager.java
License:Apache License
@Test public void testWithRetry() throws Exception { server.stop();//from w w w. j a va2s . c om CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); try { client.start(); WatcherRemovalFacade removerClient = (WatcherRemovalFacade) client.newWatcherRemoveCuratorFramework(); Watcher w = new Watcher() { @Override public void process(WatchedEvent event) { // NOP } }; try { removerClient.checkExists().usingWatcher(w).forPath("/one/two/three"); Assert.fail("Should have thrown ConnectionLossException"); } catch (KeeperException.ConnectionLossException expected) { // expected } Assert.assertEquals(removerClient.getWatcherRemovalManager().getEntries().size(), 0); } finally { TestCleanState.closeAndTestClean(client); } }
From source file:org.apache.curator.framework.imps.TestWatcherRemovalManager.java
License:Apache License
@Test public void testWithRetryInBackground() throws Exception { server.stop();/*from w ww . ja v a2 s. c o m*/ CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); try { client.start(); WatcherRemovalFacade removerClient = (WatcherRemovalFacade) client.newWatcherRemoveCuratorFramework(); Watcher w = new Watcher() { @Override public void process(WatchedEvent event) { // NOP } }; final CountDownLatch latch = new CountDownLatch(1); BackgroundCallback callback = new BackgroundCallback() { @Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { latch.countDown(); } }; removerClient.checkExists().usingWatcher(w).inBackground(callback).forPath("/one/two/three"); Assert.assertTrue(new Timing().awaitLatch(latch)); Assert.assertEquals(removerClient.getWatcherRemovalManager().getEntries().size(), 0); } finally { TestCleanState.closeAndTestClean(client); } }
From source file:org.apache.curator.framework.imps.TestWatcherRemovalManager.java
License:Apache License
@Test public void testMissingNode() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); try {//from ww w . j av a 2s .c o m client.start(); WatcherRemovalFacade removerClient = (WatcherRemovalFacade) client.newWatcherRemoveCuratorFramework(); Watcher w = new Watcher() { @Override public void process(WatchedEvent event) { // NOP } }; try { removerClient.getData().usingWatcher(w).forPath("/one/two/three"); Assert.fail("Should have thrown NoNodeException"); } catch (KeeperException.NoNodeException expected) { // expected } removerClient.removeWatchers(); } finally { TestCleanState.closeAndTestClean(client); } }
From source file:org.apache.curator.framework.imps.TestWatcherRemovalManager.java
License:Apache License
@Test public void testMissingNodeInBackground() throws Exception { final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); Callable<Void> proc = new Callable<Void>() { @Override//from www. ja v a 2s .c o m public Void call() throws Exception { client.start(); WatcherRemovalFacade removerClient = (WatcherRemovalFacade) client .newWatcherRemoveCuratorFramework(); Watcher w = new Watcher() { @Override public void process(WatchedEvent event) { // NOP } }; final CountDownLatch latch = new CountDownLatch(1); BackgroundCallback callback = new BackgroundCallback() { @Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { latch.countDown(); } }; removerClient.getData().usingWatcher(w).inBackground(callback).forPath("/one/two/three"); Assert.assertTrue(new Timing().awaitLatch(latch)); Assert.assertEquals(removerClient.getWatcherRemovalManager().getEntries().size(), 0); removerClient.removeWatchers(); return null; } }; TestCleanState.test(client, proc); }
From source file:org.apache.curator.framework.imps.TestWatcherRemovalManager.java
License:Apache License
@Test public void testSameWatcher() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); try {/*from w w w .j a v a 2 s . com*/ client.start(); client.create().forPath("/test"); WatcherRemovalFacade removerClient = (WatcherRemovalFacade) client.newWatcherRemoveCuratorFramework(); Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { // NOP } }; removerClient.getData().usingWatcher(watcher).forPath("/test"); Assert.assertEquals(removerClient.getRemovalManager().getEntries().size(), 1); removerClient.getData().usingWatcher(watcher).forPath("/test"); Assert.assertEquals(removerClient.getRemovalManager().getEntries().size(), 1); removerClient.removeWatchers(); } finally { TestCleanState.closeAndTestClean(client); } }
From source file:org.apache.curator.framework.imps.TestWatcherRemovalManager.java
License:Apache License
@Test public void testTriggered() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); try {//from w w w . j a v a 2 s . c o m client.start(); WatcherRemovalFacade removerClient = (WatcherRemovalFacade) client.newWatcherRemoveCuratorFramework(); final CountDownLatch latch = new CountDownLatch(1); Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { if (event.getType() == Event.EventType.NodeCreated) { latch.countDown(); } } }; removerClient.checkExists().usingWatcher(watcher).forPath("/yo"); Assert.assertEquals(removerClient.getRemovalManager().getEntries().size(), 1); removerClient.create().forPath("/yo"); Assert.assertTrue(new Timing().awaitLatch(latch)); Assert.assertEquals(removerClient.getRemovalManager().getEntries().size(), 0); } finally { TestCleanState.closeAndTestClean(client); } }