use of org.apache.zookeeper.AddWatchMode.PERSISTENT in project zookeeper by apache.
the class PersistentWatcherTest method testBasicAsync.
@Test
public void testBasicAsync() throws IOException, InterruptedException, KeeperException {
CountdownWatcher watcher = new CountdownWatcher() {
@Override
public synchronized void process(WatchedEvent event) {
super.process(event);
events.add(event);
}
};
try (ZooKeeper zk = createClient(watcher, hostPort)) {
final CountDownLatch latch = new CountDownLatch(1);
AsyncCallback.VoidCallback cb = (rc, path, ctx) -> {
if (rc == KeeperException.Code.OK.intValue()) {
latch.countDown();
}
};
zk.addWatch("/a/b", persistentWatcher, PERSISTENT, cb, null);
assertTrue(latch.await(5, TimeUnit.SECONDS));
// clear any events added during client connection
events.clear();
internalTestBasic(zk);
}
}
use of org.apache.zookeeper.AddWatchMode.PERSISTENT in project zookeeper by apache.
the class PersistentWatcherTest method testAsyncDefaultWatcher.
@Test
public void testAsyncDefaultWatcher() throws IOException, InterruptedException, KeeperException {
try (ZooKeeper zk = createClient(new CountdownWatcher(), hostPort)) {
final CountDownLatch latch = new CountDownLatch(1);
AsyncCallback.VoidCallback cb = (rc, path, ctx) -> {
if (rc == KeeperException.Code.OK.intValue()) {
latch.countDown();
}
};
zk.addWatch("/a/b", persistentWatcher, PERSISTENT, cb, null);
assertTrue(latch.await(5, TimeUnit.SECONDS));
internalTestBasic(zk);
}
}
use of org.apache.zookeeper.AddWatchMode.PERSISTENT in project zookeeper by apache.
the class PersistentWatcherTest method testNullWatch.
@Test
public void testNullWatch() throws IOException, InterruptedException, KeeperException {
try (ZooKeeper zk = createClient(new CountdownWatcher(), hostPort)) {
assertThrows(IllegalArgumentException.class, () -> {
zk.addWatch("/a/b", null, PERSISTENT);
});
assertThrows(IllegalArgumentException.class, () -> {
AsyncCallback.VoidCallback cb = (rc, path, ctx) -> {
};
zk.addWatch("/a/b", null, PERSISTENT, cb, null);
});
}
}
Aggregations