}
@Test
public void testAddChildWithPut() throws Exception
{
ZooKeeper zk = getClient(0);
configure("/cache04", zk);
MapCache dut = new MapCache(zk, "/cache04");
dut.start(true);
Map<String, JSONObject> cache = dut.pointInTimeCache();
JSONObject dd = new JSONObject("{key:ddval}");
dut.put("dd", dd);
while(true) {
cache = dut.pointInTimeCache();
if (cache.size() == 3) {
Thread.sleep(1);
}
else {
break;
}
}
assertEquals("Item added", 4, cache.size());
assertEquals("aaval", cache.get("/cache04/aa").get("key"));
assertEquals("bbval", cache.get("/cache04/bb").get("key"));
assertEquals("ccval", cache.get("/cache04/cc").get("key"));
assertEquals("ddval", cache.get("/cache04/dd").get("key"));
// modify the new child and make sure it has a watch set.
JSONObject dd2 = new JSONObject("{key:ddval2}");
dut.put("dd", dd2);
while(true) {
cache = dut.pointInTimeCache();
if (cache.get("/cache04/dd").get("key").equals("ddval2")) {
break;
}
}
assertEquals("Items accounted for.", 4, cache.size());
assertEquals("ddval2", cache.get("/cache04/dd").get("key"));
dut.shutdown();
zk.close();
}