Search in sources :

Example 6 with LeaderStateChanged

use of org.opendaylight.controller.cluster.notifications.LeaderStateChanged 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

Test (org.junit.Test)6 LeaderStateChanged (org.opendaylight.controller.cluster.notifications.LeaderStateChanged)6 ActorRef (akka.actor.ActorRef)5 TestActorRef (akka.testkit.TestActorRef)3 TestKit (akka.testkit.javadsl.TestKit)2 ByteString (com.google.protobuf.ByteString)2 AddressFromURIString (akka.actor.AddressFromURIString)1 Props (akka.actor.Props)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)1 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)1 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)1 FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)1 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)1 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)1 LeaderLocationListener (org.opendaylight.controller.cluster.dom.api.LeaderLocationListener)1 RegisterRoleChangeListener (org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener)1 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)1 RoleChangeNotifier (org.opendaylight.controller.cluster.notifications.RoleChangeNotifier)1 RoleChanged (org.opendaylight.controller.cluster.notifications.RoleChanged)1