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>
@Override
protected AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
@Override
protected AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
- ConcurrentDataBrokerTestCustomizer customizer = new ConcurrentDataBrokerTestCustomizer();
- if (useMTDataTreeChangeListenerExecutor) {
- customizer.useMTDataTreeChangeListenerExecutor();
- }
-
- return customizer;
+ return new ConcurrentDataBrokerTestCustomizer(useMTDataTreeChangeListenerExecutor);
private final MockSchemaService schemaService;
private ImmutableMap<LogicalDatastoreType, DOMStore> datastores;
private final BindingToNormalizedNodeCodec bindingToNormalized;
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()
public ImmutableMap<LogicalDatastoreType, DOMStore> createDatastores() {
return ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
}
public DOMStore createConfigurationDatastore() {
}
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() {
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;
}
this.schemaService.registerSchemaContextListener(store);
return store;
}
public abstract ListeningExecutorService getCommitCoordinatorExecutor();
public abstract ListeningExecutorService getCommitCoordinatorExecutor();
+ public ListeningExecutorService getDataTreeChangeListenerExecutor() {
+ return MoreExecutors.newDirectExecutorService();
+ }
+
public DataBroker createDataBroker() {
return new BindingDOMDataBrokerAdapter(getDOMDataBroker(), this.bindingToNormalized);
}
public DataBroker createDataBroker() {
return new BindingDOMDataBrokerAdapter(getDOMDataBroker(), this.bindingToNormalized);
}
return this.datastores;
}
return this.datastores;
}
- public void setDataTreeChangeListenerExecutor(ListeningExecutorService executor) {
- this.dataTreeChangeListenerExecutor = executor;
- }
-
public void updateSchema(final SchemaContext ctx) {
this.schemaService.changeSchema(ctx);
}
public void updateSchema(final SchemaContext ctx) {
this.schemaService.changeSchema(ctx);
}
*/
public class ConcurrentDataBrokerTestCustomizer extends AbstractDataBrokerTestCustomizer {
*/
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());
}
@Override
public ListeningExecutorService getCommitCoordinatorExecutor() {
return MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
- public void useMTDataTreeChangeListenerExecutor() {
- setDataTreeChangeListenerExecutor(MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()));
+ @Override
+ public ListeningExecutorService getDataTreeChangeListenerExecutor() {
+ return dataTreeChangeListenerExecutorSingleton;
*/
public class ConstantSchemaAbstractDataBrokerTest extends AbstractConcurrentDataBrokerTest {
*/
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);
@Override
protected SchemaContext getSchemaContext() throws Exception {
return SchemaContextSingleton.getSchemaContext(super::getSchemaContext);
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
public class DataBrokerTestModule {
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" })
// 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.
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) {
dataBrokerTest.setup();
return dataBrokerTest.getDataBroker();
} catch (Exception e) {