protected void applyToStore( TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode ) throws TransactionFailureException { try ( StoreApplyEvent storeApplyEvent = commitEvent.beginStoreApply() ) { storageEngine.apply( batch, mode ); } catch ( Throwable cause ) { throw new TransactionFailureException( TransactionCommitFailed, cause, "Could not apply the transaction to the store after written to log" ); } }
@Override public boolean visit( CommittedTransactionRepresentation transaction ) throws Exception { TransactionRepresentation txRepresentation = transaction.getTransactionRepresentation(); long txId = transaction.getCommitEntry().getTxId(); TransactionToApply tx = new TransactionToApply( txRepresentation, txId ); tx.commitment( NO_COMMITMENT, txId ); tx.logPosition( transaction.getStartEntry().getStartPosition() ); storageEngine.apply( tx, mode ); return false; }
@Test public void shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly() throws Exception { // GIVEN TransactionIdStore transactionIdStore = mock( TransactionIdStore.class ); TransactionAppender appender = new TestableTransactionAppender( transactionIdStore ); long txId = 11; when( transactionIdStore.nextCommittingTransactionId() ).thenReturn( txId ); IOException rootCause = new IOException( "Mock exception" ); StorageEngine storageEngine = mock( StorageEngine.class ); doThrow( new IOException( rootCause ) ).when( storageEngine ).apply( any( TransactionToApply.class ), any( TransactionApplicationMode.class ) ); TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess( appender, storageEngine ); TransactionToApply transaction = mockedTransaction(); // WHEN try { commitProcess.commit( transaction, commitEvent, INTERNAL ); } catch ( TransactionFailureException e ) { assertThat( e.getMessage(), containsString( "Could not apply the transaction to the store" ) ); assertTrue( contains( e, rootCause.getMessage(), rootCause.getClass() ) ); } // THEN // we can't verify transactionCommitted since that's part of the TransactionAppender, which we have mocked verify( transactionIdStore, times( 1 ) ).transactionClosed( eq( txId ), anyLong(), anyLong() ); }
protected void applyToStore( TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode ) throws TransactionFailureException { try ( StoreApplyEvent storeApplyEvent = commitEvent.beginStoreApply() ) { storageEngine.apply( batch, mode ); } catch ( Throwable cause ) { throw new TransactionFailureException( TransactionCommitFailed, cause, "Could not apply the transaction to the store after written to log" ); } }
@Override public boolean visit( CommittedTransactionRepresentation transaction ) throws Exception { TransactionRepresentation txRepresentation = transaction.getTransactionRepresentation(); long txId = transaction.getCommitEntry().getTxId(); TransactionToApply tx = new TransactionToApply( txRepresentation, txId ); tx.commitment( NO_COMMITMENT, txId ); tx.logPosition( transaction.getStartEntry().getStartPosition() ); storageEngine.apply( tx, mode ); return false; }