Search in sources :

Example 1 with FakeCommitment

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;
}
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 2 with FakeCommitment

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();
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) AtomicLong(java.util.concurrent.atomic.AtomicLong) SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue) Race(org.neo4j.test.Race) FakeCommitment(org.neo4j.kernel.impl.transaction.log.FakeCommitment) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 3 with FakeCommitment

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;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) FakeCommitment(org.neo4j.kernel.impl.transaction.log.FakeCommitment)

Aggregations

FakeCommitment (org.neo4j.kernel.impl.transaction.log.FakeCommitment)3 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)2 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)2 ArrayList (java.util.ArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)1 IndexConfigStore (org.neo4j.kernel.impl.index.IndexConfigStore)1 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)1 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)1 CommitEvent (org.neo4j.kernel.impl.transaction.tracing.CommitEvent)1 SynchronizedArrayIdOrderingQueue (org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue)1 TransactionApplicationMode (org.neo4j.storageengine.api.TransactionApplicationMode)1 Race (org.neo4j.test.Race)1