throws StandardException, T_Fail
{
if (!testRollback)
return;
ContextManager previousCM = contextService.getCurrentContextManager();
Transaction longtran = null;
ContextManager cm1 = null;
Transaction t1 = null;
ContextManager cm2 = null;
Transaction t2 = null;
// ContextManager cpm = null; // reserved for the checkpoint transaction
try {
T_RawStoreRow row1 = new T_RawStoreRow(REC_001);
T_RawStoreRow row2 = new T_RawStoreRow(REC_002);
T_RawStoreRow row3 = new T_RawStoreRow(REC_003);
T_RawStoreRow row4 = new T_RawStoreRow(REC_004);
T_RawStoreRow row5 = new T_RawStoreRow(REC_005);
// start a long running transaction that spans multiple checkpoints
// make sure it can be rolled back a the end
longtran = t_util.t_startTransaction();
long cid = t_util.t_addContainer(longtran, 0);
ContainerHandle c = t_util.t_openContainer(longtran, 0, cid, true);
RecordHandle r1 = t_util.t_insert(c, row1);
RecordHandle r2 = t_util.t_insert(c, row2);
t_util.t_commit(longtran);
c = t_util.t_openContainer(longtran, 0, cid, true);
Page p2 = t_util.t_getPage(c, r2.getPageNumber());
p2.update(r2, row5.getRow(), (FormatableBitSet) null);
p2.unlatch();
// a bunch of short running transactions that criss cross the
// checkpoints
cm1 = contextService.newContextManager();
contextService.setCurrentContextManager(cm1);
t1 = t_util.t_startTransaction();
long cid1 = t_util.t_addContainer(t1, 0);
ContainerHandle c1 = t_util.t_openContainer(t1, 0, cid1, true);
RecordHandle r3 = t_util.t_insert(c1, row3);
RecordHandle r4 = t_util.t_insert(c1, row4);
contextService.resetCurrentContextManager(cm1);
cm2 = contextService.newContextManager();
contextService.setCurrentContextManager(cm2);
t2 = t_util.t_startTransaction();
long cid2 = t_util.t_addContainer(t2, 0);
ContainerHandle c2 = t_util.t_openContainer(t2, 0, cid2, true);
RecordHandle r5 = t_util.t_insert(c2, row1);
t_util.t_commit(t2);
c2 = t_util.t_openContainer(t2, 0, cid2, true);
Page p5 = t_util.t_getPage(c2, r5.getPageNumber());
p5.update(r5, row5.getRow(), (FormatableBitSet) null);
p5.unlatch();
// cpm = contextService.newContextManager();
// contextService.setCurrentContextManager(cpm);
factory.checkpoint();
contextService.resetCurrentContextManager(cm2);
// make sure checkpoint did not destroy any data
contextService.setCurrentContextManager(previousCM);
t_util.t_checkFetch(c, r1, REC_001);
t_util.t_checkFetch(c, r2, REC_005);
contextService.resetCurrentContextManager(previousCM);
contextService.setCurrentContextManager(cm1);
t_util.t_checkFetch(c1, r3, REC_003);
t_util.t_checkFetch(c1, r4, REC_004);
contextService.resetCurrentContextManager(cm1);
contextService.setCurrentContextManager(cm2);
t_util.t_checkFetch(c2, r5, REC_005);
// two consecutive checkpoints
// contextService.setCurrentContextManager(cpm);
factory.checkpoint();
contextService.resetCurrentContextManager(cm2);
// we can insert some more
contextService.setCurrentContextManager(previousCM);
Page page = t_util.t_addPage(c);
RecordHandle r6 = t_util.t_insertAtSlot(page, 0, row1, Page.INSERT_UNDO_WITH_PURGE);
page.unlatch();
contextService.resetCurrentContextManager(previousCM);
// commit/abort everything except the long running transaction
contextService.setCurrentContextManager(cm1);
t_util.t_commit(t1);
contextService.resetCurrentContextManager(cm1);
contextService.setCurrentContextManager(cm2);
t_util.t_abort(t2);
contextService.resetCurrentContextManager(cm2);
contextService.setCurrentContextManager(previousCM);
t_util.t_checkFetch(c, r1, REC_001);
t_util.t_checkFetch(c, r2, REC_005);
t_util.t_checkFetch(c, r6, REC_001);
contextService.resetCurrentContextManager(previousCM);
contextService.setCurrentContextManager(cm1);
c1 = t_util.t_openContainer(t1, 0, cid1, true);
t_util.t_checkFetch(c1, r3, REC_003);
t_util.t_checkFetch(c1, r4, REC_004);
contextService.resetCurrentContextManager(cm1);
contextService.setCurrentContextManager(cm2);
c2 = t_util.t_openContainer(t2, 0, cid2, true);
t_util.t_checkFetch(c2, r5, REC_001);
// checkpoint again
// contextService.setCurrentContextManager(cpm);
factory.checkpoint();
contextService.resetCurrentContextManager(cm2);
contextService.setCurrentContextManager(previousCM);
t_util.t_abort(longtran);
c = t_util.t_openContainer(longtran, 0, cid, true);
t_util.t_checkFetch(c, r1, REC_001);
t_util.t_checkFetch(c, r2, REC_002);
Page p6 = t_util.t_getPage(c, r6.getPageNumber());
t_util.t_checkEmptyPage(p6);
p6.unlatch();
t_util.t_dropContainer(longtran, 0, cid); // cleanup
contextService.resetCurrentContextManager(previousCM);
contextService.setCurrentContextManager(cm1);
t_util.t_checkFetch(c1, r3, REC_003);
t_util.t_checkFetch(c1, r4, REC_004);
t_util.t_dropContainer(t1, 0, cid1);
contextService.resetCurrentContextManager(cm1);
contextService.setCurrentContextManager(cm2);
t_util.t_checkFetch(c2, r5, REC_001);
t_util.t_dropContainer(t2, 0, cid2);
// checkpoint again
// contextService.setCurrentContextManager(cpm);
factory.checkpoint();
contextService.resetCurrentContextManager(cm2);
PASS("CP001");
}
catch (Throwable t)
{
t.printStackTrace(System.err);
if (cm1 != null)
cm1.cleanupOnError(t);
if (cm2 != null)
cm2.cleanupOnError(t);
// if (cpm != null)
// cpm.cleanupOnError(t);
} finally {