Using a direct executor can cause deadlocks so the DTCL executor was
made configurable to use a threadpool as an opt-in. Direct executor
is still the default as many existing tests would break.
Change-Id: I41e14f1e6d3b77a44e61dfc75abff29d11a777dc
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
private void deleteAndListenAugment(final DataChangeScope scope,
final InstanceIdentifier<?> path) {
writeInitialState();
private void deleteAndListenAugment(final DataChangeScope scope,
final InstanceIdentifier<?> path) {
writeInitialState();
- TestListener listener = createListener(
- LogicalDatastoreType.OPERATIONAL, WILDCARDED_AUGMENT_PATH,
- scope);
+ TestListener listener = createListener(LogicalDatastoreType.OPERATIONAL, WILDCARDED_AUGMENT_PATH, scope, false);
delete(path);
verifyRemoved(listener.event());
}
delete(path);
verifyRemoved(listener.event());
}
@Test
public void writeTopWithListItemAugmentedListenTopSubtree() {
@Test
public void writeTopWithListItemAugmentedListenTopSubtree() {
- TestListener listener = createListener(CONFIGURATION,TOP_PATH, DataChangeScope.SUBTREE);
- listener.startCapture();
+ TestListener listener = createListener(CONFIGURATION,TOP_PATH, DataChangeScope.SUBTREE, false);
writeTopWithListItem(CONFIGURATION);
writeTopWithListItem(CONFIGURATION);
@Test
public void writeTopWithListItemAugmentedListenAugmentSubtreeWildcarded() {
@Test
public void writeTopWithListItemAugmentedListenAugmentSubtreeWildcarded() {
- TestListener listener = createListener(CONFIGURATION,AUGMENT_WILDCARD, DataChangeScope.SUBTREE);
- listener.startCapture();
+ TestListener listener = createListener(CONFIGURATION,AUGMENT_WILDCARD, DataChangeScope.SUBTREE, false);
writeTopWithListItem(CONFIGURATION);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
writeTopWithListItem(CONFIGURATION);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
public void deleteAugmentChildListenAugmentSubtreeWildcarded() {
writeTopWithListItem(CONFIGURATION);
public void deleteAugmentChildListenAugmentSubtreeWildcarded() {
writeTopWithListItem(CONFIGURATION);
- TestListener listener = createListener(CONFIGURATION, AUGMENT_WILDCARD, DataChangeScope.SUBTREE);
+ TestListener listener = createListener(CONFIGURATION, AUGMENT_WILDCARD, DataChangeScope.SUBTREE, false);
InstanceIdentifier<?> deletePath = path(TOP_FOO_KEY,USES_ONE_KEY);
deleteItem(CONFIGURATION,deletePath);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
InstanceIdentifier<?> deletePath = path(TOP_FOO_KEY,USES_ONE_KEY);
deleteItem(CONFIGURATION,deletePath);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
package org.opendaylight.controller.md.sal.binding.impl.test;
package org.opendaylight.controller.md.sal.binding.impl.test;
+import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertContains;
+import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertEmpty;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.complexUsesAugment;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.leafOnlyUsesAugment;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.top;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
+
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertContains;
-import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertEmpty;
-import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.top;
-import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
-import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
-import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.leafOnlyUsesAugment;
-import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.complexUsesAugment;
-
public class Bug1418AugmentationTest extends AbstractDataChangeListenerTest{
private static final InstanceIdentifier<Top> TOP = InstanceIdentifier.create(Top.class);
private static final InstanceIdentifier<TopLevelList> TOP_FOO = TOP.child(TopLevelList.class, TOP_FOO_KEY);
public class Bug1418AugmentationTest extends AbstractDataChangeListenerTest{
private static final InstanceIdentifier<Top> TOP = InstanceIdentifier.create(Top.class);
private static final InstanceIdentifier<TopLevelList> TOP_FOO = TOP.child(TopLevelList.class, TOP_FOO_KEY);
@Test
public void leafOnlyAugmentationCreatedTest() {
TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT,
@Test
public void leafOnlyAugmentationCreatedTest() {
TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT,
- AsyncDataBroker.DataChangeScope.SUBTREE);
+ AsyncDataBroker.DataChangeScope.SUBTREE, false);
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf"));
assertCommit(writeTx.submit());
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf"));
assertCommit(writeTx.submit());
- assertTrue(listener.hasEvent());
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
assertContains(event.getCreatedData(), SIMPLE_AUGMENT);
assertEmpty(event.getUpdatedData());
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
assertContains(event.getCreatedData(), SIMPLE_AUGMENT);
assertEmpty(event.getUpdatedData());
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf changed"));
assertCommit(writeTx.submit());
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf changed"));
assertCommit(writeTx.submit());
- assertTrue(listener.hasEvent());
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
assertContains(event.getUpdatedData(), SIMPLE_AUGMENT);
assertContains(event.getOriginalData(), SIMPLE_AUGMENT);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
assertContains(event.getUpdatedData(), SIMPLE_AUGMENT);
assertContains(event.getOriginalData(), SIMPLE_AUGMENT);
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT);
assertCommit(writeTx.submit());
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT);
assertCommit(writeTx.submit());
- assertTrue(listener.hasEvent());
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
assertContains(event.getRemovedPaths(), SIMPLE_AUGMENT);
assertContains(event.getOriginalData(), SIMPLE_AUGMENT);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
assertContains(event.getRemovedPaths(), SIMPLE_AUGMENT);
assertContains(event.getOriginalData(), SIMPLE_AUGMENT);
@Test
public void complexAugmentationCreatedTest() {
TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT,
@Test
public void complexAugmentationCreatedTest() {
TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT,
- AsyncDataBroker.DataChangeScope.SUBTREE);
+ AsyncDataBroker.DataChangeScope.SUBTREE, false);
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY));
assertCommit(writeTx.submit());
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY));
assertCommit(writeTx.submit());
- assertTrue(listener.hasEvent());
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
assertContains(event.getCreatedData(), COMPLEX_AUGMENT);
assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY));
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
assertContains(event.getCreatedData(), COMPLEX_AUGMENT);
assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY));
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY_MOD));
assertCommit(writeTx.submit());
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY_MOD));
assertCommit(writeTx.submit());
- assertTrue(listener.hasEvent());
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
assertContains(event.getUpdatedData(), COMPLEX_AUGMENT);
assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY_MOD));
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
assertContains(event.getUpdatedData(), COMPLEX_AUGMENT);
assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY_MOD));
@Test
public void writeListToList2562Root() {
final AbstractDataChangeListenerTest.TestListener listenerRoot = createListener(LogicalDatastoreType.CONFIGURATION,
@Test
public void writeListToList2562Root() {
final AbstractDataChangeListenerTest.TestListener listenerRoot = createListener(LogicalDatastoreType.CONFIGURATION,
- ROOT_PATH, AsyncDataBroker.DataChangeScope.ONE);
- listenerRoot.startCapture();
+ ROOT_PATH, AsyncDataBroker.DataChangeScope.ONE, false);
writeRoot(LogicalDatastoreType.CONFIGURATION);
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> eventRoot = listenerRoot.event();
writeRoot(LogicalDatastoreType.CONFIGURATION);
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> eventRoot = listenerRoot.event();
@Test
public void listWithMultiKeyTest() {
final AbstractDataChangeListenerTest.TestListener listener = createListener(CONFIGURATION, ROOT_PATH,
@Test
public void listWithMultiKeyTest() {
final AbstractDataChangeListenerTest.TestListener listener = createListener(CONFIGURATION, ROOT_PATH,
- AsyncDataBroker.DataChangeScope.BASE);
- listener.startCapture();
+ AsyncDataBroker.DataChangeScope.BASE, false);
write(CONFIGURATION);
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
write(CONFIGURATION);
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
assertEmpty(event.getUpdatedData());
assertEmpty(event.getRemovedPaths());
}
assertEmpty(event.getUpdatedData());
assertEmpty(event.getRemovedPaths());
}
-}
\ No newline at end of file
/**
* This testsuite tests explanation for data change scope and data modifications
* which were described in
/**
* This testsuite tests explanation for data change scope and data modifications
* which were described in
- * https://lists.opendaylight.org/pipermail/controller-dev/2014-July/005541.html
+ * https://lists.opendaylight.org/pipermail/controller-dev/2014-July/005541.html.
-public class ListInsertionDataChangeListenerTest extends AbstractDataChangeListenerTest{
+public class ListInsertionDataChangeListenerTest extends AbstractDataChangeListenerTest {
private static final InstanceIdentifier<Top> TOP = InstanceIdentifier.create(Top.class);
private static final InstanceIdentifier<TopLevelList> WILDCARDED = TOP.child(TopLevelList.class);
private static final InstanceIdentifier<Top> TOP = InstanceIdentifier.create(Top.class);
private static final InstanceIdentifier<TopLevelList> WILDCARDED = TOP.child(TopLevelList.class);
@Test
public void replaceTopNodeSubtreeListeners() {
TestListener topListener = createListener(CONFIGURATION, TOP, DataChangeScope.SUBTREE);
@Test
public void replaceTopNodeSubtreeListeners() {
TestListener topListener = createListener(CONFIGURATION, TOP, DataChangeScope.SUBTREE);
- TestListener allListener = createListener(CONFIGURATION, WILDCARDED, DataChangeScope.SUBTREE);
+ TestListener allListener = createListener(CONFIGURATION, WILDCARDED, DataChangeScope.SUBTREE, false);
TestListener fooListener = createListener(CONFIGURATION, TOP_FOO, DataChangeScope.SUBTREE);
TestListener fooListener = createListener(CONFIGURATION, TOP_FOO, DataChangeScope.SUBTREE);
- TestListener barListener = createListener(CONFIGURATION, TOP_BAR, DataChangeScope.SUBTREE);
+ TestListener barListener = createListener(CONFIGURATION, TOP_BAR, DataChangeScope.SUBTREE, false);
ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
writeTx.put(CONFIGURATION, TOP, top(topLevelList(TOP_BAR_KEY)));
assertCommit(writeTx.submit());
ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
writeTx.put(CONFIGURATION, TOP, top(topLevelList(TOP_BAR_KEY)));
assertCommit(writeTx.submit());
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> top = topListener.event();
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> all = allListener.event();
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> foo = fooListener.event();
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> bar = barListener.event();
+ final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> top = topListener.event();
+ final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> all = allListener.event();
+ final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> foo = fooListener.event();
+ final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> bar = barListener.event();
// Listener for TOP element
assertContains(top.getOriginalData(), TOP,TOP_FOO);
// Listener for TOP element
assertContains(top.getOriginalData(), TOP,TOP_FOO);
@Test
public void mergeTopNodeSubtreeListeners() {
TestListener topListener = createListener(CONFIGURATION, TOP, DataChangeScope.SUBTREE);
@Test
public void mergeTopNodeSubtreeListeners() {
TestListener topListener = createListener(CONFIGURATION, TOP, DataChangeScope.SUBTREE);
- TestListener allListener = createListener(CONFIGURATION, WILDCARDED, DataChangeScope.SUBTREE);
+ TestListener allListener = createListener(CONFIGURATION, WILDCARDED, DataChangeScope.SUBTREE, false);
TestListener fooListener = createListener(CONFIGURATION, TOP_FOO, DataChangeScope.SUBTREE);
TestListener fooListener = createListener(CONFIGURATION, TOP_FOO, DataChangeScope.SUBTREE);
- TestListener barListener = createListener(CONFIGURATION, TOP_BAR, DataChangeScope.SUBTREE);
+ TestListener barListener = createListener(CONFIGURATION, TOP_BAR, DataChangeScope.SUBTREE, false);
ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
writeTx.merge(CONFIGURATION, TOP, top(topLevelList(TOP_BAR_KEY)));
ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
writeTx.merge(CONFIGURATION, TOP, top(topLevelList(TOP_BAR_KEY)));
@Test
public void putTopBarNodeSubtreeListeners() {
TestListener topListener = createListener(CONFIGURATION, TOP, DataChangeScope.SUBTREE);
@Test
public void putTopBarNodeSubtreeListeners() {
TestListener topListener = createListener(CONFIGURATION, TOP, DataChangeScope.SUBTREE);
- TestListener allListener = createListener(CONFIGURATION, WILDCARDED, DataChangeScope.SUBTREE);
+ TestListener allListener = createListener(CONFIGURATION, WILDCARDED, DataChangeScope.SUBTREE, false);
TestListener fooListener = createListener(CONFIGURATION, TOP_FOO, DataChangeScope.SUBTREE);
TestListener fooListener = createListener(CONFIGURATION, TOP_FOO, DataChangeScope.SUBTREE);
- TestListener barListener = createListener(CONFIGURATION, TOP_BAR, DataChangeScope.SUBTREE);
+ TestListener barListener = createListener(CONFIGURATION, TOP_BAR, DataChangeScope.SUBTREE, false);
ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
writeTx.put(CONFIGURATION, TOP_BAR, topLevelList(TOP_BAR_KEY));
ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
writeTx.put(CONFIGURATION, TOP_BAR, topLevelList(TOP_BAR_KEY));
@Test
public void mergeTopBarNodeSubtreeListeners() {
TestListener topListener = createListener(CONFIGURATION, TOP, DataChangeScope.SUBTREE);
@Test
public void mergeTopBarNodeSubtreeListeners() {
TestListener topListener = createListener(CONFIGURATION, TOP, DataChangeScope.SUBTREE);
- TestListener allListener = createListener(CONFIGURATION, WILDCARDED, DataChangeScope.SUBTREE);
+ TestListener allListener = createListener(CONFIGURATION, WILDCARDED, DataChangeScope.SUBTREE, false);
TestListener fooListener = createListener(CONFIGURATION, TOP_FOO, DataChangeScope.SUBTREE);
TestListener fooListener = createListener(CONFIGURATION, TOP_FOO, DataChangeScope.SUBTREE);
- TestListener barListener = createListener(CONFIGURATION, TOP_BAR, DataChangeScope.SUBTREE);
+ TestListener barListener = createListener(CONFIGURATION, TOP_BAR, DataChangeScope.SUBTREE, false);
ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
writeTx.merge(CONFIGURATION, TOP_BAR, topLevelList(TOP_BAR_KEY));
ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
writeTx.merge(CONFIGURATION, TOP_BAR, topLevelList(TOP_BAR_KEY));
* @author Michael Vorburger
*/
public abstract class AbstractConcurrentDataBrokerTest extends AbstractBaseDataBrokerTest {
* @author Michael Vorburger
*/
public abstract class AbstractConcurrentDataBrokerTest extends AbstractBaseDataBrokerTest {
+ private final boolean useMTDataTreeChangeListenerExecutor;
+
+ protected AbstractConcurrentDataBrokerTest() {
+ this(false);
+ }
+
+ protected AbstractConcurrentDataBrokerTest(final boolean useMTDataTreeChangeListenerExecutor) {
+ this.useMTDataTreeChangeListenerExecutor = useMTDataTreeChangeListenerExecutor;
+ }
@Override
protected AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
@Override
protected AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
- return new ConcurrentDataBrokerTestCustomizer();
+ ConcurrentDataBrokerTestCustomizer customizer = new ConcurrentDataBrokerTestCustomizer();
+ if (useMTDataTreeChangeListenerExecutor) {
+ customizer.useMTDataTreeChangeListenerExecutor();
+ }
+
+ return customizer;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
+import javassist.ClassPool;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.md.sal.binding.api.NotificationService;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.md.sal.binding.api.NotificationService;
import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import javassist.ClassPool;
public abstract class AbstractDataBrokerTestCustomizer {
public abstract class AbstractDataBrokerTestCustomizer {
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", MoreExecutors.newDirectExecutorService());
+ final InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", dataTreeChangeListenerExecutor);
this.schemaService.registerSchemaContextListener(store);
return store;
}
public DOMStore createOperationalDatastore() {
this.schemaService.registerSchemaContextListener(store);
return store;
}
public DOMStore createOperationalDatastore() {
- final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService());
+ final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", dataTreeChangeListenerExecutor);
this.schemaService.registerSchemaContextListener(store);
return store;
}
this.schemaService.registerSchemaContextListener(store);
return store;
}
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);
}
*/
package org.opendaylight.controller.md.sal.binding.test;
*/
package org.opendaylight.controller.md.sal.binding.test;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.util.concurrent.SettableFuture;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
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.binding.api.DataChangeListener;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import com.google.common.util.concurrent.SettableFuture;
-
public abstract class AbstractDataChangeListenerTest extends AbstractConcurrentDataBrokerTest {
protected static final class TestListener implements DataChangeListener {
private final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event;
public abstract class AbstractDataChangeListenerTest extends AbstractConcurrentDataBrokerTest {
protected static final class TestListener implements DataChangeListener {
private final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event;
- private boolean capture = false;
+ private final CountDownLatch initialEventLatch;
+ private volatile boolean capture = false;
- private TestListener() {
+ private TestListener(boolean expectInitialEvent) {
event = SettableFuture.create();
event = SettableFuture.create();
+ initialEventLatch = new CountDownLatch(expectInitialEvent ? 1 : 0);
}
@Override
public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> arg) {
if (capture) {
event.set(arg);
}
@Override
public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> arg) {
if (capture) {
event.set(arg);
+ } else {
+ initialEventLatch.countDown();
- public void startCapture() {
+ private void waitForInitialEvent() {
+ try {
+ assertTrue("Initial DataChangeEvent was not received", initialEventLatch.await(3, TimeUnit.SECONDS));
+ } catch (InterruptedException e) {
+ throw new IllegalStateException(e);
+ }
+
+ protected AbstractDataChangeListenerTest() {
+ super(true);
+ }
+
protected final TestListener createListener(final LogicalDatastoreType store, final InstanceIdentifier<?> path,
final DataChangeScope scope) {
protected final TestListener createListener(final LogicalDatastoreType store, final InstanceIdentifier<?> path,
final DataChangeScope scope) {
- TestListener listener = new TestListener();
+ return createListener(store, path, scope, true);
+ }
+
+ protected final TestListener createListener(final LogicalDatastoreType store, final InstanceIdentifier<?> path,
+ final DataChangeScope scope, boolean expectInitialEvent) {
+ TestListener listener = new TestListener(expectInitialEvent);
getDataBroker().registerDataChangeListener(store, path, listener, scope);
getDataBroker().registerDataChangeListener(store, path, listener, scope);
- listener.startCapture();
+ listener.waitForInitialEvent();
/**
* ConcurrentDataBrokerTestCustomizer.
*
/**
* ConcurrentDataBrokerTestCustomizer.
*
- * <p>See {@link AbstractConcurrentDataBrokerTest} and <a href="https://bugs.opendaylight.org/show_bug.cgi?id=7538">bug 7538</a> for more details & background.
+ * <p>See {@link AbstractConcurrentDataBrokerTest} and
+ * <a href="https://bugs.opendaylight.org/show_bug.cgi?id=7538">bug 7538</a> for more details & background.
*
* @author Michael Vorburger
*/
*
* @author Michael Vorburger
*/
public ListeningExecutorService getCommitCoordinatorExecutor() {
return MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
public ListeningExecutorService getCommitCoordinatorExecutor() {
return MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
+
+ public void useMTDataTreeChangeListenerExecutor() {
+ setDataTreeChangeListenerExecutor(MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()));
+ }
public ListeningExecutorService getCommitCoordinatorExecutor() {
return MoreExecutors.newDirectExecutorService();
}
public ListeningExecutorService getCommitCoordinatorExecutor() {
return MoreExecutors.newDirectExecutorService();
}