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));
}
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;
}
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());
}
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());
}
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));
}
Aggregations