X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=dom%2Fmdsal-dom-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fdom%2Fbroker%2FDOMTransactionChainTest.java;h=c3f3d6a4c2c5ba52cca8f9766ecf22ba6f585ac2;hb=7e9012b9820ed399a93d1f302dfa5c0e05583493;hp=5734ad6cd33f527ca247f5e7356548a6ce6b205e;hpb=0625e7adb9ca1dec0e32c08940484126c9f70cf3;p=mdsal.git diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMTransactionChainTest.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMTransactionChainTest.java index 5734ad6cd3..c3f3d6a4c2 100644 --- a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMTransactionChainTest.java +++ b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMTransactionChainTest.java @@ -7,9 +7,10 @@ */ package org.opendaylight.mdsal.dom.broker; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL; @@ -29,10 +30,12 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction; import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; import org.opendaylight.mdsal.dom.api.DOMTransactionChain; +import org.opendaylight.mdsal.dom.spi.AbstractDOMDataBroker; import org.opendaylight.mdsal.dom.spi.store.DOMStore; import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; public class DOMTransactionChainTest extends AbstractDatastoreTest { @@ -61,12 +64,11 @@ public class DOMTransactionChainTest extends AbstractDatastoreTest { @Test public void testTransactionChainNoConflict() throws InterruptedException, ExecutionException, TimeoutException { - final BlockingTransactionChainListener listener = new BlockingTransactionChainListener(); - final DOMTransactionChain txChain = domBroker.createTransactionChain(listener); + final DOMTransactionChain txChain = domBroker.createTransactionChain(); assertNotNull(txChain); /** - * We alocate new read-write transaction and write /test. + * We allocate new read-write transaction and write /test. */ final DOMDataTreeWriteTransaction firstTx = allocateAndWrite(txChain); @@ -77,7 +79,7 @@ public class DOMTransactionChainTest extends AbstractDatastoreTest { final ListenableFuture firstWriteTxFuture = firstTx.commit(); /** - * We alocate chained transaction - read transaction. + * We allocate chained transaction - read transaction. */ final DOMDataTreeReadTransaction secondReadTx = txChain.newReadOnlyTransaction(); @@ -91,7 +93,7 @@ public class DOMTransactionChainTest extends AbstractDatastoreTest { assertTestContainerExists(secondReadTx); /** - * We alocate next transaction, which is still based on first one, but + * We allocate next transaction, which is still based on first one, but * is read-write. * */ @@ -110,13 +112,13 @@ public class DOMTransactionChainTest extends AbstractDatastoreTest { final DOMDataTreeReadTransaction storeReadTx = domBroker.newReadOnlyTransaction(); /** - * We verify transaction is commited to store, container should exists + * We verify transaction is committed to store, container should exist * in datastore. */ assertTestContainerExists(storeReadTx); /** - * third transaction is sealed and commited. + * third transaction is sealed and committed. */ assertCommitSuccessful(thirdDeleteTx.commit()); @@ -125,32 +127,27 @@ public class DOMTransactionChainTest extends AbstractDatastoreTest { */ txChain.close(); - listener.getSuccessFuture().get(1000, TimeUnit.MILLISECONDS); + txChain.future().get(1000, TimeUnit.MILLISECONDS); } - @SuppressWarnings("checkstyle:IllegalCatch") @Test - public void testTransactionChainNotSealed() throws InterruptedException, ExecutionException, TimeoutException { - final BlockingTransactionChainListener listener = new BlockingTransactionChainListener(); - final DOMTransactionChain txChain = domBroker.createTransactionChain(listener); + public void testTransactionChainNotSealed() { + final var txChain = domBroker.createTransactionChain(); assertNotNull(txChain); /** - * We alocate new read-write transaction and write /test + * We allocate new read-write transaction and write /test */ allocateAndWrite(txChain); /** - * We alocate chained transaction - read transaction, note first one is - * still not commited to datastore, so this allocation should fail with + * We allocate chained transaction - read transaction, note first one is + * still not committed to datastore, so this allocation should fail with * IllegalStateException. */ - try { - txChain.newReadOnlyTransaction(); - fail("Allocation of secondReadTx should fail with IllegalStateException"); - } catch (final Exception e) { - assertTrue(e instanceof IllegalStateException); - } + // actual backing tx allocation happens on put + final var ex = assertThrows(IllegalStateException.class, () -> allocateAndWrite(txChain)); + assertEquals("Previous transaction OPER-0 is not ready yet", ex.getMessage()); } private static DOMDataTreeWriteTransaction allocateAndDelete(final DOMTransactionChain txChain) @@ -163,9 +160,8 @@ public class DOMTransactionChainTest extends AbstractDatastoreTest { return tx; } - private static DOMDataTreeWriteTransaction allocateAndWrite(final DOMTransactionChain txChain) - throws InterruptedException, ExecutionException { - final DOMDataTreeWriteTransaction tx = txChain.newWriteOnlyTransaction(); + private static DOMDataTreeWriteTransaction allocateAndWrite(final DOMTransactionChain txChain) { + final var tx = txChain.newWriteOnlyTransaction(); writeTestContainer(tx); return tx; } @@ -182,8 +178,9 @@ public class DOMTransactionChainTest extends AbstractDatastoreTest { assertTrue(readedData.isPresent()); } - private static void writeTestContainer(final DOMDataTreeWriteTransaction tx) throws InterruptedException, - ExecutionException { - tx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); + private static void writeTestContainer(final DOMDataTreeWriteTransaction tx) { + tx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)) + .build()); } }