stringsListener.inSync();
intListener.inSync();
replay(stringsListener);
replay(intListener);
Chronicle chronicle = new IndexedChronicle(name);
DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
MapWrapper<String, String> strings = new MapWrapper<String, String>(dataStore, "strings", String.class, String.class, new LinkedHashMap<String, String>(), 16);
strings.addListener(stringsListener);
MapWrapper<Integer, Integer> ints = new MapWrapper<Integer, Integer>(dataStore, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16);
ints.addListener(intListener);
dataStore.start();
ints.put(0, 1000);
strings.put("Hello", "hi");
ints.put(1, 1001);
strings.put("World", "all");
ints.put(2, 1002);
strings.publishEvent("bye");
ints.publishEvent("now");
verify(stringsListener);
verify(intListener);
assertEquals("{Hello=hi, World=all}", strings.toString());
assertEquals("{0=1000, 1=1001, 2=1002}", ints.toString());
chronicle.close();
}
{
MapListener stringsListener = createMock("strings", MapListener.class);
stringsListener.eventStart(7, "strings");
stringsListener.add("!", "end");
stringsListener.eventEnd(true);
MapListener intListener = createMock("ints", MapListener.class);
intListener.eventStart(8, "ints");
intListener.add(3, 1003);
intListener.eventEnd(true);
stringsListener.inSync();
intListener.inSync();
replay(stringsListener);
replay(intListener);
Chronicle chronicle = new IndexedChronicle(name);
DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
MapWrapper<String, String> strings = new MapWrapper<String, String>(dataStore, "strings", String.class, String.class, new LinkedHashMap<String, String>(), 16);
strings.addListener(stringsListener);
MapWrapper<Integer, Integer> ints = new MapWrapper<Integer, Integer>(dataStore, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16);
ints.addListener(intListener);
// assume we have all the events written so far
dataStore.start(chronicle.size() - 1);
strings.put("!", "end");
ints.put(3, 1003);
verify(stringsListener);
verify(intListener);
assertEquals("{Hello=hi, World=all, !=end}", strings.toString());
assertEquals("{0=1000, 1=1001, 2=1002, 3=1003}", ints.toString());
chronicle.close();
}
}