Reduce use of waitFutureSuccess utility 72/74272/3
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Fri, 20 Jul 2018 08:21:31 +0000 (10:21 +0200)
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Sat, 21 Jul 2018 16:47:19 +0000 (16:47 +0000)
Change-Id: I5c24101645c592052155402cc3835e63dfc690d1
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImplTest.java
bmp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java
bmp/bmp-mock/src/test/java/org/opendaylight/protocol/bmp/mock/BmpMockTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCDispatcherImplTest.java

index 7731862a507475b1f8481b45e5ccf28493995f60..b6eb970b58878cabeb32eb2207826e41f768f782 100755 (executable)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.rib.impl;
 
 
 import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.checkIdleState;
-import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import com.google.common.collect.Sets;
 import io.netty.channel.Channel;
@@ -23,13 +22,13 @@ import org.opendaylight.protocol.concepts.KeyMapping;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
 
 public class BGPDispatcherImplTest extends AbstractBGPDispatcherTest {
-    @Test
+    @Test(timeout = 20000)
     public void testCreateClient() throws InterruptedException, ExecutionException {
         final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final Channel serverChannel = createServer(serverAddress);
         final Future<BGPSessionImpl> futureClient = this.clientDispatcher.createClient(this.clientAddress,
             serverAddress, 2, true);
-        waitFutureSuccess(futureClient);
+        futureClient.sync();
         final BGPSessionImpl session = futureClient.get();
         Assert.assertEquals(State.UP, this.clientListener.getState());
         Assert.assertEquals(State.UP, this.serverListener.getState());
index a9c15fed9a0c648668b8b124f0a8eb504d3f497f..585f51f4b21d19669d7c0b8063b1f2c56699da5c 100644 (file)
@@ -18,7 +18,6 @@ import static org.mockito.Mockito.doAnswer;
 import static org.opendaylight.protocol.bmp.parser.message.TestUtil.createRouteMonMsgWithEndOfRibMarker;
 import static org.opendaylight.protocol.bmp.parser.message.TestUtil.createRouteMonitMsg;
 import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
-import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import com.google.common.net.InetAddresses;
 import io.netty.bootstrap.Bootstrap;
@@ -220,7 +219,7 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest {
         });
     }
 
-    @Test
+    @Test(timeout = 20000)
     public void testRouterMonitoring() throws Exception {
         // first test if a single router monitoring is working
         final Channel channel1 = testMonitoringStation(REMOTE_ROUTER_ADDRESS_1);
@@ -245,7 +244,7 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest {
         CheckUtil.checkEquals(() -> assertFalse(channel3.isOpen()));
 
         // now if we close the channel 1 and try it again, it should succeed
-        waitFutureSuccess(channel1.close());
+        channel1.close().sync();
 
         // channel 2 is still open
         readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
@@ -260,11 +259,11 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest {
         });
 
         // close all channel altogether
-        waitFutureSuccess(channel2.close());
+        channel2.close().sync();
         Thread.sleep(100);
 
         // sleep for a while to avoid intermittent InMemoryDataTree modification conflict
-        waitFutureSuccess(channel4.close());
+        channel4.close().sync();
 
         readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
             assertEquals(0, monitor.getRouter().size());
@@ -272,8 +271,8 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest {
         });
     }
 
