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