use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class FollowerTest method shouldTruncateIfTermDoesNotMatch.
@Test
public void shouldTruncateIfTermDoesNotMatch() throws Exception {
// given
RaftLog entryLog = new InMemoryRaftLog();
entryLog.append(new RaftLogEntry(0, new RaftTestGroup(0)));
int term = 1;
RaftState state = raftState().myself(myself).entryLog(entryLog).term(term).build();
Follower follower = new Follower();
state.update(follower.handle(new AppendEntries.Request(member1, 1, 0, 0, new RaftLogEntry[] { new RaftLogEntry(2, ContentGenerator.content()) }, 0), state, log()));
RaftLogEntry[] entries = { new RaftLogEntry(1, new ReplicatedString("commit this!")) };
Outcome outcome = follower.handle(new AppendEntries.Request(member1, 1, 0, 0, entries, 0), state, log());
state.update(outcome);
// then
assertEquals(1, state.entryLog().appendIndex());
assertEquals(1, state.entryLog().readEntryTerm(1));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class CommandApplicationProcessTest method shouldIncreaseLastAppliedForStateMachineCommands.
@Test
public void shouldIncreaseLastAppliedForStateMachineCommands() throws Exception {
// given
applicationProcess.start();
// when
raftLog.append(new RaftLogEntry(0, operation(nullTx)));
raftLog.append(new RaftLogEntry(0, operation(nullTx)));
raftLog.append(new RaftLogEntry(0, operation(nullTx)));
applicationProcess.notifyCommitted(2);
applier.sync(false);
// then
assertEquals(2, applicationProcess.lastApplied());
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class CommandApplicationProcessTest method shouldFailWhenCacheAndLogMiss.
@Test
public void shouldFailWhenCacheAndLogMiss() throws Throwable {
//When an entry is not in the log, we must fail.
applicationProcess.start();
inFlightMap.put(0L, new RaftLogEntry(0, operation(nullTx)));
raftLog.append(new RaftLogEntry(0, operation(nullTx)));
raftLog.append(new RaftLogEntry(1, operation(nullTx)));
//when
applicationProcess.notifyCommitted(2);
applier.sync(false);
//then
assertFalse(dbHealth.isHealthy());
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class CommandApplicationProcessTest method outOfOrderDuplicatesShouldBeIgnoredButStillIncreaseCommandIndex.
@Test
public void outOfOrderDuplicatesShouldBeIgnoredButStillIncreaseCommandIndex() throws Exception {
// given
applicationProcess.start();
// when
raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 100), globalSession, new LocalOperationId(0, 0))));
raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 101), globalSession, new LocalOperationId(0, 1))));
raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 102), globalSession, new LocalOperationId(0, 2))));
// duplicate of tx 101
raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 101), globalSession, new LocalOperationId(0, 1))));
// duplicate of tx 100
raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 100), globalSession, new LocalOperationId(0, 0))));
raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 103), globalSession, new LocalOperationId(0, 3))));
raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 104), globalSession, new LocalOperationId(0, 4))));
applicationProcess.notifyCommitted(6);
applier.sync(false);
InOrder inOrder = inOrder(coreStateMachines, commandDispatcher);
// then
inOrder.verify(coreStateMachines).commandDispatcher();
inOrder.verify(commandDispatcher).dispatch(eq(tx((byte) 100)), eq(0L), anyCallback());
inOrder.verify(commandDispatcher).dispatch(eq(tx((byte) 101)), eq(1L), anyCallback());
inOrder.verify(commandDispatcher).dispatch(eq(tx((byte) 102)), eq(2L), anyCallback());
// duplicate of tx 101 not dispatched, at index 3
// duplicate of tx 100 not dispatched, at index 4
inOrder.verify(commandDispatcher).dispatch(eq(tx((byte) 103)), eq(5L), anyCallback());
inOrder.verify(commandDispatcher).dispatch(eq(tx((byte) 104)), eq(6L), anyCallback());
inOrder.verify(commandDispatcher).close();
verifyNoMoreInteractions(commandDispatcher);
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class AppendEntriesMessageFlowTest method shouldReturnFalseIfLogHistoryDoesNotMatch.
@Test
public void shouldReturnFalseIfLogHistoryDoesNotMatch() throws Exception {
raft.handle(appendEntriesRequest().from(otherMember).leaderTerm(0).prevLogIndex(0).prevLogTerm(0).logEntry(new RaftLogEntry(0, data(1))).build());
raft.handle(appendEntriesRequest().from(otherMember).leaderTerm(0).prevLogIndex(1).prevLogTerm(0).logEntry(new RaftLogEntry(0, data(2))).build());
raft.handle(appendEntriesRequest().from(otherMember).leaderTerm(0).prevLogIndex(2).prevLogTerm(0).logEntry(new RaftLogEntry(0, data(3))).build());
// when
raft.handle(appendEntriesRequest().from(otherMember).leaderTerm(2).prevLogIndex(3).prevLogTerm(1).logEntry(new RaftLogEntry(2, data(4))).build());
// then
InOrder invocationOrder = inOrder(outbound);
invocationOrder.verify(outbound, times(1)).send(same(otherMember), eq(appendEntriesResponse().from(myself).term(0).matchIndex(1).appendIndex(1).success().build()));
invocationOrder.verify(outbound, times(1)).send(same(otherMember), eq(appendEntriesResponse().from(myself).term(0).matchIndex(2).appendIndex(2).success().build()));
invocationOrder.verify(outbound, times(1)).send(same(otherMember), eq(appendEntriesResponse().from(myself).term(0).matchIndex(3).appendIndex(3).success().build()));
invocationOrder.verify(outbound, times(1)).send(same(otherMember), eq(appendEntriesResponse().from(myself).term(2).matchIndex(-1).appendIndex(3).failure().build()));
}
Aggregations