Search in sources :

Example 66 with TestKit

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

the class ShardManagerGetSnapshotReplyActorTest method testGetSnapshotTimeout.

@Test
public void testGetSnapshotTimeout() {
    TestKit kit = new TestKit(getSystem());
    ActorRef replyActor = getSystem().actorOf(ShardManagerGetSnapshotReplyActor.props(Arrays.asList("shard1"), "config", null, kit.getRef(), "shard-manager", Duration.create(100, TimeUnit.MILLISECONDS)), "testGetSnapshotTimeout");
    kit.watch(replyActor);
    Failure failure = kit.expectMsgClass(Failure.class);
    assertEquals("Failure cause type", TimeoutException.class, failure.cause().getClass());
    kit.expectTerminated(replyActor);
}
Also used : ActorRef(akka.actor.ActorRef) TestKit(akka.testkit.javadsl.TestKit) Failure(akka.actor.Status.Failure) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 67 with TestKit

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

the class ShardManagerGetSnapshotReplyActorTest method testSuccess.

@Test
public void testSuccess() {
    TestKit kit = new TestKit(getSystem());
    List<String> shardList = Arrays.asList("shard1", "shard2", "shard3");
    ShardManagerSnapshot shardManagerSnapshot = new ShardManagerSnapshot(shardList, Collections.emptyMap());
    ActorRef replyActor = getSystem().actorOf(ShardManagerGetSnapshotReplyActor.props(shardList, "config", shardManagerSnapshot, kit.getRef(), "shard-manager", Duration.create(100, TimeUnit.SECONDS)), "testSuccess");
    kit.watch(replyActor);
    ByteState shard1SnapshotState = ByteState.of(new byte[] { 1, 2, 3 });
    replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard1", MEMBER_1, "config").toString(), Snapshot.create(shard1SnapshotState, Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());
    ByteState shard2SnapshotState = ByteState.of(new byte[] { 4, 5, 6 });
    replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard2", MEMBER_1, "config").toString(), Snapshot.create(shard2SnapshotState, Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());
    kit.expectNoMsg(FiniteDuration.create(500, TimeUnit.MILLISECONDS));
    ByteState shard3SnapshotState = ByteState.of(new byte[] { 7, 8, 9 });
    replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard3", MEMBER_1, "config").toString(), Snapshot.create(shard3SnapshotState, Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());
    DatastoreSnapshot datastoreSnapshot = kit.expectMsgClass(DatastoreSnapshot.class);
    assertEquals("getType", "config", datastoreSnapshot.getType());
    assertEquals("getShardManagerSnapshot", shardManagerSnapshot.getShardList(), datastoreSnapshot.getShardManagerSnapshot().getShardList());
    List<ShardSnapshot> shardSnapshots = datastoreSnapshot.getShardSnapshots();
    assertEquals("ShardSnapshot size", 3, shardSnapshots.size());
    assertEquals("ShardSnapshot 1 getName", "shard1", shardSnapshots.get(0).getName());
    assertEquals("ShardSnapshot 1 getSnapshot", shard1SnapshotState, shardSnapshots.get(0).getSnapshot().getState());
    assertEquals("ShardSnapshot 2 getName", "shard2", shardSnapshots.get(1).getName());
    assertEquals("ShardSnapshot 2 getSnapshot", shard2SnapshotState, shardSnapshots.get(1).getSnapshot().getState());
    assertEquals("ShardSnapshot 3 getName", "shard3", shardSnapshots.get(2).getName());
    assertEquals("ShardSnapshot 3 getSnapshot", shard3SnapshotState, shardSnapshots.get(2).getSnapshot().getState());
    kit.expectMsgClass(Terminated.class);
}
Also used : ShardSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot) ShardManagerSnapshot(org.opendaylight.controller.cluster.datastore.persisted.ShardManagerSnapshot) ActorRef(akka.actor.ActorRef) TestKit(akka.testkit.javadsl.TestKit) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) ByteState(org.opendaylight.controller.cluster.raft.persisted.ByteState) GetSnapshotReply(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshotReply) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 68 with TestKit

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

the class ShardManagerTest method testOnReceiveFindPrimaryForInitializedShardWithNoRole.

@Test
public void testOnReceiveFindPrimaryForInitializedShardWithNoRole() throws Exception {
    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, false), getRef());
            expectMsgClass(duration("5 seconds"), NoShardLeaderException.class);
        }
    };
}
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 69 with TestKit

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

the class ShardManagerTest method testOnReceiveFindPrimaryWaitForReadyWithIsolatedLeaderShard.

@Test
public void testOnReceiveFindPrimaryWaitForReadyWithIsolatedLeaderShard() throws Exception {
    LOG.info("testOnReceiveFindPrimaryWaitForReadyWithIsolatedLeaderShard 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 RoleChangeNotification("member-1-shard-default-" + shardMrgIDSuffix, null, RaftState.IsolatedLeader.name()), mockShardActor);
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, true), getRef());
            expectMsgClass(duration("2 seconds"), NoShardLeaderException.class);
        }
    };
    LOG.info("testOnReceiveFindPrimaryWaitForReadyWithIsolatedLeaderShard 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) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) 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 70 with TestKit

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

the class ShardManagerTest method testServerChangeWhenAlreadyInProgress.

public void testServerChangeWhenAlreadyInProgress(final String shardName, final Object firstServerChange, final Class<?> firstForwardedServerChangeClass, final Object secondServerChange) throws Exception {
    new TestKit(getSystem()) {

        {
            TestKit mockShardLeaderKit = new TestKit(getSystem());
            final TestKit secondRequestKit = new TestKit(getSystem());
            MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put(shardName, Arrays.asList("member-2")).build());
            final TestActorRef<TestShardManager> shardManager = TestActorRef.create(getSystem(), newTestShardMgrBuilder().configuration(mockConfig).shardActor(mockShardActor).cluster(new MockClusterWrapper()).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardMgrID);
            shardManager.underlyingActor().setMessageInterceptor(newFindPrimaryInterceptor(mockShardLeaderKit.getRef()));
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(firstServerChange, getRef());
            mockShardLeaderKit.expectMsgClass(firstForwardedServerChangeClass);
            shardManager.tell(secondServerChange, secondRequestKit.getRef());
            secondRequestKit.expectMsgClass(duration("5 seconds"), Failure.class);
        }
    };
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) MockClusterWrapper(org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString)

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