  @Test
  public void test() throws Exception {

    class ConnectionWatcher implements Watcher {

      private ZooKeeper zk;
      private CountDownLatch latch = new CountDownLatch(1);
      
      public void connect(String hosts) throws IOException, InterruptedException {
	zk = new ZooKeeper(hosts, 5000, this);
	latch.await();
      }
      
      public ZooKeeper getZooKeeper() {
	return zk;
      }
      
      @Override
      public void process(WatchedEvent event) {
	if (event.getState() == KeeperState.SyncConnected) {
	  latch.countDown();
	}
      }
      
      public void close() throws InterruptedException {
	if (zk != null) {
	  zk.close();
	}
      }
      
    }
    
    String path = "/data";
    String data = "Hello";
    ConnectionWatcher watcher = new ConnectionWatcher();
    watcher.connect(cluster.getHosts());
    watcher.getZooKeeper().create(path, data.getBytes(), Ids.OPEN_ACL_UNSAFE,
      CreateMode.PERSISTENT);
    watcher.close();
    
    watcher = new ConnectionWatcher();
    watcher.connect(cluster.getHosts());
    byte[] actualData = watcher.getZooKeeper().getData(path, false, null);
    assertEquals(data, new String(actualData));
    watcher.close();
  }