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%2FDOMDataTreeListenerTest.java;h=51f0c04826eb5778bdb9119fc47de0733319889a;hp=c3038ca7095c8d0a1759d80ec405ab3eb180931b;hb=cfd2e240178039a439001c4d3f1ca5f26097dcdd;hpb=ba3433c7bf94e551a4ea520c95165a9358bf9227 diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMDataTreeListenerTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMDataTreeListenerTest.java index c3038ca709..51f0c04826 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMDataTreeListenerTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMDataTreeListenerTest.java @@ -7,12 +7,13 @@ */ package org.opendaylight.controller.md.sal.dom.broker.impl; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; +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 static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL; + import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.ForwardingExecutorService; import com.google.common.util.concurrent.ListeningExecutorService; @@ -21,6 +22,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -30,7 +32,6 @@ import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitDeadlockException; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService; @@ -63,21 +64,18 @@ public class DOMDataTreeListenerTest { private CommitExecutorService commitExecutor; private static final DataContainerChild OUTER_LIST = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME) - .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)) - .build(); + .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build(); - private static final DataContainerChild OUTER_LIST_2 = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME) - .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2)) - .build(); + private static final DataContainerChild OUTER_LIST_2 = ImmutableNodes + .mapNodeBuilder(TestModel.OUTER_LIST_QNAME) + .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2)).build(); private static final NormalizedNode TEST_CONTAINER = Builders.containerBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) - .withChild(OUTER_LIST) + .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(OUTER_LIST) .build(); private static final NormalizedNode TEST_CONTAINER_2 = Builders.containerBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) - .withChild(OUTER_LIST_2) + .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(OUTER_LIST_2) .build(); private static DOMDataTreeIdentifier ROOT_DATA_TREE_ID = new DOMDataTreeIdentifier( @@ -88,24 +86,26 @@ public class DOMDataTreeListenerTest { @Before public void setupStore() { - InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", - MoreExecutors.newDirectExecutorService()); - InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", - MoreExecutors.newDirectExecutorService()); + InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService()); + InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.newDirectExecutorService()); schemaContext = TestModel.createTestContext(); operStore.onGlobalContextUpdated(schemaContext); configStore.onGlobalContextUpdated(schemaContext); - ImmutableMap stores = ImmutableMap.builder() // + final ImmutableMap stores = ImmutableMap.builder() // .put(CONFIGURATION, configStore) // .put(OPERATIONAL, operStore) // .build(); commitExecutor = new CommitExecutorService(Executors.newSingleThreadExecutor()); - futureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(1, 5, "FCB"); + futureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(1, 5, "FCB", + DOMDataTreeListenerTest.class); executor = new DeadlockDetectingListeningExecutorService(commitExecutor, - TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER, futureExecutor); + TransactionCommitDeadlockException + .DEADLOCK_EXCEPTION_SUPPLIER, + futureExecutor); domBroker = new SerializedDOMDataBroker(stores, executor); } @@ -125,16 +125,15 @@ public class DOMDataTreeListenerTest { CountDownLatch latch = new CountDownLatch(1); DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService(); - assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", - dataTreeChangeService); + assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService); final TestDataTreeListener listener = new TestDataTreeListener(latch); - final ListenerRegistration listenerReg = - dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener); + final ListenerRegistration listenerReg = dataTreeChangeService + .registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener); final DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER); - writeTx.submit(); + writeTx.commit(); latch.await(5, TimeUnit.SECONDS); @@ -150,23 +149,22 @@ public class DOMDataTreeListenerTest { } @Test - public void replaceContainerContainerInTreeTest() throws InterruptedException, TransactionCommitFailedException { - CountDownLatch latch = new CountDownLatch(2); + public void replaceContainerContainerInTreeTest() throws InterruptedException, ExecutionException { + final CountDownLatch latch = new CountDownLatch(2); DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService(); - assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", - dataTreeChangeService); + assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService); DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER); - writeTx.submit().checkedGet(); + writeTx.commit().get(); final TestDataTreeListener listener = new TestDataTreeListener(latch); - final ListenerRegistration listenerReg = - dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener); + final ListenerRegistration listenerReg = dataTreeChangeService + .registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener); writeTx = domBroker.newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER_2); - writeTx.submit(); + writeTx.commit(); latch.await(5, TimeUnit.SECONDS); @@ -190,24 +188,23 @@ public class DOMDataTreeListenerTest { } @Test - public void deleteContainerContainerInTreeTest() throws InterruptedException, TransactionCommitFailedException { - CountDownLatch latch = new CountDownLatch(2); + public void deleteContainerContainerInTreeTest() throws InterruptedException, ExecutionException { + final CountDownLatch latch = new CountDownLatch(2); DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService(); - assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", - dataTreeChangeService); + assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService); DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER); - writeTx.submit().checkedGet(); + writeTx.commit().get(); final TestDataTreeListener listener = new TestDataTreeListener(latch); - final ListenerRegistration listenerReg = - dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener); + final ListenerRegistration listenerReg = dataTreeChangeService + .registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener); writeTx = domBroker.newWriteOnlyTransaction(); writeTx.delete(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH); - writeTx.submit(); + writeTx.commit(); latch.await(5, TimeUnit.SECONDS); @@ -231,24 +228,23 @@ public class DOMDataTreeListenerTest { } @Test - public void replaceChildListContainerInTreeTest() throws InterruptedException, TransactionCommitFailedException { - CountDownLatch latch = new CountDownLatch(2); + public void replaceChildListContainerInTreeTest() throws InterruptedException, ExecutionException { + final CountDownLatch latch = new CountDownLatch(2); DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService(); - assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", - dataTreeChangeService); + assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService); DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER); - writeTx.submit().checkedGet(); + writeTx.commit().get(); final TestDataTreeListener listener = new TestDataTreeListener(latch); - final ListenerRegistration listenerReg = - dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener); + final ListenerRegistration listenerReg = dataTreeChangeService + .registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener); writeTx = domBroker.newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH, OUTER_LIST_2); - writeTx.submit(); + writeTx.commit(); latch.await(5, TimeUnit.SECONDS); @@ -268,32 +264,31 @@ public class DOMDataTreeListenerTest { assertNotNull(candidate); candidateRoot = candidate.getRootNode(); checkChange(TEST_CONTAINER, TEST_CONTAINER_2, ModificationType.SUBTREE_MODIFIED, candidateRoot); - final DataTreeCandidateNode modifiedChild = candidateRoot.getModifiedChild( - new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)); + final DataTreeCandidateNode modifiedChild = candidateRoot + .getModifiedChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)); assertNotNull(modifiedChild); checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, modifiedChild); listenerReg.close(); } @Test - public void rootModificationChildListenerTest() throws InterruptedException, TransactionCommitFailedException { - CountDownLatch latch = new CountDownLatch(2); + public void rootModificationChildListenerTest() throws InterruptedException, ExecutionException { + final CountDownLatch latch = new CountDownLatch(2); DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService(); - assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", - dataTreeChangeService); + assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService); DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER); - writeTx.submit().checkedGet(); + writeTx.commit().get(); final TestDataTreeListener listener = new TestDataTreeListener(latch); - final ListenerRegistration listenerReg = - dataTreeChangeService.registerDataTreeChangeListener(OUTER_LIST_DATA_TREE_ID, listener); + final ListenerRegistration listenerReg = dataTreeChangeService + .registerDataTreeChangeListener(OUTER_LIST_DATA_TREE_ID, listener); writeTx = domBroker.newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER_2); - writeTx.submit().checkedGet(); + writeTx.commit().get(); latch.await(1, TimeUnit.SECONDS); @@ -317,44 +312,44 @@ public class DOMDataTreeListenerTest { } @Test - public void listEntryChangeNonRootRegistrationTest() throws InterruptedException, TransactionCommitFailedException { - CountDownLatch latch = new CountDownLatch(2); + public void listEntryChangeNonRootRegistrationTest() throws InterruptedException, ExecutionException { + final CountDownLatch latch = new CountDownLatch(2); DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService(); - assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", - dataTreeChangeService); + assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService); DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER); - writeTx.submit().checkedGet(); + writeTx.commit().get(); final TestDataTreeListener listener = new TestDataTreeListener(latch); - final ListenerRegistration listenerReg = - dataTreeChangeService.registerDataTreeChangeListener(OUTER_LIST_DATA_TREE_ID, listener); - - final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId1 = - new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1); - final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId2 = - new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2); - final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId3 = - new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3); + final ListenerRegistration listenerReg = dataTreeChangeService + .registerDataTreeChangeListener(OUTER_LIST_DATA_TREE_ID, listener); + + final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId1 + = new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, + TestModel.ID_QNAME, 1); + final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId2 + = new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, + TestModel.ID_QNAME, 2); + final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId3 + = new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, + TestModel.ID_QNAME, 3); final MapEntryNode outerListEntry1 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1); final MapEntryNode outerListEntry2 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2); final MapEntryNode outerListEntry3 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3); - final MapNode listAfter = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME) - .withChild(outerListEntry2) - .withChild(outerListEntry3) - .build(); + final MapNode listAfter = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(outerListEntry2) + .withChild(outerListEntry3).build(); writeTx = domBroker.newWriteOnlyTransaction(); writeTx.delete(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId1)); writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId2), - outerListEntry2); + outerListEntry2); writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId3), - outerListEntry3); - writeTx.submit(); + outerListEntry3); + writeTx.commit(); latch.await(5, TimeUnit.SECONDS); @@ -383,10 +378,8 @@ public class DOMDataTreeListenerTest { listenerReg.close(); } - private static void checkChange(NormalizedNode expectedBefore, - NormalizedNode expectedAfter, - ModificationType expectedMod, - DataTreeCandidateNode candidateNode) { + private static void checkChange(final NormalizedNode expectedBefore, final NormalizedNode expectedAfter, + final ModificationType expectedMod, final DataTreeCandidateNode candidateNode) { if (expectedBefore != null) { assertTrue(candidateNode.getDataBefore().isPresent()); assertEquals(expectedBefore, candidateNode.getDataBefore().get()); @@ -405,8 +398,7 @@ public class DOMDataTreeListenerTest { } private DOMDataTreeChangeService getDOMDataTreeChangeService() { - final DOMDataBrokerExtension extension = domBroker.getSupportedExtensions() - .get(DOMDataTreeChangeService.class); + final DOMDataBrokerExtension extension = domBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class); if (extension == null) { return null; } @@ -422,7 +414,7 @@ public class DOMDataTreeListenerTest { ExecutorService delegate; - public CommitExecutorService(final ExecutorService delegate) { + CommitExecutorService(final ExecutorService delegate) { this.delegate = delegate; } @@ -434,10 +426,10 @@ public class DOMDataTreeListenerTest { static class TestDataTreeListener implements DOMDataTreeChangeListener { - private List> receivedChanges = new ArrayList<>(); - private CountDownLatch latch; + private final List> receivedChanges = new ArrayList<>(); + private final CountDownLatch latch; - public TestDataTreeListener(final CountDownLatch latch) { + TestDataTreeListener(final CountDownLatch latch) { this.latch = latch; }