Search in sources :

Example 26 with RoleChangeNotification

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

the class ShardManagerTest method testChangeServersVotingStatusWithNoLeader.

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

        {
            String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
            ActorRef respondActor = actorFactory.createActor(Props.create(MockRespondActor.class, ChangeServersVotingStatus.class, new ServerChangeReply(ServerChangeStatus.NO_LEADER, null)), memberId);
            ActorRef shardManager = getSystem().actorOf(newPropsShardMgrWithMockShardActor(respondActor));
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), respondActor);
            shardManager.tell(new RoleChangeNotification(memberId, null, RaftState.Follower.name()), respondActor);
            shardManager.tell(new ChangeShardMembersVotingStatus("default", ImmutableMap.of("member-2", Boolean.TRUE)), getRef());
            MessageCollectorActor.expectFirstMatching(respondActor, ChangeServersVotingStatus.class);
            Status.Failure resp = expectMsgClass(duration("5 seconds"), Status.Failure.class);
            assertEquals("Failure resposnse", true, resp.cause() instanceof NoShardLeaderException);
        }
    };
}
Also used : ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) Status(akka.actor.Status) ServerChangeStatus(org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) ServerChangeReply(org.opendaylight.controller.cluster.raft.messages.ServerChangeReply) Failure(akka.actor.Status.Failure) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 27 with RoleChangeNotification

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

the class ShardManagerTest method testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards.

@Test
public void testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards() throws Exception {
    LOG.info("testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards starting");
    TestShardManager shardManager = newTestShardManager(newShardMgrProps(new MockConfiguration() {

        @Override
        public List<String> getMemberShardNames(final MemberName memberName) {
            return Arrays.asList("default", "astronauts");
        }
    }));
    // Initially will be false
    assertEquals(false, shardManager.getMBean().getSyncStatus());
    // Make default shard leader
    String defaultShardId = "member-1-shard-default-" + shardMrgIDSuffix;
    shardManager.onReceiveCommand(new RoleChangeNotification(defaultShardId, RaftState.Follower.name(), RaftState.Leader.name()));
    // default = Leader, astronauts is unknown so sync status remains false
    assertEquals(false, shardManager.getMBean().getSyncStatus());
    // Make astronauts shard leader as well
    String astronautsShardId = "member-1-shard-astronauts-" + shardMrgIDSuffix;
    shardManager.onReceiveCommand(new RoleChangeNotification(astronautsShardId, RaftState.Follower.name(), RaftState.Leader.name()));
    // Now sync status should be true
    assertEquals(true, shardManager.getMBean().getSyncStatus());
    // Make astronauts a Follower
    shardManager.onReceiveCommand(new RoleChangeNotification(astronautsShardId, RaftState.Leader.name(), RaftState.Follower.name()));
    // Sync status is not true
    assertEquals(false, shardManager.getMBean().getSyncStatus());
    // Make the astronauts follower sync status true
    shardManager.onReceiveCommand(new FollowerInitialSyncUpStatus(true, astronautsShardId));
    // Sync status is now true
    assertEquals(true, shardManager.getMBean().getSyncStatus());
    LOG.info("testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards ending");
}
Also used : RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) AddressFromURIString(akka.actor.AddressFromURIString) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 28 with RoleChangeNotification

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

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

Aggregations

RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)29 Test (org.junit.Test)28 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)26 AddressFromURIString (akka.actor.AddressFromURIString)22 TestKit (akka.testkit.javadsl.TestKit)22 ActorRef (akka.actor.ActorRef)20 TestActorRef (akka.testkit.TestActorRef)20 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)18 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)18 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)18 FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)11 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)7 ActorSystem (akka.actor.ActorSystem)6 ClusterWrapperImpl (org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl)6 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)6 LocalPrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound)5 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)4 RemotePrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)4 ChangeServersVotingStatus (org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus)4 Status (akka.actor.Status)3