use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.
the class AppendEntriesRequestTest method shouldTruncateOnReceiptOfConflictingEntry.
@Test
public void shouldTruncateOnReceiptOfConflictingEntry() throws Exception {
// given
InMemoryRaftLog raftLog = new InMemoryRaftLog();
RaftState state = raftState().myself(myself).term(5).entryLog(raftLog).build();
long leaderTerm = state.term() + leaderTermDifference;
raftLog.append(new RaftLogEntry(state.term() - 1, content()));
raftLog.append(new RaftLogEntry(state.term() - 1, content()));
// when
long previousIndex = raftLog.appendIndex() - 1;
Outcome outcome = role.handler.handle(appendEntriesRequest().from(leader).leaderTerm(leaderTerm).prevLogIndex(previousIndex).prevLogTerm(raftLog.readEntryTerm(previousIndex)).logEntry(new RaftLogEntry(leaderTerm, content())).build(), state, log());
// then
assertTrue(((Response) messageFor(outcome, leader)).success());
assertThat(outcome.getLogCommands(), hasItem(new TruncateLogCommand(1)));
}
use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.
the class AppendEntriesRequestTest method bootstrappedLog.
private RaftLog bootstrappedLog() throws IOException {
InMemoryRaftLog raftLog = new InMemoryRaftLog();
raftLog.append(new RaftLogEntry(0, content()));
return raftLog;
}
use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.
the class RaftMachineTest method shouldAppendNewLeaderBarrierAfterBecomingLeader.
@Test
public void shouldAppendNewLeaderBarrierAfterBecomingLeader() throws Exception {
// Given
FakeClock fakeClock = Clocks.fakeClock();
ControlledRenewableTimeoutService timeouts = new ControlledRenewableTimeoutService(fakeClock);
OutboundMessageCollector messages = new OutboundMessageCollector();
InMemoryRaftLog raftLog = new InMemoryRaftLog();
RaftMachine raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).timeoutService(timeouts).clock(fakeClock).outbound(messages).raftLog(raftLog).build();
raft.installCoreState(new RaftCoreState(new MembershipEntry(0, asSet(myself, member1, member2))));
raft.startTimers();
// When
timeouts.invokeTimeout(ELECTION);
raft.handle(voteResponse().from(member1).term(1).grant().build());
// Then
assertEquals(new NewLeaderBarrier(), readLogEntry(raftLog, raftLog.appendIndex()).content());
}
use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.
the class ComparableRaftStateTest method twoIdenticalStatesShouldBeEqual.
@Test
public void twoIdenticalStatesShouldBeEqual() throws Exception {
// given
NullLogProvider logProvider = NullLogProvider.getInstance();
ComparableRaftState state1 = new ComparableRaftState(member(0), asSet(member(0), member(1), member(2)), asSet(member(0), member(1), member(2)), new InMemoryRaftLog(), new InFlightMap<>(), logProvider);
ComparableRaftState state2 = new ComparableRaftState(member(0), asSet(member(0), member(1), member(2)), asSet(member(0), member(1), member(2)), new InMemoryRaftLog(), new InFlightMap<>(), logProvider);
// then
assertEquals(state1, state2);
}
use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.
the class BatchAppendLogEntriesTest method shouldApplyMultipleEntries.
@Test
public void shouldApplyMultipleEntries() throws Exception {
// given
InMemoryRaftLog raftLog = new InMemoryRaftLog();
BatchAppendLogEntries batchAppendLogEntries = new BatchAppendLogEntries(0, 0, new RaftLogEntry[] { entryA, entryB, entryC });
// when
batchAppendLogEntries.applyTo(raftLog, log);
// then
assertEquals(entryA, readLogEntry(raftLog, 0));
assertEquals(entryB, readLogEntry(raftLog, 1));
assertEquals(entryC, readLogEntry(raftLog, 2));
assertEquals(2, raftLog.appendIndex());
}
Aggregations