use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class DataTreeChangeListenerProxyTest method testLocalShardNotInitialized.
@Test(timeout = 10000)
public void testLocalShardNotInitialized() {
new TestKit(getSystem()) {
{
ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockListener, path);
new Thread(() -> proxy.init("shard-1")).start();
FiniteDuration timeout = duration("5 seconds");
FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
reply(new NotInitializedException("not initialized"));
within(duration("1 seconds"), () -> {
expectNoMsg();
return null;
});
proxy.close();
}
};
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class DataTreeChangeListenerProxyTest method testFailedRegistration.
@Test
public void testFailedRegistration() {
new TestKit(getSystem()) {
{
ActorSystem mockActorSystem = mock(ActorSystem.class);
ActorRef mockActor = getSystem().actorOf(Props.create(DoNothingActor.class), "testFailedRegistration");
doReturn(mockActor).when(mockActorSystem).actorOf(any(Props.class));
ExecutionContextExecutor executor = ExecutionContexts.fromExecutor(MoreExecutors.directExecutor());
ActorContext actorContext = mock(ActorContext.class);
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
doReturn(executor).when(actorContext).getClientDispatcher();
doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
doReturn(mockActorSystem).when(actorContext).getActorSystem();
String shardName = "shard-1";
final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockListener, path);
doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
doReturn(Futures.failed(new RuntimeException("mock"))).when(actorContext).executeOperationAsync(any(ActorRef.class), any(Object.class), any(Timeout.class));
doReturn(mock(DatastoreContext.class)).when(actorContext).getDatastoreContext();
proxy.init("shard-1");
Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor());
proxy.close();
}
};
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class DataTreeChangeListenerProxyTest method testLocalShardNotFound.
@Test(timeout = 10000)
public void testLocalShardNotFound() {
new TestKit(getSystem()) {
{
ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockListener, path);
new Thread(() -> proxy.init("shard-1")).start();
FiniteDuration timeout = duration("5 seconds");
FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
reply(new LocalShardNotFound("shard-1"));
expectNoMsg(duration("1 seconds"));
proxy.close();
}
};
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class DataTreeChangeListenerSupportTest method testInitialChangeListenerEventWithContainerPath.
@Test
public void testInitialChangeListenerEventWithContainerPath() throws DataValidationFailedException {
writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
Entry<MockDataTreeChangeListener, ActorSelection> entry = registerChangeListener(TEST_PATH, 1);
MockDataTreeChangeListener listener = entry.getKey();
listener.waitForChangeEvents();
listener.verifyNotifiedData(TEST_PATH);
listener.reset(1);
writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
listener.waitForChangeEvents();
listener.verifyNotifiedData(TEST_PATH);
listener.reset(1);
TestKit kit = new TestKit(getSystem());
entry.getValue().tell(CloseDataTreeNotificationListenerRegistration.getInstance(), kit.getRef());
kit.expectMsgClass(kit.duration("5 seconds"), CloseDataTreeNotificationListenerRegistrationReply.class);
writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
listener.verifyNoNotifiedData(TEST_PATH);
}
use of akka.testkit.javadsl.TestKit in project controller by opendaylight.
the class ShardSnapshotActorTest method testSerializeSnapshot.
private static void testSerializeSnapshot(final String testName, final ShardDataTreeSnapshot snapshot, final boolean withInstallSnapshot) throws Exception {
new TestKit(getSystem()) {
{
final ActorRef snapshotActor = getSystem().actorOf(ShardSnapshotActor.props(), testName);
watch(snapshotActor);
final NormalizedNode<?, ?> expectedRoot = snapshot.getRootNode().get();
ByteArrayOutputStream installSnapshotStream = withInstallSnapshot ? new ByteArrayOutputStream() : null;
ShardSnapshotActor.requestSnapshot(snapshotActor, snapshot, Optional.ofNullable(installSnapshotStream), getRef());
final CaptureSnapshotReply reply = expectMsgClass(duration("3 seconds"), CaptureSnapshotReply.class);
assertNotNull("getSnapshotState is null", reply.getSnapshotState());
assertEquals("SnapshotState type", ShardSnapshotState.class, reply.getSnapshotState().getClass());
assertEquals("Snapshot", snapshot, ((ShardSnapshotState) reply.getSnapshotState()).getSnapshot());
if (installSnapshotStream != null) {
final ShardDataTreeSnapshot deserialized;
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(installSnapshotStream.toByteArray()))) {
deserialized = ShardDataTreeSnapshot.deserialize(in);
}
assertEquals("Deserialized snapshot type", snapshot.getClass(), deserialized.getClass());
final Optional<NormalizedNode<?, ?>> maybeNode = deserialized.getRootNode();
assertEquals("isPresent", true, maybeNode.isPresent());
assertEquals("Root node", expectedRoot, maybeNode.get());
}
}
};
}
Aggregations