private void assertAccepted( HighestTransactionId highest, long txId ) { TransactionId current = highest.get(); assertTrue( highest.offer( txId, -1, -1 ) ); assertTrue( txId > current.transactionId() ); }
private void assertRejected( HighestTransactionId highest, long txId ) { TransactionId current = highest.get(); assertFalse( highest.offer( txId, -1, -1 ) ); assertEquals( current, highest.get() ); } }
@Test public void shouldKeepHighestDuringConcurrentOfferings() throws Throwable { // GIVEN final HighestTransactionId highest = new HighestTransactionId( -1, -1, -1 ); Race race = new Race(); int updaters = max( 2, getRuntime().availableProcessors() ); final AtomicInteger accepted = new AtomicInteger(); for ( int i = 0; i < updaters; i++ ) { final long id = i + 1; race.addContestant( () -> { if ( highest.offer( id, id, id ) ) { accepted.incrementAndGet(); } } ); } // WHEN race.go(); // THEN assertTrue( accepted.get() > 0 ); assertEquals( updaters, highest.get().transactionId() ); }
if ( highestCommittedTransaction.offer( transactionId, checksum, commitTimestamp ) )
if ( highestCommittedTransaction.offer( transactionId, checksum, commitTimestamp ) )