use of org.neo4j.causalclustering.core.consensus.log.RaftLog in project neo4j by neo4j.
the class AppendEntriesRequestTest method shouldAcceptInitialEntriesAfterBootstrap.
@Test
public void shouldAcceptInitialEntriesAfterBootstrap() throws Exception {
RaftLog raftLog = bootstrappedLog();
RaftState state = raftState().entryLog(raftLog).myself(myself).build();
long leaderTerm = state.term() + leaderTermDifference;
RaftLogEntry logEntry1 = new RaftLogEntry(leaderTerm, content());
RaftLogEntry logEntry2 = new RaftLogEntry(leaderTerm, content());
// when
Outcome outcome = role.handler.handle(appendEntriesRequest().from(leader).leaderTerm(leaderTerm).prevLogIndex(0).prevLogTerm(0).logEntry(logEntry1).logEntry(logEntry2).build(), state, log());
// then
assertTrue(((Response) messageFor(outcome, leader)).success());
assertThat(outcome.getLogCommands(), hasItem(new BatchAppendLogEntries(1, 0, new RaftLogEntry[] { logEntry1, logEntry2 })));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLog in project neo4j by neo4j.
the class AppendEntriesRequestTest method shouldAcceptInitialEntryAfterBootstrap.
@Test
public void shouldAcceptInitialEntryAfterBootstrap() throws Exception {
RaftLog raftLog = bootstrappedLog();
RaftState state = raftState().entryLog(raftLog).myself(myself).build();
long leaderTerm = state.term() + leaderTermDifference;
RaftLogEntry logEntry = new RaftLogEntry(leaderTerm, content());
// when
Outcome outcome = role.handler.handle(appendEntriesRequest().from(leader).leaderTerm(leaderTerm).prevLogIndex(0).prevLogTerm(0).logEntry(logEntry).build(), state, log());
// then
assertTrue(((Response) messageFor(outcome, leader)).success());
assertThat(outcome.getLogCommands(), hasItem(new BatchAppendLogEntries(1, 0, new RaftLogEntry[] { logEntry })));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLog 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.RaftLog in project neo4j by neo4j.
the class RaftLogShipperTest method setup.
@Before
public void setup() {
// defaults
outbound = new OutboundMessageCollector();
raftLog = new InMemoryRaftLog();
clock = Clocks.systemClock();
leader = member(0);
follower = member(1);
leaderTerm = 0;
leaderCommit = 0;
retryTimeMillis = 100000;
logProvider = mock(LogProvider.class);
log = mock(Log.class);
when(logProvider.getLog(RaftLogShipper.class)).thenReturn(log);
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLog in project neo4j by neo4j.
the class FollowerTest method followerLearningAboutHigherCommitCausesValuesTobeAppliedToItsLog.
// TODO move this to outcome tests
@Test
public void followerLearningAboutHigherCommitCausesValuesTobeAppliedToItsLog() throws Exception {
// given
RaftLog entryLog = new InMemoryRaftLog();
entryLog.append(new RaftLogEntry(0, new RaftTestGroup(0)));
RaftState state = raftState().myself(myself).entryLog(entryLog).build();
Follower follower = new Follower();
appendSomeEntriesToLog(state, follower, 3, 0, 1);
// when receiving AppEntries with high leader commit (4)
Outcome outcome = follower.handle(new AppendEntries.Request(myself, 0, 3, 0, new RaftLogEntry[] { new RaftLogEntry(0, ContentGenerator.content()) }, 4), state, log());
state.update(outcome);
// then
assertEquals(4, state.commitIndex());
}
Aggregations