final String MON_B = "I am mon B";
ChangeSource changeSource = new MockChangeSource(Arrays.asList(new Change[] {
newChange(0, MON_A), newChange(0, MON_B), newChange(1, MON_A),
newChange(1, MON_B), newChange(2, MON_B), newChange(2, MON_A)
}));
CheckpointAndChangeQueue q = new CheckpointAndChangeQueue(changeSource,
persistDir, internalFactory, clientFactory);
q.setMaximumQueueSize(2);
String checkpoint = null;
q.start(checkpoint);
List<CheckpointAndChange> batch = q.resume(checkpoint);
Map<String, MonitorCheckpoint> monPoints = q.getMonitorRestartPoints();
assertEquals(2, monPoints.size());
assertTrue(monPoints.containsKey(MON_A));
assertTrue(monPoints.containsKey(MON_B));
assertEquals(0, monPoints.get(MON_A).getOffset1());
assertEquals(0, monPoints.get(MON_B).getOffset1());
assertEquals(0, monPoints.get(MON_A).getOffset2());
assertEquals(0, monPoints.get(MON_B).getOffset2());
checkpoint = batch.get(0).getCheckpoint().toString();
batch = q.resume(checkpoint);
monPoints = q.getMonitorRestartPoints();
assertEquals(2, monPoints.size());
assertTrue(monPoints.containsKey(MON_A));
assertTrue(monPoints.containsKey(MON_B));
assertEquals(1, monPoints.get(MON_A).getOffset1());
assertEquals(0, monPoints.get(MON_B).getOffset1());
assertEquals(1, monPoints.get(MON_A).getOffset2());
assertEquals(0, monPoints.get(MON_B).getOffset2());
// Can do it again.
batch = q.resume(checkpoint);
monPoints = q.getMonitorRestartPoints();
assertEquals(2, monPoints.size());
assertTrue(monPoints.containsKey(MON_A));
assertTrue(monPoints.containsKey(MON_B));
assertEquals(1, monPoints.get(MON_A).getOffset1());
assertEquals(0, monPoints.get(MON_B).getOffset1());