ZkclientZookeeperClient extends AbstractZookeeperClient<IZkChildListener> { @Override public boolean isConnected() { return state == KeeperState.SyncConnected; } ZkclientZookeeperClient(String serverAddr); @Override void createPersistent(String path); @Override void createEphemeral(String path); @Override void delete(String path); @Override List<String> getChildren(String path); @Override boolean checkExists(String path); @Override boolean isConnected(); @Override void doClose(); @Override IZkChildListener createTargetChildListener(String path, final ChildListener listener); @Override List<String> addTargetChildListener(String path, final IZkChildListener listener); @Override void removeTargetChildListener(String path, IZkChildListener listener);  }
@Test public void testConnectState() throws Exception { assertThat(zkclientZookeeperClient.isConnected(), is(true)); final CountDownLatch stopLatch = new CountDownLatch(1); zkclientZookeeperClient.addStateListener(new StateListener() { @Override public void stateChanged(int connected) { stopLatch.countDown(); } }); zkServer.stop(); stopLatch.await(); assertThat(zkclientZookeeperClient.isConnected(), is(false)); }