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);
}
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);
}
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);
}
};
}
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");
}
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);
}
};
}
Aggregations