File persistDirA = testDirectoryManager.makeDirectory("queue-A");
File persistDirB = testDirectoryManager.makeDirectory("queue-B");
{ /* Make recovery file that finishes 2nd batch. */
ChangeSource changeSource = new MockChangeSource(6);
CheckpointAndChangeQueue q = new CheckpointAndChangeQueue(changeSource,
persistDirA, internalFactory, clientFactory);
q.setMaximumQueueSize(2);
q.start(null);
List<CheckpointAndChange> firstBatch = q.resume(null);
String checkpoint = firstBatch.get(1).getCheckpoint().toString();
List<CheckpointAndChange> secondBatch = q.resume(checkpoint);
checkpoint = secondBatch.get(1).getCheckpoint().toString();
q.resume(checkpoint);
File recoveryFile = persistDirA.listFiles()[0];
recoveryFile.renameTo(new File(persistDir, recoveryFile.getName()));
}
List<CheckpointAndChange> secondBatch;
String checkpoint;
{ /* Make recovery file that finishes 1st batch. */
ChangeSource changeSource = new MockChangeSource(6);
CheckpointAndChangeQueue q = new CheckpointAndChangeQueue(changeSource,
persistDirB, internalFactory, clientFactory);
q.setMaximumQueueSize(2);
q.start(null);
List<CheckpointAndChange> firstBatch = q.resume(null);
checkpoint = firstBatch.get(1).getCheckpoint().toString();
secondBatch = q.resume(checkpoint);
File recoveryFile = persistDirB.listFiles()[0];
recoveryFile.renameTo(new File(persistDir, recoveryFile.getName()));
}
ChangeSource changeSource = new MockChangeSource(6);
CheckpointAndChangeQueue q = new CheckpointAndChangeQueue(changeSource,
persistDir, internalFactory, clientFactory);
q.setMaximumQueueSize(2);
q.start(checkpoint);
List<CheckpointAndChange> secondBatchAgain = q.resume(checkpoint);
assertEquals(secondBatch, secondBatchAgain);
assertTrue(deleteDir(persistDirA));
assertTrue(deleteDir(persistDirB));
}