Fix NPE while accessing DomTxChain when bgp/app peer singleton service is restarted
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / config / BgpPeerTest.java
index aa658e008ddee6e81f8c1230de1ad71854d88743..44cc622c96c04c3f5d53c56244674cd99f73e5d3 100644 (file)
@@ -154,8 +154,10 @@ public class BgpPeerTest extends AbstractConfig {
         }
         this.bgpPeer.setServiceRegistration(this.serviceRegistration);
         this.bgpPeer.closeServiceInstance();
-        this.bgpPeer.close();
+        verify(this.bgpPeerRegistry).removePeer(any());
         verify(this.future).cancel(true);
+        this.bgpPeer.close();
+        verify(this.serviceRegistration).unregister();
 
         this.bgpPeer.restart(this.rib, null, this.peerGroupLoader, this.tableTypeRegistry);
         this.bgpPeer.instantiateServiceInstance();
@@ -170,9 +172,19 @@ public class BgpPeerTest extends AbstractConfig {
         verify(this.bgpPeerRegistry).removePeer(any(IpAddress.class));
 
         this.bgpPeer.closeServiceInstance();
+        verify(this.bgpPeerRegistry, times(2)).removePeer(any());
+        verify(this.future, times(2)).cancel(true);
+
+        this.bgpPeer.instantiateServiceInstance();
+        verify(this.bgpPeerRegistry, times(3)).addPeer(any(), any(), any());
+        verify(this.dispatcher, times(3)).createReconnectingClient(any(InetSocketAddress.class),
+                any(), anyInt(), any(KeyMapping.class));
+
+        this.bgpPeer.closeServiceInstance();
+        verify(this.bgpPeerRegistry, times(3)).removePeer(any());
+        verify(this.future, times(3)).cancel(true);
         this.bgpPeer.close();
         verify(this.serviceRegistration).unregister();
-        verify(this.future, times(2)).cancel(true);
 
         final Neighbor neighborDiffConfig = new NeighborBuilder().setNeighborAddress(NEIGHBOR_ADDRESS)
                 .setAfiSafis(createAfiSafi()).build();
@@ -180,4 +192,4 @@ public class BgpPeerTest extends AbstractConfig {
         assertTrue(this.bgpPeer.containsEqualConfiguration(neighborDiffConfig));
         this.bgpPeer.close();
     }
-}
\ No newline at end of file
+}