Search in sources :

Example 16 with RequestVote

use of org.opendaylight.controller.cluster.raft.messages.RequestVote in project controller by opendaylight.

the class CandidateTest method testResponseToRequestVoteWithLowerTerm.

@Test
public void testResponseToRequestVoteWithLowerTerm() {
    candidate = new Candidate(createActorContext());
    setupPeers(1);
    candidate.handleMessage(peerActors[0], new RequestVote(1, "test", 0, 0));
    RequestVoteReply reply = MessageCollectorActor.expectFirstMatching(peerActors[0], RequestVoteReply.class);
    assertEquals("isVoteGranted", false, reply.isVoteGranted());
    assertEquals("getTerm", 2, reply.getTerm());
}
Also used : RequestVoteReply(org.opendaylight.controller.cluster.raft.messages.RequestVoteReply) RequestVote(org.opendaylight.controller.cluster.raft.messages.RequestVote) Test(org.junit.Test)

Example 17 with RequestVote

use of org.opendaylight.controller.cluster.raft.messages.RequestVote in project controller by opendaylight.

the class ShardTest method testRegisterRoleChangeListener.

@Test
public void testRegisterRoleChangeListener() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testRegisterRoleChangeListener");
            waitUntilLeader(shard);
            final ActorRef listener = getSystem().actorOf(MessageCollectorActor.props());
            shard.tell(new RegisterRoleChangeListener(), listener);
            MessageCollectorActor.expectFirstMatching(listener, RegisterRoleChangeListenerReply.class);
            ShardLeaderStateChanged leaderStateChanged = MessageCollectorActor.expectFirstMatching(listener, ShardLeaderStateChanged.class);
            assertEquals("getLocalShardDataTree present", true, leaderStateChanged.getLocalShardDataTree().isPresent());
            assertSame("getLocalShardDataTree", shard.underlyingActor().getDataStore().getDataTree(), leaderStateChanged.getLocalShardDataTree().get());
            MessageCollectorActor.clearMessages(listener);
            // Force a leader change
            shard.tell(new RequestVote(10000, "member2", 50, 50), getRef());
            leaderStateChanged = MessageCollectorActor.expectFirstMatching(listener, ShardLeaderStateChanged.class);
            assertEquals("getLocalShardDataTree present", false, leaderStateChanged.getLocalShardDataTree().isPresent());
        }
    };
}
Also used : RegisterRoleChangeListener(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RequestVote(org.opendaylight.controller.cluster.raft.messages.RequestVote) Test(org.junit.Test)

Aggregations

RequestVote (org.opendaylight.controller.cluster.raft.messages.RequestVote)17 Test (org.junit.Test)11 RequestVoteReply (org.opendaylight.controller.cluster.raft.messages.RequestVoteReply)10 MockRaftActorContext (org.opendaylight.controller.cluster.raft.MockRaftActorContext)8 AbstractActorTest (org.opendaylight.controller.cluster.raft.AbstractActorTest)3 InstallSnapshot (org.opendaylight.controller.cluster.raft.messages.InstallSnapshot)3 RaftRPC (org.opendaylight.controller.cluster.raft.messages.RaftRPC)3 FiniteDuration (scala.concurrent.duration.FiniteDuration)3 ActorRef (akka.actor.ActorRef)2 TestActorRef (akka.testkit.TestActorRef)2 ElectionTimeout (org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout)2 TimeoutNow (org.opendaylight.controller.cluster.raft.base.messages.TimeoutNow)2 AppendEntries (org.opendaylight.controller.cluster.raft.messages.AppendEntries)2 ActorSelection (akka.actor.ActorSelection)1 Props (akka.actor.Props)1 UntypedActor (akka.actor.UntypedActor)1 Dispatchers (akka.dispatch.Dispatchers)1 TestKit (akka.testkit.javadsl.TestKit)1 Optional (com.google.common.base.Optional)1 Stopwatch (com.google.common.base.Stopwatch)1