Search in sources :

Example 1 with ElectionTerm

use of org.opendaylight.controller.cluster.raft.ElectionTerm in project controller by opendaylight.

the class CandidateTest method testBecomeLeaderOnReceivingMajorityVotesWithNonVotingPeers.

@Test
public void testBecomeLeaderOnReceivingMajorityVotesWithNonVotingPeers() {
    ElectionTerm mockElectionTerm = Mockito.mock(ElectionTerm.class);
    Mockito.doReturn(1L).when(mockElectionTerm).getCurrentTerm();
    RaftActorContext raftActorContext = new RaftActorContextImpl(candidateActor, candidateActor.actorContext(), "candidate", mockElectionTerm, -1, -1, setupPeers(4), new DefaultConfigParamsImpl(), new NonPersistentDataProvider(Runnable::run), applyState -> {
    }, LOG);
    raftActorContext.setReplicatedLog(new MockRaftActorContext.MockReplicatedLogBuilder().build());
    raftActorContext.getPeerInfo("peer1").setVotingState(VotingState.NON_VOTING);
    raftActorContext.getPeerInfo("peer4").setVotingState(VotingState.NON_VOTING);
    candidate = new Candidate(raftActorContext);
    MessageCollectorActor.expectFirstMatching(peerActors[1], RequestVote.class);
    MessageCollectorActor.expectFirstMatching(peerActors[2], RequestVote.class);
    MessageCollectorActor.assertNoneMatching(peerActors[0], RequestVote.class, 300);
    MessageCollectorActor.assertNoneMatching(peerActors[3], RequestVote.class, 100);
    candidate = candidate.handleMessage(peerActors[1], new RequestVoteReply(1, false));
    assertEquals("Behavior", RaftState.Candidate, candidate.state());
    candidate = candidate.handleMessage(peerActors[2], new RequestVoteReply(1, true));
    assertEquals("Behavior", RaftState.Leader, candidate.state());
}
Also used : ElectionTerm(org.opendaylight.controller.cluster.raft.ElectionTerm) RaftActorContextImpl(org.opendaylight.controller.cluster.raft.RaftActorContextImpl) NonPersistentDataProvider(org.opendaylight.controller.cluster.NonPersistentDataProvider) RaftActorContext(org.opendaylight.controller.cluster.raft.RaftActorContext) MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) DefaultConfigParamsImpl(org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl) RequestVoteReply(org.opendaylight.controller.cluster.raft.messages.RequestVoteReply) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 NonPersistentDataProvider (org.opendaylight.controller.cluster.NonPersistentDataProvider)1 DefaultConfigParamsImpl (org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl)1 ElectionTerm (org.opendaylight.controller.cluster.raft.ElectionTerm)1 MockRaftActorContext (org.opendaylight.controller.cluster.raft.MockRaftActorContext)1 RaftActorContext (org.opendaylight.controller.cluster.raft.RaftActorContext)1 RaftActorContextImpl (org.opendaylight.controller.cluster.raft.RaftActorContextImpl)1 RequestVoteReply (org.opendaylight.controller.cluster.raft.messages.RequestVoteReply)1