//simple checkpoint
Checkpoint cp1 = new Checkpoint();
cp1.setFlexible();
CacheEntry cacheEntry = checkpointProvider.new CacheEntry(streamId, null);
assertTrue(cacheEntry.setCheckpoint(cp1));
assertTrue(checkpointFile.exists());
CacheEntry cacheEntry2 = checkpointProvider.new CacheEntry(streamId, null);
Checkpoint cp2 = cacheEntry2.getCheckpoint();
assertNotNull(cp2);
//TODO need to use a Checkpoint.equals() method
assertEquals(DbusClientMode.ONLINE_CONSUMPTION, cp2.getConsumptionMode());
assertTrue(cp2.getFlexible());
//more complex checkpoint plus overwriting current state
Checkpoint cp3 = new Checkpoint();
cp3.setWindowScn(1234L);
cp3.setWindowOffset(9876);
cp3.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION);
assertTrue(cacheEntry.setCheckpoint(cp3));
assertTrue(checkpointFile.exists());
File cpBackupFile = new File(checkpointDir, streamId + ".oldcurrent");
assertTrue(cpBackupFile.exists());
cacheEntry2 = checkpointProvider.new CacheEntry(streamId, null);
cp2 = cacheEntry2.getCheckpoint();
assertNotNull(cp2);
//TODO need to use a Checkpoint.equals() method
assertEquals(cp3.getConsumptionMode(), cp2.getConsumptionMode());
assertEquals(cp3.getWindowScn(), cp2.getWindowScn());
assertEquals(cp3.getPrevScn(), cp2.getPrevScn());
assertEquals(cp3.getWindowOffset(), cp2.getWindowOffset());
//make sure the backup still works
assertTrue(checkpointFile.delete());
assertTrue(!checkpointFile.exists());
if (!cpBackupFile.renameTo(checkpointFile))
LOG.error("file rename failed: " + cpBackupFile.getAbsolutePath() + " --> " +
checkpointFile.getAbsolutePath());
assertTrue(checkpointFile.exists());
cacheEntry2 = checkpointProvider.new CacheEntry(streamId, null);
cp2 = cacheEntry2.getCheckpoint();
assertNotNull(cp2);
//TODO need to use a Checkpoint.equals() method
assertEquals(DbusClientMode.ONLINE_CONSUMPTION, cp2.getConsumptionMode());
assertTrue(cp2.getFlexible());
//try to keep some stuff around and see if things go south
Checkpoint cp4 = new Checkpoint();
cp4.setWindowScn(1111L);
cp4.setWindowOffset(2222);
cp4.setConsumptionMode(DbusClientMode.BOOTSTRAP_CATCHUP);
File newCpFile = new File(checkpointDir, streamId + ".newcheckpoint");
PrintWriter tmpWriter = new PrintWriter(newCpFile);
try{
tmpWriter.println("Dummy");
assertTrue(cacheEntry.setCheckpoint(cp4));
assertTrue(checkpointFile.exists());
cacheEntry2 = checkpointProvider.new CacheEntry(streamId, null);
cp2 = cacheEntry2.getCheckpoint();
assertNotNull(cp2);
//TODO need to use a Checkpoint.equals() method
assertEquals(cp4.getConsumptionMode(), cp2.getConsumptionMode());
assertEquals(cp4.getWindowScn(), cp2.getWindowScn());
assertEquals(cp4.getPrevScn(), cp2.getPrevScn());