use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot in project controller by opendaylight.
the class ShardDataTreeTransactionChain method newReadWriteTransaction.
ReadWriteShardDataTreeTransaction newReadWriteTransaction(final TransactionIdentifier txId) {
final DataTreeSnapshot snapshot = getSnapshot();
LOG.debug("Allocated read-write transaction {} snapshot {}", txId, snapshot);
openTransaction = new ReadWriteShardDataTreeTransaction(this, txId, snapshot.newModification());
return openTransaction;
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot in project controller by opendaylight.
the class ShardDataTreeTransactionChain method newReadOnlyTransaction.
ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final TransactionIdentifier txId) {
final DataTreeSnapshot snapshot = getSnapshot();
LOG.debug("Allocated read-only transaction {} snapshot {}", txId, snapshot);
return new ReadOnlyShardDataTreeTransaction(this, txId, snapshot);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot in project controller by opendaylight.
the class AbstractDataStoreClientBehaviorTest method testGetConnection.
@Test
public void testGetConnection() throws Exception {
// set up data tree mock
final CursorAwareDataTreeModification modification = mock(CursorAwareDataTreeModification.class);
when(modification.readNode(YangInstanceIdentifier.EMPTY)).thenReturn(Optional.empty());
final DataTreeSnapshot snapshot = mock(DataTreeSnapshot.class);
when(snapshot.newModification()).thenReturn(modification);
final DataTree dataTree = mock(DataTree.class);
when(dataTree.takeSnapshot()).thenReturn(snapshot);
final TestProbe backendProbe = new TestProbe(system, "backend");
final long shard = 0L;
behavior.createTransaction().read(YangInstanceIdentifier.EMPTY);
final AbstractClientConnection<ShardBackendInfo> connection = behavior.getConnection(shard);
// check cached connection for same shard
Assert.assertSame(connection, behavior.getConnection(shard));
final ConnectClientRequest connectClientRequest = actorContextProbe.expectMsgClass(ConnectClientRequest.class);
Assert.assertEquals(CLIENT_ID, connectClientRequest.getTarget());
final long sequence = 0L;
Assert.assertEquals(sequence, connectClientRequest.getSequence());
actorContextProbe.reply(new ConnectClientSuccess(CLIENT_ID, sequence, backendProbe.ref(), Collections.emptyList(), dataTree, 3));
Assert.assertEquals(clientActorProbe.ref(), connection.localActor());
// capture and execute command passed to client context
final InternalCommand<ShardBackendInfo> command = clientActorProbe.expectMsgClass(InternalCommand.class);
command.execute(behavior);
// check, whether command was reaplayed
verify(modification).readNode(YangInstanceIdentifier.EMPTY);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot in project controller by opendaylight.
the class SnapshotBackedReadTransaction method read.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
LOG.debug("Tx: {} Read: {}", getIdentifier(), path);
checkNotNull(path, "Path must not be null.");
final DataTreeSnapshot snapshot = stableSnapshot;
if (snapshot == null) {
return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed"));
}
try {
return Futures.immediateCheckedFuture(Optional.fromJavaUtil(snapshot.readNode(path)));
} catch (RuntimeException e) {
LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e);
return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed", e));
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot in project controller by opendaylight.
the class ShardDataTreeTest method getCars.
private static NormalizedNode<?, ?> getCars(final ShardDataTree shardDataTree) {
final ReadOnlyShardDataTreeTransaction readOnlyShardDataTreeTransaction = shardDataTree.newReadOnlyTransaction(nextTransactionId());
final DataTreeSnapshot snapshot1 = readOnlyShardDataTreeTransaction.getSnapshot();
final Optional<NormalizedNode<?, ?>> optional = snapshot1.readNode(CarsModel.BASE_PATH);
assertEquals(true, optional.isPresent());
return optional.get();
}
Aggregations