From 5997e14efab9c12e7be2b7fb83f7efe16c2bfe7c Mon Sep 17 00:00:00 2001 From: Tomas Cere Date: Mon, 22 May 2017 13:22:46 +0200 Subject: [PATCH] BUG 8525: Prevent NPE in test-app listeners Prevents the NPE thrown when the listeners didn't receive any notifications. Change-Id: I0d774913a15b4341abce779c64d6ee8f75d6a0e1 Signed-off-by: Tomas Cere --- .../provider/MdsalLowLevelTestProvider.java | 28 +++++++++++++------ .../impl/IdIntsDOMDataTreeLIstener.java | 4 +++ .../it/provider/impl/IdIntsListener.java | 4 +++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java index bea3bcd11f..240741cf20 100644 --- a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java @@ -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.failed().withRpcError(error).build()); } @@ -456,15 +456,19 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService return Futures.immediateFuture(RpcResultBuilder.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.failed() + .withRpcError(error).build()); + } + final DOMDataReadOnlyTransaction rTx = domDataBroker.newReadOnlyTransaction(); + try { final Optional> 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.failed() + .withRpcError(error).build()); + } + final String shardName = ClusterUtils.getCleanShardName(ProduceTransactionsHandler.ID_INTS_YID); LOG.debug("Creating distributed datastore client for shard {}", shardName); diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/IdIntsDOMDataTreeLIstener.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/IdIntsDOMDataTreeLIstener.java index 3f9a3c52f6..4e1291e1dd 100644 --- a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/IdIntsDOMDataTreeLIstener.java +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/IdIntsDOMDataTreeLIstener.java @@ -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); } diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/IdIntsListener.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/IdIntsListener.java index fc3f9adfdd..c5c4eb9530 100644 --- a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/IdIntsListener.java +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/IdIntsListener.java @@ -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); } -- 2.36.6