Bug 8163: getDataTreeChangeListenerExecutor() & DataBrokerTestModule 12/60312/1
authorMichael Vorburger <vorburger@redhat.com>
Thu, 13 Jul 2017 21:17:24 +0000 (02:47 +0530)
committerMichael Vorburger <vorburger@redhat.com>
Thu, 13 Jul 2017 21:17:24 +0000 (02:47 +0530)
Adjust AbstractDataBrokerTestCustomizer with a
getDataTreeChangeListenerExecutor() instead of a
setDataTreeChangeListenerExecutor(), just for more consistency with the
existing getCommitCoordinatorExecutor() method.  Also less confusing (to
me) than seeing the private Executor set by default which may get
changed by the setter later.

Adjust ConcurrentDataBrokerTestCustomizer with the
useMTDataTreeChangeListenerExecutor as a constructor argument, instead
of an useMTDataTreeChangeListenerExecutor() method, just for consistency
for how you already have it in AbstractConcurrentDataBrokerTest.

Extend ConstantSchemaAbstractDataBrokerTest and DataBrokerTestModule to
allow passing through this new opt-in tweak flag, so that tests in
downstream projects such as genius and netvirt can staring exploring
enabling this.

Change-Id: I4ad85ac48163d2f4bac865f46a3b047d5b7d333a
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/AbstractConcurrentDataBrokerTest.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/AbstractDataBrokerTestCustomizer.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/ConcurrentDataBrokerTestCustomizer.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/ConstantSchemaAbstractDataBrokerTest.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/DataBrokerTestModule.java

index 77c0c3f83f740a246a1e7e1033d4e3ca491b7fb7..de4d0ec13a6069ee385b4a0aa02ec546f8c639c4 100644 (file)
@@ -31,12 +31,7 @@ public abstract class AbstractConcurrentDataBrokerTest extends AbstractBaseDataB
 
     @Override
     protected AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
-        ConcurrentDataBrokerTestCustomizer customizer = new ConcurrentDataBrokerTestCustomizer();
-        if (useMTDataTreeChangeListenerExecutor) {
-            customizer.useMTDataTreeChangeListenerExecutor();
-        }
-
-        return customizer;
+        return new ConcurrentDataBrokerTestCustomizer(useMTDataTreeChangeListenerExecutor);
     }
 
 }
