Search in sources :

Example 1 with TransactionCommitProcess

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

the class CommunityCommitProcessFactoryTest method createReadOnlyCommitProcess.

@Test
public void createReadOnlyCommitProcess() {
    CommunityCommitProcessFactory factory = new CommunityCommitProcessFactory();
    Config config = Config.embeddedDefaults(stringMap(GraphDatabaseSettings.read_only.name(), "true"));
    TransactionCommitProcess commitProcess = factory.create(mock(TransactionAppender.class), mock(StorageEngine.class), config);
    assertThat(commitProcess, instanceOf(ReadOnlyTransactionCommitProcess.class));
}
Also used : Config(org.neo4j.kernel.configuration.Config) ReadOnlyTransactionCommitProcess(org.neo4j.kernel.impl.api.ReadOnlyTransactionCommitProcess) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) ReadOnlyTransactionCommitProcess(org.neo4j.kernel.impl.api.ReadOnlyTransactionCommitProcess) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Test(org.junit.Test)

Example 2 with TransactionCommitProcess

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

the class ReplicatedTransactionStateMachineTest method createFakeTransactionCommitProcess.

private TransactionCommitProcess createFakeTransactionCommitProcess(long txId) throws TransactionFailureException {
    TransactionCommitProcess localCommitProcess = mock(TransactionCommitProcess.class);
    when(localCommitProcess.commit(any(TransactionToApply.class), any(CommitEvent.class), any(TransactionApplicationMode.class))).thenAnswer(invocation -> {
        TransactionToApply txToApply = (TransactionToApply) invocation.getArguments()[0];
        txToApply.commitment(new FakeCommitment(txId, mock(TransactionIdStore.class)), txId);
        txToApply.commitment().publishAsCommitted();
        txToApply.commitment().publishAsClosed();
        txToApply.close();
        return txId;
    });
    return localCommitProcess;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) CommitEvent(org.neo4j.kernel.impl.transaction.tracing.CommitEvent) FakeCommitment(org.neo4j.kernel.impl.transaction.log.FakeCommitment)

Example 3 with TransactionCommitProcess

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

the class ReplicatedTransactionStateMachineTest method shouldAcceptTransactionCommittedWithNoLockManager.

@Test
public void shouldAcceptTransactionCommittedWithNoLockManager() throws Exception {
    // given
    int txLockSessionId = Locks.Client.NO_LOCK_SESSION_ID;
    int currentLockSessionId = 24;
    long txId = 42L;
    ReplicatedTransaction tx = ReplicatedTransactionFactory.createImmutableReplicatedTransaction(physicalTx(txLockSessionId));
    TransactionCommitProcess localCommitProcess = createFakeTransactionCommitProcess(txId);
    ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(lockState(currentLockSessionId), batchSize, logProvider);
    stateMachine.installCommitProcess(localCommitProcess, -1L);
    AtomicBoolean called = new AtomicBoolean();
    // when
    stateMachine.applyCommand(tx, 0, result -> {
        called.set(true);
        try {
            assertEquals(txId, (long) result.consume());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    stateMachine.ensuredApplied();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) Test(org.junit.Test)

Example 4 with TransactionCommitProcess

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

the class ReplicatedTransactionStateMachineTest method shouldFailFutureForTransactionCommittedUnderWrongLockSession.

@Test
public void shouldFailFutureForTransactionCommittedUnderWrongLockSession() throws Exception {
    // given
    int txLockSessionId = 23;
    int currentLockSessionId = 24;
    ReplicatedTransaction tx = ReplicatedTransactionFactory.createImmutableReplicatedTransaction(physicalTx(txLockSessionId));
    TransactionCommitProcess localCommitProcess = mock(TransactionCommitProcess.class);
    final ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(lockState(currentLockSessionId), batchSize, logProvider);
    stateMachine.installCommitProcess(localCommitProcess, -1L);
    AtomicBoolean called = new AtomicBoolean();
    // when
    stateMachine.applyCommand(tx, 0, result -> {
        called.set(true);
        try {
            result.consume();
            fail("should have thrown");
        } catch (TransactionFailureException tfe) {
            assertEquals(Status.Transaction.LockSessionExpired, tfe.status());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    stateMachine.ensuredApplied();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) Test(org.junit.Test)

Example 5 with TransactionCommitProcess

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

the class HighlyAvailableCommitProcessFactoryTest method createReadOnlyCommitProcess.

@Test
public void createReadOnlyCommitProcess() {
    HighlyAvailableCommitProcessFactory factory = new HighlyAvailableCommitProcessFactory(new DelegateInvocationHandler<>(TransactionCommitProcess.class));
    Config config = Config.embeddedDefaults(stringMap(GraphDatabaseSettings.read_only.name(), "true"));
    TransactionCommitProcess commitProcess = factory.create(mock(TransactionAppender.class), mock(StorageEngine.class), config);
    assertThat(commitProcess, instanceOf(ReadOnlyTransactionCommitProcess.class));
}
Also used : Config(org.neo4j.kernel.configuration.Config) ReadOnlyTransactionCommitProcess(org.neo4j.kernel.impl.api.ReadOnlyTransactionCommitProcess) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) ReadOnlyTransactionCommitProcess(org.neo4j.kernel.impl.api.ReadOnlyTransactionCommitProcess) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Test(org.junit.Test)

Aggregations

TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)18 Test (org.junit.Test)10 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)6 TransactionAppender (org.neo4j.kernel.impl.transaction.log.TransactionAppender)5 StorageEngine (org.neo4j.storageengine.api.StorageEngine)5 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)4 ReadOnlyTransactionCommitProcess (org.neo4j.kernel.impl.api.ReadOnlyTransactionCommitProcess)4 CommitEvent (org.neo4j.kernel.impl.transaction.tracing.CommitEvent)4 TransactionApplicationMode (org.neo4j.storageengine.api.TransactionApplicationMode)4 KernelTransactions (org.neo4j.kernel.impl.api.KernelTransactions)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Dependencies (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies)2 Config (org.neo4j.kernel.configuration.Config)2 DelegateInvocationHandler (org.neo4j.kernel.ha.DelegateInvocationHandler)2 TransactionRepresentationCommitProcess (org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess)2 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)2 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)2 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 Consumer (java.util.function.Consumer)1