Search in sources :

Example 1 with ConflictingModificationAppliedException

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

the class ConcurrentTreeModificationTest method deleteWriteFooBar2ndLevelEmptyContainerTest.

@Test
public void deleteWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
    final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
    initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
    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(OUTER_LIST_2_PATH, BAR_NODE);
    modificationTree1.ready();
    modificationTree2.ready();
    inMemoryDataTree.validate(modificationTree1);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
    inMemoryDataTree.commit(prepare1);
    try {
        inMemoryDataTree.validate(modificationTree2);
        final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
        inMemoryDataTree.commit(prepare2);
        fail("Exception should have been thrown");
    } catch (final ConflictingModificationAppliedException e) {
        LOG.debug("Exception was thrown because path no longer exist in tree", e);
    }
    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 2 with ConflictingModificationAppliedException

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

the class ConcurrentTreeModificationTest method writeWriteFooBar1stLevelEmptyContainerTest.

@Test
public void writeWriteFooBar1stLevelEmptyContainerTest() 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.write(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 3 with ConflictingModificationAppliedException

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

the class ConcurrentTreeModificationTest method deleteMergeFooBar2ndLevelEmptyContainerTest.

@Test
public void deleteMergeFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
    final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
    initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
    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(OUTER_LIST_2_PATH, BAR_NODE);
    modificationTree1.ready();
    modificationTree2.ready();
    inMemoryDataTree.validate(modificationTree1);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
    inMemoryDataTree.commit(prepare1);
    try {
        inMemoryDataTree.validate(modificationTree2);
        final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
        inMemoryDataTree.commit(prepare2);
        fail("Exception should have been thrown");
    } catch (final ConflictingModificationAppliedException e) {
        LOG.debug("Exception was thrown because path no longer exist in tree", e);
    }
    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 4 with ConflictingModificationAppliedException

use of org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException 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 5 with ConflictingModificationAppliedException

use of org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException 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)

Aggregations

ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException)11 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)10 Test (org.junit.Test)9 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)9 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)2 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1 UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)1 DataValidationFailedException (org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException)1 ModifiedNodeDoesNotExistException (org.opendaylight.yangtools.yang.data.tree.api.ModifiedNodeDoesNotExistException)1 MutableTreeNode (org.opendaylight.yangtools.yang.data.tree.impl.node.MutableTreeNode)1 TreeNode (org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode)1