use of org.neo4j.causalclustering.core.consensus.state.RaftState in project neo4j by neo4j.
the class NonFollowerVoteRequestTest method shouldRejectVoteRequestFromPreviousTerm.
@Test
public void shouldRejectVoteRequestFromPreviousTerm() throws Exception {
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
assertFalse(((RaftMessages.Vote.Response) messageFor(outcome, member1)).voteGranted());
assertEquals(role, outcome.getRole());
}
use of org.neo4j.causalclustering.core.consensus.state.RaftState in project neo4j by neo4j.
the class NonFollowerVoteRequestTest method shouldRejectVoteRequestFromCurrentTerm.
@Test
public void shouldRejectVoteRequestFromCurrentTerm() throws Exception {
RaftState state = newState();
// when
final long candidateTerm = state.term();
Outcome outcome = role.handler.handle(voteRequest().from(member1).term(candidateTerm).lastLogIndex(0).lastLogTerm(-1).build(), state, log());
// then
assertFalse(((RaftMessages.Vote.Response) messageFor(outcome, member1)).voteGranted());
assertEquals(role, outcome.getRole());
}
use of org.neo4j.causalclustering.core.consensus.state.RaftState in project neo4j by neo4j.
the class CandidateTest method shouldUpdateTermOnReceivingVoteResponseWithLaterTerm.
@Test
public void shouldUpdateTermOnReceivingVoteResponseWithLaterTerm() throws Exception {
// given
RaftState state = newState();
final long voterTerm = state.term() + 1;
// when
Outcome outcome = CANDIDATE.handler.handle(voteResponse().term(voterTerm).from(member1).grant().build(), state, log());
// then
assertEquals(FOLLOWER, outcome.getRole());
assertEquals(voterTerm, outcome.getTerm());
}
use of org.neo4j.causalclustering.core.consensus.state.RaftState in project neo4j by neo4j.
the class CandidateTest method shouldBeElectedLeaderOnReceivingGrantedVoteResponseWithCurrentTerm.
@Test
public void shouldBeElectedLeaderOnReceivingGrantedVoteResponseWithCurrentTerm() throws Exception {
// given
RaftState state = RaftStateBuilder.raftState().term(1).myself(myself).votingMembers(member1, member2).replicationMembers(member1, member2).build();
// when
Outcome outcome = CANDIDATE.handler.handle(voteResponse().term(state.term()).from(member1).grant().build(), state, log());
// then
assertEquals(LEADER, outcome.getRole());
assertEquals(true, outcome.electionTimeoutRenewed());
assertThat(outcome.getLogCommands(), hasItem(new AppendLogEntry(0, new RaftLogEntry(state.term(), new NewLeaderBarrier()))));
assertThat(outcome.getOutgoingMessages(), hasItems(new RaftMessages.Directed(member1, new RaftMessages.Heartbeat(myself, state.term(), -1, -1)), new RaftMessages.Directed(member2, new RaftMessages.Heartbeat(myself, state.term(), -1, -1))));
}
use of org.neo4j.causalclustering.core.consensus.state.RaftState in project neo4j by neo4j.
the class CandidateTest method shouldRejectVoteResponseWithOldTerm.
@Test
public void shouldRejectVoteResponseWithOldTerm() throws Exception {
// given
RaftState state = newState();
final long voterTerm = state.term() - 1;
// when
Outcome outcome = CANDIDATE.handler.handle(voteResponse().term(voterTerm).from(member1).grant().build(), state, log());
// then
assertEquals(CANDIDATE, outcome.getRole());
}
Aggregations