Fix the UnimgrIT test instability at source. 36/39936/1
authorDonald Hunter <donaldh@cisco.com>
Tue, 7 Jun 2016 10:33:39 +0000 (11:33 +0100)
committerDonald Hunter <donaldh@cisco.com>
Tue, 7 Jun 2016 10:34:07 +0000 (11:34 +0100)
The change listener was handling changes as adds, causing a feedback loop.

Change-Id: Icac5ef9b498a24876f20b1bbbfbb0f69d6e199c7
Signed-off-by: Donald Hunter <donaldh@cisco.com>
impl/src/main/java/org/opendaylight/unimgr/api/UnimgrDataTreeChangeListener.java
impl/src/main/java/org/opendaylight/unimgr/impl/UniDataTreeChangeListener.java
it/src/test/java/org/opendaylight/unimgr/it/UnimgrIT.java

index 8703d59557d93e4da46b72f580335f00b70682b9..5f40056b7b038d1264c6a9fbd2cdc524a65b7094 100644 (file)
@@ -42,7 +42,13 @@ public abstract class UnimgrDataTreeChangeListener<D extends DataObject>
                     update(change);
                     break;
                 case WRITE:
-                    add(change);
+                    // Treat an overwrite as an update
+                    boolean update = change.getRootNode().getDataBefore() != null;
+                    if (update) {
+                        update(change);
+                    } else {
+                        add(change);
+                    }
                     break;
                 case DELETE:
                     remove(change);
index cff249643aab62699e303bb60c80766ad5fcb039..94577503b559a00e4f6ec952ac9efc0f3d019434 100644 (file)
@@ -74,7 +74,7 @@ public class UniDataTreeChangeListener extends UnimgrDataTreeChangeListener<Node
     @Override
     public void update(final DataTreeModification<Node> modifiedDataObject) {
         if (modifiedDataObject.getRootPath() != null && modifiedDataObject.getRootNode() != null) {
-            LOG.info("uni node {} created", modifiedDataObject.getRootNode().getIdentifier());
+            LOG.info("uni node {} updated", modifiedDataObject.getRootNode().getIdentifier());
             final UniUpdateCommand uniUpdateCmd = new UniUpdateCommand(dataBroker, modifiedDataObject);
             uniUpdateCmd.execute();
         }
index a50d7be6279cb620aef8615a71e0aaaf9af13b7f..0f53eabf593be96e51c5498bba334a40aae0cea0 100644 (file)
@@ -83,7 +83,6 @@ public class UnimgrIT extends AbstractMdsalTestBase {
     private static final String IP_1 = "10.0.0.1";
     private static final String IP_2 = "10.0.0.2";
     private static final String EVC_ID_1 = "1";
-    private static final int MAX_RETRIES = 5;
 
     @Override
     public void setup() throws Exception {
@@ -224,25 +223,22 @@ public class UnimgrIT extends AbstractMdsalTestBase {
 
         NodeId uniNodeId = new NodeId(new NodeId("uni://" + uni.getIpAddress().getIpv4Address().getValue().toString()));
         InstanceIdentifier<Node> uniNodeIid = null;
-            uniNodeIid = getUniIid("uni://" + uni.getIpAddress().getIpv4Address().getValue().toString());
-            NodeKey uniNodeKey = new NodeKey(uniNodeId);
-            Node nodeData = new NodeBuilder()
+        uniNodeIid = getUniIid("uni://" + uni.getIpAddress().getIpv4Address().getValue().toString());
+        NodeKey uniNodeKey = new NodeKey(uniNodeId);
+        Node nodeData = new NodeBuilder()
                                     .setNodeId(uniNodeId)
                                     .setKey(uniNodeKey)
                                     .addAugmentation(UniAugmentation.class, uni)
                                     .build();
-        for (int i = 0; i < MAX_RETRIES; i++) {
-            WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
-            try {
-                writeUNI(uniNodeIid, nodeData, transaction);
-                LOG.info("Created and submitted a new Uni node {}", nodeData.getNodeId());
-                return uniNodeIid;
-            } catch (Exception e) {
-                transaction.cancel();
-                LOG.warn("Exception while creating Uni Node" + "Uni Node Id: {}, {} retrying", uniNodeId, e);
-            }
+        WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+        try {
+            writeUNI(uniNodeIid, nodeData, transaction);
+            LOG.info("Created and submitted a new Uni node {}", nodeData.getNodeId());
+            return uniNodeIid;
+        } catch (Exception e) {
+            transaction.cancel();
+            LOG.error("Could not create Uni Node - Id: {}, {}", uniNodeId, e);
         }
-        LOG.error("Couldn't create Uni Node" + "Uni Node Id: {}", uniNodeId);
         return null;
     }