List of usage examples for org.apache.zookeeper KeeperException code
Code code
To view the source code for org.apache.zookeeper KeeperException code.
Click Source Link
From source file:com.linkedin.d2.discovery.stores.zk.SymlinkAwareZooKeeperTest.java
License:Apache License
@Test public void testSymlinkGetChildren() throws InterruptedException, ExecutionException, IOException { final CountDownLatch latch = new CountDownLatch(1); AsyncCallback.ChildrenCallback callback = new AsyncCallback.ChildrenCallback() { @Override//from w ww . j av a2s . c o m public void processResult(int rc, String path, Object ctx, List<String> children) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.OK); Assert.assertEquals(path, "/foo/$link"); Assert.assertEquals(children.size(), 10); latch.countDown(); } }; // symlink: /foo/$link -> /foo/bar _zkClient.getZooKeeper().getChildren("/foo/$link", null, callback, null); latch.await(30, TimeUnit.SECONDS); }
From source file:com.linkedin.d2.discovery.stores.zk.SymlinkAwareZooKeeperTest.java
License:Apache License
@Test public void testSymlinkGetChildren2() throws InterruptedException, ExecutionException, IOException, KeeperException { final CountDownLatch latch = new CountDownLatch(1); Stat expectedStat = _zkClient.getZooKeeper().exists("/foo/bar", false); AsyncCallback.Children2Callback callback = new AsyncCallback.Children2Callback() { @Override/* w w w .j a v a2 s.c o m*/ public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.OK); Assert.assertEquals(path, "/foo/$link"); Assert.assertEquals(children.size(), 10); Assert.assertEquals(stat, expectedStat); latch.countDown(); } }; // symlink: /foo/$link -> /foo/bar _zkClient.getZooKeeper().getChildren("/foo/$link", null, callback, null); latch.await(30, TimeUnit.SECONDS); }
From source file:com.linkedin.d2.discovery.stores.zk.SymlinkAwareZooKeeperTest.java
License:Apache License
@Test public void testMultiSymlink() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); AsyncCallback.ChildrenCallback callback = new AsyncCallback.ChildrenCallback() { @Override/*from w w w. j a v a 2s. c o m*/ public void processResult(int rc, String path, Object ctx, List<String> children) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.OK); Assert.assertEquals(path, "/$bar/$link"); Assert.assertEquals(children.size(), 10); latch.countDown(); } }; // symlink: /$bar -> /foo // symlink: /foo/$link -> /foo/bar _zkClient.getZooKeeper().getChildren("/$bar/$link", null, callback, null); latch.await(30, TimeUnit.SECONDS); }
From source file:com.linkedin.d2.discovery.stores.zk.SymlinkAwareZooKeeperTest.java
License:Apache License
@Test public void testSymlinkGetData() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback() { @Override/*from w w w . j a v a2 s . c om*/ public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) { String value = null; try { value = new String(data, "UTF-8"); } catch (UnsupportedEncodingException e) { Assert.fail(e.getMessage()); } finally { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.OK); Assert.assertEquals(value, (String) ctx); Assert.assertNotNull(stat); latch.countDown(); } } }; // symlink: /foo/$link/1 -> /foo/bar/1 _zkClient.getZooKeeper().getData("/foo/$link/1", null, callback, "1"); latch.await(30, TimeUnit.SECONDS); }
From source file:com.linkedin.d2.discovery.stores.zk.SymlinkAwareZooKeeperTest.java
License:Apache License
@Test public void testNonexistentSymlink() throws ExecutionException, InterruptedException { final CountDownLatch latch = new CountDownLatch(3); AsyncCallback.StatCallback statCallback = new AsyncCallback.StatCallback() { @Override//w w w. j a v a 2 s . co m public void processResult(int rc, String path, Object ctx, Stat stat) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.NONODE); latch.countDown(); } }; AsyncCallback.DataCallback dataCallback = new AsyncCallback.DataCallback() { @Override public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.NONODE); latch.countDown(); } }; AsyncCallback.ChildrenCallback childrenCallback = new AsyncCallback.ChildrenCallback() { @Override public void processResult(int rc, String path, Object ctx, List<String> children) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.NONODE); latch.countDown(); } }; // symlink: /foo/$badlink -> null _zkClient.getZooKeeper().exists("/foo/$badlink", false, statCallback, null); _zkClient.getZooKeeper().getData("/foo/$badlink", false, dataCallback, null); _zkClient.getZooKeeper().getChildren("/foo/$badlink", false, childrenCallback, null); latch.await(30, TimeUnit.SECONDS); }
From source file:com.linkedin.d2.discovery.stores.zk.SymlinkAwareZooKeeperTest.java
License:Apache License
@Test public void testSymlinkWithExistWatch() throws InterruptedException, ExecutionException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); final AsyncCallback.StatCallback existCallback = new AsyncCallback.StatCallback() { @Override/*from w w w.ja v a 2s.c om*/ public void processResult(int rc, String path, Object ctx, Stat stat) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.OK); latch.countDown(); } }; Watcher existWatch = new Watcher() { @Override public void process(WatchedEvent event) { Assert.assertEquals(event.getType(), Event.EventType.NodeCreated); _zkClient.getZooKeeper().exists(event.getPath(), null, existCallback, null); } }; AsyncCallback.StatCallback existCallback2 = new AsyncCallback.StatCallback() { @Override public void processResult(int rc, String path, Object ctx, Stat stat) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.NONODE); latch2.countDown(); } }; // symlink: /foo/$link/newNode -> /foo/bar/newNode _zkClient.getZooKeeper().exists("/foo/$link/newNode", existWatch, existCallback2, null); latch2.await(30, TimeUnit.SECONDS); _zkClient.ensurePersistentNodeExists("/foo/bar/newNode", new FutureCallback<None>()); latch.await(30, TimeUnit.SECONDS); _zkClient.removeNodeUnsafe("/foo/bar/newNode", new FutureCallback<None>()); }
From source file:com.linkedin.d2.discovery.stores.zk.SymlinkAwareZooKeeperTest.java
License:Apache License
@Test public void testSymlinkWithExistWatch2() throws InterruptedException, ExecutionException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); final AsyncCallback.StatCallback existCallback = new AsyncCallback.StatCallback() { @Override/* w w w.ja v a2 s . co m*/ public void processResult(int rc, String path, Object ctx, Stat stat) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.OK); latch.countDown(); } }; Watcher existWatch = new Watcher() { @Override public void process(WatchedEvent event) { Assert.assertEquals(event.getType(), Event.EventType.NodeDataChanged); _zkClient.getZooKeeper().exists(event.getPath(), null, existCallback, null); } }; AsyncCallback.StatCallback existCallback2 = new AsyncCallback.StatCallback() { @Override public void processResult(int rc, String path, Object ctx, Stat stat) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.NONODE); latch2.countDown(); } }; // symlink: /foo/$link/foo -> /foo/bar/foo, which doesn't exist _zkClient.getZooKeeper().exists("/foo/$link/foo", existWatch, existCallback2, null); latch2.await(30, TimeUnit.SECONDS); // update symlink. now it points to /bar/foo, which does exist. _zkClient.setSymlinkData("/foo/$link", "/bar", new FutureCallback<None>()); latch.await(30, TimeUnit.SECONDS); // restore symlink _zkClient.setSymlinkData("/foo/$link", "/foo/bar", new FutureCallback<None>()); }
From source file:com.linkedin.d2.discovery.stores.zk.SymlinkAwareZooKeeperTest.java
License:Apache License
@Test public void testSymlinkWithExistWatch3() throws InterruptedException, ExecutionException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); final AsyncCallback.StatCallback existCallback = new AsyncCallback.StatCallback() { @Override/*from w w w.ja va 2s .c om*/ public void processResult(int rc, String path, Object ctx, Stat stat) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.OK); latch.countDown(); } }; Watcher existWatch = new Watcher() { @Override public void process(WatchedEvent event) { Assert.assertEquals(event.getType(), Event.EventType.NodeCreated); _zkClient.getZooKeeper().exists(event.getPath(), null, existCallback, null); } }; AsyncCallback.StatCallback existCallback2 = new AsyncCallback.StatCallback() { @Override public void processResult(int rc, String path, Object ctx, Stat stat) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.NONODE); latch2.countDown(); } }; // symlink /$link doesn't exist. _zkClient.getZooKeeper().exists("/$link", existWatch, existCallback2, null); latch2.await(30, TimeUnit.SECONDS); // create symlink /$link -> /foo/bar. existWatch should be notified. _zkClient.createSymlink("/$link", "/foo/bar", new FutureCallback<None>()); latch.await(30, TimeUnit.SECONDS); // delete symlink /$link _zkClient.removeNodeUnsafe("/$link", new FutureCallback<None>()); }
From source file:com.linkedin.d2.discovery.stores.zk.SymlinkAwareZooKeeperTest.java
License:Apache License
@Test public void testSymlinkWithChildrenWatch() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); final AsyncCallback.ChildrenCallback childrenCallback = new AsyncCallback.ChildrenCallback() { @Override//from w w w . ja v a 2 s . c om public void processResult(int rc, String path, Object ctx, List<String> children) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.OK); Assert.assertEquals(children.size(), 11); latch.countDown(); } }; Watcher childrenWatch = new Watcher() { @Override public void process(WatchedEvent event) { Assert.assertEquals(event.getType(), Event.EventType.NodeChildrenChanged); _zkClient.getZooKeeper().getChildren(event.getPath(), null, childrenCallback, null); } }; AsyncCallback.ChildrenCallback childrenCallback2 = new AsyncCallback.ChildrenCallback() { @Override public void processResult(int rc, String path, Object ctx, List<String> children) { KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.OK); latch2.countDown(); } }; // symlink: /foo/$link -> /foo/bar _zkClient.getZooKeeper().getChildren("/foo/$link", childrenWatch, childrenCallback2, null); latch2.await(30, TimeUnit.SECONDS); _zkClient.ensurePersistentNodeExists("/foo/bar/newNode", new FutureCallback<None>()); latch.await(30, TimeUnit.SECONDS); _zkClient.removeNodeUnsafe("/foo/bar/newNode", new FutureCallback<None>()); }
From source file:com.linkedin.d2.discovery.stores.zk.SymlinkAwareZooKeeperTest.java
License:Apache License
@Test public void testInvalidSymlinkWithExists() throws ExecutionException, InterruptedException { final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); final AsyncCallback.StatCallback callback = new AsyncCallback.StatCallback() { @Override//from ww w . j av a 2s. co m public void processResult(int rc, String path, Object ctx, Stat stat) { Assert.assertEquals(path, "/foo/$link"); KeeperException.Code result = KeeperException.Code.get(rc); Assert.assertEquals(result, KeeperException.Code.NONODE); latch1.countDown(); } }; final Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { Assert.assertEquals(event.getType(), Event.EventType.NodeDataChanged); latch2.countDown(); } }; FutureCallback<None> fcb = new FutureCallback<None>(); _zkClient.setSymlinkData("/foo/$link", "INVALID", fcb); fcb.get(); _zkClient.getZooKeeper().exists("/foo/$link", watcher, callback, null); latch1.await(30, TimeUnit.SECONDS); _zkClient.setSymlinkData("/foo/$link", "/foo/bar", fcb); if (!latch2.await(30, TimeUnit.SECONDS)) { Assert.fail("Exists Watch is not triggered"); } }