use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testGetSnapshot.
@Test
public void testGetSnapshot() throws Exception {
LOG.info("testGetSnapshot starting");
TestKit kit = new TestKit(getSystem());
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("shard1", Arrays.asList("member-1")).put("shard2", Arrays.asList("member-1")).put("astronauts", Collections.<String>emptyList()).build());
TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newShardMgrProps(mockConfig).withDispatcher(Dispatchers.DefaultDispatcherId()));
shardManager.tell(GetSnapshot.INSTANCE, kit.getRef());
Failure failure = kit.expectMsgClass(Failure.class);
assertEquals("Failure cause type", IllegalStateException.class, failure.cause().getClass());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), ActorRef.noSender());
waitForShardInitialized(shardManager, "shard1", kit);
waitForShardInitialized(shardManager, "shard2", kit);
shardManager.tell(GetSnapshot.INSTANCE, kit.getRef());
DatastoreSnapshot datastoreSnapshot = expectMsgClassOrFailure(DatastoreSnapshot.class, kit, "GetSnapshot");
assertEquals("getType", shardMrgIDSuffix, datastoreSnapshot.getType());
assertNull("Expected null ShardManagerSnapshot", datastoreSnapshot.getShardManagerSnapshot());
Function<ShardSnapshot, String> shardNameTransformer = ShardSnapshot::getName;
assertEquals("Shard names", Sets.newHashSet("shard1", "shard2"), Sets.newHashSet(Lists.transform(datastoreSnapshot.getShardSnapshots(), shardNameTransformer)));
// Add a new replica
TestKit mockShardLeaderKit = new TestKit(getSystem());
TestShardManager shardManagerInstance = shardManager.underlyingActor();
shardManagerInstance.setMessageInterceptor(newFindPrimaryInterceptor(mockShardLeaderKit.getRef()));
shardManager.tell(new AddShardReplica("astronauts"), kit.getRef());
mockShardLeaderKit.expectMsgClass(AddServer.class);
mockShardLeaderKit.reply(new AddServerReply(ServerChangeStatus.OK, ""));
kit.expectMsgClass(Status.Success.class);
waitForShardInitialized(shardManager, "astronauts", kit);
// Send another GetSnapshot and verify
shardManager.tell(GetSnapshot.INSTANCE, kit.getRef());
datastoreSnapshot = expectMsgClassOrFailure(DatastoreSnapshot.class, kit, "GetSnapshot");
assertEquals("Shard names", Sets.newHashSet("shard1", "shard2", "astronauts"), Sets.newHashSet(Lists.transform(datastoreSnapshot.getShardSnapshots(), shardNameTransformer)));
ShardManagerSnapshot snapshot = datastoreSnapshot.getShardManagerSnapshot();
assertNotNull("Expected ShardManagerSnapshot", snapshot);
assertEquals("Shard names", Sets.newHashSet("shard1", "shard2", "astronauts"), Sets.newHashSet(snapshot.getShardList()));
LOG.info("testGetSnapshot ending");
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindPrimaryWaitForReadyWithCandidateShard.
@Test
public void testOnReceiveFindPrimaryWaitForReadyWithCandidateShard() throws Exception {
LOG.info("testOnReceiveFindPrimaryWaitForReadyWithCandidateShard 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.Candidate.name()), mockShardActor);
shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, true), getRef());
expectMsgClass(duration("2 seconds"), NoShardLeaderException.class);
}
};
LOG.info("testOnReceiveFindPrimaryWaitForReadyWithCandidateShard ending");
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testRestoreFromSnapshot.
@Test
public void testRestoreFromSnapshot() throws Exception {
LOG.info("testRestoreFromSnapshot starting");
datastoreContextBuilder.shardInitializationTimeout(3, TimeUnit.SECONDS);
TestKit kit = new TestKit(getSystem());
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("shard1", Collections.<String>emptyList()).put("shard2", Collections.<String>emptyList()).put("astronauts", Collections.<String>emptyList()).build());
ShardManagerSnapshot snapshot = new ShardManagerSnapshot(Arrays.asList("shard1", "shard2", "astronauts"), Collections.emptyMap());
DatastoreSnapshot restoreFromSnapshot = new DatastoreSnapshot(shardMrgIDSuffix, snapshot, Collections.<ShardSnapshot>emptyList());
TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newTestShardMgrBuilder(mockConfig).restoreFromSnapshot(restoreFromSnapshot).props().withDispatcher(Dispatchers.DefaultDispatcherId()));
shardManager.underlyingActor().waitForRecoveryComplete();
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), ActorRef.noSender());
waitForShardInitialized(shardManager, "shard1", kit);
waitForShardInitialized(shardManager, "shard2", kit);
waitForShardInitialized(shardManager, "astronauts", kit);
shardManager.tell(GetSnapshot.INSTANCE, kit.getRef());
DatastoreSnapshot datastoreSnapshot = expectMsgClassOrFailure(DatastoreSnapshot.class, kit, "GetSnapshot");
assertEquals("getType", shardMrgIDSuffix, datastoreSnapshot.getType());
assertNotNull("Expected ShardManagerSnapshot", datastoreSnapshot.getShardManagerSnapshot());
assertEquals("Shard names", Sets.newHashSet("shard1", "shard2", "astronauts"), Sets.newHashSet(datastoreSnapshot.getShardManagerSnapshot().getShardList()));
LOG.info("testRestoreFromSnapshot ending");
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindPrimaryForRemoteShard.
@Test
public void testOnReceiveFindPrimaryForRemoteShard() throws Exception {
LOG.info("testOnReceiveFindPrimaryForRemoteShard starting");
String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
// Create an ActorSystem ShardManager actor for member-1.
final ActorSystem system1 = newActorSystem("Member1");
Cluster.get(system1).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
final TestActorRef<TestShardManager> shardManager1 = TestActorRef.create(system1, newTestShardMgrBuilderWithMockShardActor().cluster(new ClusterWrapperImpl(system1)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
// Create an ActorSystem ShardManager actor for member-2.
final ActorSystem system2 = newActorSystem("Member2");
Cluster.get(system2).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
final ActorRef mockShardActor2 = newMockShardActor(system2, "astronauts", "member-2");
MockConfiguration mockConfig2 = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-2")).build());
final TestActorRef<TestShardManager> shardManager2 = TestActorRef.create(system2, newTestShardMgrBuilder(mockConfig2).shardActor(mockShardActor2).cluster(new ClusterWrapperImpl(system2)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
new TestKit(system1) {
{
shardManager1.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager2.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager2.tell(new ActorInitialized(), mockShardActor2);
String memberId2 = "member-2-shard-astronauts-" + shardMrgIDSuffix;
short leaderVersion = DataStoreVersions.CURRENT_VERSION - 1;
shardManager2.tell(new ShardLeaderStateChanged(memberId2, memberId2, mock(DataTree.class), leaderVersion), mockShardActor2);
shardManager2.tell(new RoleChangeNotification(memberId2, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor2);
shardManager1.underlyingActor().waitForMemberUp();
shardManager1.tell(new FindPrimary("astronauts", false), getRef());
RemotePrimaryShardFound found = expectMsgClass(duration("5 seconds"), RemotePrimaryShardFound.class);
String path = found.getPrimaryPath();
assertTrue("Unexpected primary path " + path, path.contains("member-2-shard-astronauts-config"));
assertEquals("getPrimaryVersion", leaderVersion, found.getPrimaryVersion());
shardManager2.underlyingActor().verifyFindPrimary();
// This part times out quite a bit on jenkins for some reason
// Cluster.get(system2).down(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
//
// shardManager1.underlyingActor().waitForMemberRemoved();
//
// shardManager1.tell(new FindPrimary("astronauts", false), getRef());
//
// expectMsgClass(duration("5 seconds"), PrimaryNotFoundException.class);
}
};
LOG.info("testOnReceiveFindPrimaryForRemoteShard ending");
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindPrimaryWaitForShardLeader.
@Test
public void testOnReceiveFindPrimaryWaitForShardLeader() throws Exception {
LOG.info("testOnReceiveFindPrimaryWaitForShardLeader starting");
datastoreContextBuilder.shardInitializationTimeout(10, TimeUnit.SECONDS);
new TestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
// We're passing waitUntilInitialized = true to FindPrimary so
// the response should be
// delayed until we send ActorInitialized and
// RoleChangeNotification.
shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, true), getRef());
expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
shardManager.tell(new ActorInitialized(), mockShardActor);
expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor);
expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
DataTree mockDataTree = mock(DataTree.class);
shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mockDataTree, DataStoreVersions.CURRENT_VERSION), mockShardActor);
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());
expectNoMsg(FiniteDuration.create(200, TimeUnit.MILLISECONDS));
}
};
LOG.info("testOnReceiveFindPrimaryWaitForShardLeader ending");
}
Aggregations