use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project mdsal by opendaylight.
the class SnapshotBackedReadTransaction method read.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public FluentFuture<Optional<NormalizedNode>> read(final YangInstanceIdentifier path) {
LOG.debug("Tx: {} Read: {}", getIdentifier(), path);
requireNonNull(path, "Path must not be null.");
final DataTreeSnapshot snapshot = stableSnapshot;
if (snapshot == null) {
return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Transaction is closed"));
}
try {
return FluentFutures.immediateFluentFuture(snapshot.readNode(path));
} catch (Exception e) {
LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e);
return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Read failed", e));
}
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project mdsal by opendaylight.
the class SnapshotBackedReadTransaction method close.
@Override
public void close() {
final DataTreeSnapshot prev = SNAPSHOT_UPDATER.getAndSet(this, null);
if (prev == null) {
LOG.debug("Store transaction: {} : previously closed", getIdentifier());
return;
}
LOG.debug("Store transaction: {} : Closed", getIdentifier());
if (closeImpl != null) {
closeImpl.transactionClosed(this);
closeImpl = null;
}
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project mdsal by opendaylight.
the class SnapshotBackedReadTransactionTest method basicTest.
@Test
public void basicTest() throws Exception {
final NormalizedNode testNode = mock(NormalizedNode.class);
final Optional<NormalizedNode> optional = Optional.of(testNode);
doReturn("testNode").when(testNode).toString();
doReturn(Optional.of(testNode)).when(DATA_TREE_SNAPSHOT).readNode(YangInstanceIdentifier.empty());
assertTrue(snapshotBackedReadTransaction.exists(YangInstanceIdentifier.empty()).get());
assertEquals(optional, snapshotBackedReadTransaction.read(YangInstanceIdentifier.empty()).get());
final Field stableSnapshotField = SnapshotBackedReadTransaction.class.getDeclaredField("stableSnapshot");
stableSnapshotField.setAccessible(true);
DataTreeSnapshot stableSnapshot = (DataTreeSnapshot) stableSnapshotField.get(snapshotBackedReadTransaction);
assertNotNull(stableSnapshot);
snapshotBackedReadTransaction.close();
stableSnapshot = (DataTreeSnapshot) stableSnapshotField.get(snapshotBackedReadTransaction);
assertNull(stableSnapshot);
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project mdsal by opendaylight.
the class InMemoryDataStoreTest method testReadWithReadOnlyTransactionFailure.
@SuppressWarnings("checkstyle:IllegalThrows")
@Test(expected = ReadFailedException.class)
public void testReadWithReadOnlyTransactionFailure() throws Throwable {
DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class);
Mockito.doThrow(new RuntimeException("mock ex")).when(mockSnapshot).readNode(Mockito.any(YangInstanceIdentifier.class));
DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadTransaction("1", true, mockSnapshot);
doReadAndThrowEx(readTx);
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project yangtools by opendaylight.
the class Bug4454Test method minMaxLeafListPass.
@Test
public void minMaxLeafListPass() throws DataValidationFailedException {
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
final NodeWithValue<?> barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar");
final NodeWithValue<?> gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo");
final LeafSetEntryNode<Object> barLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(barPath).withValue("bar").build();
final LeafSetEntryNode<Object> gooLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(gooPath).withValue("goo").build();
final LeafSetNode<Object> fooLeafSetNode = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME)).withChildValue("foo").build();
modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode);
modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare1);
DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
DataTreeModification tempMod1 = test1.newModification();
tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry);
tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
tempMod1.ready();
inMemoryDataTree.validate(tempMod1);
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
inMemoryDataTree.commit(prepare2);
final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
final Optional<NormalizedNode> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
assertTrue(masterContainer.isPresent());
final Optional<NormalizedNodeContainer<?>> leafList = ((DistinctNodeContainer) masterContainer.get()).findChildByArg(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
assertTrue(leafList.isPresent());
assertEquals(3, leafList.get().size());
}
Aggregations