use of org.opendaylight.controller.cluster.raft.messages.RequestVoteReply in project controller by opendaylight.
the class FollowerTest method testHandleRequestVoteWhenSenderTermEqualToCurrentTermAndVotedForIsNull.
@Test
public void testHandleRequestVoteWhenSenderTermEqualToCurrentTermAndVotedForIsNull() {
logStart("testHandleRequestVoteWhenSenderTermEqualToCurrentTermAndVotedForIsNull");
MockRaftActorContext context = createActorContext();
long term = 1000;
context.getTermInformation().update(term, null);
follower = createBehavior(context);
follower.handleMessage(leaderActor, new RequestVote(term, "test", 10000, 999));
RequestVoteReply reply = MessageCollectorActor.expectFirstMatching(leaderActor, RequestVoteReply.class);
assertEquals("isVoteGranted", true, reply.isVoteGranted());
assertEquals("getTerm", term, reply.getTerm());
verify(follower).scheduleElection(any(FiniteDuration.class));
}
use of org.opendaylight.controller.cluster.raft.messages.RequestVoteReply in project controller by opendaylight.
the class FollowerTest method testHandleRequestVoteWhenSenderTermEqualToCurrentTermAndVotedForIsNotTheSameAsCandidateId.
@Test
public void testHandleRequestVoteWhenSenderTermEqualToCurrentTermAndVotedForIsNotTheSameAsCandidateId() {
logStart("testHandleRequestVoteWhenSenderTermEqualToCurrentTermAndVotedForIsNotTheSameAsCandidateId");
MockRaftActorContext context = createActorContext();
long term = 1000;
context.getTermInformation().update(term, "test");
follower = createBehavior(context);
follower.handleMessage(leaderActor, new RequestVote(term, "candidate", 10000, 999));
RequestVoteReply reply = MessageCollectorActor.expectFirstMatching(leaderActor, RequestVoteReply.class);
assertEquals("isVoteGranted", false, reply.isVoteGranted());
verify(follower, never()).scheduleElection(any(FiniteDuration.class));
}
use of org.opendaylight.controller.cluster.raft.messages.RequestVoteReply in project controller by opendaylight.
the class LeaderTest method testHandleRequestVoteReply.
@Test
public void testHandleRequestVoteReply() {
logStart("testHandleRequestVoteReply");
MockRaftActorContext leaderActorContext = createActorContext();
leader = new Leader(leaderActorContext);
// Should be a no-op.
RaftActorBehavior raftActorBehavior = leader.handleRequestVoteReply(followerActor, new RequestVoteReply(1, true));
assertEquals(RaftState.Leader, raftActorBehavior.state());
raftActorBehavior = leader.handleRequestVoteReply(followerActor, new RequestVoteReply(1, false));
assertEquals(RaftState.Leader, raftActorBehavior.state());
}
use of org.opendaylight.controller.cluster.raft.messages.RequestVoteReply in project controller by opendaylight.
the class PartitionedCandidateOnStartupElectionScenarioTest method resolvePartitionAndSendElectionTimeoutsToCandidateMember3.
private void resolvePartitionAndSendElectionTimeoutsToCandidateMember3() {
testLog.info("resolvePartitionAndSendElectionTimeoutsToCandidateMember3 starting");
// Now send a couple more ElectionTimeouts to Candidate member 3 with the partition resolved.
//
// On the first RequestVote, Leader member 1 should switch to Follower as its term (s) is less than
// the RequestVote's term (8) from member 3. No RequestVoteReply should be sent by member 1.
// Follower member 2 should update its term since it less than the RequestVote's term and
// should return a RequestVoteReply but should not grant the vote as its last term and index
// is greater than the RequestVote's lastLogTerm and lastLogIndex, ie member 2's log is later
// or more up to date than member 3's.
//
// On the second RequestVote, both member 1 and 2 are followers so they should update their
// term and return a RequestVoteReply but should not grant the vote.
candidateElectionTerm += 2;
for (int i = 0; i < 2; i++) {
member1Actor.clear();
member1Actor.expectMessageClass(RequestVote.class, 1);
member2Actor.clear();
member2Actor.expectMessageClass(RequestVote.class, 1);
member3Actor.clear();
member3Actor.expectMessageClass(RequestVoteReply.class, 1);
member3ActorRef.tell(ElectionTimeout.INSTANCE, ActorRef.noSender());
member1Actor.waitForExpectedMessages(RequestVote.class);
member2Actor.waitForExpectedMessages(RequestVote.class);
member3Actor.waitForExpectedMessages(RequestVoteReply.class);
RequestVoteReply requestVoteReply = member3Actor.getCapturedMessage(RequestVoteReply.class);
assertEquals("getTerm", member3Context.getTermInformation().getCurrentTerm(), requestVoteReply.getTerm());
assertEquals("isVoteGranted", false, requestVoteReply.isVoteGranted());
}
verifyBehaviorState("member 1", member1Actor, RaftState.Follower);
verifyBehaviorState("member 2", member2Actor, RaftState.Follower);
verifyBehaviorState("member 3", member3Actor, RaftState.Candidate);
// Even though member 3 didn't get voted for, member 1 and 2 should have updated their term
// to member 3's.
assertEquals("member 1 election term", candidateElectionTerm, member1Context.getTermInformation().getCurrentTerm());
assertEquals("member 2 election term", candidateElectionTerm, member2Context.getTermInformation().getCurrentTerm());
assertEquals("member 3 election term", candidateElectionTerm, member3Context.getTermInformation().getCurrentTerm());
testLog.info("resolvePartitionAndSendElectionTimeoutsToCandidateMember3 ending");
}
use of org.opendaylight.controller.cluster.raft.messages.RequestVoteReply in project controller by opendaylight.
the class AbstractRaftActorBehaviorTest method testHandleRequestVoteWhenSenderLogMoreUpToDate.
/**
* This test verifies that when a RequestVote is received by the RaftActor
* with the senders' log is more up to date than the receiver that the receiver grants
* the vote to the sender.
*/
@Test
public void testHandleRequestVoteWhenSenderLogMoreUpToDate() {
MockRaftActorContext context = createActorContext();
behavior = createBehavior(context);
context.getTermInformation().update(1, "test");
behavior.handleMessage(behaviorActor, new RequestVote(context.getTermInformation().getCurrentTerm(), "test", 10000, 999));
RequestVoteReply reply = MessageCollectorActor.expectFirstMatching(behaviorActor, RequestVoteReply.class);
assertEquals("isVoteGranted", true, reply.isVoteGranted());
}
Aggregations