X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-inmemory-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2FInMemoryDataStoreTest.java;h=72e06d63a81b32dde1bf5592d9076449d6faf9b3;hp=369a7da138731dd6149d4b426096af7cc2a553dc;hb=c5f3be93482d6b06d95ebf22b2ef2723fd813f89;hpb=b1e455ac4685602b7b3290192906c607d2c92c71 diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java index 369a7da138..72e06d63a8 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java @@ -1,248 +1,480 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.md.sal.dom.store.impl; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; +import java.util.concurrent.ExecutionException; +import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.mockito.Mockito; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain; +import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; +import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedTransactions; +import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction.TransactionReadyPrototype; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import java.util.concurrent.ExecutionException; +public class InMemoryDataStoreTest { -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; + private SchemaContext schemaContext; + private InMemoryDOMDataStore domStore; + @Before + public void setupStore() { + domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.newDirectExecutorService()); + schemaContext = TestModel.createTestContext(); + domStore.onGlobalContextUpdated(schemaContext); + } -public class InMemoryDataStoreTest { + @Test + public void testTransactionIsolation() throws InterruptedException, ExecutionException { - private SchemaContext schemaContext; - private InMemoryDOMDataStore domStore; + assertNotNull(domStore); - @Before - public void setupStore() { - domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.sameThreadExecutor()); - schemaContext = TestModel.createTestContext(); - domStore.onGlobalContextUpdated(schemaContext); + DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction(); + assertNotNull(readTx); - } + DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); + assertNotNull(writeTx); - @Test - public void testTransactionIsolation() throws InterruptedException, ExecutionException { + /* + * Writes /test in writeTx + */ + NormalizedNode testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + writeTx.write(TestModel.TEST_PATH, testNode); - assertNotNull(domStore); + /* + * Reads /test from writeTx Read should return container. + */ + ListenableFuture>> writeTxContainer = writeTx.read(TestModel.TEST_PATH); + assertEquals("read: isPresent", true, writeTxContainer.get().isPresent()); + assertEquals("read: data", testNode, writeTxContainer.get().get()); - DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction(); - assertNotNull(readTx); + /* + * Reads /test from readTx Read should return Absent. + */ + ListenableFuture>> readTxContainer = readTx.read(TestModel.TEST_PATH); + assertEquals("read: isPresent", false, readTxContainer.get().isPresent()); + } - DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); - assertNotNull(writeTx); - /** - * - * Writes /test in writeTx - * - */ - writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); + @Test + public void testTransactionCommit() throws InterruptedException, ExecutionException { - /** - * - * Reads /test from writeTx Read should return container. - * - */ - ListenableFuture>> writeTxContainer = writeTx.read(TestModel.TEST_PATH); - assertTrue(writeTxContainer.get().isPresent()); + DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); + assertNotNull(writeTx); - /** - * - * Reads /test from readTx Read should return Absent. - * - */ - ListenableFuture>> readTxContainer = readTx.read(TestModel.TEST_PATH); - assertFalse(readTxContainer.get().isPresent()); - } + /* + * Writes /test in writeTx + */ + NormalizedNode testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + writeTx.write(TestModel.TEST_PATH, testNode); - @Test - public void testTransactionCommit() throws InterruptedException, ExecutionException { + /* + * Reads /test from writeTx Read should return container. + */ + ListenableFuture>> writeTxContainer = writeTx.read(TestModel.TEST_PATH); + assertEquals("read: isPresent", true, writeTxContainer.get().isPresent()); + assertEquals("read: data", testNode, writeTxContainer.get().get()); - DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); - assertNotNull(writeTx); - /** - * - * Writes /test in writeTx - * - */ - writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); + DOMStoreThreePhaseCommitCohort cohort = writeTx.ready(); - /** - * - * Reads /test from writeTx Read should return container. - * - */ - ListenableFuture>> writeTxContainer = writeTx.read(TestModel.TEST_PATH); - assertTrue(writeTxContainer.get().isPresent()); + assertThreePhaseCommit(cohort); - DOMStoreThreePhaseCommitCohort cohort = writeTx.ready(); + Optional> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH) + .get(); + assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent()); + assertEquals("After commit read: data", testNode, afterCommitRead.get()); + } - assertThreePhaseCommit(cohort); + @Test + public void testDelete() throws Exception { - Optional> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH) - .get(); - assertTrue(afterCommitRead.isPresent()); - } + DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction(); + assertNotNull(writeTx); - @Test - public void testTransactionAbort() throws InterruptedException, ExecutionException { + // Write /test and commit - DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); - assertNotNull(writeTx); + writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - assertTestContainerWrite(writeTx); + assertThreePhaseCommit(writeTx.ready()); - DOMStoreThreePhaseCommitCohort cohort = writeTx.ready(); + Optional> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH) + .get(); + assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent()); - assertTrue(cohort.canCommit().get().booleanValue()); - cohort.preCommit().get(); - cohort.abort().get(); + // Delete /test and verify - Optional> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH) - .get(); - assertFalse(afterCommitRead.isPresent()); - } + writeTx = domStore.newWriteOnlyTransaction(); - @Test - public void testTransactionChain() throws InterruptedException, ExecutionException { - DOMStoreTransactionChain txChain = domStore.createTransactionChain(); - assertNotNull(txChain); + writeTx.delete(TestModel.TEST_PATH); - /** - * We alocate new read-write transaction and write /test - * - * - */ - DOMStoreReadWriteTransaction firstTx = txChain.newReadWriteTransaction(); - assertTestContainerWrite(firstTx); + assertThreePhaseCommit(writeTx.ready()); - /** - * First transaction is marked as ready, we are able to allocate chained - * transactions - */ - DOMStoreThreePhaseCommitCohort firstWriteTxCohort = firstTx.ready(); + afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get(); + assertEquals("After commit read: isPresent", false, afterCommitRead.isPresent()); + } - /** - * We alocate chained transaction - read transaction, note first one is - * still not commited to datastore. - */ - DOMStoreReadTransaction secondReadTx = txChain.newReadOnlyTransaction(); + @Test + public void testMerge() throws Exception { - /** - * - * We test if we are able to read data from tx, read should not fail - * since we are using chained transaction. - * - * - */ - assertTestContainerExists(secondReadTx); + DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction(); + assertNotNull(writeTx); - /** - * - * We alocate next transaction, which is still based on first one, but - * is read-write. - * - */ - DOMStoreReadWriteTransaction thirdDeleteTx = txChain.newReadWriteTransaction(); + 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(); - /** - * We test existence of /test in third transaction container should - * still be visible from first one (which is still uncommmited). - * - * - */ - assertTestContainerExists(thirdDeleteTx); + writeTx.merge(TestModel.TEST_PATH, containerNode); - /** - * We delete node in third transaction - */ - thirdDeleteTx.delete(TestModel.TEST_PATH); + assertThreePhaseCommit(writeTx.ready()); - /** - * third transaction is sealed. - */ - DOMStoreThreePhaseCommitCohort thirdDeleteTxCohort = thirdDeleteTx.ready(); + Optional> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH) + .get(); + assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent()); + assertEquals("After commit read: data", containerNode, afterCommitRead.get()); - /** - * We commit first transaction - * - */ - assertThreePhaseCommit(firstWriteTxCohort); + // Merge a new list entry node - // Alocates store transacion - DOMStoreReadTransaction storeReadTx = domStore.newReadOnlyTransaction(); - /** - * We verify transaction is commited to store, container should exists - * in datastore. - */ - assertTestContainerExists(storeReadTx); - /** - * We commit third transaction - * - */ - assertThreePhaseCommit(thirdDeleteTxCohort); - } + writeTx = domStore.newWriteOnlyTransaction(); + assertNotNull(writeTx); - @Test - @Ignore - public void testTransactionConflict() throws InterruptedException, ExecutionException { - DOMStoreReadWriteTransaction txOne = domStore.newReadWriteTransaction(); - DOMStoreReadWriteTransaction txTwo = domStore.newReadWriteTransaction(); - assertTestContainerWrite(txOne); - assertTestContainerWrite(txTwo); + 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(); - /** - * Commits transaction - */ - assertThreePhaseCommit(txOne.ready()); + writeTx.merge(TestModel.TEST_PATH, containerNode); - /** - * Asserts that txTwo could not be commited - */ - assertFalse(txTwo.ready().canCommit().get()); - } - - private static void assertThreePhaseCommit(final DOMStoreThreePhaseCommitCohort cohort) - throws InterruptedException, ExecutionException { - assertTrue(cohort.canCommit().get().booleanValue()); - cohort.preCommit().get(); - cohort.commit().get(); - } - - private static Optional> assertTestContainerWrite(final DOMStoreReadWriteTransaction writeTx) - throws InterruptedException, ExecutionException { - /** - * - * Writes /test in writeTx - * - */ - writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); + 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()); + } - return assertTestContainerExists(writeTx); - } - /** - * Reads /test from readTx Read should return container. - */ - private static Optional> assertTestContainerExists(DOMStoreReadTransaction readTx) - throws InterruptedException, ExecutionException { + @Test + public void testExistsForExistingData() throws Exception { - ListenableFuture>> writeTxContainer = readTx.read(TestModel.TEST_PATH); - assertTrue(writeTxContainer.get().isPresent()); - return writeTxContainer.get(); - } + DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); + 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); + + CheckedFuture exists = + writeTx.exists(TestModel.TEST_PATH); + + assertEquals(true, exists.checkedGet()); + + DOMStoreThreePhaseCommitCohort ready = writeTx.ready(); + + ready.preCommit().get(); + + ready.commit().get(); + + DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction(); + assertNotNull(readTx); + + exists = + readTx.exists(TestModel.TEST_PATH); + + assertEquals(true, exists.checkedGet()); + } + + @Test + public void testExistsForNonExistingData() throws Exception { + + DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); + assertNotNull(writeTx); + + CheckedFuture exists = + writeTx.exists(TestModel.TEST_PATH); + + assertEquals(false, exists.checkedGet()); + + DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction(); + assertNotNull(readTx); + + exists = + readTx.exists(TestModel.TEST_PATH); + + assertEquals(false, exists.checkedGet()); + } + + @Test(expected = ReadFailedException.class) + public void testExistsThrowsReadFailedException() throws Exception { + + DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction(); + assertNotNull(readTx); + + readTx.close(); + + readTx.exists(TestModel.TEST_PATH).checkedGet(); + } + + @Test(expected = ReadFailedException.class) + public void testReadWithReadOnlyTransactionClosed() throws Exception { + + DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction(); + assertNotNull(readTx); + + readTx.close(); + + doReadAndThrowEx(readTx); + } + + @Test(expected = ReadFailedException.class) + public void testReadWithReadOnlyTransactionFailure() throws Exception { + + 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); + } + + @Test(expected = ReadFailedException.class) + public void testReadWithReadWriteTransactionClosed() throws Exception { + + DOMStoreReadTransaction readTx = domStore.newReadWriteTransaction(); + assertNotNull(readTx); + + readTx.close(); + + doReadAndThrowEx(readTx); + } + + @Test(expected = ReadFailedException.class) + public void testReadWithReadWriteTransactionFailure() throws Exception { + + DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class); + DataTreeModification mockModification = Mockito.mock(DataTreeModification.class); + Mockito.doThrow(new RuntimeException("mock ex")).when(mockModification) + .readNode(Mockito.any(YangInstanceIdentifier.class)); + Mockito.doReturn(mockModification).when(mockSnapshot).newModification(); + @SuppressWarnings("unchecked") + TransactionReadyPrototype mockReady = Mockito.mock(TransactionReadyPrototype.class); + DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadWriteTransaction("1", false, mockSnapshot, + mockReady); + + doReadAndThrowEx(readTx); + } + + private static void doReadAndThrowEx(final DOMStoreReadTransaction readTx) throws ReadFailedException { + readTx.read(TestModel.TEST_PATH).checkedGet(); + } + + @Test(expected = IllegalStateException.class) + public void testWriteWithTransactionReady() throws Exception { + + DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction(); + + writeTx.ready(); + + // Should throw ex + writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); + } + + @Test(expected = IllegalStateException.class) + public void testReadyWithTransactionAlreadyReady() throws Exception { + + DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction(); + + writeTx.ready(); + + // Should throw ex + writeTx.ready(); + } + + @Test + public void testReadyWithMissingMandatoryData() throws InterruptedException { + DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction(); + NormalizedNode testNode = ImmutableContainerNodeBuilder.create() + .withNodeIdentifier(new NodeIdentifier(TestModel.MANDATORY_DATA_TEST_QNAME)) + .addChild(ImmutableNodes.leafNode(TestModel.OPTIONAL_QNAME, "data")) + .build(); + writeTx.write(TestModel.MANDATORY_DATA_TEST_PATH, testNode); + DOMStoreThreePhaseCommitCohort ready = writeTx.ready(); + try { + ready.canCommit().get(); + Assert.fail("Expected exception on canCommit"); + } catch (ExecutionException e) { + // nop + } + } + + @Test + public void testTransactionAbort() throws InterruptedException, ExecutionException { + + DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); + assertNotNull(writeTx); + + assertTestContainerWrite(writeTx); + + DOMStoreThreePhaseCommitCohort cohort = writeTx.ready(); + + assertTrue(cohort.canCommit().get().booleanValue()); + cohort.preCommit().get(); + cohort.abort().get(); + + Optional> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH) + .get(); + assertFalse(afterCommitRead.isPresent()); + } + + @Test + public void testTransactionChain() throws InterruptedException, ExecutionException { + DOMStoreTransactionChain txChain = domStore.createTransactionChain(); + assertNotNull(txChain); + + /* + * We alocate new read-write transaction and write /test + */ + DOMStoreReadWriteTransaction firstTx = txChain.newReadWriteTransaction(); + assertTestContainerWrite(firstTx); + + /* + * First transaction is marked as ready, we are able to allocate chained + * transactions + */ + final DOMStoreThreePhaseCommitCohort firstWriteTxCohort = firstTx.ready(); + + /* + * We alocate chained transaction - read transaction, note first one is + * still not commited to datastore. + */ + DOMStoreReadTransaction secondReadTx = txChain.newReadOnlyTransaction(); + + /* + * We test if we are able to read data from tx, read should not fail + * since we are using chained transaction. + */ + assertTestContainerExists(secondReadTx); + + /* + * We alocate next transaction, which is still based on first one, but + * is read-write. + */ + DOMStoreReadWriteTransaction thirdDeleteTx = txChain.newReadWriteTransaction(); + + /* + * We test existence of /test in third transaction container should + * still be visible from first one (which is still uncommmited). + */ + assertTestContainerExists(thirdDeleteTx); + + /* + * We delete node in third transaction + */ + thirdDeleteTx.delete(TestModel.TEST_PATH); + + /* + * third transaction is sealed. + */ + DOMStoreThreePhaseCommitCohort thirdDeleteTxCohort = thirdDeleteTx.ready(); + + /* + * We commit first transaction + */ + assertThreePhaseCommit(firstWriteTxCohort); + + // Alocates store transacion + DOMStoreReadTransaction storeReadTx = domStore.newReadOnlyTransaction(); + + /* + * We verify transaction is commited to store, container should exists + * in datastore. + */ + assertTestContainerExists(storeReadTx); + + /* + * We commit third transaction + */ + assertThreePhaseCommit(thirdDeleteTxCohort); + } + + @Test + @Ignore + public void testTransactionConflict() throws InterruptedException, ExecutionException { + DOMStoreReadWriteTransaction txOne = domStore.newReadWriteTransaction(); + DOMStoreReadWriteTransaction txTwo = domStore.newReadWriteTransaction(); + assertTestContainerWrite(txOne); + assertTestContainerWrite(txTwo); + + /* + * Commits transaction + */ + assertThreePhaseCommit(txOne.ready()); + + /* + * Asserts that txTwo could not be commited + */ + assertFalse(txTwo.ready().canCommit().get()); + } + + private static void assertThreePhaseCommit(final DOMStoreThreePhaseCommitCohort cohort) + throws InterruptedException, ExecutionException { + assertTrue(cohort.canCommit().get().booleanValue()); + cohort.preCommit().get(); + cohort.commit().get(); + } + + private static Optional> assertTestContainerWrite(final DOMStoreReadWriteTransaction writeTx) + throws InterruptedException, ExecutionException { + /* + * Writes /test in writeTx + */ + writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); + + return assertTestContainerExists(writeTx); + } + + /** + * Reads /test from readTx Read should return container. + */ + private static Optional> assertTestContainerExists(final DOMStoreReadTransaction readTx) + throws InterruptedException, ExecutionException { + ListenableFuture>> writeTxContainer = readTx.read(TestModel.TEST_PATH); + assertTrue(writeTxContainer.get().isPresent()); + return writeTxContainer.get(); + } }