use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testAddShardReplicaWithFindPrimaryTimeout.
@Test
public void testAddShardReplicaWithFindPrimaryTimeout() throws Exception {
LOG.info("testAddShardReplicaWithFindPrimaryTimeout starting");
datastoreContextBuilder.shardInitializationTimeout(100, TimeUnit.MILLISECONDS);
new TestKit(getSystem()) {
{
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("astronauts", Arrays.asList("member-2")).build());
final ActorRef newReplicaShardManager = actorFactory.createActor(newTestShardMgrBuilder(mockConfig).shardActor(mockShardActor).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardMgrID);
newReplicaShardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
MockClusterWrapper.sendMemberUp(newReplicaShardManager, "member-2", AddressFromURIString.parse("akka://non-existent@127.0.0.1:5").toString());
newReplicaShardManager.tell(new AddShardReplica("astronauts"), getRef());
Status.Failure resp = expectMsgClass(duration("5 seconds"), Status.Failure.class);
assertEquals("Failure obtained", true, resp.cause() instanceof RuntimeException);
}
};
LOG.info("testAddShardReplicaWithFindPrimaryTimeout ending");
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindPrimaryForLocalLeaderShard.
@Test
public void testOnReceiveFindPrimaryForLocalLeaderShard() throws Exception {
LOG.info("testOnReceiveFindPrimaryForLocalLeaderShard starting");
new TestKit(getSystem()) {
{
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
DataTree mockDataTree = mock(DataTree.class);
shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mockDataTree, DataStoreVersions.CURRENT_VERSION), getRef());
MessageCollectorActor.expectFirstMatching(mockShardActor, RegisterRoleChangeListener.class);
shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor);
shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, false), getRef());
LocalPrimaryShardFound primaryFound = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
assertTrue("Unexpected primary path " + primaryFound.getPrimaryPath(), primaryFound.getPrimaryPath().contains("member-1-shard-default"));
assertSame("getLocalShardDataTree", mockDataTree, primaryFound.getLocalShardDataTree());
}
};
LOG.info("testOnReceiveFindPrimaryForLocalLeaderShard ending");
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindPrimaryForNonLocalLeaderShard.
@Test
public void testOnReceiveFindPrimaryForNonLocalLeaderShard() throws Exception {
LOG.info("testOnReceiveFindPrimaryForNonLocalLeaderShard starting");
new TestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
String memberId2 = "member-2-shard-default-" + shardMrgIDSuffix;
MockClusterWrapper.sendMemberUp(shardManager, "member-2", getRef().path().toString());
String memberId1 = "member-1-shard-default-" + shardMrgIDSuffix;
shardManager.tell(new RoleChangeNotification(memberId1, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor);
short leaderVersion = DataStoreVersions.CURRENT_VERSION - 1;
shardManager.tell(new ShardLeaderStateChanged(memberId1, memberId2, leaderVersion), mockShardActor);
shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, false), getRef());
RemotePrimaryShardFound primaryFound = expectMsgClass(duration("5 seconds"), RemotePrimaryShardFound.class);
assertTrue("Unexpected primary path " + primaryFound.getPrimaryPath(), primaryFound.getPrimaryPath().contains("member-2-shard-default"));
assertEquals("getPrimaryVersion", leaderVersion, primaryFound.getPrimaryVersion());
}
};
LOG.info("testOnReceiveFindPrimaryForNonLocalLeaderShard ending");
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindPrimaryWaitForReadyWithUninitializedShard.
@Test
public void testOnReceiveFindPrimaryWaitForReadyWithUninitializedShard() throws Exception {
LOG.info("testOnReceiveFindPrimaryWaitForReadyWithUninitializedShard starting");
new TestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, true), getRef());
expectMsgClass(duration("2 seconds"), NotInitializedException.class);
shardManager.tell(new ActorInitialized(), mockShardActor);
expectNoMsg(FiniteDuration.create(200, TimeUnit.MILLISECONDS));
}
};
LOG.info("testOnReceiveFindPrimaryWaitForReadyWithUninitializedShard ending");
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testRemoveShardReplicaForNonExistentShard.
@Test
public void testRemoveShardReplicaForNonExistentShard() throws Exception {
new TestKit(getSystem()) {
{
ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
shardManager.tell(new RemoveShardReplica("model-inventory", MEMBER_1), getRef());
Status.Failure resp = expectMsgClass(duration("10 seconds"), Status.Failure.class);
assertEquals("Failure obtained", true, resp.cause() instanceof PrimaryNotFoundException);
}
};
}
Aggregations