From: Claudio D. Gasparini Date: Mon, 28 Nov 2016 10:46:33 +0000 (+0100) Subject: BUG-7222: Fix clustering BGPPeer NPE X-Git-Tag: release/boron-sr2~1 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=20f0ead22adb474614a5efc83555db5627a0c27e;p=bgpcep.git BUG-7222: Fix clustering BGPPeer NPE Fix NPE: Any call to rib should be done during singleton service instantiation or after. Any call before can cause a NPE since RIB might be on undefined status yet. Change-Id: Ia1ebbc334f07362f325ac599f39f9d601e717321 Signed-off-by: Claudio D. Gasparini --- diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java index 42995e6985..230ef3029c 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java @@ -130,9 +130,6 @@ public class BGPPeer implements BGPSessionListener, Peer, AutoCloseable, BGPPeer this.name = name; this.rpcRegistry = rpcRegistry; this.peerStats = new BGPPeerStatsImpl(this.name, this.tables); - - // add current peer to "configured BGP peer" stats - this.rib.getRenderStats().getConfiguredPeerCounter().increaseCount(); this.chain = rib.createPeerChain(this); } @@ -141,6 +138,8 @@ public class BGPPeer implements BGPSessionListener, Peer, AutoCloseable, BGPPeer } public void instantiateServiceInstance() { + // add current peer to "configured BGP peer" stats + this.rib.getRenderStats().getConfiguredPeerCounter().increaseCount(); this.ribWriter = AdjRibInWriter.create(rib.getYangRibId(), this.peerRole, this.simpleRoutingPolicy, this.chain); } diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/BgpPeerTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/BgpPeerTest.java index 83a31dd264..3cde1b5a25 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/BgpPeerTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/BgpPeerTest.java @@ -77,13 +77,13 @@ public class BgpPeerTest extends AbstractConfig { } @Test + @SuppressWarnings("unchecked") public void testBgpPeer() throws Exception { final Neighbor neighbor = new NeighborBuilder().setAfiSafis(createAfiSafi()).setConfig(createConfig()).setNeighborAddress(NEIGHBOR_ADDRESS) .setRouteReflector(createRR()).setTimers(createTimers()).setTransport(createTransport()).setAddPaths(createAddPath()).build(); this.bgpPeer.start(this.rib, neighbor, this.mappingService, this.configurationWriter); Mockito.verify(this.mappingService).toPeerRole(any()); - Mockito.verify(this.render).getConfiguredPeerCounter(); Mockito.verify(this.rib).createPeerChain(any()); Mockito.verify(this.rib, times(2)).getLocalAs(); Mockito.verify(this.rib).getLocalTables(); @@ -93,6 +93,7 @@ public class BgpPeerTest extends AbstractConfig { Mockito.verify(this.rib).registerClusterSingletonService(any(ClusterSingletonService.class)); this.singletonService.instantiateServiceInstance(); + Mockito.verify(this.render).getConfiguredPeerCounter(); Mockito.verify(this.configurationWriter).apply(); Mockito.verify(this.bgpPeerRegistry).addPeer(any(), any(), any()); Mockito.verify(this.dispatcher).createReconnectingClient(any(InetSocketAddress.class), any(BGPPeerRegistry.class), anyInt(), any(Optional.class)); @@ -107,7 +108,6 @@ public class BgpPeerTest extends AbstractConfig { this.bgpPeer.close(); this.bgpPeer.restart(this.rib, this.mappingService); Mockito.verify(this.mappingService, times(2)).toPeerRole(any()); - Mockito.verify(this.render, times(2)).getConfiguredPeerCounter(); Mockito.verify(this.rib, times(2)).createPeerChain(any()); Mockito.verify(this.rib, times(4)).getLocalAs(); Mockito.verify(this.rib, times(2)).getLocalTables(); @@ -116,7 +116,7 @@ public class BgpPeerTest extends AbstractConfig { Mockito.verify(this.rib, times(2)).getRibIServiceGroupIdentifier(); Mockito.verify(this.rib, times(2)).registerClusterSingletonService(any(ClusterSingletonService.class)); this.singletonService.instantiateServiceInstance(); - + Mockito.verify(this.render, times(2)).getConfiguredPeerCounter(); assertNotNull(this.bgpPeer.getBgpPeerState()); assertNotNull(this.bgpPeer.getBgpSessionState()); this.bgpPeer.resetStats();