The {@link TxManager} uses this class to keep a transaction log fortransaction recovery.
69707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
{ 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() )
150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
{ file.delete(); } try { TxLog txLog = new TxLog( txFile() ); byte globalId[] = new byte[64]; byte branchId[] = new byte[45]; txLog.txStart( globalId ); txLog.addBranch( globalId, branchId ); txLog.markAsCommitting( globalId ); txLog.truncate(); assertEquals( 0, getRecordLists( txLog.getDanglingRecords() ).length ); txLog.close(); txLog = new TxLog( txFile() ); txLog.txStart( globalId ); txLog.addBranch( globalId, branchId ); txLog.markAsCommitting( globalId ); txLog.close(); txLog = new TxLog( txFile() ); assertEquals( 1, getRecordLists( txLog.getDanglingRecords() ).length ); txLog.truncate(); assertEquals( 0, getRecordLists( txLog.getDanglingRecords() ).length ); } finally { file = new File( txFile() ); if ( file.exists() )