Search in sources :

Example 6 with TransactionAppender

use of org.neo4j.kernel.impl.transaction.log.TransactionAppender 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 7 with TransactionAppender

use of org.neo4j.kernel.impl.transaction.log.TransactionAppender 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 8 with TransactionAppender

use of org.neo4j.kernel.impl.transaction.log.TransactionAppender 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

TransactionAppender (org.neo4j.kernel.impl.transaction.log.TransactionAppender)8 StorageEngine (org.neo4j.storageengine.api.StorageEngine)7 TestableTransactionAppender (org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender)6 IOException (java.io.IOException)5 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)3 TransactionFailureException (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)2 BatchingTransactionAppender (org.neo4j.kernel.impl.transaction.log.BatchingTransactionAppender)2 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)2 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)2 TransactionMetadataCache (org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache)2 LogAppendEvent (org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent)2 File (java.io.File)1 Clock (java.time.Clock)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1