From 28d88d8b66fa62b7d83f1df2983982745ef77909 Mon Sep 17 00:00:00 2001 From: "Claudio D. Gasparini" Date: Fri, 20 Jul 2018 10:21:31 +0200 Subject: [PATCH] Reduce use of waitFutureSuccess utility Change-Id: I5c24101645c592052155402cc3835e63dfc690d1 Signed-off-by: Claudio D. Gasparini --- .../bgp/rib/impl/BGPDispatcherImplTest.java | 5 ++-- .../bmp/impl/app/BmpMonitorImplTest.java | 15 ++++++------ .../protocol/bmp/mock/BmpMockTest.java | 7 +++--- .../pcep/impl/PCEPDispatcherImplTest.java | 23 +++++++++---------- .../pcep/pcc/mock/PCCDispatcherImplTest.java | 7 +++--- 5 files changed, 26 insertions(+), 31 deletions(-) diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImplTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImplTest.java index 7731862a50..b6eb970b58 100755 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImplTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImplTest.java @@ -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 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()); diff --git a/bmp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java b/bmp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java index a9c15fed9a..585f51f4b2 100644 --- a/bmp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java +++ b/bmp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java @@ -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(); } diff --git a/bmp/bmp-mock/src/test/java/org/opendaylight/protocol/bmp/mock/BmpMockTest.java b/bmp/bmp-mock/src/test/java/org/opendaylight/protocol/bmp/mock/BmpMockTest.java index f5b42957c3..b7333a5ea7 100644 --- a/bmp/bmp-mock/src/test/java/org/opendaylight/protocol/bmp/mock/BmpMockTest.java +++ b/bmp/bmp-mock/src/test/java/org/opendaylight/protocol/bmp/mock/BmpMockTest.java @@ -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()) { diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java index 5d705a7813..51ae9f35bf 100755 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java @@ -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 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)); } diff --git a/pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCDispatcherImplTest.java b/pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCDispatcherImplTest.java index ea5bbcb7dc..9130eed56c 100644 --- a/pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCDispatcherImplTest.java +++ b/pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCDispatcherImplTest.java @@ -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 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()); -- 2.36.6