Search in sources :

Example 16 with DataTreeSnapshot

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project yangtools by opendaylight.

the class ConcurrentTreeModificationTest method mergeWriteFooBar1stLevelEmptyTreeTest.

@Test
public void mergeWriteFooBar1stLevelEmptyTreeTest() throws DataValidationFailedException {
    final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
    final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification();
    final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification();
    modificationTree1.merge(TestModel.TEST_PATH, createFooTestContainerNode());
    modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode());
    modificationTree1.ready();
    modificationTree2.ready();
    inMemoryDataTree.validate(modificationTree1);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
    inMemoryDataTree.commit(prepare1);
    try {
        inMemoryDataTree.validate(modificationTree2);
        fail("Exception should have been thrown.");
        final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
        inMemoryDataTree.commit(prepare2);
    } catch (final ConflictingModificationAppliedException ex) {
        LOG.debug("ConflictingModificationAppliedException - was thrown as expected", ex);
    }
    final DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
    assertFalse(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH).isPresent());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) ConflictingModificationAppliedException(org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) Test(org.junit.Test)

Example 17 with DataTreeSnapshot

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project yangtools by opendaylight.

the class ConcurrentTreeModificationTest method deleteWriteFooBar1stLevelEmptyContainerTest.

@Test
public void deleteWriteFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException {
    final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
    initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    initialDataTreeModification.ready();
    inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
    final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
    final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification();
    final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification();
    modificationTree1.delete(TestModel.TEST_PATH);
    modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode());
    modificationTree1.ready();
    modificationTree2.ready();
    inMemoryDataTree.validate(modificationTree1);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
    inMemoryDataTree.commit(prepare1);
    try {
        inMemoryDataTree.validate(modificationTree2);
        fail("Exception should have been thrown.");
        final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
        inMemoryDataTree.commit(prepare2);
    } catch (final ConflictingModificationAppliedException ex) {
        LOG.debug("ConflictingModificationAppliedException was thrown as expected", ex);
    }
    final DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    assertFalse(snapshotAfterCommits.readNode(TestModel.TEST_PATH).isPresent());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) ConflictingModificationAppliedException(org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) Test(org.junit.Test)

Example 18 with DataTreeSnapshot

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project yangtools by opendaylight.

the class ConcurrentTreeModificationTest method writeMergeFooBar1stLevelEmptyTreeTest.

@Test
public void writeMergeFooBar1stLevelEmptyTreeTest() throws DataValidationFailedException {
    final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
    final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification();
    final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification();
    modificationTree1.write(TestModel.TEST_PATH, createFooTestContainerNode());
    modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode());
    modificationTree1.ready();
    modificationTree2.ready();
    inMemoryDataTree.validate(modificationTree1);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
    inMemoryDataTree.commit(prepare1);
    inMemoryDataTree.validate(modificationTree2);
    final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
    inMemoryDataTree.commit(prepare2);
    final DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
    assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) Test(org.junit.Test)

Example 19 with DataTreeSnapshot

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project yangtools by opendaylight.

the class ConcurrentTreeModificationTest method deleteMergeFooBar1stLevelEmptyContainerTest.

@Test
public void deleteMergeFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException {
    final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
    initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    initialDataTreeModification.ready();
    inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
    final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
    final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification();
    final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification();
    modificationTree1.delete(TestModel.TEST_PATH);
    modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode());
    modificationTree1.ready();
    modificationTree2.ready();
    inMemoryDataTree.validate(modificationTree1);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
    inMemoryDataTree.commit(prepare1);
    inMemoryDataTree.validate(modificationTree2);
    final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
    inMemoryDataTree.commit(prepare2);
    final DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) Test(org.junit.Test)

Example 20 with DataTreeSnapshot

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project yangtools by opendaylight.

the class ListConstraintsValidation method prepare.

@Before
public void prepare() throws DataValidationFailedException {
    inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, schemaContext);
    final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
    final DataTreeModification modificationTree = initialDataTreeSnapshot.newModification();
    modificationTree.write(MASTER_CONTAINER_PATH, ImmutableNodes.containerNode(MASTER_CONTAINER_QNAME));
    modificationTree.ready();
    inMemoryDataTree.commit(inMemoryDataTree.prepare(modificationTree));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Before(org.junit.Before)

Aggregations

DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)41 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)36 Test (org.junit.Test)30 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)25 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)18 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)11 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)11 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException)9 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)4 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)2 QName (org.opendaylight.yangtools.yang.common.QName)2 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)2 NodeWithValue (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue)2 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)2 NormalizedNodeContainer (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer)2 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)2