BUG 8525: Prevent NPE in test-app listeners 21/57621/3
authorTomas Cere <tcere@cisco.com>
Mon, 22 May 2017 11:22:46 +0000 (13:22 +0200)
committerRobert Varga <nite@hq.sk>
Sun, 28 May 2017 14:52:22 +0000 (14:52 +0000)
Prevents the NPE thrown when the listeners didn't
receive any notifications.

Change-Id: I0d774913a15b4341abce779c64d6ee8f75d6a0e1
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/IdIntsDOMDataTreeLIstener.java
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/IdIntsListener.java

index bea3bcd11f0c6f68c02c69cccc79c250bc2fc54c..240741cf2042948ad7517c930a71711eb16c9cce 100644 (file)
@@ -437,7 +437,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService
 
         if (flappingSingletonService != null) {
             final RpcError error = RpcResultBuilder.newError(
-                    ErrorType.RPC, "Registration present.", "flappin-singleton already registered");
+                    ErrorType.RPC, "Registration present.", "flapping-singleton already registered");
             return Futures.immediateFuture(RpcResultBuilder.<Void>failed().withRpcError(error).build());
         }
 
@@ -456,15 +456,19 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService
             return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
         }
 
-        final DOMDataReadOnlyTransaction rTx = domDataBroker.newReadOnlyTransaction();
-        try {
-            if (dtclReg != null) {
-                dtclReg.close();
-                dtclReg = null;
-            }
-
+        dtclReg.close();
+        dtclReg = null;
 
+        if (!idIntsListener.hasTriggered()) {
+            final RpcError error = RpcResultBuilder.newError(
+                    ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" +
+                            "any notifications.");
+            return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed()
+                    .withRpcError(error).build());
+        }
 
+        final DOMDataReadOnlyTransaction rTx = domDataBroker.newReadOnlyTransaction();
+        try {
             final Optional<NormalizedNode<?, ?>> readResult =
                     rTx.read(CONTROLLER_CONFIG, WriteTransactionsHandler.ID_INT_YID).checkedGet();
 
@@ -599,6 +603,14 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService
         ddtlReg.close();
         ddtlReg = null;
 
+        if (!idIntsDdtl.hasTriggered()) {
+            final RpcError error = RpcResultBuilder.newError(
+                    ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" +
+                            "any notifications.");
+            return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed()
+                    .withRpcError(error).build());
+        }
+
         final String shardName = ClusterUtils.getCleanShardName(ProduceTransactionsHandler.ID_INTS_YID);
         LOG.debug("Creating distributed datastore client for shard {}", shardName);
 
index 3f9a3c52f6a7426d05a700dd7e6ac7056c137fb9..4e1291e1ddf85628f5649e1361e7ce0c32d17fb8 100644 (file)
@@ -59,6 +59,10 @@ public class IdIntsDOMDataTreeLIstener implements DOMDataTreeListener {
 
     }
 
+    public boolean hasTriggered() {
+        return localCopy != null;
+    }
+
     public boolean checkEqual(final NormalizedNode<?, ?> expected) {
         return localCopy.equals(expected);
     }
index fc3f9adfddf71b2f4759d21875012b04b17fd92a..c5c4eb95308ce2cdd94dc95cecf634b9d52b46df 100644 (file)
@@ -53,6 +53,10 @@ public class IdIntsListener implements DOMDataTreeChangeListener {
         });
     }
 
+    public boolean hasTriggered() {
+        return localCopy != null;
+    }
+
     public boolean checkEqual(final NormalizedNode<?, ?> expected) {
         return localCopy.equals(expected);
     }