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());
}
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());
}
Aggregations