Search in sources :

Example 41 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class ShardManagerTest method testServerRemovedShardActorRunning.

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

        {
            MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-2")).put("people", Arrays.asList("member-1", "member-2")).build());
            String shardId = ShardIdentifier.create("default", MEMBER_1, shardMrgIDSuffix).toString();
            ActorRef shard = actorFactory.createActor(MessageCollectorActor.props(), shardId);
            TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newTestShardMgrBuilder(mockConfig).addShardActor("default", shard).props().withDispatcher(Dispatchers.DefaultDispatcherId()));
            shardManager.underlyingActor().waitForRecoveryComplete();
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), shard);
            waitForShardInitialized(shardManager, "people", this);
            waitForShardInitialized(shardManager, "default", this);
            // Removed the default shard replica from member-1
            shardManager.tell(new ServerRemoved(shardId), getRef());
            shardManager.underlyingActor().verifySnapshotPersisted(Sets.newHashSet("people"));
            MessageCollectorActor.expectFirstMatching(shard, Shutdown.class);
        }
    };
    LOG.info("testServerRemovedShardActorRunning ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ServerRemoved(org.opendaylight.controller.cluster.raft.messages.ServerRemoved) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 42 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindPrimaryWaitForReadyWithNoRoleShard.

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

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, true), getRef());
            expectMsgClass(duration("2 seconds"), NoShardLeaderException.class);
        }
    };
    LOG.info("testOnReceiveFindPrimaryWaitForReadyWithNoRoleShard ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 43 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindLocalShardForNotInitializedShard.

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

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
            expectMsgClass(duration("5 seconds"), NotInitializedException.class);
        }
    };
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 44 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class ShardManagerTest method testReadyCountDownForMemberUpAfterLeaderStateChanged.

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

        {
            TestShardManager shardManager = newTestShardManager();
            String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
            shardManager.onReceiveCommand(new RoleChangeNotification(memberId, null, RaftState.Follower.name()));
            verify(ready, never()).countDown();
            shardManager.onReceiveCommand(new ShardLeaderStateChanged(memberId, "member-2-shard-default-" + shardMrgIDSuffix, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION));
            shardManager.onReceiveCommand(MockClusterWrapper.createMemberUp("member-2", getRef().path().toString()));
            verify(ready, times(1)).countDown();
        }
    };
}
Also used : ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 45 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindLocalShardForNonExistentShard.

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

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new FindLocalShard("non-existent", false), getRef());
            LocalShardNotFound notFound = expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
            assertEquals("getShardName", "non-existent", notFound.getShardName());
        }
    };
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

TestKit (akka.testkit.javadsl.TestKit)124 Test (org.junit.Test)115 ActorRef (akka.actor.ActorRef)84 TestActorRef (akka.testkit.TestActorRef)63 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)44 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)37 AddressFromURIString (akka.actor.AddressFromURIString)28 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)26 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)22 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)22 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)17 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)17 FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)16 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)16 Props (akka.actor.Props)15 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)15 Failure (akka.actor.Status.Failure)14 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)14 FiniteDuration (scala.concurrent.duration.FiniteDuration)14 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)13