BUG-6038: Fix race condition when Open message...
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / BGPSessionImplTest.java
index 411f1465e14b41e240a06a2ab10059cbd2fa5533..e694f03b377354ab54449084701f754ad94def94 100644 (file)
@@ -136,13 +136,16 @@ public class BGPSessionImplTest {
             }
         }).when(this.eventLoop).schedule(Mockito.any(Runnable.class), Mockito.any(long.class), Mockito.any(TimeUnit.class));
         doReturn("TestingChannel").when(this.speakerListener).toString();
+        doReturn(true).when(this.speakerListener).isWritable();
         doReturn(new InetSocketAddress(InetAddress.getByName(BGP_ID.getValue()), 179)).when(this.speakerListener).remoteAddress();
         doReturn(new InetSocketAddress(InetAddress.getByName(LOCAL_IP), LOCAL_PORT)).when(this.speakerListener).localAddress();
         doReturn(this.pipeline).when(this.speakerListener).pipeline();
         doReturn(this.pipeline).when(this.pipeline).replace(Mockito.any(ChannelHandler.class), Mockito.any(String.class), Mockito.any(ChannelHandler.class));
         doReturn(null).when(this.pipeline).replace(Matchers.<Class<ChannelHandler>>any(), Mockito.any(String.class), Mockito.any(ChannelHandler.class));
         doReturn(this.pipeline).when(this.pipeline).addLast(Mockito.any(ChannelHandler.class));
-        doReturn(mock(ChannelFuture.class)).when(this.speakerListener).close();
+        final ChannelFuture futureChannel = mock(ChannelFuture.class);
+        doReturn(null).when(futureChannel).addListener(Mockito.<GenericFutureListener<? extends Future<? super Void>>>any());
+        doReturn(futureChannel).when(this.speakerListener).close();
         this.listener = new SimpleSessionListener();
         this.bgpSession = new BGPSessionImpl(this.listener, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer(), null);
     }
@@ -154,7 +157,8 @@ public class BGPSessionImplTest {
         assertEquals(AS_NUMBER, this.bgpSession.getAsNumber());
         assertEquals(BGP_ID, this.bgpSession.getBgpId());
         assertEquals(1, this.bgpSession.getAdvertisedTableTypes().size());
-        assertTrue(this.listener.up);
+        Assert.assertEquals(BGPSessionImpl.State.UP, this.listener.getState());
+
         //test stats
         final BgpSessionState state = this.bgpSession.getBgpSessionState();
         assertEquals(HOLD_TIMER, state.getHoldtimeCurrent().intValue());
@@ -232,11 +236,12 @@ public class BGPSessionImplTest {
     }
 
     @Test
-    public void testEndOfInput() {
+    public void testEndOfInput() throws InterruptedException {
         this.bgpSession.sessionUp();
-        Assert.assertFalse(this.listener.down);
+        Assert.assertEquals(BGPSessionImpl.State.UP, this.listener.getState());
         this.bgpSession.endOfInput();
-        Assert.assertTrue(this.listener.down);
+        Thread.sleep(3000);
+        Assert.assertEquals(BGPSessionImpl.State.IDLE, this.listener.getState());
     }
 
     @Test