Search in sources :

Example 86 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class CommandApplicationProcessTest method duplicatesShouldBeIgnoredButStillIncreaseCommandIndex.

@Test
public void duplicatesShouldBeIgnoredButStillIncreaseCommandIndex() throws Exception {
    // given
    applicationProcess.start();
    // when
    raftLog.append(new RaftLogEntry(0, new NewLeaderBarrier()));
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(nullTx, globalSession, new LocalOperationId(0, 0))));
    // duplicate
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(nullTx, globalSession, new LocalOperationId(0, 0))));
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(nullTx, globalSession, new LocalOperationId(0, 1))));
    applicationProcess.notifyCommitted(3);
    applier.sync(false);
    InOrder inOrder = inOrder(coreStateMachines, commandDispatcher);
    // then
    inOrder.verify(coreStateMachines).commandDispatcher();
    inOrder.verify(commandDispatcher).dispatch(eq(nullTx), eq(1L), anyCallback());
    // duplicate not dispatched
    inOrder.verify(commandDispatcher).dispatch(eq(nullTx), eq(3L), anyCallback());
    inOrder.verify(commandDispatcher).close();
    verifyNoMoreInteractions(commandDispatcher);
}
Also used : InOrder(org.mockito.InOrder) LocalOperationId(org.neo4j.causalclustering.core.replication.session.LocalOperationId) DistributedOperation(org.neo4j.causalclustering.core.replication.DistributedOperation) NewLeaderBarrier(org.neo4j.causalclustering.core.consensus.NewLeaderBarrier) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 87 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class CommandApplicationProcessTest method shouldFallbackToLogCursorOnCacheMiss.

@Test
public void shouldFallbackToLogCursorOnCacheMiss() throws Throwable {
    // if the cache does not contain all things to be applied, make sure we fall back to the log
    // should only happen in recovery, otherwise this is probably a bug.
    applicationProcess.start();
    //given cache with missing entry
    ReplicatedContent operation0 = operation(nullTx);
    ReplicatedContent operation1 = operation(nullTx);
    ReplicatedContent operation2 = operation(nullTx);
    inFlightMap.put(0L, new RaftLogEntry(0, operation0));
    inFlightMap.put(2L, new RaftLogEntry(2, operation2));
    raftLog.append(new RaftLogEntry(0, operation0));
    raftLog.append(new RaftLogEntry(1, operation1));
    raftLog.append(new RaftLogEntry(2, operation2));
    //when
    applicationProcess.notifyCommitted(2);
    applier.sync(false);
    //then the cache stops being used after it finds 1 is missing
    verify(inFlightMap, times(1)).get(0L);
    verify(inFlightMap, times(1)).get(1L);
    verify(inFlightMap, times(0)).get(2L);
    // we only look up 1 so let's remove that from the cache
    verify(inFlightMap, times(1)).remove(0L);
    verify(commandDispatcher, times(1)).dispatch(eq(nullTx), eq(0L), anyCallback());
    verify(commandDispatcher, times(1)).dispatch(eq(nullTx), eq(1L), anyCallback());
    verify(commandDispatcher, times(1)).dispatch(eq(nullTx), eq(2L), anyCallback());
    verify(raftLog, times(1)).getEntryCursor(1);
}
Also used : CoreReplicatedContent(org.neo4j.causalclustering.core.state.machines.tx.CoreReplicatedContent) ReplicatedContent(org.neo4j.causalclustering.core.replication.ReplicatedContent) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Aggregations

RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)87 Test (org.junit.Test)69 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)27 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)25 RaftState (org.neo4j.causalclustering.core.consensus.state.RaftState)20 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)12 RaftLog (org.neo4j.causalclustering.core.consensus.log.RaftLog)10 ReadableRaftState (org.neo4j.causalclustering.core.consensus.state.ReadableRaftState)10 AppendLogEntry (org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry)8 NewLeaderBarrier (org.neo4j.causalclustering.core.consensus.NewLeaderBarrier)7 AppendEntries (org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries)7 MemberId (org.neo4j.causalclustering.identity.MemberId)7 InOrder (org.mockito.InOrder)6 RaftLogCursor (org.neo4j.causalclustering.core.consensus.log.RaftLogCursor)6 ReadableRaftLog (org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog)5 RaftTestGroup (org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup)5 BatchAppendLogEntries (org.neo4j.causalclustering.core.consensus.outcome.BatchAppendLogEntries)5 ShipCommand (org.neo4j.causalclustering.core.consensus.outcome.ShipCommand)5 TruncateLogCommand (org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand)5 File (java.io.File)4