import com.google.common.util.concurrent.SettableFuture;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
-public class DataTreeChangeListenerTest extends AbstractDataBrokerTest {
+public class DataTreeChangeListenerTest extends AbstractConcurrentDataBrokerTest {
private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
- private static final PathArgument TOP_ARGUMENT= TOP_PATH.getPathArguments().iterator().next();
+ private static final PathArgument TOP_ARGUMENT = TOP_PATH.getPathArguments().iterator().next();
private static final InstanceIdentifier<TopLevelList> FOO_PATH = path(TOP_FOO_KEY);
private static final PathArgument FOO_ARGUMENT = Iterables.getLast(FOO_PATH.getPathArguments());
private static final TopLevelList FOO_DATA = topLevelList(TOP_FOO_KEY, complexUsesAugment(USES_ONE_KEY));
);
}
- @Override
- protected void setupWithDataBroker(final DataBroker dataBroker) {
- dataBrokerImpl = (BindingDOMDataBrokerAdapter) dataBroker;
+ @Before
+ public void setupWithDataBroker() {
+ dataBrokerImpl = (BindingDOMDataBrokerAdapter) getDataBroker();
}
@Test
import com.google.common.collect.ImmutableSet;
import java.util.concurrent.ExecutionException;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.compat.HydrogenDataBrokerAdapter;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.binding.test.DataBrokerTestCustomizer;
import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
@Deprecated
-public class ForwardedBackwardsCompatibleDataBrokerTest extends
- AbstractDataBrokerTest {
+public class ForwardedBackwardsCompatibleDataBrokerTest extends AbstractConcurrentDataBrokerTest {
private HydrogenDataBrokerAdapter dataBroker;
private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
return new DataBrokerTestCustomizer();
}
- @Override
- protected void setupWithDataBroker(final DataBroker dataBroker) {
- super.setupWithDataBroker(dataBroker);
- this.dataBroker = new HydrogenDataBrokerAdapter(dataBroker);
+ @Before
+ public void setupWithDataBroker() {
+ this.dataBroker = new HydrogenDataBrokerAdapter(getDataBroker());
}
-
-
-
/**
* The purpose of this test is to exercise the backwards compatible broker
* <p>
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.Before;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
- *
* 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
- *
- *
*/
public class ListInsertionDataChangeListenerTest extends AbstractDataChangeListenerTest{
private static final InstanceIdentifier<TopLevelList> TOP_FOO = TOP.child(TopLevelList.class, TOP_FOO_KEY);
private static final InstanceIdentifier<TopLevelList> TOP_BAR = TOP.child(TopLevelList.class, TOP_BAR_KEY);
-
- @Override
- protected void setupWithDataBroker(final DataBroker dataBroker) {
- WriteTransaction initialTx = dataBroker.newWriteOnlyTransaction();
+ @Before
+ public void setupWithDataBroker() {
+ WriteTransaction initialTx = getDataBroker().newWriteOnlyTransaction();
initialTx.put(CONFIGURATION, TOP, top(topLevelList(TOP_FOO_KEY)));
assertCommit(initialTx.submit());
}
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
import com.google.common.base.Optional;
-public class WriteTransactionTest extends AbstractDataBrokerTest {
+public class WriteTransactionTest extends AbstractConcurrentDataBrokerTest {
private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
private static final TopLevelListKey TOP_LIST_KEY = new TopLevelListKey("foo");
private static final InstanceIdentifier<TopLevelList> NODE_PATH = TOP_PATH.child(TopLevelList.class, TOP_LIST_KEY);
private static final TopLevelList NODE = new TopLevelListBuilder().setKey(TOP_LIST_KEY).build();
+
@Test
public void test() throws InterruptedException, ExecutionException {
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
@Test
public void testPutCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
-
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
writeTx.submit().checkedGet();
@Test
public void testMergeCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
-
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
writeTx.submit().checkedGet();
--- /dev/null
+/*
+ * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.test;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public abstract class AbstractBaseDataBrokerTest extends AbstractSchemaAwareTest {
+
+ private static final int ASSERT_COMMIT_DEFAULT_TIMEOUT = 5000;
+
+ private AbstractDataBrokerTestCustomizer testCustomizer;
+ private DataBroker dataBroker;
+ private DOMDataBroker domBroker;
+
+ protected abstract AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer();
+
+ @Override
+ protected void setupWithSchema(final SchemaContext context) {
+ testCustomizer = createDataBrokerTestCustomizer();
+ dataBroker = testCustomizer.createDataBroker();
+ domBroker = testCustomizer.createDOMDataBroker();
+ testCustomizer.updateSchema(context);
+ }
+
+ public DataBroker getDataBroker() {
+ return dataBroker;
+ }
+
+ public DOMDataBroker getDomBroker() {
+ return domBroker;
+ }
+
+ protected static final void assertCommit(final ListenableFuture<Void> commit) {
+ assertCommit(commit, ASSERT_COMMIT_DEFAULT_TIMEOUT);
+ }
+
+ protected static final void assertCommit(final ListenableFuture<Void> commit, long timeoutInMS) {
+ try {
+ commit.get(timeoutInMS, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.test;
+
+/**
+ * AbstractConcurrentDataBrokerTest.
+ *
+ * <p>Uses single thread executor for the Serialized DOM DataBroker (instead of the
+ * direct executor used by the {@literal @}Deprecated AbstractDataBrokerTest) in order
+ * to allow tests to use the DataBroker concurrently from several threads.
+ *
+ * <p>See also <a href="https://bugs.opendaylight.org/show_bug.cgi?id=7538">bug 7538</a> for more details.
+ *
+ * @author Michael Vorburger
+ */
+public abstract class AbstractConcurrentDataBrokerTest extends AbstractBaseDataBrokerTest {
+
+ @Override
+ protected AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
+ return new ConcurrentDataBrokerTestCustomizer();
+ }
+
+}
*/
package org.opendaylight.controller.md.sal.binding.test;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import com.google.common.util.concurrent.ListenableFuture;
-
-public class AbstractDataBrokerTest extends AbstractSchemaAwareTest {
-
- private DataBrokerTestCustomizer testCustomizer;
- private DataBroker dataBroker;
- private DOMDataBroker domBroker;
-
+/**
+ * AbstractDataBrokerTest.
+ *
+ * @deprecated Please now use the AbstractConcurrentDataBrokerTest instead of
+ * this. Normally in a well written test this should be a drop-in
+ * replacement. Instead of {@literal @}Override
+ * setupWithDataBroker(DataBroker dataBroker), please just use
+ * JUnit's {@literal @}Before before() { ... getDataBroker() }. Some
+ * tests which relied on the Test DataBroker being synchronous,
+ * contrary to its specification as well as the production
+ * implementation, may require changes to e.g. use get() on
+ * submit()'ed transaction to make the test wait before asserts. See
+ * also
+ * <a href="https://bugs.opendaylight.org/show_bug.cgi?id=7538">bug
+ * 7538</a> for more details.
+ */
+@Deprecated
+public class AbstractDataBrokerTest extends AbstractBaseDataBrokerTest {
@Override
- protected void setupWithSchema(final SchemaContext context) {
- testCustomizer = createDataBrokerTestCustomizer();
- dataBroker = testCustomizer.createDataBroker();
- domBroker = testCustomizer.createDOMDataBroker();
- testCustomizer.updateSchema(context);
- setupWithDataBroker(dataBroker);
- }
-
- protected void setupWithDataBroker(final DataBroker dataBroker) {
- // Intentionally left No-op, subclasses may customize it
- }
-
- protected DataBrokerTestCustomizer createDataBrokerTestCustomizer() {
+ protected AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
return new DataBrokerTestCustomizer();
}
- public DataBroker getDataBroker() {
- return dataBroker;
- }
-
- public DOMDataBroker getDomBroker() {
- return domBroker;
+ @Override
+ protected void setupWithSchema(SchemaContext context) {
+ super.setupWithSchema(context);
+ setupWithDataBroker(getDataBroker());
}
- protected static final void assertCommit(final ListenableFuture<Void> commit) {
- try {
- commit.get(500, TimeUnit.MILLISECONDS);
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
- throw new IllegalStateException(e);
- }
+ protected void setupWithDataBroker(final DataBroker dataBroker) {
+ // Intentionally left No-op, subclasses may customize it
}
-
}
--- /dev/null
+/*
+ * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.test;
+
+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.impl.BindingDOMDataBrokerAdapter;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationServiceAdapter;
+import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter;
+import org.opendaylight.controller.md.sal.dom.broker.impl.SerializedDOMDataBroker;
+import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
+import org.opendaylight.controller.sal.binding.test.util.MockSchemaService;
+import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.controller.sal.core.spi.data.DOMStore;
+import org.opendaylight.yangtools.binding.data.codec.gen.impl.DataObjectSerializerGenerator;
+import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
+import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
+import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
+import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public abstract class AbstractDataBrokerTestCustomizer {
+
+ private DOMDataBroker domDataBroker;
+ private final DOMNotificationRouter domNotificationRouter;
+ private final MockSchemaService schemaService;
+ private ImmutableMap<LogicalDatastoreType, DOMStore> datastores;
+ private final BindingToNormalizedNodeCodec bindingToNormalized;
+
+ public ImmutableMap<LogicalDatastoreType, DOMStore> createDatastores() {
+ return ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
+ .put(LogicalDatastoreType.OPERATIONAL, createOperationalDatastore())
+ .put(LogicalDatastoreType.CONFIGURATION,createConfigurationDatastore())
+ .build();
+ }
+
+ public AbstractDataBrokerTestCustomizer() {
+ schemaService = new MockSchemaService();
+ final ClassPool pool = ClassPool.getDefault();
+ final DataObjectSerializerGenerator generator = StreamWriterGenerator.create(JavassistUtils.forClassPool(pool));
+ final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(generator);
+ final GeneratedClassLoadingStrategy loading = GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy();
+ bindingToNormalized = new BindingToNormalizedNodeCodec(loading, codecRegistry);
+ schemaService.registerSchemaContextListener(bindingToNormalized);
+ domNotificationRouter = DOMNotificationRouter.create(16);
+ }
+
+ public DOMStore createConfigurationDatastore() {
+ final InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", MoreExecutors.newDirectExecutorService());
+ schemaService.registerSchemaContextListener(store);
+ return store;
+ }
+
+ public DOMStore createOperationalDatastore() {
+ final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService());
+ schemaService.registerSchemaContextListener(store);
+ return store;
+ }
+
+ public DOMDataBroker createDOMDataBroker() {
+ return new SerializedDOMDataBroker(getDatastores(), getCommitCoordinatorExecutor());
+ }
+
+ public NotificationService createNotificationService() {
+ return new BindingDOMNotificationServiceAdapter(bindingToNormalized.getCodecRegistry(), domNotificationRouter);
+ }
+
+ public NotificationPublishService createNotificationPublishService() {
+ return new BindingDOMNotificationPublishServiceAdapter(bindingToNormalized, domNotificationRouter);
+ }
+
+ public abstract ListeningExecutorService getCommitCoordinatorExecutor();
+
+ public DataBroker createDataBroker() {
+ return new BindingDOMDataBrokerAdapter(getDOMDataBroker(), bindingToNormalized);
+ }
+
+ public BindingToNormalizedNodeCodec getBindingToNormalized() {
+ return bindingToNormalized;
+ }
+
+ public SchemaService getSchemaService() {
+ return schemaService;
+ }
+
+ private DOMDataBroker getDOMDataBroker() {
+ if (domDataBroker == null) {
+ domDataBroker = createDOMDataBroker();
+ }
+ return domDataBroker;
+ }
+
+ private synchronized ImmutableMap<LogicalDatastoreType, DOMStore> getDatastores() {
+ if (datastores == null) {
+ datastores = createDatastores();
+ }
+ return datastores;
+ }
+
+ public void updateSchema(final SchemaContext ctx) {
+ schemaService.changeSchema(ctx);
+ }
+
+ public DOMNotificationRouter getDomNotificationRouter() {
+ return domNotificationRouter;
+ }
+}
import com.google.common.util.concurrent.SettableFuture;
-public abstract class AbstractDataChangeListenerTest extends AbstractDataBrokerTest {
+public abstract class AbstractDataChangeListenerTest extends AbstractConcurrentDataBrokerTest {
protected static final class TestListener implements DataChangeListener {
import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public class AbstractNotificationBrokerTest extends AbstractSchemaAwareTest{
+public class AbstractNotificationBrokerTest extends AbstractSchemaAwareTest {
+
private BindingToNormalizedNodeCodec bindingToNormalizedNodeCodec;
private DOMNotificationRouter domNotificationRouter;
private NotificationService notificationService;
private NotificationPublishService notificationPublishService;
-
@Override
protected void setupWithSchema(final SchemaContext context) {
final DataBrokerTestCustomizer testCustomizer = createDataBrokerTestCustomizer();
--- /dev/null
+/*
+ * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.test;
+
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+import java.util.concurrent.Executors;
+
+/**
+ * ConcurrentDataBrokerTestCustomizer.
+ *
+ * <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
+ */
+public class ConcurrentDataBrokerTestCustomizer extends AbstractDataBrokerTestCustomizer {
+
+ @Override
+ public ListeningExecutorService getCommitCoordinatorExecutor() {
+ return MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
+ }
+}
*
* @author Michael Vorburger
*/
-public class ConstantSchemaAbstractDataBrokerTest extends AbstractDataBrokerTest {
+public class ConstantSchemaAbstractDataBrokerTest extends AbstractConcurrentDataBrokerTest {
@Override
protected SchemaContext getSchemaContext() throws Exception {
*/
package org.opendaylight.controller.md.sal.binding.test;
-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.impl.BindingDOMDataBrokerAdapter;
-import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter;
-import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationServiceAdapter;
-import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter;
-import org.opendaylight.controller.md.sal.dom.broker.impl.SerializedDOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
-import org.opendaylight.controller.sal.binding.test.util.MockSchemaService;
-import org.opendaylight.controller.sal.core.api.model.SchemaService;
-import org.opendaylight.controller.sal.core.spi.data.DOMStore;
-import org.opendaylight.yangtools.binding.data.codec.gen.impl.DataObjectSerializerGenerator;
-import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
-import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
-import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
-import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-
-public class DataBrokerTestCustomizer {
-
- private DOMDataBroker domDataBroker;
- private final DOMNotificationRouter domNotificationRouter;
- private final MockSchemaService schemaService;
- private ImmutableMap<LogicalDatastoreType, DOMStore> datastores;
- private final BindingToNormalizedNodeCodec bindingToNormalized;
-
- public ImmutableMap<LogicalDatastoreType, DOMStore> createDatastores() {
- return ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
- .put(LogicalDatastoreType.OPERATIONAL, createOperationalDatastore())
- .put(LogicalDatastoreType.CONFIGURATION,createConfigurationDatastore())
- .build();
- }
-
- public DataBrokerTestCustomizer() {
- schemaService = new MockSchemaService();
- final ClassPool pool = ClassPool.getDefault();
- final DataObjectSerializerGenerator generator = StreamWriterGenerator.create(JavassistUtils.forClassPool(pool));
- final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(generator);
- final GeneratedClassLoadingStrategy loading = GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy();
- bindingToNormalized = new BindingToNormalizedNodeCodec(loading, codecRegistry);
- schemaService.registerSchemaContextListener(bindingToNormalized);
- domNotificationRouter = DOMNotificationRouter.create(16);
- }
-
- public DOMStore createConfigurationDatastore() {
- final InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", MoreExecutors.newDirectExecutorService());
- schemaService.registerSchemaContextListener(store);
- return store;
- }
-
- public DOMStore createOperationalDatastore() {
- final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService());
- schemaService.registerSchemaContextListener(store);
- return store;
- }
-
- public DOMDataBroker createDOMDataBroker() {
- return new SerializedDOMDataBroker(getDatastores(), getCommitCoordinatorExecutor());
- }
-
- public NotificationService createNotificationService() {
- return new BindingDOMNotificationServiceAdapter(bindingToNormalized.getCodecRegistry(), domNotificationRouter);
- }
-
- public NotificationPublishService createNotificationPublishService() {
- return new BindingDOMNotificationPublishServiceAdapter(bindingToNormalized, domNotificationRouter);
- }
+/**
+ * DataBrokerTestCustomizer.
+ *
+ * @deprecated Please use the ConcurrentDataBrokerTestCustomizer instead of
+ * this; see AbstractDataBrokerTest for more details.
+ */
+@Deprecated
+public class DataBrokerTestCustomizer extends AbstractDataBrokerTestCustomizer {
+ @Override
public ListeningExecutorService getCommitCoordinatorExecutor() {
return MoreExecutors.newDirectExecutorService();
}
- public DataBroker createDataBroker() {
- return new BindingDOMDataBrokerAdapter(getDOMDataBroker(), bindingToNormalized);
- }
-
- public BindingToNormalizedNodeCodec getBindingToNormalized() {
- return bindingToNormalized;
- }
-
- public SchemaService getSchemaService() {
- return schemaService;
- }
-
- private DOMDataBroker getDOMDataBroker() {
- if(domDataBroker == null) {
- domDataBroker = createDOMDataBroker();
- }
- return domDataBroker;
- }
-
- private synchronized ImmutableMap<LogicalDatastoreType, DOMStore> getDatastores() {
- if (datastores == null) {
- datastores = createDatastores();
- }
- return datastores;
- }
-
- public void updateSchema(final SchemaContext ctx) {
- schemaService.changeSchema(ctx);
- }
-
- public DOMNotificationRouter getDomNotificationRouter() {
- return domNotificationRouter;
- }
}
import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path;
import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
+import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
* @author Michael Vorburger
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class AbstractDataBrokerTestTest extends AbstractDataBrokerTest {
+public class AbstractDataBrokerTestTest extends AbstractConcurrentDataBrokerTest {
private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
+ @Before
+ public void before() {
+ assertThat(getDataBroker()).isNotNull();
+ }
+
@Test
public void aEnsureDataBrokerIsNotNull() {
assertThat(getDataBroker()).isNotNull();