Search in sources :

Example 26 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class SlaveTransactionCommitProcessTest method shouldForwardLockIdentifierToMaster.

@Test
public void shouldForwardLockIdentifierToMaster() throws Exception {
    // Given
    when(master.commit(requestContext, tx)).thenReturn(response);
    // When
    commitProcess.commit(new TransactionToApply(tx), CommitEvent.NULL, TransactionApplicationMode.INTERNAL);
    // Then
    assertThat(lastSeenEventIdentifier.get(), is(1337));
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) Test(org.junit.Test)

Example 27 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class CommitProcessStateMachineCollaborationTest method shouldFailTransactionIfLockSessionChanges.

@Test
public void shouldFailTransactionIfLockSessionChanges() throws Exception {
    // given
    int initialLockSessionId = 23;
    TransactionToApply transactionToApply = new TransactionToApply(physicalTx(initialLockSessionId));
    int finalLockSessionId = 24;
    TransactionCommitProcess localCommitProcess = mock(TransactionCommitProcess.class);
    ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(lockState(finalLockSessionId), 16, NullLogProvider.getInstance());
    stateMachine.installCommitProcess(localCommitProcess, -1L);
    DirectReplicator<ReplicatedTransaction> replicator = new DirectReplicator<>(stateMachine);
    ReplicatedTransactionCommitProcess commitProcess = new ReplicatedTransactionCommitProcess(replicator);
    // when
    try {
        commitProcess.commit(transactionToApply, NULL, EXTERNAL);
        fail("Should have thrown exception.");
    } catch (TransactionFailureException e) {
    // expected
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) DirectReplicator(org.neo4j.causalclustering.core.replication.DirectReplicator) Test(org.junit.Test)

Example 28 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class ReplayableCommitProcessTest method shouldNotCommitTransactionsThatAreAlreadyCommittedLocally.

@Test
public void shouldNotCommitTransactionsThatAreAlreadyCommittedLocally() throws Exception {
    // given
    TransactionToApply alreadyCommittedTx1 = mock(TransactionToApply.class);
    TransactionToApply alreadyCommittedTx2 = mock(TransactionToApply.class);
    TransactionToApply newTx = mock(TransactionToApply.class);
    StubLocalDatabase localDatabase = new StubLocalDatabase(3);
    final ReplayableCommitProcess txListener = new ReplayableCommitProcess(localDatabase, localDatabase);
    // when
    txListener.commit(alreadyCommittedTx1, NULL, EXTERNAL);
    txListener.commit(alreadyCommittedTx2, NULL, EXTERNAL);
    txListener.commit(newTx, NULL, EXTERNAL);
    // then
    verify(localDatabase.commitProcess, times(1)).commit(eq(newTx), any(CommitEvent.class), any(TransactionApplicationMode.class));
    verifyNoMoreInteractions(localDatabase.commitProcess);
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) CommitEvent(org.neo4j.kernel.impl.transaction.tracing.CommitEvent) Test(org.junit.Test)

Example 29 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class ReplicatedTransactionCommitProcessTest method tx.

private TransactionToApply tx() {
    TransactionRepresentation tx = mock(TransactionRepresentation.class);
    when(tx.additionalHeader()).thenReturn(new byte[] {});
    return new TransactionToApply(tx);
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation)

Example 30 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class CommandHandlerContract method apply.

/**
     * In case the transactions do not have the commands to apply, use this method to apply any commands you want with a
     * given {@link ApplyFunction} instead.
     *
     * @param applier to use
     * @param function which knows what to do with the {@link TransactionApplier}.
     * @param transactions are only used to create {@link TransactionApplier}s. The actual work is delegated to the
     * function.
     * @return the boolean-and result of all function operations.
     */
public static boolean apply(BatchTransactionApplier applier, ApplyFunction function, TransactionToApply... transactions) throws Exception {
    boolean result = true;
    for (TransactionToApply tx : transactions) {
        try (TransactionApplier txApplier = applier.startTx(tx, new LockGroup())) {
            result &= function.apply(txApplier);
        }
    }
    applier.close();
    return result;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) LockGroup(org.neo4j.kernel.impl.locking.LockGroup) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) TransactionApplier(org.neo4j.kernel.impl.api.TransactionApplier)

Aggregations

TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)46 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)14 Test (org.junit.jupiter.api.Test)11 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)11 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)9 Test (org.junit.Test)7 IOException (java.io.IOException)6 CursorContext (org.neo4j.io.pagecache.context.CursorContext)6 DbmsLogEntryWriterFactory (org.neo4j.kernel.database.DbmsLogEntryWriterFactory)6 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)4 TransactionId (org.neo4j.storageengine.api.TransactionId)4 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)3 CommitEvent (org.neo4j.kernel.impl.transaction.tracing.CommitEvent)3 ArrayList (java.util.ArrayList)2 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)2 TransactionApplier (org.neo4j.kernel.impl.api.TransactionApplier)2 LockGroup (org.neo4j.kernel.impl.locking.LockGroup)2 FakeCommitment (org.neo4j.kernel.impl.transaction.log.FakeCommitment)2 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)2 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)2