final CuratorFramework curator = CuratorFrameworkFactory.builder()
.retryPolicy(retryPolicy)
.connectString(zk().connectString())
.build();
final ZooKeeperClient client = new DefaultZooKeeperClient(curator, zkClusterId);
client.start();
// This should work since the cluster ID exists
client.create("/test");
// Now let's remove the cluster ID
client.delete(Paths.configId(zkClusterId));
// Sleep so the watcher thread in ZooKeeperClient has a chance to update state
Thread.sleep(500);
// Try the same operation again, and it should fail this time
try {
client.ensurePath(Paths.configJobs());
fail("ZooKeeper operation should have failed because cluster ID was removed");
} catch (IllegalStateException ignore) {
}
}