Search in sources :

Example 1 with SimpleReplicatedLog

use of org.opendaylight.controller.cluster.raft.MockRaftActorContext.SimpleReplicatedLog in project controller by opendaylight.

the class PartitionedCandidateOnStartupElectionScenarioTest method setupPartitionedCandidateMember3AndSendElectionTimeouts.

private void setupPartitionedCandidateMember3AndSendElectionTimeouts() {
    testLog.info("setupPartitionedCandidateMember3AndSendElectionTimeouts starting");
    // Create member 3's behavior initially as a Candidate.
    member3Context = newRaftActorContext("member3", member3ActorRef, ImmutableMap.<String, String>builder().put("member1", member1ActorRef.path().toString()).put("member2", member2ActorRef.path().toString()).build());
    DefaultConfigParamsImpl member3ConfigParams = newConfigParams();
    member3Context.setConfigParams(member3ConfigParams);
    // Initialize the ReplicatedLog and election term info for Candidate member 3. The current term
    // will be 2 and the last term will be 1 so it is behind the leader's log.
    SimpleReplicatedLog candidateReplicatedLog = new SimpleReplicatedLog();
    candidateReplicatedLog.append(new SimpleReplicatedLogEntry(0, 2, new MockPayload("")));
    member3Context.setReplicatedLog(candidateReplicatedLog);
    member3Context.setCommitIndex(candidateReplicatedLog.lastIndex());
    member3Context.setLastApplied(candidateReplicatedLog.lastIndex());
    member3Context.getTermInformation().update(2, member1Context.getId());
    // The member 3 Candidate will start a new term and send RequestVotes. However it will be
    // partitioned from the cluster by having member 1 and 2 drop its RequestVote messages.
    candidateElectionTerm = member3Context.getTermInformation().getCurrentTerm() + numCandidateElections;
    member1Actor.dropMessagesToBehavior(RequestVote.class, numCandidateElections);
    member2Actor.dropMessagesToBehavior(RequestVote.class, numCandidateElections);
    member3Actor.self().tell(new SetBehavior(new Candidate(member3Context), member3Context), ActorRef.noSender());
    for (int i = 0; i < numCandidateElections - 1; i++) {
        member3ActorRef.tell(ElectionTimeout.INSTANCE, ActorRef.noSender());
    }
    member1Actor.waitForExpectedMessages(RequestVote.class);
    member2Actor.waitForExpectedMessages(RequestVote.class);
    verifyBehaviorState("member 1", member1Actor, RaftState.Leader);
    verifyBehaviorState("member 2", member2Actor, RaftState.Follower);
    verifyBehaviorState("member 3", member3Actor, RaftState.Candidate);
    assertEquals("member 1 election term", 3, member1Context.getTermInformation().getCurrentTerm());
    assertEquals("member 2 election term", 3, member2Context.getTermInformation().getCurrentTerm());
    assertEquals("member 3 election term", candidateElectionTerm, member3Context.getTermInformation().getCurrentTerm());
    testLog.info("setupPartitionedCandidateMember3AndSendElectionTimeouts ending");
}
Also used : SimpleReplicatedLog(org.opendaylight.controller.cluster.raft.MockRaftActorContext.SimpleReplicatedLog) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) DefaultConfigParamsImpl(org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload)

Example 2 with SimpleReplicatedLog

use of org.opendaylight.controller.cluster.raft.MockRaftActorContext.SimpleReplicatedLog in project controller by opendaylight.

the class PartitionedCandidateOnStartupElectionScenarioTest method setupInitialMember1AndMember2Behaviors.

private void setupInitialMember1AndMember2Behaviors() {
    testLog.info("setupInitialMember1AndMember2Behaviors starting");
    // Initialize the ReplicatedLog and election term info for member 1 and 2. The current term
    // will be 3 and the last term will be 2.
    SimpleReplicatedLog replicatedLog = new SimpleReplicatedLog();
    replicatedLog.append(new SimpleReplicatedLogEntry(0, 2, new MockPayload("")));
    replicatedLog.append(new SimpleReplicatedLogEntry(1, 3, new MockPayload("")));
    // Create member 2's behavior as Follower.
    member2Context = newRaftActorContext("member2", member2ActorRef, ImmutableMap.<String, String>builder().put("member1", member1ActorRef.path().toString()).put("member3", member3ActorRef.path().toString()).build());
    DefaultConfigParamsImpl member2ConfigParams = newConfigParams();
    member2Context.setConfigParams(member2ConfigParams);
    member2Context.setReplicatedLog(replicatedLog);
    member2Context.setCommitIndex(replicatedLog.lastIndex());
    member2Context.setLastApplied(replicatedLog.lastIndex());
    member2Context.getTermInformation().update(3, "member1");
    member2Actor.self().tell(new SetBehavior(new Follower(member2Context), member2Context), ActorRef.noSender());
    // Create member 1's behavior as Leader.
    member1Context = newRaftActorContext("member1", member1ActorRef, ImmutableMap.<String, String>builder().put("member2", member2ActorRef.path().toString()).put("member3", member3ActorRef.path().toString()).build());
    DefaultConfigParamsImpl member1ConfigParams = newConfigParams();
    member1Context.setConfigParams(member1ConfigParams);
    member1Context.setReplicatedLog(replicatedLog);
    member1Context.setCommitIndex(replicatedLog.lastIndex());
    member1Context.setLastApplied(replicatedLog.lastIndex());
    member1Context.getTermInformation().update(3, "member1");
    initializeLeaderBehavior(member1Actor, member1Context, 1);
    member2Actor.clear();
    member3Actor.clear();
    testLog.info("setupInitialMember1AndMember2Behaviors ending");
}
Also used : SimpleReplicatedLog(org.opendaylight.controller.cluster.raft.MockRaftActorContext.SimpleReplicatedLog) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) DefaultConfigParamsImpl(org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload)

Aggregations

DefaultConfigParamsImpl (org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl)2 MockPayload (org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload)2 SimpleReplicatedLog (org.opendaylight.controller.cluster.raft.MockRaftActorContext.SimpleReplicatedLog)2 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)2