use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class InFlightLogEntryReaderTest method shouldUseTheRaftLogWhenTheIndexIsNotPresent.
@Test
public void shouldUseTheRaftLogWhenTheIndexIsNotPresent() throws Exception {
// given
InFlightLogEntryReader reader = new InFlightLogEntryReader(raftLog, inFlightMap, clearCache);
startingFromIndexReturnEntries(inFlightMap, logIndex, null);
startingFromIndexReturnEntries(raftLog, logIndex, entry);
// when
RaftLogEntry raftLogEntry = reader.get(logIndex);
// then
assertEquals(entry, raftLogEntry);
verify(inFlightMap).get(logIndex);
verify(raftLog).getEntryCursor(logIndex);
assertCacheIsUpdated(inFlightMap, logIndex);
verifyNoMoreInteractions(inFlightMap);
verifyNoMoreInteractions(raftLog);
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class InFlightLogEntryReaderTest method startingFromIndexReturnEntries.
private void startingFromIndexReturnEntries(ReadableRaftLog raftLog, long startIndex, RaftLogEntry entry, RaftLogEntry... otherEntries) throws IOException {
RaftLogCursor cursor = mock(RaftLogCursor.class);
when(raftLog.getEntryCursor(startIndex)).thenReturn(cursor, (RaftLogCursor) null);
Boolean[] bools = new Boolean[otherEntries.length + 1];
Arrays.fill(bools, Boolean.TRUE);
bools[otherEntries.length] = Boolean.FALSE;
when(cursor.next()).thenReturn(true, bools);
Long[] indexes = new Long[otherEntries.length + 1];
for (int offset = 0; offset < indexes.length; offset++) {
indexes[offset] = startIndex + 1 + offset;
}
indexes[otherEntries.length] = -1L;
when(cursor.index()).thenReturn(startIndex, indexes);
RaftLogEntry[] raftLogEntries = Arrays.copyOf(otherEntries, otherEntries.length + 1);
when(cursor.get()).thenReturn(entry, raftLogEntries);
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class AppendEntriesMessageFlowTest method setup.
@Before
public void setup() throws IOException {
// given
RaftLog raftLog = new InMemoryRaftLog();
raftLog.append(new RaftLogEntry(0, new RaftTestGroup(0)));
raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).raftLog(raftLog).outbound(outbound).build();
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class AppendEntriesMessageFlowTest method shouldAcceptSequenceOfAppendEntries.
@Test
public void shouldAcceptSequenceOfAppendEntries() throws Exception {
// when
raft.handle(appendEntriesRequest().from(otherMember).leaderTerm(0).prevLogIndex(0).prevLogTerm(0).logEntry(new RaftLogEntry(0, data(1))).leaderCommit(-1).build());
raft.handle(appendEntriesRequest().from(otherMember).leaderTerm(0).prevLogIndex(1).prevLogTerm(0).logEntry(new RaftLogEntry(0, data(2))).leaderCommit(-1).build());
raft.handle(appendEntriesRequest().from(otherMember).leaderTerm(0).prevLogIndex(2).prevLogTerm(0).logEntry(new RaftLogEntry(0, data(3))).leaderCommit(0).build());
raft.handle(appendEntriesRequest().from(otherMember).leaderTerm(1).prevLogIndex(3).prevLogTerm(0).logEntry(new RaftLogEntry(1, data(4))).leaderCommit(1).build());
raft.handle(appendEntriesRequest().from(otherMember).leaderTerm(1).prevLogIndex(4).prevLogTerm(1).logEntry(new RaftLogEntry(1, data(5))).leaderCommit(2).build());
raft.handle(appendEntriesRequest().from(otherMember).leaderTerm(1).prevLogIndex(5).prevLogTerm(1).logEntry(new RaftLogEntry(1, data(6))).leaderCommit(4).build());
// then
InOrder invocationOrder = inOrder(outbound);
invocationOrder.verify(outbound, times(1)).send(same(otherMember), eq(appendEntriesResponse().from(myself).term(0).appendIndex(1).matchIndex(1).success().build()));
invocationOrder.verify(outbound, times(1)).send(same(otherMember), eq(appendEntriesResponse().from(myself).term(0).appendIndex(2).matchIndex(2).success().build()));
invocationOrder.verify(outbound, times(1)).send(same(otherMember), eq(appendEntriesResponse().from(myself).term(0).appendIndex(3).matchIndex(3).success().build()));
invocationOrder.verify(outbound, times(1)).send(same(otherMember), eq(appendEntriesResponse().from(myself).term(1).appendIndex(4).matchIndex(4).success().build()));
invocationOrder.verify(outbound, times(1)).send(same(otherMember), eq(appendEntriesResponse().from(myself).term(1).appendIndex(5).matchIndex(5).success().build()));
invocationOrder.verify(outbound, times(1)).send(same(otherMember), eq(appendEntriesResponse().from(myself).term(1).appendIndex(6).matchIndex(6).success().build()));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class AppendEntriesMessageFlowTest method shouldReturnFalseOnAppendRequestWhenPrevLogEntryNotMatched.
@Test
public void shouldReturnFalseOnAppendRequestWhenPrevLogEntryNotMatched() throws Exception {
// when
raft.handle(appendEntriesRequest().from(otherMember).leaderTerm(0).prevLogIndex(0).prevLogTerm(1).logEntry(new RaftLogEntry(0, data)).build());
// then
verify(outbound).send(same(otherMember), eq(appendEntriesResponse().matchIndex(-1).appendIndex(0).from(myself).term(0).failure().build()));
}
Aggregations