X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Fovsdb-it-utils%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fovsdb%2Futils%2Fovsdb%2Fit%2Futils%2FNodeInfo.java;h=b5d69c3cdaa4ca33c31d62a9b3414afa5c455026;hb=80ca55c9ce626a6a91b4bfbf583fdbdd7cef142c;hp=5f81aa3e24adb6f737d11292c635d0c12f730062;hpb=58044263d7dda8ee0363f356ce4fd39ae1ef55d8;p=ovsdb.git diff --git a/utils/ovsdb-it-utils/src/main/java/org/opendaylight/ovsdb/utils/ovsdb/it/utils/NodeInfo.java b/utils/ovsdb-it-utils/src/main/java/org/opendaylight/ovsdb/utils/ovsdb/it/utils/NodeInfo.java index 5f81aa3e2..b5d69c3cd 100644 --- a/utils/ovsdb-it-utils/src/main/java/org/opendaylight/ovsdb/utils/ovsdb/it/utils/NodeInfo.java +++ b/utils/ovsdb-it-utils/src/main/java/org/opendaylight/ovsdb/utils/ovsdb/it/utils/NodeInfo.java @@ -14,8 +14,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.util.List; - import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerNotifyingDataChangeListener; import org.opendaylight.ovsdb.utils.mdsal.utils.NotifyingDataChangeListener; import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo; @@ -32,16 +32,16 @@ public class NodeInfo { private static final Logger LOG = LoggerFactory.getLogger(NodeInfo.class); public static final String INTEGRATION_BRIDGE_NAME = "br-int"; - private ConnectionInfo connectionInfo; - private InstanceIdentifier ovsdbIid; - InstanceIdentifier bridgeIid; + private final ConnectionInfo connectionInfo; + private final InstanceIdentifier ovsdbIid; + private final InstanceIdentifier bridgeIid; public long datapathId; public Node ovsdbNode; public Node bridgeNode; - NotifyingDataChangeListener ovsdbWaiter; - NotifyingDataChangeListener bridgeWaiter; - List waitList; - OvsdbItUtils itUtils; + private ControllerNotifyingDataChangeListener ovsdbWaiter; + private ControllerNotifyingDataChangeListener bridgeWaiter; + private final List waitList; + private final OvsdbItUtils itUtils; /** * Create a new NodeInfo object. @@ -49,7 +49,8 @@ public class NodeInfo { * @param itUtils OvsdbItUtils instance * @param waitList for tracking outstanding md-sal events */ - NodeInfo(ConnectionInfo connectionInfo, OvsdbItUtils itUtils, List waitList) { + NodeInfo(ConnectionInfo connectionInfo, OvsdbItUtils itUtils, + List waitList) { this.connectionInfo = connectionInfo; this.itUtils = itUtils; this.waitList = waitList; @@ -57,16 +58,27 @@ public class NodeInfo { bridgeIid = SouthboundUtils.createInstanceIdentifier(connectionInfo, INTEGRATION_BRIDGE_NAME); } + private void addWaiters() { + ovsdbWaiter = new ControllerNotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, + ControllerNotifyingDataChangeListener.BIT_CREATE, ovsdbIid, waitList); + ovsdbWaiter.registerDataChangeListener(itUtils.dataBroker); + bridgeWaiter = new ControllerNotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, + ControllerNotifyingDataChangeListener.BIT_CREATE, bridgeIid, waitList); + bridgeWaiter.registerDataChangeListener(itUtils.dataBroker); + } + + private void closeWaiters() throws Exception { + ovsdbWaiter.close(); + bridgeWaiter.close(); + } + /** * Connect to the OVSDB node, wait for the connection to be established and for the integration bridge * to be successfully created. Contains assertions for unexpected states * @throws InterruptedException if interrupted while waiting for connection */ - public void connect() throws InterruptedException { - ovsdbWaiter = new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, ovsdbIid, waitList); - ovsdbWaiter.registerDataChangeListener(itUtils.dataBroker); - bridgeWaiter = new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, bridgeIid, waitList); - bridgeWaiter.registerDataChangeListener(itUtils.dataBroker); + public void connect() throws Exception { + addWaiters(); assertNotNull("connection failed", itUtils.southboundUtils.addOvsdbNode(connectionInfo, 0)); @@ -90,15 +102,16 @@ public class NodeInfo { * Remove integration bridge and teardown connection. Contains assertions for unexpected states. * @throws InterruptedException if interrupted while waiting for disconnect to complete */ - public void disconnect() throws InterruptedException { + public void disconnect() throws Exception { + ovsdbWaiter.setMask(NotifyingDataChangeListener.BIT_DELETE); + bridgeWaiter.setMask(NotifyingDataChangeListener.BIT_DELETE); assertTrue(itUtils.southboundUtils.deleteBridge(connectionInfo, INTEGRATION_BRIDGE_NAME, 0)); bridgeWaiter.waitForDeletion(); - Node bridgeNode = itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid); - assertNull("Bridge should not be found", bridgeNode); + assertNull("Bridge should not be found", itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid)); assertTrue(itUtils.southboundUtils.disconnectOvsdbNode(connectionInfo, 0)); ovsdbWaiter.waitForDeletion(); - Node ovsdbNode = itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, ovsdbIid); - assertNull("Ovsdb node should not be found", ovsdbNode); + assertNull("Ovsdb node should not be found", + itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, ovsdbIid)); + closeWaiters(); } - }