use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testChangeServersVotingStatusWithNoLeader.
@Test
public void testChangeServersVotingStatusWithNoLeader() throws Exception {
new TestKit(getSystem()) {
{
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
ActorRef respondActor = actorFactory.createActor(Props.create(MockRespondActor.class, ChangeServersVotingStatus.class, new ServerChangeReply(ServerChangeStatus.NO_LEADER, null)), memberId);
ActorRef shardManager = getSystem().actorOf(newPropsShardMgrWithMockShardActor(respondActor));
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), respondActor);
shardManager.tell(new RoleChangeNotification(memberId, null, RaftState.Follower.name()), respondActor);
shardManager.tell(new ChangeShardMembersVotingStatus("default", ImmutableMap.of("member-2", Boolean.TRUE)), getRef());
MessageCollectorActor.expectFirstMatching(respondActor, ChangeServersVotingStatus.class);
Status.Failure resp = expectMsgClass(duration("5 seconds"), Status.Failure.class);
assertEquals("Failure resposnse", true, resp.cause() instanceof NoShardLeaderException);
}
};
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testOnCreateShard.
@Test
public void testOnCreateShard() {
LOG.info("testOnCreateShard starting");
new TestKit(getSystem()) {
{
datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
SchemaContext schemaContext = TestModel.createTestContext();
shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
DatastoreContext datastoreContext = DatastoreContext.newBuilder().shardElectionTimeoutFactor(100).persistent(false).build();
Shard.Builder shardBuilder = Shard.builder();
ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module", "foo", null, members("member-1", "member-5", "member-6"));
shardManager.tell(new CreateShard(config, shardBuilder, datastoreContext), getRef());
expectMsgClass(duration("5 seconds"), Success.class);
shardManager.tell(new FindLocalShard("foo", true), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
assertEquals("isRecoveryApplicable", false, shardBuilder.getDatastoreContext().isPersistent());
assertTrue("Epxected ShardPeerAddressResolver", shardBuilder.getDatastoreContext().getShardRaftConfig().getPeerAddressResolver() instanceof ShardPeerAddressResolver);
assertEquals("peerMembers", Sets.newHashSet(ShardIdentifier.create("foo", MemberName.forName("member-5"), shardMrgIDSuffix).toString(), ShardIdentifier.create("foo", MemberName.forName("member-6"), shardMrgIDSuffix).toString()), shardBuilder.getPeerAddresses().keySet());
assertEquals("ShardIdentifier", ShardIdentifier.create("foo", MEMBER_1, shardMrgIDSuffix), shardBuilder.getId());
assertSame("schemaContext", schemaContext, shardBuilder.getSchemaContext());
// Send CreateShard with same name - should return Success with
// a message.
shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
Success success = expectMsgClass(duration("5 seconds"), Success.class);
assertNotNull("Success status is null", success.status());
}
};
LOG.info("testOnCreateShard ending");
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardManagerTest method testShutDown.
@Test
public void testShutDown() throws Exception {
LOG.info("testShutDown starting");
new TestKit(getSystem()) {
{
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("shard1", Arrays.asList("member-1")).put("shard2", Arrays.asList("member-1")).build());
String shardId1 = ShardIdentifier.create("shard1", MEMBER_1, shardMrgIDSuffix).toString();
ActorRef shard1 = actorFactory.createActor(MessageCollectorActor.props(), shardId1);
String shardId2 = ShardIdentifier.create("shard2", MEMBER_1, shardMrgIDSuffix).toString();
ActorRef shard2 = actorFactory.createActor(MessageCollectorActor.props(), shardId2);
ActorRef shardManager = actorFactory.createActor(newTestShardMgrBuilder(mockConfig).addShardActor("shard1", shard1).addShardActor("shard2", shard2).props());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), shard1);
shardManager.tell(new ActorInitialized(), shard2);
FiniteDuration duration = FiniteDuration.create(5, TimeUnit.SECONDS);
Future<Boolean> stopFuture = Patterns.gracefulStop(shardManager, duration, Shutdown.INSTANCE);
MessageCollectorActor.expectFirstMatching(shard1, Shutdown.class);
MessageCollectorActor.expectFirstMatching(shard2, Shutdown.class);
try {
Await.ready(stopFuture, FiniteDuration.create(500, TimeUnit.MILLISECONDS));
fail("ShardManager actor stopped without waiting for the Shards to be stopped");
} catch (TimeoutException e) {
// expected
}
actorFactory.killActor(shard1, this);
actorFactory.killActor(shard2, this);
Boolean stopped = Await.result(stopFuture, duration);
assertEquals("Stopped", Boolean.TRUE, stopped);
}
};
LOG.info("testShutDown ending");
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ActorContextTest method testExecuteRemoteOperation.
@Test
public void testExecuteRemoteOperation() {
new TestKit(getSystem()) {
{
ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class));
ActorRef shardManagerActorRef = getSystem().actorOf(MockShardManager.props(true, shardActorRef));
ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef, mock(ClusterWrapper.class), mock(Configuration.class));
ActorSelection actor = actorContext.actorSelection(shardActorRef.path());
Object out = actorContext.executeOperation(actor, "hello");
assertEquals("hello", out);
}
};
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveBatchedModifications.
@Test
public void testOnReceiveBatchedModifications() throws Exception {
new TestKit(getSystem()) {
{
ShardDataTreeTransactionParent parent = Mockito.mock(ShardDataTreeTransactionParent.class);
DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
ReadWriteShardDataTreeTransaction mockWriteTx = new ReadWriteShardDataTreeTransaction(parent, nextTransactionId(), mockModification);
final ActorRef transaction = newTransactionActor(RW, mockWriteTx, "testOnReceiveBatchedModifications");
YangInstanceIdentifier writePath = TestModel.TEST_PATH;
NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
YangInstanceIdentifier mergePath = TestModel.OUTER_LIST_PATH;
NormalizedNode<?, ?> mergeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
YangInstanceIdentifier deletePath = TestModel.TEST_PATH;
BatchedModifications batched = new BatchedModifications(nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
batched.addModification(new WriteModification(writePath, writeData));
batched.addModification(new MergeModification(mergePath, mergeData));
batched.addModification(new DeleteModification(deletePath));
transaction.tell(batched, getRef());
BatchedModificationsReply reply = expectMsgClass(duration("5 seconds"), BatchedModificationsReply.class);
assertEquals("getNumBatched", 3, reply.getNumBatched());
InOrder inOrder = Mockito.inOrder(mockModification);
inOrder.verify(mockModification).write(writePath, writeData);
inOrder.verify(mockModification).merge(mergePath, mergeData);
inOrder.verify(mockModification).delete(deletePath);
}
};
}
Aggregations