index 8d968b0a01526da6cbd6892f20d775e57f5cec31..375a9f119c3787adaec7e8b3f36f704d72ce19f7 100644 (file)
@@ -40,7 +40,6 @@ public abstract class AbstractDataBrokerTestCustomizer {
     private final MockSchemaService schemaService;
     private ImmutableMap<LogicalDatastoreType, DOMStore> datastores;
     private final BindingToNormalizedNodeCodec bindingToNormalized;
-    private ListeningExecutorService dataTreeChangeListenerExecutor = MoreExecutors.newDirectExecutorService();
 
     public ImmutableMap<LogicalDatastoreType, DOMStore> createDatastores() {
         return ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
@@ -61,13 +60,13 @@ public abstract class AbstractDataBrokerTestCustomizer {
     }
 
     public DOMStore createConfigurationDatastore() {
-        final InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", dataTreeChangeListenerExecutor);
+        final InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", getDataTreeChangeListenerExecutor());
         this.schemaService.registerSchemaContextListener(store);
         return store;
     }
 
     public DOMStore createOperationalDatastore() {
-        final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", dataTreeChangeListenerExecutor);
+        final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", getDataTreeChangeListenerExecutor());
         this.schemaService.registerSchemaContextListener(store);
         return store;
     }
@@ -86,6 +85,10 @@ public abstract class AbstractDataBrokerTestCustomizer {
 
     public abstract ListeningExecutorService getCommitCoordinatorExecutor();
 
+    public ListeningExecutorService getDataTreeChangeListenerExecutor() {
+        return MoreExecutors.newDirectExecutorService();
+    }
+
     public DataBroker createDataBroker() {
         return new BindingDOMDataBrokerAdapter(getDOMDataBroker(), this.bindingToNormalized);
     }
@@ -112,10 +115,6 @@ public abstract class AbstractDataBrokerTestCustomizer {
         return this.datastores;
     }
 
-    public void setDataTreeChangeListenerExecutor(ListeningExecutorService executor) {
-        this.dataTreeChangeListenerExecutor = executor;
-    }
-
     public void updateSchema(final SchemaContext ctx) {
         this.schemaService.changeSchema(ctx);
     }
index 0b2de070f8f5109694cc2bfb2e3ca5adb0be7560..ee761f4919c0a480ea2268156a2ecfff98c502d8 100644 (file)
@@ -21,12 +21,24 @@ import java.util.concurrent.Executors;
  */
 public class ConcurrentDataBrokerTestCustomizer extends AbstractDataBrokerTestCustomizer {
 
+    private final ListeningExecutorService dataTreeChangeListenerExecutorSingleton;
+
+    public ConcurrentDataBrokerTestCustomizer(boolean useMTDataTreeChangeListenerExecutor) {
+        if (useMTDataTreeChangeListenerExecutor) {
+            dataTreeChangeListenerExecutorSingleton = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
+        } else {
+            dataTreeChangeListenerExecutorSingleton = MoreExecutors.newDirectExecutorService();
+        }
+    }
+
     @Override
     public ListeningExecutorService getCommitCoordinatorExecutor() {
         return MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
     }
 
-    public void useMTDataTreeChangeListenerExecutor() {
-        setDataTreeChangeListenerExecutor(MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()));
+    @Override
+    public ListeningExecutorService getDataTreeChangeListenerExecutor() {
+        return dataTreeChangeListenerExecutorSingleton;
     }
+
 }
index 5c09a4f863c4838d2055d1459cec97442841f222..ba646c48589d3eb876a6af5a63989126484396e4 100644 (file)
@@ -18,6 +18,14 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
  */
 public class ConstantSchemaAbstractDataBrokerTest extends AbstractConcurrentDataBrokerTest {
 
+    public ConstantSchemaAbstractDataBrokerTest() {
+        super();
+    }
+
+    public ConstantSchemaAbstractDataBrokerTest(final boolean useMTDataTreeChangeListenerExecutor) {
+        super(useMTDataTreeChangeListenerExecutor);
+    }
+
     @Override
     protected SchemaContext getSchemaContext() throws Exception {
         return SchemaContextSingleton.getSchemaContext(super::getSchemaContext);
index c71049e444041e53a131f9877637f88a82a97bba..990d75a91708ce8d9b0c2c7e701eeca5ba1a79b1 100644 (file)
@@ -9,19 +9,29 @@ package org.opendaylight.controller.md.sal.binding.test;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 
-// @Module
 public class DataBrokerTestModule {
 
+    public static DataBroker dataBroker() {
+        return new DataBrokerTestModule(false).getDataBroker();
+    }
+
+    private final boolean useMTDataTreeChangeListenerExecutor;
+
+    public DataBrokerTestModule(boolean useMTDataTreeChangeListenerExecutor) {
+        this.useMTDataTreeChangeListenerExecutor = useMTDataTreeChangeListenerExecutor;
+    }
+
     // Suppress IllegalCatch because of AbstractDataBrokerTest (change later)
     @SuppressWarnings({ "checkstyle:IllegalCatch", "checkstyle:IllegalThrows" })
-    public static /* @Provides @Singleton */ DataBroker dataBroker() throws RuntimeException {
+    public DataBroker getDataBroker() throws RuntimeException {
         try {
             // This is a little bit "upside down" - in the future,
             // we should probably put what is in AbstractDataBrokerTest
             // into this DataBrokerTestModule, and make AbstractDataBrokerTest
             // use it, instead of the way around it currently is (the opposite);
             // this is just for historical reasons... and works for now.
-            ConstantSchemaAbstractDataBrokerTest dataBrokerTest = new ConstantSchemaAbstractDataBrokerTest();
+            ConstantSchemaAbstractDataBrokerTest dataBrokerTest
+                = new ConstantSchemaAbstractDataBrokerTest(useMTDataTreeChangeListenerExecutor);
             dataBrokerTest.setup();
             return dataBrokerTest.getDataBroker();
         } catch (Exception e) {