NETVIRT-1630 migrate to md-sal APIs
[netvirt.git] / elanmanager / impl / src / test / java / org / opendaylight / netvirt / elan / l2gw / nodehandlertest / NodeConnectedHandlerTest.java
index a62950a926a9121879d8ce25cc922ba7abe82b40..fdebbd4c89b7e2750bc9fd9d610500e91c10a554 100644 (file)
@@ -7,18 +7,21 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.nodehandlertest;
 
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
 
-import com.google.common.base.Optional;
+import java.util.Optional;
 import java.util.UUID;
 import org.junit.Assert;
 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.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
+import org.mockito.Mockito;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netvirt.elan.l2gw.ha.handlers.NodeConnectedHandler;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
@@ -45,9 +48,8 @@ public class NodeConnectedHandlerTest extends AbstractConcurrentDataBrokerTest {
     // public @Rule RunUntilFailureRule repeater = new RunUntilFailureRule(classRepeater);
 
     static Logger LOG = LoggerFactory.getLogger(NodeConnectedHandlerTest.class);
-    DataBroker dataBroker;
 
-    NodeConnectedHandler nodeConnectedHandler = new NodeConnectedHandler(this.dataBroker);
+    NodeConnectedHandler nodeConnectedHandler;
     NodeConnectedHandlerUtils handlerUtils = new NodeConnectedHandlerUtils();
 
     String d1UUID;
@@ -84,7 +86,6 @@ public class NodeConnectedHandlerTest extends AbstractConcurrentDataBrokerTest {
 
     @Before
     public void setupForHANode() {
-        dataBroker = getDataBroker();
         d1UUID = java.util.UUID.nameUUIDFromBytes("d1uuid".getBytes()).toString();
         d2UUID = java.util.UUID.nameUUIDFromBytes("d2uuid".getBytes()).toString();
         d1NodePath = getInstanceIdentifier(d1UUID);
@@ -102,33 +103,39 @@ public class NodeConnectedHandlerTest extends AbstractConcurrentDataBrokerTest {
         d2PsNodePath = createInstanceIdentifier(d2PsNodeIdVal);
 
         haPsNodePath = createInstanceIdentifier(haNodeId.getValue() + "/physicalswitch/" + switchName);
+
+        nodeConnectedHandler = new NodeConnectedHandler(getDataBroker(), Mockito.mock(HwvtepNodeHACache.class));
     }
 
     @Test
     public void testD1Connect() throws Exception {
-        ReadWriteTransaction tx = this.dataBroker.newReadWriteTransaction();
-        handlerUtils.addPsNode(d1PsNodePath, d1NodePath, DataProvider.getPortNameListD1(), tx).checkedGet();
+        ManagedNewTransactionRunner txRunner = new ManagedNewTransactionRunnerImpl(getDataBroker());
+        txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL,
+            tx -> handlerUtils.addPsNode(d1PsNodePath, d1NodePath, DataProvider.getPortNameListD1(), tx)).get();
 
-        tx = this.dataBroker.newReadWriteTransaction();
-        handlerUtils.addNode(d1NodePath, d1PsNodePath, DataProvider.getLogicalSwitchDataD1(),
+        txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL,
+            tx -> handlerUtils.addNode(d1NodePath, d1PsNodePath, DataProvider.getLogicalSwitchDataD1(),
                 DataProvider.getLocalUcasMacDataD1(), DataProvider.getLocalMcastDataD1(),
                 DataProvider.getRemoteMcastDataD1(), DataProvider.getRemoteUcasteMacDataD1(),
-                DataProvider.getGlobalTerminationPointIpD1(), tx).checkedGet();
+                DataProvider.getGlobalTerminationPointIpD1(), tx)).get();
 
         readNodes();
-        tx = this.dataBroker.newReadWriteTransaction();
-        nodeConnectedHandler.handleNodeConnected(d1GlobalOpNode.get(), d1NodePath, haNodePath, haGlobalConfigNode,
-                haPsConfigNode, tx);
-        tx.submit().checkedGet();
+        txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+            confTx -> txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL,
+                operTx -> nodeConnectedHandler.handleNodeConnected(d1GlobalOpNode.get(), d1NodePath, haNodePath,
+                    haGlobalConfigNode, haPsConfigNode, confTx, operTx)).get()).get();
         readNodes();
         //verify global ha manager config should have ha_children
