From e2b5df8ccdcc89d972548974255bdaf6718221d8 Mon Sep 17 00:00:00 2001 From: Michal Rehak Date: Tue, 4 Oct 2016 16:48:30 +0200 Subject: [PATCH] BUG-6858: adapt to ise api, fix NPE in listener when missing masterDB - added Optional structure for case where topology from notification contains null list of nodes Change-Id: I24af46a0b69410dc472772e51f2bbccde4163688 Signed-off-by: Michal Rehak (cherry picked from commit ebba85849d74d3438500bebc5be84ad6cb8665ad) --- .../impl/dao/MasterDatabaseBindingDaoImpl.java | 13 ++++++++++--- .../listen/EPForwardingTemplateListenerImpl.java | 1 + .../dao/MasterDatabaseBindingDaoImplTest.java | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/sxp-integration/sxp-ep-provider/src/main/java/org/opendaylight/groupbasedpolicy/sxp/ep/provider/impl/dao/MasterDatabaseBindingDaoImpl.java b/sxp-integration/sxp-ep-provider/src/main/java/org/opendaylight/groupbasedpolicy/sxp/ep/provider/impl/dao/MasterDatabaseBindingDaoImpl.java index ebf16d3e0..01a7320d9 100644 --- a/sxp-integration/sxp-ep-provider/src/main/java/org/opendaylight/groupbasedpolicy/sxp/ep/provider/impl/dao/MasterDatabaseBindingDaoImpl.java +++ b/sxp-integration/sxp-ep-provider/src/main/java/org/opendaylight/groupbasedpolicy/sxp/ep/provider/impl/dao/MasterDatabaseBindingDaoImpl.java @@ -14,6 +14,7 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import javax.annotation.Nonnull; @@ -89,11 +90,17 @@ public class MasterDatabaseBindingDaoImpl implements DSAsyncDao input) { - if (input.isPresent()) { + if (input != null) { // clean cache cachedDao.invalidateCache(); - for (Node node : input.get().getNode()) { + final List nodeList = java.util.Optional.ofNullable(input.orNull()) + .map(Topology::getNode) + .orElseGet(() -> { + LOG.warn("failed to update cache of SxpMasterDB - no data"); + return Collections.emptyList(); + }); + for (Node node : nodeList) { java.util.Optional.ofNullable(node.getAugmentation(SxpNodeIdentity.class)) .map(SxpNodeIdentity::getSxpDomains) .map(SxpDomains::getSxpDomain) @@ -119,7 +126,7 @@ public class MasterDatabaseBindingDaoImpl implements DSAsyncDaoany())).thenReturn(Optional.absent()); + Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(rTx); + Mockito.when(rTx.read(Matchers.eq(LogicalDatastoreType.CONFIGURATION), + Matchers.>any())).thenReturn( + Futures., ReadFailedException>immediateCheckedFuture( + Optional.of(new TopologyBuilder().build()))); + + + final ListenableFuture> read = dao.read(IP_PREFIX); + Assert.assertTrue(read.isDone()); + Assert.assertFalse(read.get().isPresent()); + } + @Test public void testRead_presentCached() throws Exception { Mockito.when(cachedDao.find(Matchers.any())).thenReturn(Optional.of(MASTER_DB_BINDING_VALUE)); -- 2.36.6