use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class TransactionProxyTest method testWriteAfterAsyncRead.
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testWriteAfterAsyncRead() throws Exception {
ActorRef actorRef = setupActorContextWithoutInitialCreateTransaction(getSystem(), DefaultShardStrategy.DEFAULT_SHARD);
Promise<Object> createTxPromise = akka.dispatch.Futures.promise();
doReturn(createTxPromise).when(mockActorContext).executeOperationAsync(eq(getSystem().actorSelection(actorRef.path())), eqCreateTransaction(memberName, READ_WRITE), any(Timeout.class));
doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));
expectBatchedModificationsReady(actorRef);
final NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
final TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
final CountDownLatch readComplete = new CountDownLatch(1);
final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
com.google.common.util.concurrent.Futures.addCallback(transactionProxy.read(TestModel.TEST_PATH), new FutureCallback<Optional<NormalizedNode<?, ?>>>() {
@Override
public void onSuccess(final Optional<NormalizedNode<?, ?>> result) {
try {
transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
} catch (Exception e) {
caughtEx.set(e);
} finally {
readComplete.countDown();
}
}
@Override
public void onFailure(final Throwable failure) {
caughtEx.set(failure);
readComplete.countDown();
}
}, MoreExecutors.directExecutor());
createTxPromise.success(createTransactionReply(actorRef, DataStoreVersions.CURRENT_VERSION));
Uninterruptibles.awaitUninterruptibly(readComplete, 5, TimeUnit.SECONDS);
final Throwable t = caughtEx.get();
if (t != null) {
Throwables.propagateIfPossible(t, Exception.class);
throw new RuntimeException(t);
}
// This sends the batched modification.
transactionProxy.ready();
verifyOneBatchedModification(actorRef, new WriteModification(TestModel.TEST_PATH, nodeToWrite), true);
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode 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());
}
}
};
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class LocalTransactionContextTest method testRead.
@Test
public void testRead() {
YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
doReturn(Futures.immediateCheckedFuture(Optional.of(normalizedNode))).when(readWriteTransaction).read(yangInstanceIdentifier);
localTransactionContext.executeRead(new ReadData(yangInstanceIdentifier, DataStoreVersions.CURRENT_VERSION), SettableFuture.<Optional<NormalizedNode<?, ?>>>create());
verify(readWriteTransaction).read(yangInstanceIdentifier);
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class NormalizedNodePrunerTest method countNodes.
private static int countNodes(final NormalizedNode<?, ?> normalizedNode, final String namespaceFilter) {
if (normalizedNode == null) {
return 0;
}
final AtomicInteger count = new AtomicInteger();
new NormalizedNodeNavigator((level, parentPath, normalizedNode1) -> {
if (!(normalizedNode1.getIdentifier() instanceof AugmentationIdentifier)) {
if (normalizedNode1.getIdentifier().getNodeType().getNamespace().toString().contains(namespaceFilter)) {
count.incrementAndGet();
}
}
}).navigate(YangInstanceIdentifier.EMPTY.toString(), normalizedNode);
return count.get();
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class InMemoryDOMStoreTreeChangePublisher method registerTreeChangeListener.
<L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerTreeChangeListener(final YangInstanceIdentifier treeId, final L listener, final DataTreeSnapshot snapshot) {
final AbstractDOMDataTreeChangeListenerRegistration<L> reg = registerTreeChangeListener(treeId, listener);
final Optional<NormalizedNode<?, ?>> node = snapshot.readNode(YangInstanceIdentifier.EMPTY);
if (node.isPresent()) {
final DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode(YangInstanceIdentifier.EMPTY, node.get());
InMemoryDOMStoreTreeChangePublisher publisher = new InMemoryDOMStoreTreeChangePublisher(notificationManager);
publisher.registerTreeChangeListener(treeId, listener);
publisher.publishChange(candidate);
}
return reg;
}
Aggregations