-        Assert.assertTrue(haGlobalConfigNode.isPresent() && d1GlobalOpNode.isPresent());
+        Assert.assertTrue(haGlobalConfigNode.isPresent());
+        Assert.assertTrue(d1GlobalOpNode.isPresent());
         TestUtil.verifyHAconfigNode(haGlobalConfigNode.get(), d1GlobalOpNode.get());
 
-        Assert.assertTrue(d1GlobalOpNode.isPresent() && haGlobalOpNode.isPresent() && d1PsOpNode.isPresent()
-                && haPsOpNode.isPresent());
+        Assert.assertTrue(d1GlobalOpNode.isPresent());
+        Assert.assertTrue(haGlobalOpNode.isPresent());
+        Assert.assertTrue(d1PsOpNode.isPresent());
+        Assert.assertTrue(haPsOpNode.isPresent());
         TestUtil.verifyHAOpNode(d1GlobalOpNode.get(), haGlobalOpNode.get(),
-                d1PsOpNode.get(), haPsOpNode.get(), haNodePath, d1PsNodePath, haPsNodePath, haNodeId, this.dataBroker);
+                d1PsOpNode.get(), haPsOpNode.get(), haNodePath, d1PsNodePath, haPsNodePath, getDataBroker());
     }
 
     public static InstanceIdentifier<Node> createInstanceIdentifier(String nodeIdString) {
@@ -157,22 +164,22 @@ public class NodeConnectedHandlerTest extends AbstractConcurrentDataBrokerTest {
     }
 
     public void readNodes() throws Exception {
-        ReadOnlyTransaction tx = this.dataBroker.newReadOnlyTransaction();
-        d1GlobalOpNode = TestUtil.readNode(OPERATIONAL, d1NodePath, tx);
-        d2GlobalOpNode = TestUtil.readNode(OPERATIONAL, d2NodePath, tx);
-        haGlobalOpNode = TestUtil.readNode(OPERATIONAL, haNodePath, tx);
-
-        d1PsOpNode = TestUtil.readNode(OPERATIONAL, d1PsNodePath, tx);
-        d2PsOpNode = TestUtil.readNode(OPERATIONAL, d2PsNodePath, tx);
-        haPsOpNode = TestUtil.readNode(OPERATIONAL, haPsNodePath, tx);
-
-        haGlobalConfigNode = TestUtil.readNode(CONFIGURATION, haNodePath, tx);
-        d1GlobalConfigNode = TestUtil.readNode(CONFIGURATION, d1NodePath, tx);
-        d2GlobalConfigNode = TestUtil.readNode(CONFIGURATION, d2NodePath, tx);
-
-        haPsConfigNode = TestUtil.readNode(CONFIGURATION, haPsNodePath, tx);
-        d1PsConfigNode = TestUtil.readNode(CONFIGURATION, d1PsNodePath, tx);
-        d2PsConfigNode = TestUtil.readNode(CONFIGURATION, d2PsNodePath, tx);
+        ReadTransaction tx = getDataBroker().newReadOnlyTransaction();
+        d1GlobalOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d1NodePath, tx);
+        d2GlobalOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d2NodePath, tx);
+        haGlobalOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, haNodePath, tx);
+
+        d1PsOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d1PsNodePath, tx);
+        d2PsOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d2PsNodePath, tx);
+        haPsOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, haPsNodePath, tx);
+
+        haGlobalConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, haNodePath, tx);
+        d1GlobalConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d1NodePath, tx);
+        d2GlobalConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d2NodePath, tx);
+
+        haPsConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, haPsNodePath, tx);
+        d1PsConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d1PsNodePath, tx);
+        d2PsConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d2PsNodePath, tx);
 
         tx.close();
     }