Search in sources :

Example 6 with DOMStoreWriteTransaction

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction in project controller by opendaylight.

the class InMemoryDataStoreTest method testMerge.

@Test
public void testMerge() throws Exception {
    DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
    assertNotNull(writeTx);
    ContainerNode containerNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).addChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build()).build();
    writeTx.merge(TestModel.TEST_PATH, containerNode);
    assertThreePhaseCommit(writeTx.ready());
    Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
    assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
    assertEquals("After commit read: data", containerNode, afterCommitRead.get());
    // Merge a new list entry node
    writeTx = domStore.newWriteOnlyTransaction();
    assertNotNull(writeTx);
    containerNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).addChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2)).build()).build();
    writeTx.merge(TestModel.TEST_PATH, containerNode);
    assertThreePhaseCommit(writeTx.ready());
    afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
    assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
    assertEquals("After commit read: data", containerNode, afterCommitRead.get());
}
Also used : DOMStoreWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 7 with DOMStoreWriteTransaction

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction in project controller by opendaylight.

the class InMemoryDataStoreTest method testDelete.

@Test
public void testDelete() throws Exception {
    DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
    assertNotNull(writeTx);
    // Write /test and commit
    writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    assertThreePhaseCommit(writeTx.ready());
    Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
    assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
    // Delete /test and verify
    writeTx = domStore.newWriteOnlyTransaction();
    writeTx.delete(TestModel.TEST_PATH);
    assertThreePhaseCommit(writeTx.ready());
    afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
    assertEquals("After commit read: isPresent", false, afterCommitRead.isPresent());
}
Also used : DOMStoreWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

DOMStoreWriteTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction)7 Test (org.junit.Test)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 DOMStoreThreePhaseCommitCohort (org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)2 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)2 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1 DOMStoreReadWriteTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1