Search in sources :

Example 1 with RoleChangeNotifier

use of org.opendaylight.controller.cluster.notifications.RoleChangeNotifier in project controller by opendaylight.

the class RoleChangeNotifierTest method testHandleRaftRoleChanged.

@Test
public void testHandleRaftRoleChanged() throws Exception {
    new TestKit(getSystem()) {

        {
            String memberId = "testHandleRegisterRoleChangeListenerWithNotificationSet";
            ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props());
            ActorRef shardActor = getTestActor();
            TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(), RoleChangeNotifier.getProps(memberId), memberId);
            notifierTestActorRef.tell(new RoleChanged(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), shardActor);
            // no notification should be sent as listener has not yet
            // registered
            assertNull(MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class));
            // listener registers after role has been changed, ensure we
            // sent the latest role change after a reply
            notifierTestActorRef.tell(new RegisterRoleChangeListener(), listenerActor);
            RegisterRoleChangeListenerReply reply = MessageCollectorActor.getFirstMatching(listenerActor, RegisterRoleChangeListenerReply.class);
            assertNotNull(reply);
            RoleChangeNotification notification = MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class);
            assertNotNull(notification);
            assertEquals(RaftState.Candidate.name(), notification.getOldRole());
            assertEquals(RaftState.Leader.name(), notification.getNewRole());
        }
    };
}
Also used : RoleChangeNotifier(org.opendaylight.controller.cluster.notifications.RoleChangeNotifier) RegisterRoleChangeListener(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener) TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) RegisterRoleChangeListenerReply(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListenerReply) TestKit(akka.testkit.javadsl.TestKit) RoleChanged(org.opendaylight.controller.cluster.notifications.RoleChanged) Test(org.junit.Test)

Example 2 with RoleChangeNotifier

use of org.opendaylight.controller.cluster.notifications.RoleChangeNotifier in project controller by opendaylight.

the class RoleChangeNotifierTest method testHandleRegisterRoleChangeListener.

@Test
public void testHandleRegisterRoleChangeListener() throws Exception {
    new TestKit(getSystem()) {

        {
            String memberId = "testHandleRegisterRoleChangeListener";
            ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props());
            TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(), RoleChangeNotifier.getProps(memberId), memberId);
            notifierTestActorRef.tell(new RegisterRoleChangeListener(), listenerActor);
            RegisterRoleChangeListenerReply reply = MessageCollectorActor.getFirstMatching(listenerActor, RegisterRoleChangeListenerReply.class);
            assertNotNull(reply);
            RoleChangeNotification notification = MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class);
            assertNull(notification);
        }
    };
}
Also used : RoleChangeNotifier(org.opendaylight.controller.cluster.notifications.RoleChangeNotifier) RegisterRoleChangeListener(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener) TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) RegisterRoleChangeListenerReply(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListenerReply) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Example 3 with RoleChangeNotifier

use of org.opendaylight.controller.cluster.notifications.RoleChangeNotifier in project controller by opendaylight.

the class RoleChangeNotifierTest method testHandleLeaderStateChanged.

@Test
public void testHandleLeaderStateChanged() throws Exception {
    new TestKit(getSystem()) {

        {
            String actorId = "testHandleLeaderStateChanged";
            TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(), RoleChangeNotifier.getProps(actorId), actorId);
            notifierTestActorRef.tell(new LeaderStateChanged("member1", "leader1", (short) 5), ActorRef.noSender());
            // listener registers after the sate has been changed, ensure we
            // sent the latest state change after a reply
            notifierTestActorRef.tell(new RegisterRoleChangeListener(), getRef());
            expectMsgClass(RegisterRoleChangeListenerReply.class);
            LeaderStateChanged leaderStateChanged = expectMsgClass(LeaderStateChanged.class);
            assertEquals("getMemberId", "member1", leaderStateChanged.getMemberId());
            assertEquals("getLeaderId", "leader1", leaderStateChanged.getLeaderId());
            assertEquals("getLeaderPayloadVersion", 5, leaderStateChanged.getLeaderPayloadVersion());
            notifierTestActorRef.tell(new LeaderStateChanged("member1", "leader2", (short) 6), ActorRef.noSender());
            leaderStateChanged = expectMsgClass(LeaderStateChanged.class);
            assertEquals("getMemberId", "member1", leaderStateChanged.getMemberId());
            assertEquals("getLeaderId", "leader2", leaderStateChanged.getLeaderId());
            assertEquals("getLeaderPayloadVersion", 6, leaderStateChanged.getLeaderPayloadVersion());
        }
    };
}
Also used : RoleChangeNotifier(org.opendaylight.controller.cluster.notifications.RoleChangeNotifier) RegisterRoleChangeListener(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener) TestKit(akka.testkit.javadsl.TestKit) LeaderStateChanged(org.opendaylight.controller.cluster.notifications.LeaderStateChanged) Test(org.junit.Test)

Aggregations

TestKit (akka.testkit.javadsl.TestKit)3 Test (org.junit.Test)3 RegisterRoleChangeListener (org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener)3 RoleChangeNotifier (org.opendaylight.controller.cluster.notifications.RoleChangeNotifier)3 ActorRef (akka.actor.ActorRef)2 TestActorRef (akka.testkit.TestActorRef)2 RegisterRoleChangeListenerReply (org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListenerReply)2 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)2 LeaderStateChanged (org.opendaylight.controller.cluster.notifications.LeaderStateChanged)1 RoleChanged (org.opendaylight.controller.cluster.notifications.RoleChanged)1