use of org.neo4j.kernel.impl.transaction.log.FakeCommitment 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.transaction.log.FakeCommitment in project neo4j by neo4j.
the class LegacyBatchIndexApplierTest method shouldOrderTransactionsMakingLegacyIndexChanges.
@Test
public void shouldOrderTransactionsMakingLegacyIndexChanges() throws Throwable {
// GIVEN
Map<String, Integer> names = MapUtil.genericMap("first", 0, "second", 1);
Map<String, Integer> keys = MapUtil.genericMap("key", 0);
String applierName = "test-applier";
LegacyIndexApplierLookup applierLookup = mock(LegacyIndexApplierLookup.class);
when(applierLookup.newApplier(anyString(), anyBoolean())).thenReturn(mock(TransactionApplier.class));
IndexConfigStore config = newIndexConfigStore(names, applierName);
// WHEN multiple legacy index transactions are running, they should be done in order
SynchronizedArrayIdOrderingQueue queue = new SynchronizedArrayIdOrderingQueue(10);
final AtomicLong lastAppliedTxId = new AtomicLong(-1);
Race race = new Race();
for (long i = 0; i < 100; i++) {
final long txId = i;
race.addContestant(() -> {
try (LegacyBatchIndexApplier applier = new LegacyBatchIndexApplier(config, applierLookup, queue, INTERNAL)) {
TransactionToApply txToApply = new TransactionToApply(new PhysicalTransactionRepresentation(new ArrayList<>()));
FakeCommitment commitment = new FakeCommitment(txId, mock(TransactionIdStore.class));
commitment.setHasLegacyIndexChanges(true);
txToApply.commitment(commitment, txId);
TransactionApplier txApplier = applier.startTx(txToApply);
// Make sure threads are unordered
Thread.sleep(ThreadLocalRandom.current().nextInt(5));
// THEN
assertTrue(lastAppliedTxId.compareAndSet(txId - 1, txId));
// Closing manually instead of using try-with-resources since we have no additional work to do in
// txApplier
txApplier.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
queue.offer(txId);
}
race.go();
}
use of org.neo4j.kernel.impl.transaction.log.FakeCommitment in project neo4j by neo4j.
the class RecordStorageEngineTest method newTransactionThatFailsWith.
private static TransactionToApply newTransactionThatFailsWith(Exception error) throws IOException {
TransactionRepresentation transaction = mock(TransactionRepresentation.class);
when(transaction.additionalHeader()).thenReturn(new byte[0]);
// allow to build validated index updates but fail on actual tx application
doThrow(error).when(transaction).accept(any());
long txId = ThreadLocalRandom.current().nextLong(0, 1000);
TransactionToApply txToApply = new TransactionToApply(transaction);
FakeCommitment commitment = new FakeCommitment(txId, mock(TransactionIdStore.class));
commitment.setHasLegacyIndexChanges(false);
txToApply.commitment(commitment, txId);
return txToApply;
}
Aggregations