Skip to content

Commit

Permalink
Adds test ensuring TRCP commits txs with no commands
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalstain authored and apcj committed Dec 8, 2015
1 parent 598497c commit 4ee19a5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Expand Up @@ -22,6 +22,7 @@
import org.junit.Test;

import java.io.IOException;
import java.util.Collections;

import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.exceptions.TransactionFailureException;
Expand All @@ -31,6 +32,8 @@
import org.neo4j.kernel.impl.storageengine.StorageEngine;
import org.neo4j.kernel.impl.store.UnderlyingStorageException;
import org.neo4j.kernel.impl.transaction.TransactionRepresentation;
import org.neo4j.kernel.impl.transaction.log.FakeCommitment;
import org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation;
import org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender;
import org.neo4j.kernel.impl.transaction.log.TransactionAppender;
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore;
Expand Down Expand Up @@ -59,20 +62,16 @@ public class TransactionRepresentationCommitProcessTest
private final CommitEvent commitEvent = CommitEvent.NULL;

@Test
public void shouldNotIncrementLastCommittedTxIdIfAppendFails() throws Exception
public void shouldFailWithProperMessageOnAppendException() throws Exception
{
// GIVEN
TransactionAppender appender = mock( TransactionAppender.class );
long txId = 11;
IOException rootCause = new IOException( "Mock exception" );
doThrow( new IOException( rootCause ) ).when( appender ).append( any( TransactionToApply.class ),
any( LogAppendEvent.class ) );
TransactionIdStore transactionIdStore = mock( TransactionIdStore.class );
StorageEngine storageEngine = mock( StorageEngine.class );
TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess(
appender,
storageEngine,
mockedIndexUpdatesValidator() );
appender, storageEngine, mockedIndexUpdatesValidator() );

// WHEN
try
Expand All @@ -85,8 +84,6 @@ public void shouldNotIncrementLastCommittedTxIdIfAppendFails() throws Exception
assertThat( e.getMessage(), containsString( "Could not append transaction representation to log" ) );
assertTrue( contains( e, rootCause.getMessage(), rootCause.getClass() ) );
}

verify( transactionIdStore, times( 0 ) ).transactionCommitted( txId, 0 );
}

@Test
Expand Down Expand Up @@ -150,6 +147,31 @@ public void shouldThrowWhenIndexUpdatesValidationFails() throws IOException
}
}

@Test
public void shouldSuccessfullyCommitTransactionWithNoCommands() throws Exception
{
// GIVEN
long txId = 11;
TransactionIdStore transactionIdStore = mock( TransactionIdStore.class );
TransactionAppender appender = new TestableTransactionAppender( transactionIdStore );
when( transactionIdStore.nextCommittingTransactionId() ).thenReturn( txId );

StorageEngine storageEngine = mock( StorageEngine.class );

TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess(
appender,
storageEngine,
mockedIndexUpdatesValidator() );
PhysicalTransactionRepresentation noCommandTx = new PhysicalTransactionRepresentation( Collections.emptyList() );
noCommandTx.setHeader( new byte[0], -1, -1, -1, -1, -1, -1 );

// WHEN

commitProcess.commit( new TransactionToApply( noCommandTx ), commitEvent, INTERNAL );

verify( transactionIdStore ).transactionCommitted( txId, FakeCommitment.CHECKSUM );
}

private TransactionToApply mockedTransaction()
{
TransactionRepresentation transaction = mock( TransactionRepresentation.class );
Expand Down
Expand Up @@ -21,6 +21,7 @@

public class FakeCommitment implements Commitment
{
public static final int CHECKSUM = 3;
private final long id;
private final TransactionIdStore transactionIdStore;
private boolean committed;
Expand All @@ -42,7 +43,7 @@ public FakeCommitment( long id, TransactionIdStore transactionIdStore, boolean m
public void publishAsCommitted()
{
committed = true;
transactionIdStore.transactionCommitted( id, 3 );
transactionIdStore.transactionCommitted( id, CHECKSUM );
}

@Override
Expand Down

0 comments on commit 4ee19a5

Please sign in to comment.