-    private static void waitWriteAndFlushSuccess(final ChannelFuture channelFuture) {
-        waitFutureSuccess(channelFuture);
+    private static void waitWriteAndFlushSuccess(final ChannelFuture channelFuture) throws InterruptedException {
+        channelFuture.sync();
     }
 
     private Channel testMonitoringStation(final String remoteRouterIpAddr) throws InterruptedException,
@@ -477,7 +476,7 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest {
         b.localAddress(new InetSocketAddress(routerIp, 0));
         b.option(ChannelOption.SO_REUSEADDR, true);
         final ChannelFuture future = b.connect(new InetSocketAddress(MONITOR_LOCAL_ADDRESS, MONITOR_LOCAL_PORT)).sync();
-        waitFutureSuccess(future);
+        future.sync();
         return future.channel();
     }
 
index f5b42957c3791119fb8534713c8701f5cc24a80c..b7333a5ea7adeb5f07d6fa1c52f21bed844f199f 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.protocol.bmp.mock;
 
 import static org.mockito.Mockito.verify;
-import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
@@ -58,7 +57,7 @@ public class BmpMockTest {
         this.bmpDispatcher.close();
     }
 
-    @Test
+    @Test(timeout = 20000)
     public void testMain() throws Exception {
         final InetSocketAddress serverAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final BmpSessionListenerFactory bmpSessionListenerFactory = () -> BmpMockTest.this.sessionListener;
@@ -94,7 +93,7 @@ public class BmpMockTest {
         }
     }
 
-    @Test
+    @Test(timeout = 20000)
     public void testMainInPassiveMode() throws Exception {
         final InetSocketAddress serverAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final BmpSessionListenerFactory bmpSessionListenerFactory = () -> BmpMockTest.this.sessionListener;
@@ -104,7 +103,7 @@ public class BmpMockTest {
             "--peers_count", "3", "--pre_policy_routes", "3", "--passive"});
         final ChannelFuture futureServer = this.bmpDispatcher.createClient(serverAddr,
                 bmpSessionListenerFactory, KeyMapping.getKeyMapping());
-        waitFutureSuccess(futureServer);
+        futureServer.sync();
         final Channel serverChannel;
         final int sessionUpWait;
         if (futureServer.isSuccess()) {
index 5d705a7813ee302153f80b77a51528e593f6859c..51ae9f35bf0fb99d3a380a33324ddbaa2c095ec8 100755 (executable)
@@ -12,7 +12,6 @@ import static java.util.Objects.requireNonNull;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doReturn;
-import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.ChannelFuture;
@@ -98,7 +97,7 @@ public class PCEPDispatcherImplTest {
                 new PCEPHandlerFactory(msgReg));
     }
 
-    @Test
+    @Test(timeout = 20000)
     public void testCreateClientServer() throws InterruptedException, ExecutionException {
         final int port = InetSocketAddressUtil.getRandomPort();
         final InetSocketAddress serverAddr = new InetSocketAddress("0.0.0.0", port);
@@ -109,7 +108,7 @@ public class PCEPDispatcherImplTest {
         doReturn(this.listenerFactory).when(this.dispatcherDependencies).getListenerFactory();
         doReturn(new SimpleSessionListener()).when(this.listenerFactory).getSessionListener();
         final ChannelFuture futureChannel = this.dispatcher.createServer(this.dispatcherDependencies);
-        waitFutureSuccess(futureChannel);
+        futureChannel.sync();
         final PCEPSessionImpl session1 = this.pccMock.createClient(clientAddr1,
                 RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
 
@@ -130,7 +129,7 @@ public class PCEPDispatcherImplTest {
         Assert.assertTrue(futureChannel.channel().isActive());
     }
 
-    @Test
+    @Test(timeout = 20000)
     public void testCreateDuplicateClient() throws InterruptedException, ExecutionException {
         final int port = InetSocketAddressUtil.getRandomPort();
         final InetSocketAddress serverAddr = new InetSocketAddress("0.0.0.0", port);
@@ -140,10 +139,10 @@ public class PCEPDispatcherImplTest {
         doReturn(this.listenerFactory).when(this.dispatcherDependencies).getListenerFactory();
         doReturn(new SimpleSessionListener()).when(this.listenerFactory).getSessionListener();
 
-        waitFutureSuccess(this.dispatcher.createServer(this.dispatcherDependencies));
+        this.dispatcher.createServer(this.dispatcherDependencies).sync();
         final Future<PCEPSessionImpl> futureClient = this.pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
                 SimpleSessionListener::new);
-        waitFutureSuccess(futureClient);
+        futureClient.sync();
 
         try (PCEPSessionImpl ignored = futureClient.get()) {
             this.pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
@@ -154,7 +153,7 @@ public class PCEPDispatcherImplTest {
         }
     }
 
-    @Test
+    @Test(timeout = 20000)
     public void testReconectClient() throws InterruptedException, ExecutionException {
         final int port = InetSocketAddressUtil.getRandomPort();
         final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
@@ -162,14 +161,14 @@ public class PCEPDispatcherImplTest {
         doReturn(new InetSocketAddress("0.0.0.0", port)).when(this.dispatcherDependencies).getAddress();
         doReturn(this.listenerFactory).when(this.dispatcherDependencies).getListenerFactory();
         doReturn(new SimpleSessionListener()).when(this.listenerFactory).getSessionListener();
-        waitFutureSuccess(this.dispatcher.createServer(this.dispatcherDependencies));
+        this.dispatcher.createServer(this.dispatcherDependencies).sync();
         final PCEPSessionImpl session1 = this.pccMock.createClient(clientAddr,
                 RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
 
         assertEquals(clientAddr.getAddress(), session1.getRemoteAddress());
         assertEquals(DEAD_TIMER, session1.getDeadTimerValue().shortValue());
         assertEquals(KEEP_ALIVE, session1.getKeepAliveTimerValue().shortValue());
-        waitFutureSuccess(session1.closeChannel());
+        session1.closeChannel().sync();
 
         final PCEPSessionImpl session2 = this.pccMock.createClient(clientAddr,
                 RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
@@ -181,8 +180,8 @@ public class PCEPDispatcherImplTest {
         session2.close();
     }
 
-    @Test
-    public void testCustomizeBootstrap() {
+    @Test(timeout = 20000)
+    public void testCustomizeBootstrap() throws InterruptedException {
         final int port = InetSocketAddressUtil.getRandomPort();
         final InetSocketAddress clientAddr1 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
         final InetSocketAddress clientAddr2 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
@@ -194,7 +193,7 @@ public class PCEPDispatcherImplTest {
         doReturn(new SimpleSessionListener()).when(this.listenerFactory).getSessionListener();
 
         final ChannelFuture futureChannel = this.disp2Spy.createServer(this.dispatcherDependencies);
-        waitFutureSuccess(futureChannel);
+        futureChannel.sync();
         Mockito.verify(this.disp2Spy).createServerBootstrap(any(PCEPDispatcherImpl.ChannelPipelineInitializer.class));
     }
 
index ea5bbcb7dc00cd7101ba128da88c29890083c2c3..9130eed56ce39941f89bbc90d858ec93134cee8e 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.pcep.pcc.mock;
 
 import static org.mockito.Mockito.doReturn;
 import static org.opendaylight.protocol.pcep.pcc.mock.PCCMockCommon.checkSessionListenerNotNull;
-import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
@@ -86,7 +85,7 @@ public class PCCDispatcherImplTest {
         this.bossGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS);
     }
 
-    @Test
+    @Test(timeout = 20000)
     public void testClientReconnect() throws Exception {
         final Future<PCEPSession> futureSession = this.dispatcher
                 .createClient(this.serverAddress, 1, new TestingSessionListenerFactory(), this.nf,
@@ -95,7 +94,7 @@ public class PCCDispatcherImplTest {
         doReturn(slf).when(this.dispatcherDependencies).getListenerFactory();
 
         final ChannelFuture futureServer = this.pcepDispatcher.createServer(this.dispatcherDependencies);
-        waitFutureSuccess(futureServer);
+        futureServer.sync();
         final Channel channel = futureServer.channel();
         Assert.assertNotNull(futureSession.get());
         checkSessionListenerNotNull(slf, this.clientAddress.getHostString());
@@ -115,7 +114,7 @@ public class PCCDispatcherImplTest {
         final TestingSessionListenerFactory slf2 = new TestingSessionListenerFactory();
         doReturn(slf2).when(this.dispatcherDependencies).getListenerFactory();
         final ChannelFuture future2 = this.pcepDispatcher.createServer(this.dispatcherDependencies);
-        waitFutureSuccess(future2);
+        future2.sync();
         final Channel channel2 = future2.channel();
         final TestingSessionListener sl2
                 = checkSessionListenerNotNull(slf2, this.clientAddress.getAddress().getHostAddress());