Bug-6889: BGPCEP Boron Autorelease Breaking 76/47176/2
authorAjay <ajayl.bro@gmail.com>
Wed, 19 Oct 2016 22:55:55 +0000 (22:55 +0000)
committerMilos Fabian <milfabia@cisco.com>
Thu, 20 Oct 2016 08:15:13 +0000 (08:15 +0000)
- if server is not ready when client connects, wait for client reconnection
  before checking for test pass/fail criteria

Change-Id: I172d3e829f70081f0d943458dd43c6139381bf61
Signed-off-by: Ajay <ajayl.bro@gmail.com>
bgp/bmp-mock/src/test/java/org/opendaylight/protocol/bmp/mock/BmpMockDispatcherTest.java
bgp/bmp-mock/src/test/java/org/opendaylight/protocol/bmp/mock/BmpMockTest.java

index 5e960b4f99a30146ea83a751784fe6eafe41df4a..298194009c43dd6cac01996a405d8f91655bd888 100644 (file)
@@ -8,7 +8,7 @@
 
 package org.opendaylight.protocol.bmp.mock;
 
-import static org.opendaylight.protocol.bmp.mock.BmpMockTest.waitFutureSuccess;
+import static org.opendaylight.protocol.bmp.mock.BmpMockTest.waitFutureComplete;
 
 import com.google.common.base.Optional;
 import com.google.common.net.InetAddresses;
@@ -40,10 +40,10 @@ public class BmpMockDispatcherTest {
         final BmpDispatcherImpl serverDispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(),
             this.registry, this.sessionFactory);
         final ChannelFuture futureServer = serverDispatcher.createServer(serverAddr, this.slf, Optional.<KeyMapping>absent());
-        waitFutureSuccess(futureServer);
+        waitFutureComplete(futureServer);
         final ChannelFuture channelFuture = dispatcher.createClient(InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0),
             serverAddr);
-        waitFutureSuccess(channelFuture);
+        waitFutureComplete(channelFuture);
         final Channel channel = channelFuture.sync().channel();
 
         Assert.assertTrue(channel.isActive());
@@ -58,9 +58,9 @@ public class BmpMockDispatcherTest {
         final BmpDispatcherImpl serverDispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(),
             this.registry, this.sessionFactory);
         final ChannelFuture futureServer = dispatcher.createServer(new InetSocketAddress(InetAddresses.forString("0.0.0.0"), port));
-        waitFutureSuccess(futureServer);
+        waitFutureComplete(futureServer);
         final ChannelFuture channelFuture = serverDispatcher.createClient(InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port), this.slf, Optional.<KeyMapping>absent());
-        waitFutureSuccess(channelFuture);
+        waitFutureComplete(channelFuture);
         final Channel channel = channelFuture.sync().channel();
 
         Assert.assertTrue(channel.isActive());
index 4ba2de627015d076b643d6966ca8154e29cbb0c1..388ed30c4099270b8898d26c3d34363fc81f6af3 100644 (file)
@@ -63,15 +63,27 @@ public class BmpMockTest {
         final BmpSessionListenerFactory bmpSessionListenerFactory = () -> BmpMockTest.this.sessionListener;
         final ChannelFuture futureServer = bmpDispatcher.createServer(serverAddr,
             bmpSessionListenerFactory, Optional.<KeyMapping>absent());
-        waitFutureSuccess(futureServer);
-        Channel serverChannel = futureServer.channel();
+        waitFutureComplete(futureServer);
+        Channel serverChannel;
+        int sessionUpWait;
+        if (futureServer.isSuccess()) {
+            serverChannel = futureServer.channel();
+            sessionUpWait = 10;
+        } else {
+            serverChannel = null;
+            // wait longer for the reconnection attempt
+            sessionUpWait = 40;
+        }
 
         BmpMock.main(new String[]{"--remote_address", InetSocketAddressUtil.toHostAndPort(serverAddr).toString(), "--peers_count", "3", "--pre_policy_routes", "3"});
-        Mockito.verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(10))).onSessionUp(Mockito.any(BmpSession.class));
+
+        Mockito.verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(sessionUpWait))).onSessionUp(Mockito.any(BmpSession.class));
         //1 * Initiate message + 3 * PeerUp Notification + 9 * Route Monitoring message
         Mockito.verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(10)).times(13)).onMessage(Mockito.any(Notification.class));
 
-        serverChannel.close().sync();
+        if (serverChannel != null) {
+            serverChannel.close().sync();
+        }
     }
 
     @Test
@@ -84,16 +96,28 @@ public class BmpMockTest {
             "--peers_count", "3", "--pre_policy_routes", "3", "--passive"});
         final ChannelFuture futureServer = bmpDispatcher.createClient(serverAddr,
             bmpSessionListenerFactory, Optional.<KeyMapping>absent());
-        waitFutureSuccess(futureServer);
-        Channel serverChannel = futureServer.channel();
-        Mockito.verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(10))).onSessionUp(Mockito.any(BmpSession.class));
+        waitFutureComplete(futureServer);
+        Channel serverChannel;
+        int sessionUpWait;
+        if (futureServer.isSuccess()) {
+            serverChannel = futureServer.channel();
+            sessionUpWait = 10;
+        } else {
+            serverChannel = null;
+            // wait longer for the reconnection attempt
+            sessionUpWait = 40;
+        }
+
+        Mockito.verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(sessionUpWait))).onSessionUp(Mockito.any(BmpSession.class));
         //1 * Initiate message + 3 * PeerUp Notification + 9 * Route Monitoring message
         Mockito.verify(this.sessionListener, Mockito.timeout(TimeUnit.SECONDS.toMillis(10)).times(13)).onMessage(Mockito.any(Notification.class));
 
-        serverChannel.close().sync();
+        if (serverChannel != null) {
+            serverChannel.close().sync();
+        }
     }
 
-    static void waitFutureSuccess(final ChannelFuture future) throws InterruptedException {
+    static void waitFutureComplete(final ChannelFuture future) throws InterruptedException {
         final CountDownLatch latch = new CountDownLatch(1);
         future.addListener(future1 -> latch.countDown());
         Uninterruptibles.awaitUninterruptibly(latch, 10, TimeUnit.SECONDS);