use of org.opendaylight.controller.cluster.raft.MockRaftActorContext in project controller by opendaylight.
the class AbstractRaftActorBehaviorTest method testHandleRequestVoteWhenSenderTermLessThanCurrentTerm.
/**
* This test verifies that the receiving RaftActor will not grant a vote
* to a sender if the sender's term is lesser than the currentTerm of the
* recipient RaftActor.
*/
@Test
public void testHandleRequestVoteWhenSenderTermLessThanCurrentTerm() {
MockRaftActorContext context = createActorContext();
context.getTermInformation().update(1000, null);
behavior = createBehavior(context);
behavior.handleMessage(behaviorActor, new RequestVote(999, "test", 10000, 999));
RequestVoteReply reply = MessageCollectorActor.expectFirstMatching(behaviorActor, RequestVoteReply.class);
assertEquals("isVoteGranted", false, reply.isVoteGranted());
}
use of org.opendaylight.controller.cluster.raft.MockRaftActorContext in project controller by opendaylight.
the class AbstractRaftActorBehaviorTest method testHandleRaftRPCWithNewerTerm.
/**
* This test checks that when a new Raft RPC message is received with a newer
* term the RaftActor gets into the Follower state.
*/
@Test
public void testHandleRaftRPCWithNewerTerm() {
MockRaftActorContext actorContext = createActorContext();
assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(actorContext, behaviorActor, createAppendEntriesWithNewerTerm());
assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(actorContext, behaviorActor, createAppendEntriesReplyWithNewerTerm());
assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(actorContext, behaviorActor, createRequestVoteWithNewerTerm());
assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(actorContext, behaviorActor, createRequestVoteReplyWithNewerTerm());
}
use of org.opendaylight.controller.cluster.raft.MockRaftActorContext in project controller by opendaylight.
the class AbstractRaftActorBehaviorTest method testHandleRequestVoteWhenSenderLogLessUptoDate.
/**
* This test verifies that when a RaftActor receives a RequestVote message
* with a term that is greater than it's currentTerm but a less up-to-date
* log then the receiving RaftActor will not grant the vote to the sender.
*/
@Test
public void testHandleRequestVoteWhenSenderLogLessUptoDate() {
MockRaftActorContext context = createActorContext();
behavior = createBehavior(context);
context.getTermInformation().update(1, "test");
int index = 2000;
setLastLogEntry(context, context.getTermInformation().getCurrentTerm(), index, new MockRaftActorContext.MockPayload(""));
behavior.handleMessage(behaviorActor, new RequestVote(context.getTermInformation().getCurrentTerm(), "test", index - 1, context.getTermInformation().getCurrentTerm()));
RequestVoteReply reply = MessageCollectorActor.expectFirstMatching(behaviorActor, RequestVoteReply.class);
assertEquals("isVoteGranted", false, reply.isVoteGranted());
}
use of org.opendaylight.controller.cluster.raft.MockRaftActorContext in project controller by opendaylight.
the class CandidateTest method testHandleRequestVoteWhenSenderTermEqualToCurrentTermAndVotedForDoesNotMatch.
@Test
public void testHandleRequestVoteWhenSenderTermEqualToCurrentTermAndVotedForDoesNotMatch() {
MockRaftActorContext context = createActorContext();
context.getTermInformation().update(1000, null);
// Once a candidate is created it will immediately increment the current term so after
// construction the currentTerm should be 1001
candidate = new Candidate(context);
setupPeers(1);
// RequestVote candidate ID ("candidate2") does not match this candidate's votedFor
// (it votes for itself)
candidate.handleMessage(peerActors[0], new RequestVote(1001, "candidate2", 10000, 999));
RequestVoteReply reply = MessageCollectorActor.expectFirstMatching(peerActors[0], RequestVoteReply.class);
assertEquals("isVoteGranted", false, reply.isVoteGranted());
assertEquals("getTerm", 1001, reply.getTerm());
}
use of org.opendaylight.controller.cluster.raft.MockRaftActorContext in project controller by opendaylight.
the class CandidateTest method testThatAnElectionTimeoutIsTriggered.
@Test
public void testThatAnElectionTimeoutIsTriggered() {
MockRaftActorContext actorContext = createActorContext();
candidate = new Candidate(actorContext);
MessageCollectorActor.expectFirstMatching(candidateActor, ElectionTimeout.class, actorContext.getConfigParams().getElectionTimeOutInterval().$times(6).toMillis());
}
Aggregations