Java Code Examples for org.apache.zookeeper.Watcher.Event.EventType#DataWatchRemoved
The following examples show how to use
org.apache.zookeeper.Watcher.Event.EventType#DataWatchRemoved .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestWatchesBuilder.java From curator with Apache License 2.0 | 5 votes |
@Test public void testRemoveCuratorWatch() throws Exception { Timing timing = new Timing(); CuratorFrameworkImpl client = (CuratorFrameworkImpl)CuratorFrameworkFactory.builder(). connectString(server.getConnectString()). retryPolicy(new RetryOneTime(1)). build(); try { client.start(); final CountDownLatch removedLatch = new CountDownLatch(1); final String path = "/"; CuratorWatcher watcher = new CuratorWatcher() { @Override public void process(WatchedEvent event) throws Exception { if(event.getPath().equals(path) && event.getType() == EventType.DataWatchRemoved) { removedLatch.countDown(); } } }; client.checkExists().usingWatcher(watcher).forPath(path); client.watches().remove(watcher).forPath(path); Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch removal"); } finally { CloseableUtils.closeQuietly(client); } }
Example 2
Source File: TestWatchesBuilder.java From curator with Apache License 2.0 | 5 votes |
@Test public void testRemoveWatch() throws Exception { Timing timing = new Timing(); CuratorFrameworkImpl client = (CuratorFrameworkImpl)CuratorFrameworkFactory.builder(). connectString(server.getConnectString()). retryPolicy(new RetryOneTime(1)). build(); try { client.start(); final CountDownLatch removedLatch = new CountDownLatch(1); final String path = "/"; Watcher watcher = new CountDownWatcher(path, removedLatch, EventType.DataWatchRemoved); client.checkExists().usingWatcher(watcher).forPath(path); client.watches().remove(watcher).forPath(path); Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch removal"); } finally { CloseableUtils.closeQuietly(client); } }
Example 3
Source File: TestWatchesBuilder.java From curator with Apache License 2.0 | 5 votes |
@Test public void testRemoveWatchInBackgroundWithNoCallback() throws Exception { Timing timing = new Timing(); CuratorFrameworkImpl client = (CuratorFrameworkImpl)CuratorFrameworkFactory.builder(). connectString(server.getConnectString()). retryPolicy(new RetryOneTime(1)). build(); try { client.start(); final String path = "/"; final CountDownLatch removedLatch = new CountDownLatch(1); Watcher watcher = new CountDownWatcher(path, removedLatch, EventType.DataWatchRemoved); client.checkExists().usingWatcher(watcher).forPath(path); client.watches().remove(watcher).inBackground().forPath(path); Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch removal"); } finally { CloseableUtils.closeQuietly(client); } }
Example 4
Source File: TestWatchesBuilder.java From curator with Apache License 2.0 | 5 votes |
@Test public void testRemoveAllWatches() throws Exception { Timing timing = new Timing(); CuratorFrameworkImpl client = (CuratorFrameworkImpl)CuratorFrameworkFactory.builder(). connectString(server.getConnectString()). retryPolicy(new RetryOneTime(1)). build(); try { client.start(); final String path = "/"; final CountDownLatch removedLatch = new CountDownLatch(2); Watcher watcher1 = new CountDownWatcher(path, removedLatch, EventType.ChildWatchRemoved); Watcher watcher2 = new CountDownWatcher(path, removedLatch, EventType.DataWatchRemoved); client.getChildren().usingWatcher(watcher1).forPath(path); client.checkExists().usingWatcher(watcher2).forPath(path); client.watches().removeAll().forPath(path); Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch removal"); } finally { CloseableUtils.closeQuietly(client); } }
Example 5
Source File: TestWatchesBuilder.java From curator with Apache License 2.0 | 5 votes |
@Test public void testRemoveAllDataWatches() throws Exception { Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.builder(). connectString(server.getConnectString()). retryPolicy(new RetryOneTime(1)). build(); try { client.start(); final String path = "/"; final AtomicBoolean removedFlag = new AtomicBoolean(false); final CountDownLatch removedLatch = new CountDownLatch(1); Watcher watcher1 = new BooleanWatcher(path, removedFlag, EventType.ChildWatchRemoved); Watcher watcher2 = new CountDownWatcher(path, removedLatch, EventType.DataWatchRemoved); client.getChildren().usingWatcher(watcher1).forPath(path); client.checkExists().usingWatcher(watcher2).forPath(path); client.watches().removeAll().ofType(WatcherType.Data).forPath(path); Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch removal"); Assert.assertEquals(removedFlag.get(), false); } finally { CloseableUtils.closeQuietly(client); } }
Example 6
Source File: TestWatchesBuilder.java From curator with Apache License 2.0 | 5 votes |
@Test public void testRemoveAllChildWatches() throws Exception { Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.builder(). connectString(server.getConnectString()). retryPolicy(new RetryOneTime(1)). build(); try { client.start(); final String path = "/"; final AtomicBoolean removedFlag = new AtomicBoolean(false); final CountDownLatch removedLatch = new CountDownLatch(1); Watcher watcher1 = new BooleanWatcher(path, removedFlag, EventType.DataWatchRemoved); Watcher watcher2 = new CountDownWatcher(path, removedLatch, EventType.ChildWatchRemoved); client.checkExists().usingWatcher(watcher1).forPath(path); client.getChildren().usingWatcher(watcher2).forPath(path); client.watches().removeAll().ofType(WatcherType.Children).forPath(path); Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch removal"); Assert.assertEquals(removedFlag.get(), false); } finally { CloseableUtils.closeQuietly(client); } }
Example 7
Source File: TestWatchesBuilder.java From curator with Apache License 2.0 | 5 votes |
@Test public void testRemoveLocalWatch() throws Exception { Timing timing = new Timing(); CuratorFrameworkImpl client = (CuratorFrameworkImpl)CuratorFrameworkFactory.builder(). connectString(server.getConnectString()). retryPolicy(new RetryOneTime(1)). build(); try { client.start(); AtomicReference<ConnectionState> stateRef = registerConnectionStateListener(client); final String path = "/"; final CountDownLatch removedLatch = new CountDownLatch(1); Watcher watcher = new CountDownWatcher(path, removedLatch, EventType.DataWatchRemoved); client.checkExists().usingWatcher(watcher).forPath(path); //Stop the server so we can check if we can remove watches locally when offline server.stop(); Assert.assertTrue(blockUntilDesiredConnectionState(stateRef, timing, ConnectionState.SUSPENDED)); client.watches().removeAll().locally().forPath(path); Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch removal"); } finally { CloseableUtils.closeQuietly(client); } }
Example 8
Source File: TestWatchesBuilder.java From curator with Apache License 2.0 | 5 votes |
@Test public void testRemoveLocalWatchInBackground() throws Exception { Timing timing = new Timing(); CuratorFrameworkImpl client = (CuratorFrameworkImpl)CuratorFrameworkFactory.builder(). connectString(server.getConnectString()). retryPolicy(new RetryOneTime(1)). build(); try { client.start(); AtomicReference<ConnectionState> stateRef = registerConnectionStateListener(client); final String path = "/"; final CountDownLatch removedLatch = new CountDownLatch(1); Watcher watcher = new CountDownWatcher(path, removedLatch, EventType.DataWatchRemoved); client.checkExists().usingWatcher(watcher).forPath(path); //Stop the server so we can check if we can remove watches locally when offline server.stop(); Assert.assertTrue(blockUntilDesiredConnectionState(stateRef, timing, ConnectionState.SUSPENDED)); client.watches().removeAll().locally().inBackground().forPath(path); Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch removal"); } finally { CloseableUtils.closeQuietly(client); } }
Example 9
Source File: TestWatchesBuilder.java From curator with Apache License 2.0 | 5 votes |
/** * Test the case where we try and remove an unregistered watcher but have the quietly flag set. In this case we expect success. * @throws Exception */ @Test public void testRemoveUnregisteredWatcherQuietly() throws Exception { Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.builder(). connectString(server.getConnectString()). retryPolicy(new RetryOneTime(1)). build(); try { client.start(); final AtomicBoolean watcherRemoved = new AtomicBoolean(false); final String path = "/"; Watcher watcher = new BooleanWatcher(path, watcherRemoved, EventType.DataWatchRemoved); client.watches().remove(watcher).quietly().forPath(path); timing.sleepABit(); //There should be no watcher removed as none were registered. Assert.assertEquals(watcherRemoved.get(), false); } finally { CloseableUtils.closeQuietly(client); } }
Example 10
Source File: TestWatchesBuilder.java From curator with Apache License 2.0 | 4 votes |
@Test public void testGuaranteedRemoveWatch() throws Exception { Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.builder(). connectString(server.getConnectString()). retryPolicy(new RetryOneTime(1)). build(); try { client.start(); AtomicReference<ConnectionState> stateRef = registerConnectionStateListener(client); String path = "/"; CountDownLatch removeLatch = new CountDownLatch(1); Watcher watcher = new CountDownWatcher(path, removeLatch, EventType.DataWatchRemoved); client.checkExists().usingWatcher(watcher).forPath(path); server.stop(); Assert.assertTrue(blockUntilDesiredConnectionState(stateRef, timing, ConnectionState.SUSPENDED)); //Remove the watch while we're not connected try { client.watches().remove(watcher).guaranteed().forPath(path); Assert.fail(); } catch(KeeperException.ConnectionLossException e) { //Expected } server.restart(); timing.awaitLatch(removeLatch); } finally { CloseableUtils.closeQuietly(client); } }
Example 11
Source File: TestWatchesBuilder.java From curator with Apache License 2.0 | 4 votes |
@Test public void testGuaranteedRemoveWatchInBackground() throws Exception { Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new ExponentialBackoffRetry(100, 3)); try { client.start(); AtomicReference<ConnectionState> stateRef = registerConnectionStateListener(client); final CountDownLatch guaranteeAddedLatch = new CountDownLatch(1); ((CuratorFrameworkImpl)client).getFailedRemoveWatcherManager().debugListener = new FailedOperationManager.FailedOperationManagerListener<FailedRemoveWatchManager.FailedRemoveWatchDetails>() { @Override public void pathAddedForGuaranteedOperation( FailedRemoveWatchDetails detail) { guaranteeAddedLatch.countDown(); } }; String path = "/"; CountDownLatch removeLatch = new CountDownLatch(1); Watcher watcher = new CountDownWatcher(path, removeLatch, EventType.DataWatchRemoved); client.checkExists().usingWatcher(watcher).forPath(path); server.stop(); Assert.assertTrue(blockUntilDesiredConnectionState(stateRef, timing, ConnectionState.SUSPENDED)); //Remove the watch while we're not connected client.watches().remove(watcher).guaranteed().inBackground().forPath(path); timing.awaitLatch(guaranteeAddedLatch); server.restart(); timing.awaitLatch(removeLatch); } finally { CloseableUtils.closeQuietly(client); } }