assertTrue(localWatcher.events.isEmpty());
zk.setData("/watchtest/child", new byte[1], -1);
zk.create("/watchtest/child2", new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
WatchedEvent e = localWatcher.events.poll(1, TimeUnit.MILLISECONDS);
if (!ClientCnxn.disableAutoWatchReset) {
assertEquals(e.getPath(), EventType.NodeDataChanged, e.getType());
assertEquals("/watchtest/child", e.getPath());
} else {
assertNull("unexpected event", e);
}
e = localWatcher.events.poll(1000, TimeUnit.MILLISECONDS);
if (!ClientCnxn.disableAutoWatchReset) {
// The create will trigger the get children and the exist
// watches
assertEquals(EventType.NodeCreated, e.getType());
assertEquals("/watchtest/child2", e.getPath());
} else {
assertNull("unexpected event", e);
}
e = localWatcher.events.poll(1000, TimeUnit.MILLISECONDS);
if (!ClientCnxn.disableAutoWatchReset) {
assertEquals(EventType.NodeChildrenChanged, e.getType());
assertEquals("/watchtest", e.getPath());
} else {
assertNull("unexpected event", e);
}
// Make sure PINGs don't screw us up!
Thread.sleep(4000);
assertTrue(localWatcher.events.isEmpty()); // ensure no late arrivals
stopServer();
globalWatcher.waitForDisconnected(3000);
try {
try {
localWatcher.waitForDisconnected(500);
if (!isGlobal && !ClientCnxn.disableAutoWatchReset) {
fail("Got an event when I shouldn't have");
}
} catch(TimeoutException toe) {
if (ClientCnxn.disableAutoWatchReset) {
fail("Didn't get an event when I should have");
}
// Else what we are expecting since there are no outstanding watches
}
} catch (Exception e1) {
LOG.error("bad", e1);
throw new RuntimeException(e1);
}
startServer();
globalWatcher.waitForConnected(3000);
if (isGlobal) {
zk.getChildren("/watchtest", true);
zk.getData("/watchtest/child", true, new Stat());
zk.exists("/watchtest/child2", true);
} else {
zk.getChildren("/watchtest", localWatcher);
zk.getData("/watchtest/child", localWatcher, new Stat());
zk.exists("/watchtest/child2", localWatcher);
}
// Do trigger an event to make sure that we do not get
// it later
zk.delete("/watchtest/child2", -1);
e = localWatcher.events.poll(1, TimeUnit.MILLISECONDS);
assertEquals(EventType.NodeDeleted, e.getType());
assertEquals("/watchtest/child2", e.getPath());
e = localWatcher.events.poll(1, TimeUnit.MILLISECONDS);
assertEquals(EventType.NodeChildrenChanged, e.getType());
assertEquals("/watchtest", e.getPath());
assertTrue(localWatcher.events.isEmpty());
stopServer();
globalWatcher.waitForDisconnected(3000);
localWatcher.waitForDisconnected(500);
startServer();
globalWatcher.waitForConnected(3000);
if (!isGlobal && !ClientCnxn.disableAutoWatchReset) {
localWatcher.waitForConnected(500);
}
zk.delete("/watchtest/child", -1);
zk.delete("/watchtest", -1);
e = localWatcher.events.poll(1, TimeUnit.MILLISECONDS);
if (!ClientCnxn.disableAutoWatchReset) {
assertEquals(EventType.NodeDeleted, e.getType());
assertEquals("/watchtest/child", e.getPath());
} else {
assertNull("unexpected event", e);
}
// Make sure nothing is straggling!