BUG-7222: Fix clustering BGPPeer NPE 32/48732/2
authorClaudio D. Gasparini <cgaspari@cisco.com>
Mon, 28 Nov 2016 10:46:33 +0000 (11:46 +0100)
committerClaudio D. Gasparini <cgaspari@cisco.com>
Mon, 28 Nov 2016 12:39:34 +0000 (13:39 +0100)
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 <cgaspari@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/BgpPeerTest.java

index 42995e6985560a7c55b42ae37a74eecd4532d105..fe62c9efb29c3449d9a4023e8c9c0885e8f040c3 100644 (file)
@@ -131,8 +131,6 @@ public class BGPPeer implements BGPSessionListener, Peer, AutoCloseable, BGPPeer
         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 +139,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);
     }
 
index 5c10686f8b1b3d684ed6de6aa182160e588df8e8..2768f65f821d01f0cf429c5a95022e683b4ff01a 100644 (file)
@@ -81,7 +81,6 @@ public class BgpPeerTest extends AbstractConfig {
             .setRouteReflector(createRR()).setTimers(createTimers()).setTransport(createTransport()).setAddPaths(createAddPath()).build();
 
         this.bgpPeer.start(this.rib, neighbor, this.tableTypeRegistry, this.configurationWriter);
-        Mockito.verify(this.render).getConfiguredPeerCounter();
         Mockito.verify(this.rib).createPeerChain(any());
         Mockito.verify(this.rib, times(2)).getLocalAs();
         Mockito.verify(this.rib).getLocalTables();
@@ -89,6 +88,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));
@@ -102,14 +102,13 @@ public class BgpPeerTest extends AbstractConfig {
         this.bgpPeer.setServiceRegistration(this.serviceRegistration);
         this.bgpPeer.close();
         this.bgpPeer.restart(this.rib, this.tableTypeRegistry);
-        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();
         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();