private void publishAsCommitted( TransactionToApply batch ) { while ( batch != null ) { batch.commitment().publishAsCommitted(); batch = batch.next(); } }
public void queue( TransactionToApply transaction ) throws Exception { if ( isEmpty() ) { first = last = transaction; } else { last.next( transaction ); last = transaction; } if ( ++size == maxSize ) { empty(); } }
@Override public long commit( TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode ) { assert transaction == null : "Designed to only allow one transaction"; assert batch.next() == null : "Designed to only allow one transaction"; transaction = batch.transactionRepresentation(); return ++txId; } }
private static TransactionToApply toApply( Collection<TransactionRepresentation> transactions ) { TransactionToApply first = null; TransactionToApply last = null; for ( TransactionRepresentation transactionRepresentation : transactions ) { TransactionToApply transaction = new TransactionToApply( transactionRepresentation ); if ( first == null ) { first = last = transaction; } else { last.next( transaction ); last = transaction; } } return first; }
private TransactionToApply batchOf( TransactionRepresentation... transactions ) { TransactionToApply first = null; TransactionToApply last = null; for ( TransactionRepresentation transaction : transactions ) { TransactionToApply tx = new TransactionToApply( transaction ); if ( first == null ) { first = last = tx; } else { last.next( tx ); last = tx; } } return first; } }
private void close( TransactionToApply batch ) { while ( batch != null ) { if ( batch.commitment().markedAsCommitted() ) { batch.commitment().publishAsClosed(); } batch.close(); batch = batch.next(); } } }
@Test public void shouldLinkTogetherTransactions() throws Exception { // GIVEN Applier applier = mock( Applier.class ); int batchSize = 10; TransactionQueue queue = new TransactionQueue( batchSize, applier ); // WHEN TransactionToApply[] txs = new TransactionToApply[batchSize]; for ( int i = 0; i < batchSize; i++ ) { queue.queue( txs[i] = new TransactionToApply( mock( TransactionRepresentation.class ) ) ); } // THEN verify( applier, times( 1 ) ).apply( any(), any() ); for ( int i = 0; i < txs.length - 1; i++ ) { assertEquals( txs[i + 1], txs[i].next() ); } } }
@Override public long append( TransactionToApply batch, LogAppendEvent logAppendEvent ) { long txId = TransactionIdStore.BASE_TX_ID; while ( batch != null ) { txId = transactionIdStore.nextCommittingTransactionId(); batch.commitment( new FakeCommitment( txId, transactionIdStore ), txId ); batch.commitment().publishAsCommitted(); batch = batch.next(); } return txId; }
@Test public void shouldAppendBatchOfTransactions() throws Exception { // GIVEN when( logFile.getWriter() ).thenReturn( channel ); TransactionAppender appender = life.add( createTransactionAppender() ); when( transactionIdStore.nextCommittingTransactionId() ).thenReturn( 2L, 3L, 4L ); TransactionToApply batch = batchOf( transaction( singleCreateNodeCommand( 0 ), new byte[0], 0, 0, 0, 1, 0 ), transaction( singleCreateNodeCommand( 1 ), new byte[0], 0, 0, 0, 1, 0 ), transaction( singleCreateNodeCommand( 2 ), new byte[0], 0, 0, 0, 1, 0 ) ); // WHEN appender.append( batch, logAppendEvent ); // THEN TransactionToApply tx = batch; assertEquals( 2L, tx.transactionId() ); tx = tx.next(); assertEquals( 3L, tx.transactionId() ); tx = tx.next(); assertEquals( 4L, tx.transactionId() ); assertNull( tx.next() ); }
tx.commitment( commitment, transactionId ); tx.logPosition( commitment.logPosition() ); tx = tx.next(); lastTransactionId = transactionId;
private void verifyIndex( TransactionToApply tx ) throws Exception { try ( IndexReader reader = index.newReader() ) { NodeVisitor visitor = new NodeVisitor(); for ( int i = 0; tx != null; i++ ) { tx.transactionRepresentation().accept( visitor.clear() ); Value propertyValue = propertyValue( id, base + i ); IndexQuery.ExactPredicate query = IndexQuery.exact( descriptor.getPropertyId(), propertyValue ); LongIterator hits = reader.query( query ); assertEquals( "Index doesn't contain " + visitor.nodeId + " " + propertyValue, visitor.nodeId, hits.next() ); assertFalse( hits.hasNext() ); tx = tx.next(); } } } }
private void publishAsCommitted( TransactionToApply batch ) { while ( batch != null ) { batch.commitment().publishAsCommitted(); batch = batch.next(); } }
public void queue( TransactionToApply transaction ) throws Exception { if ( isEmpty() ) { first = last = transaction; } else { last.next( transaction ); last = transaction; } if ( ++size == maxSize ) { empty(); } }
private void close( TransactionToApply batch ) { while ( batch != null ) { if ( batch.commitment().markedAsCommitted() ) { batch.commitment().publishAsClosed(); } batch.close(); batch = batch.next(); } } }
tx.commitment( commitment, transactionId ); tx.logPosition( commitment.logPosition() ); tx = tx.next(); lastTransactionId = transactionId;