X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fbroker%2Fimpl%2FDOMBrokerTest.java;fp=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fbroker%2Fimpl%2FDOMBrokerTest.java;h=b2fb3c2c3e9421f832576a0f21b90c3859dcbb3a;hb=8e4580f8989c7a40861be1c025822ebba4f1cb07;hp=519c364050083a72133610a2b260b16e141a23c7;hpb=258d8039ac144aeee2efa7943228c0fc6cdaf651;p=controller.git diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java index 519c364050..b2fb3c2c3e 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.md.sal.dom.broker.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; @@ -18,13 +17,10 @@ import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastor import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.ForwardingExecutorService; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import java.util.Collections; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -36,12 +32,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; 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.DOMDataChangeListener; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; @@ -50,7 +43,6 @@ import org.opendaylight.controller.md.sal.dom.store.impl.TestModel; import org.opendaylight.controller.sal.core.spi.data.DOMStore; import org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService; import org.opendaylight.yangtools.util.concurrent.SpecialExecutors; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; 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; @@ -211,139 +203,6 @@ public class DOMBrokerTest { } } - /** - * Tests a simple DataChangeListener notification after a write. - */ - @Test - @SuppressWarnings("checkstyle:IllegalThrows") - public void testDataChangeListener() throws Throwable { - - final NormalizedNode testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); - - TestDOMDataChangeListener dcListener = new TestDOMDataChangeListener(); - - domBroker.registerDataChangeListener(OPERATIONAL, TestModel.TEST_PATH, dcListener, DataChangeScope.BASE); - - final DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction(); - assertNotNull(writeTx); - - writeTx.put(OPERATIONAL, TestModel.TEST_PATH, testNode); - - AtomicReference caughtEx = submitTxAsync(writeTx); - - dcListener.waitForChange(); - - if (caughtEx.get() != null) { - throw caughtEx.get(); - } - - NormalizedNode actualNode = dcListener.capturedChange.getCreatedData().get(TestModel.TEST_PATH); - assertEquals("Created node", testNode, actualNode); - } - - /** - * Tests a DataChangeListener that does an async submit of a write Tx in its onDataChanged method. - * This should succeed without deadlock. - */ - @Test - @SuppressWarnings("checkstyle:IllegalThrows") - public void testDataChangeListenerDoingAsyncWriteTxSubmit() throws Throwable { - - final AtomicReference caughtCommitEx = new AtomicReference<>(); - final CountDownLatch commitCompletedLatch = new CountDownLatch(1); - - TestDOMDataChangeListener dcListener = new TestDOMDataChangeListener() { - @Override - public void onDataChanged(final AsyncDataChangeEvent> change) { - - DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction(); - writeTx.put(OPERATIONAL, TestModel.TEST2_PATH, ImmutableNodes.containerNode(TestModel.TEST2_QNAME)); - Futures.addCallback(writeTx.submit(), new FutureCallback() { - @Override - public void onSuccess(final Void result) { - commitCompletedLatch.countDown(); - } - - @Override - public void onFailure(final Throwable throwable) { - caughtCommitEx.set(throwable); - commitCompletedLatch.countDown(); - } - }, MoreExecutors.directExecutor()); - - super.onDataChanged(change); - } - }; - - domBroker.registerDataChangeListener(OPERATIONAL, TestModel.TEST_PATH, dcListener, DataChangeScope.BASE); - - final DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction(); - assertNotNull(writeTx); - - writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - - AtomicReference caughtEx = submitTxAsync(writeTx); - - dcListener.waitForChange(); - - if (caughtEx.get() != null) { - throw caughtEx.get(); - } - - assertTrue("Commit Future was not invoked", commitCompletedLatch.await(5, TimeUnit.SECONDS)); - - if (caughtCommitEx.get() != null) { - throw caughtCommitEx.get(); - } - } - - /** - * Tests a DataChangeListener that does a blocking submit of a write Tx in its onDataChanged method. - * This should throw an exception and not deadlock. - */ - @Test(expected = TransactionCommitDeadlockException.class) - @SuppressWarnings({"checkstyle:IllegalThrows", "checkstyle:IllegalCatch"}) - public void testDataChangeListenerDoingBlockingWriteTxSubmit() throws Throwable { - - final AtomicReference caughtCommitEx = new AtomicReference<>(); - - TestDOMDataChangeListener dcListener = new TestDOMDataChangeListener() { - @Override - public void onDataChanged(final AsyncDataChangeEvent> change) { - DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction(); - writeTx.put(OPERATIONAL, TestModel.TEST2_PATH, ImmutableNodes.containerNode(TestModel.TEST2_QNAME)); - try { - writeTx.commit().get(); - } catch (ExecutionException e) { - caughtCommitEx.set(e.getCause()); - } catch (Exception e) { - caughtCommitEx.set(e); - } finally { - super.onDataChanged(change); - } - } - }; - - domBroker.registerDataChangeListener(OPERATIONAL, TestModel.TEST_PATH, dcListener, DataChangeScope.BASE); - - final DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction(); - assertNotNull(writeTx); - - writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - - AtomicReference caughtEx = submitTxAsync(writeTx); - - dcListener.waitForChange(); - - if (caughtEx.get() != null) { - throw caughtEx.get(); - } - - if (caughtCommitEx.get() != null) { - throw caughtCommitEx.get(); - } - } - @SuppressWarnings("checkstyle:IllegalCatch") AtomicReference submitTxAsync(final DOMDataWriteTransaction writeTx) { final AtomicReference caughtEx = new AtomicReference<>(); @@ -358,21 +217,6 @@ public class DOMBrokerTest { return caughtEx; } - static class TestDOMDataChangeListener implements DOMDataChangeListener { - - volatile AsyncDataChangeEvent> capturedChange; - private final CountDownLatch latch = new CountDownLatch(1); - - @Override - public void onDataChanged(final AsyncDataChangeEvent> change) { - this.capturedChange = change; - latch.countDown(); - } - - void waitForChange() throws InterruptedException { - assertTrue("onDataChanged was not called", latch.await(5, TimeUnit.SECONDS)); - } - } static class CommitExecutorService extends ForwardingExecutorService {