use of org.neo4j.causalclustering.core.consensus.outcome.Outcome in project neo4j by neo4j.
the class VoteRequestTest method shouldUpdateTermIfRequestIsFromLaterTerm.
@Test
public void shouldUpdateTermIfRequestIsFromLaterTerm() throws Exception {
// given
RaftState state = newState();
// when
final long candidateTerm = state.term() + 1;
Outcome outcome = role.handler.handle(voteRequest().from(member1).term(candidateTerm).lastLogIndex(0).lastLogTerm(-1).build(), state, log());
// then
assertEquals(candidateTerm, outcome.getTerm());
}
use of org.neo4j.causalclustering.core.consensus.outcome.Outcome in project neo4j by neo4j.
the class VoteRequestTest method shouldMoveToFollowerIfRequestIsFromLaterTerm.
@Test
public void shouldMoveToFollowerIfRequestIsFromLaterTerm() throws Exception {
// given
RaftState state = newState();
// when
final long candidateTerm = state.term() + 1;
Outcome outcome = role.handler.handle(voteRequest().from(member1).term(candidateTerm).lastLogIndex(0).lastLogTerm(-1).build(), state, log());
// then
assertEquals(Role.FOLLOWER, outcome.getRole());
}
use of org.neo4j.causalclustering.core.consensus.outcome.Outcome 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.outcome.Outcome in project neo4j by neo4j.
the class AppendEntriesRequestTest method shouldRejectDiscontinuousEntries.
@Test
public void shouldRejectDiscontinuousEntries() throws Exception {
// given
RaftState state = raftState().myself(myself).build();
long leaderTerm = state.term() + leaderTermDifference;
// when
Outcome outcome = role.handler.handle(appendEntriesRequest().from(leader).leaderTerm(leaderTerm).prevLogIndex(state.entryLog().appendIndex() + 1).prevLogTerm(leaderTerm).logEntry(new RaftLogEntry(leaderTerm, content())).build(), state, log());
// then
Response response = (Response) messageFor(outcome, leader);
assertEquals(state.entryLog().appendIndex(), response.appendIndex());
assertFalse(response.success());
}
use of org.neo4j.causalclustering.core.consensus.outcome.Outcome in project neo4j by neo4j.
the class AppendEntriesRequestTest method shouldAcceptContinuousEntries.
@Test
public void shouldAcceptContinuousEntries() throws Exception {
InMemoryRaftLog raftLog = new InMemoryRaftLog();
RaftState state = raftState().myself(myself).entryLog(raftLog).build();
long leaderTerm = state.term() + leaderTermDifference;
raftLog.append(new RaftLogEntry(leaderTerm, content()));
// when
Outcome outcome = role.handler.handle(appendEntriesRequest().from(leader).leaderTerm(leaderTerm).prevLogIndex(raftLog.appendIndex()).prevLogTerm(leaderTerm).logEntry(new RaftLogEntry(leaderTerm, content())).build(), state, log());
// then
assertTrue(((Response) messageFor(outcome, leader)).success());
}
Aggregations