Search in sources :

Example 26 with ActorInitialized

use of org.opendaylight.controller.cluster.datastore.messages.ActorInitialized 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 ActorInitialized

use of org.opendaylight.controller.cluster.datastore.messages.ActorInitialized in project controller by opendaylight.

the class ShardManagerTest method testShutDown.

@Test
public void testShutDown() throws Exception {
    LOG.info("testShutDown starting");
    new TestKit(getSystem()) {

        {
            MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("shard1", Arrays.asList("member-1")).put("shard2", Arrays.asList("member-1")).build());
            String shardId1 = ShardIdentifier.create("shard1", MEMBER_1, shardMrgIDSuffix).toString();
            ActorRef shard1 = actorFactory.createActor(MessageCollectorActor.props(), shardId1);
            String shardId2 = ShardIdentifier.create("shard2", MEMBER_1, shardMrgIDSuffix).toString();
            ActorRef shard2 = actorFactory.createActor(MessageCollectorActor.props(), shardId2);
            ActorRef shardManager = actorFactory.createActor(newTestShardMgrBuilder(mockConfig).addShardActor("shard1", shard1).addShardActor("shard2", shard2).props());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), shard1);
            shardManager.tell(new ActorInitialized(), shard2);
            FiniteDuration duration = FiniteDuration.create(5, TimeUnit.SECONDS);
            Future<Boolean> stopFuture = Patterns.gracefulStop(shardManager, duration, Shutdown.INSTANCE);
            MessageCollectorActor.expectFirstMatching(shard1, Shutdown.class);
            MessageCollectorActor.expectFirstMatching(shard2, Shutdown.class);
            try {
                Await.ready(stopFuture, FiniteDuration.create(500, TimeUnit.MILLISECONDS));
                fail("ShardManager actor stopped without waiting for the Shards to be stopped");
            } catch (TimeoutException e) {
            // expected
            }
            actorFactory.killActor(shard1, this);
            actorFactory.killActor(shard2, this);
            Boolean stopped = Await.result(stopFuture, duration);
            assertEquals("Stopped", Boolean.TRUE, stopped);
        }
    };
    LOG.info("testShutDown ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FiniteDuration(scala.concurrent.duration.FiniteDuration) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) List(java.util.List) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)27 ActorRef (akka.actor.ActorRef)26 TestActorRef (akka.testkit.TestActorRef)26 TestKit (akka.testkit.javadsl.TestKit)26 Test (org.junit.Test)26 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)26 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)26 AddressFromURIString (akka.actor.AddressFromURIString)18 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)18 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)15 FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)14 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)8 ActorSystem (akka.actor.ActorSystem)6 ClusterWrapperImpl (org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl)6 LocalPrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound)5 List (java.util.List)4 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)4 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)4 RemotePrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)4 ChangeServersVotingStatus (org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus)4