@@ -0,0 +1,1989 @@
+/**%0A * %0A */%0Apackage istc.bigdawg.zookeeper;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport java.io.IOException;%0Aimport java.util.concurrent.ExecutionException;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.Future;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.concurrent.TimeoutException;%0A%0Aimport org.apache.zookeeper.CreateMode;%0Aimport org.apache.zookeeper.KeeperException;%0Aimport org.apache.zookeeper.Watcher.Event.EventType;%0Aimport org.apache.zookeeper.ZooDefs;%0Aimport org.apache.zookeeper.ZooKeeper;%0Aimport org.junit.Test;%0A%0Aimport istc.bigdawg.exceptions.NetworkException;%0Aimport istc.bigdawg.network.NetworkUtils;%0Aimport istc.bigdawg.zookeeper.znode.NodeInfo;%0A%0A/**%0A * @author Adam Dziedzic%0A * %0A *%0A */%0Apublic class ZooKeeperHandlerTest %7B%0A%0A%09/**%0A%09 * Path to the test znode in ZooKeeper.%0A%09 */%0A%09private final static String znodePath = %22/_test_zookeeper_watch_event_%22;%0A%0A%09@Test%0A%09public void testWatchEvent()%0A%09%09%09throws NetworkException, KeeperException, InterruptedException,%0A%09%09%09IOException, ExecutionException, TimeoutException %7B%0A%09%09/* open the connection to ZooKeeper */%0A%09%09int sessionTimeout = 5000;%0A%09%09ZooKeeper zk = ZooKeeperHandler.connect(%22localhost%22, sessionTimeout);%0A%09%09ZooKeeperHandler zooHandler = new ZooKeeperHandler(zk);%0A%09%09zooHandler.createZnodeIfNotExists(znodePath,%0A%09%09%09%09NetworkUtils.serialize(new NodeInfo(%22test%22)),%0A%09%09%09%09ZooDefs.Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT);%0A%09%09EventType eventType = EventType.NodeDeleted;%0A%0A%09%09ExecutorService executor = Executors.newFixedThreadPool(1);%0A%09%09Future%3CObject%3E futureResultFromCallable = executor%0A%09%09%09%09.submit(zooHandler.callableWatch(znodePath, eventType));%0A%09%09zooHandler.deleteZnode(znodePath);%0A%09%09String result = (String) futureResultFromCallable.get(10,%0A%09%09%09%09TimeUnit.SECONDS);%0A%09%09System.out.println(%22Result from the watcher: %22 + result);%0A%09%09assertEquals(ZooKeeperHandler.watchMessagePrefix + eventType + %22 path: %22%0A%09%09%09%09+ znodePath, result);%0A%09%09zk.close();%0A%09%7D%0A%0A%7D%0A

test for zookeeper