Add a wrapping DataBroker test wiring ... 45/79945/1
authorStephen Kitt <skitt@redhat.com>
Mon, 28 Jan 2019 09:51:46 +0000 (10:51 +0100)
committerStephen Kitt <skitt@redhat.com>
Mon, 28 Jan 2019 09:51:46 +0000 (10:51 +0100)
which wraps an MD-SAL DataBroker with a Controller DataBroker for test
purposes. (This will be removed once the migration is complete in
Genius and NetVirt.)

Change-Id: I7b8e9316d9e12f6c4252c6d64dfaeb3f482616c3
Signed-off-by: Stephen Kitt <skitt@redhat.com>
mdsalutil/mdsalutil-testutils/src/main/java/org/opendaylight/genius/datastoreutils/testutils/WrappingDataBrokerTestWiring.java [new file with mode: 0644]

diff --git a/mdsalutil/mdsalutil-testutils/src/main/java/org/opendaylight/genius/datastoreutils/testutils/WrappingDataBrokerTestWiring.java b/mdsalutil/mdsalutil-testutils/src/main/java/org/opendaylight/genius/datastoreutils/testutils/WrappingDataBrokerTestWiring.java
new file mode 100644 (file)
index 0000000..02926d2
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright © 2019 Red Hat, Inc. and others.
+ *
+ * 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.genius.datastoreutils.testutils;
+
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+import java.util.concurrent.Executors;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.test.AbstractBaseDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTestCustomizer;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+import org.opendaylight.controller.sal.core.compat.LegacyDOMDataBrokerAdapter;
+
+/**
+ * Legacy (Controller) DataBroker test wiring which wraps an MD-SAL DataBroker.
+ */
+public class WrappingDataBrokerTestWiring {
+    private final AbstractBaseDataBrokerTest test;
+
+    public WrappingDataBrokerTestWiring(org.opendaylight.mdsal.dom.api.DOMDataBroker domDataBroker) throws Exception {
+        test = new AbstractBaseDataBrokerTest() {
+            @Override
+            protected AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
+                return new AbstractDataBrokerTestCustomizer() {
+                    @Override
+                    public ListeningExecutorService getCommitCoordinatorExecutor() {
+                        return MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
+                    }
+
+                    @Override
+                    public DOMDataBroker createDOMDataBroker() {
+                        return new LegacyDOMDataBrokerAdapter(domDataBroker);
+                    }
+                };
+            }
+        };
+        test.setup();
+    }
+
+    public DataBroker getDataBroker() {
+        return test.getDataBroker();
+    }
+}