X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fbroker%2Fimpl%2FDOMTransactionChainTest.java;h=3ea0bcefa5bab97ea12a9ead64e40cce49b78277;hp=b360cb1694eab7224980ed6ed078f39a51942e1e;hb=0219d667fd81b48cd3f05faee7d39aa1acce73a4;hpb=2cf314976a3f81c7115f94c44fb37e967f8a4426 diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java index b360cb1694..3ea0bcefa5 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.md.sal.dom.broker.impl; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -21,7 +20,6 @@ import java.util.concurrent.TimeoutException; import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; @@ -29,7 +27,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; import org.opendaylight.controller.md.sal.dom.store.impl.TestModel; import org.opendaylight.controller.sal.core.spi.data.DOMStore; -import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -71,8 +68,8 @@ public class DOMTransactionChainTest { /** * We alocate new read-write transaction and write /test - * - * + * + * */ DOMDataReadWriteTransaction firstTx = allocateAndWrite(txChain); @@ -80,7 +77,7 @@ public class DOMTransactionChainTest { * First transaction is marked as ready, we are able to allocate chained * transactions */ - ListenableFuture> firstWriteTxFuture = firstTx.commit(); + ListenableFuture firstWriteTxFuture = firstTx.submit(); /** * We alocate chained transaction - read transaction. @@ -88,44 +85,45 @@ public class DOMTransactionChainTest { DOMDataReadTransaction 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. - * + * */ DOMDataReadWriteTransaction thirdDeleteTx = allocateAndDelete(txChain); - /** - * third transaction is sealed. - */ - ListenableFuture> thirdDeleteTxFuture = thirdDeleteTx.commit(); - /** * We commit first transaction - * + * */ assertCommitSuccessful(firstWriteTxFuture); - // Alocates store transaction + /** + * + * Allocates transaction from data store. + * + */ DOMDataReadTransaction storeReadTx = domBroker.newReadOnlyTransaction(); + /** * We verify transaction is commited to store, container should exists * in datastore. */ assertTestContainerExists(storeReadTx); + /** - * We commit third transaction - * + * third transaction is sealed and commited */ + ListenableFuture thirdDeleteTxFuture = thirdDeleteTx.submit(); assertCommitSuccessful(thirdDeleteTxFuture); /** @@ -144,8 +142,8 @@ public class DOMTransactionChainTest { /** * We alocate new read-write transaction and write /test - * - * + * + * */ allocateAndWrite(txChain); @@ -155,21 +153,21 @@ public class DOMTransactionChainTest { * IllegalStateException. */ try { - DOMDataReadTransaction secondReadTx = txChain.newReadOnlyTransaction(); + txChain.newReadOnlyTransaction(); fail("Allocation of secondReadTx should fail with IllegalStateException"); } catch (Exception e) { assertTrue(e instanceof IllegalStateException); } } - private static DOMDataReadWriteTransaction allocateAndDelete(DOMTransactionChain txChain) + private static DOMDataReadWriteTransaction allocateAndDelete(final DOMTransactionChain txChain) throws InterruptedException, ExecutionException { DOMDataReadWriteTransaction tx = txChain.newReadWriteTransaction(); /** * We test existence of /test in third transaction container should * still be visible from first one (which is still uncommmited). - * + * */ assertTestContainerExists(tx); @@ -180,28 +178,26 @@ public class DOMTransactionChainTest { return tx; } - private static DOMDataReadWriteTransaction allocateAndWrite(DOMTransactionChain txChain) + private static DOMDataReadWriteTransaction allocateAndWrite(final DOMTransactionChain txChain) throws InterruptedException, ExecutionException { DOMDataReadWriteTransaction tx = txChain.newReadWriteTransaction(); assertTestContainerWrite(tx); return tx; } - private static void assertCommitSuccessful(ListenableFuture> future) + private static void assertCommitSuccessful(final ListenableFuture future) throws InterruptedException, ExecutionException { - RpcResult rpcResult = future.get(); - assertTrue(rpcResult.isSuccessful()); - assertEquals(TransactionStatus.COMMITED, rpcResult.getResult()); + future.get(); } - private static void assertTestContainerExists(DOMDataReadTransaction readTx) throws InterruptedException, + private static void assertTestContainerExists(final DOMDataReadTransaction readTx) throws InterruptedException, ExecutionException { ListenableFuture>> readFuture = readTx.read(OPERATIONAL, TestModel.TEST_PATH); Optional> readedData = readFuture.get(); assertTrue(readedData.isPresent()); } - private static void assertTestContainerWrite(DOMDataReadWriteTransaction tx) throws InterruptedException, + private static void assertTestContainerWrite(final DOMDataReadWriteTransaction tx) throws InterruptedException, ExecutionException { tx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); assertTestContainerExists(tx);