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;
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());
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;
});
}
- @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);
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 -> {
});
// 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());
});
}
- 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,
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();
}
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;
this.bmpDispatcher.close();
}
- @Test
+ @Test(timeout = 20000)
public void testMain() throws Exception {
final InetSocketAddress serverAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
final BmpSessionListenerFactory bmpSessionListenerFactory = () -> BmpMockTest.this.sessionListener;
}
}
- @Test
+ @Test(timeout = 20000)
public void testMainInPassiveMode() throws Exception {
final InetSocketAddress serverAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
final BmpSessionListenerFactory bmpSessionListenerFactory = () -> BmpMockTest.this.sessionListener;
"--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()) {
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;
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);
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();
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);
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,
}
}
- @Test
+ @Test(timeout = 20000)
public void testReconectClient() throws InterruptedException, ExecutionException {
final int port = InetSocketAddressUtil.getRandomPort();
final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
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();
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);
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));
}
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;
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,
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());
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());