Search in sources :

Example 41 with MockRaftActorContext

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());
}
Also used : MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) RequestVoteReply(org.opendaylight.controller.cluster.raft.messages.RequestVoteReply) RequestVote(org.opendaylight.controller.cluster.raft.messages.RequestVote) AbstractActorTest(org.opendaylight.controller.cluster.raft.AbstractActorTest) Test(org.junit.Test)

Example 42 with MockRaftActorContext

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());
}
Also used : MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) AbstractActorTest(org.opendaylight.controller.cluster.raft.AbstractActorTest) Test(org.junit.Test)

Example 43 with MockRaftActorContext

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());
}
Also used : MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) RequestVoteReply(org.opendaylight.controller.cluster.raft.messages.RequestVoteReply) RequestVote(org.opendaylight.controller.cluster.raft.messages.RequestVote) AbstractActorTest(org.opendaylight.controller.cluster.raft.AbstractActorTest) Test(org.junit.Test)

Example 44 with MockRaftActorContext

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());
}
Also used : MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) RequestVoteReply(org.opendaylight.controller.cluster.raft.messages.RequestVoteReply) RequestVote(org.opendaylight.controller.cluster.raft.messages.RequestVote) Test(org.junit.Test)

Example 45 with MockRaftActorContext

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());
}
Also used : MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) Test(org.junit.Test)

Aggregations

MockRaftActorContext (org.opendaylight.controller.cluster.raft.MockRaftActorContext)100 Test (org.junit.Test)93 AppendEntries (org.opendaylight.controller.cluster.raft.messages.AppendEntries)44 AppendEntriesReply (org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply)40 DefaultConfigParamsImpl (org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl)30 FiniteDuration (scala.concurrent.duration.FiniteDuration)29 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)28 ReplicatedLogEntry (org.opendaylight.controller.cluster.raft.ReplicatedLogEntry)24 ByteString (com.google.protobuf.ByteString)19 HashMap (java.util.HashMap)16 InstallSnapshot (org.opendaylight.controller.cluster.raft.messages.InstallSnapshot)11 RequestVoteReply (org.opendaylight.controller.cluster.raft.messages.RequestVoteReply)11 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)9 RequestVote (org.opendaylight.controller.cluster.raft.messages.RequestVote)8 ArrayList (java.util.ArrayList)7 AbstractActorTest (org.opendaylight.controller.cluster.raft.AbstractActorTest)7 CaptureSnapshot (org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot)7 FollowerLogInformation (org.opendaylight.controller.cluster.raft.FollowerLogInformation)6 SendInstallSnapshot (org.opendaylight.controller.cluster.raft.base.messages.SendInstallSnapshot)6 InstallSnapshotReply (org.opendaylight.controller.cluster.raft.messages.InstallSnapshotReply)6