X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-inmemory-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2FInMemoryDataStoreTest.java;h=c609e13e791c375979ad99bce62ed27df9d321f8;hb=51e91f6bdcc88c5aa96f956e516d31dbb5e5d5e0;hp=4d38858667173df23ed112fa5e13c139914bdb73;hpb=24c8edfec01c5a61bf40a930aec018502cd37275;p=controller.git 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 4d38858667..c609e13e79 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 @@ -7,13 +7,10 @@ */ 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 java.util.concurrent.ExecutionException; - +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 org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -35,9 +32,12 @@ 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 com.google.common.base.Optional; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class InMemoryDataStoreTest { @@ -185,6 +185,74 @@ public class InMemoryDataStoreTest { assertEquals( "After commit read: data", containerNode, afterCommitRead.get() ); } + + @Test + public void testExistsForExistingData() throws Exception { + + 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 Throwable {