Search in sources :

Example 1 with TestableTransactionAppender

use of org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender in project neo4j by neo4j.

the class InternalTransactionCommitProcessTest method shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly.

@Test
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 InternalTransactionCommitProcess(appender, storageEngine);
    TransactionToApply transaction = mockedTransaction();
    // WHEN
    TransactionFailureException exception = assertThrows(TransactionFailureException.class, () -> commitProcess.commit(transaction, commitEvent, INTERNAL));
    assertThat(exception.getMessage()).contains("Could not apply the transaction to the store");
    assertTrue(contains(exception, rootCause.getMessage(), rootCause.getClass()));
    // THEN
    // we can't verify transactionCommitted since that's part of the TransactionAppender, which we have mocked
    verify(transactionIdStore).transactionClosed(eq(txId), anyLong(), anyLong(), any(CursorContext.class));
}
Also used : TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) IOException(java.io.IOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Test(org.junit.jupiter.api.Test)

Example 2 with TestableTransactionAppender

use of org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender in project neo4j by neo4j.

the class TransactionRepresentationCommitProcessTest method shouldSuccessfullyCommitTransactionWithNoCommands.

@Test
public void shouldSuccessfullyCommitTransactionWithNoCommands() throws Exception {
    // GIVEN
    long txId = 11;
    long commitTimestamp = System.currentTimeMillis();
    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);
    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, FakeCommitment.TIMESTAMP);
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) StorageEngine(org.neo4j.storageengine.api.StorageEngine) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 3 with TestableTransactionAppender

use of org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender in project neo4j by neo4j.

the class TransactionRepresentationCommitProcessTest method shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly.

@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());
}
Also used : TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) IOException(java.io.IOException) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Test(org.junit.Test)

Example 4 with TestableTransactionAppender

use of org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender in project neo4j by neo4j.

the class InternalTransactionCommitProcessTest method shouldSuccessfullyCommitTransactionWithNoCommands.

@Test
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 InternalTransactionCommitProcess(appender, storageEngine);
    PhysicalTransactionRepresentation noCommandTx = new PhysicalTransactionRepresentation(Collections.emptyList());
    noCommandTx.setHeader(new byte[0], -1, -1, -1, -1, ANONYMOUS);
    // WHEN
    commitProcess.commit(new TransactionToApply(noCommandTx, NULL), commitEvent, INTERNAL);
    verify(transactionIdStore).transactionCommitted(txId, FakeCommitment.CHECKSUM, FakeCommitment.TIMESTAMP, NULL);
}
Also used : TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) StorageEngine(org.neo4j.storageengine.api.StorageEngine) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.jupiter.api.Test)

Aggregations

TestableTransactionAppender (org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender)4 TransactionAppender (org.neo4j.kernel.impl.transaction.log.TransactionAppender)4 StorageEngine (org.neo4j.storageengine.api.StorageEngine)4 IOException (java.io.IOException)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)2 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)2 TransactionApplicationMode (org.neo4j.storageengine.api.TransactionApplicationMode)2 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)2 TransactionFailureException (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException)1 CursorContext (org.neo4j.io.pagecache.context.CursorContext)1 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)1