{
file.delete();
}
try
{
TxLog txLog = new TxLog( txFile() );
assertTrue( !txLog.getDanglingRecords().hasNext() );
byte globalId[] = new byte[64];
byte branchId[] = new byte[45];
txLog.txStart( globalId );
txLog.addBranch( globalId, branchId );
assertEquals( 2, txLog.getRecordCount() );
// List lists[] = txLog.getDanglingRecords();
List<?> lists[] = getRecordLists( txLog.getDanglingRecords() );
assertEquals( 1, lists.length );
List<?> records = lists[0];
assertEquals( 2, records.size() );
TxLog.Record record = (TxLog.Record) records.get( 0 );
assertEquals( TxLog.TX_START, record.getType() );
assertEqualByteArray( globalId, record.getGlobalId() );
assertTrue( null == record.getBranchId() );
record = (TxLog.Record) records.get( 1 );
assertEquals( TxLog.BRANCH_ADD, record.getType() );
assertEqualByteArray( globalId, record.getGlobalId() );
assertEqualByteArray( branchId, record.getBranchId() );
txLog.markAsCommitting( globalId );
assertEquals( 3, txLog.getRecordCount() );
txLog.close();
txLog = new TxLog( txFile() );
assertEquals( 0, txLog.getRecordCount() );
lists = getRecordLists( txLog.getDanglingRecords() );
assertEquals( 1, lists.length );
records = lists[0];
assertEquals( 3, records.size() );
record = (TxLog.Record) records.get( 0 );
assertEquals( TxLog.TX_START, record.getType() );
assertEqualByteArray( globalId, record.getGlobalId() );
assertTrue( null == record.getBranchId() );
record = (TxLog.Record) records.get( 1 );
assertEquals( TxLog.BRANCH_ADD, record.getType() );
assertEqualByteArray( globalId, record.getGlobalId() );
assertEqualByteArray( branchId, record.getBranchId() );
record = (TxLog.Record) records.get( 2 );
assertEquals( TxLog.MARK_COMMIT, record.getType() );
assertEqualByteArray( globalId, record.getGlobalId() );
assertTrue( null == record.getBranchId() );
txLog.txDone( globalId );
assertEquals( 1, txLog.getRecordCount() );
assertEquals( 0,
getRecordLists( txLog.getDanglingRecords() ).length );
txLog.close();
txLog = new TxLog( txFile() );
assertEquals( 0,
getRecordLists( txLog.getDanglingRecords() ).length );
txLog.close();
}
finally
{
file = new File( txFile() );
if ( file.exists() )