use of io.netty.channel.DefaultChannelPromise in project bgpcep by opendaylight.
the class PeerTest method mockSession.
private void mockSession() {
final EventLoop eventLoop = mock(EventLoop.class);
final Channel channel = mock(Channel.class);
final ChannelPipeline pipeline = mock(ChannelPipeline.class);
doReturn(null).when(eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
doReturn(eventLoop).when(channel).eventLoop();
doReturn(Boolean.TRUE).when(channel).isWritable();
doReturn(null).when(channel).close();
doReturn(pipeline).when(channel).pipeline();
doCallRealMethod().when(channel).toString();
doReturn(pipeline).when(pipeline).addLast(any(ChannelHandler.class));
doReturn(new DefaultChannelPromise(channel)).when(channel).writeAndFlush(any(Notification.class));
doReturn(new InetSocketAddress("localhost", 12345)).when(channel).remoteAddress();
doReturn(new InetSocketAddress("localhost", 12345)).when(channel).localAddress();
final List<BgpParameters> params = Lists.newArrayList(new BgpParametersBuilder().setOptionalCapabilities(Lists.newArrayList(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()).build()).build()).build())).build());
final Open openObj = new OpenBuilder().setBgpIdentifier(new Ipv4Address("1.1.1.1")).setHoldTimer(50).setMyAsNumber(72).setBgpParameters(params).build();
this.session = new BGPSessionImpl(this.classic, channel, openObj, 30, null);
this.session.setChannelExtMsgCoder(openObj);
}
use of io.netty.channel.DefaultChannelPromise in project drill by axbaretto.
the class WebSessionResourcesTest method testChannelPromiseWithValidExecutor.
/**
* Validates successful {@link WebSessionResources#close()} with valid CloseFuture and other parameters.
* @throws Exception
*/
@Test
public void testChannelPromiseWithValidExecutor() throws Exception {
try {
EventExecutor mockExecutor = mock(EventExecutor.class);
ChannelPromise closeFuture = new DefaultChannelPromise(null, mockExecutor);
webSessionResources = new WebSessionResources(mock(BufferAllocator.class), mock(SocketAddress.class), mock(UserSession.class), closeFuture);
webSessionResources.close();
verify(webSessionResources.getAllocator()).close();
verify(webSessionResources.getSession()).close();
verify(mockExecutor).inEventLoop();
verify(mockExecutor).execute(any(Runnable.class));
assertTrue(webSessionResources.getCloseFuture() == null);
assertTrue(!listenerComplete);
} catch (Exception e) {
fail();
}
}
use of io.netty.channel.DefaultChannelPromise in project drill by axbaretto.
the class WebSessionResourcesTest method testCloseWithListener.
/**
* Validates successful {@link WebSessionResources#close()} with valid CloseFuture and {@link TestClosedListener}
* getting invoked which is added to the close future.
* @throws Exception
*/
@Test
public void testCloseWithListener() throws Exception {
try {
// Assign latch, executor and closeListener for this test case
GenericFutureListener<Future<Void>> closeListener = new TestClosedListener();
latch = new CountDownLatch(1);
executor = TransportCheck.createEventLoopGroup(1, "Test-Thread").next();
ChannelPromise closeFuture = new DefaultChannelPromise(null, executor);
// create WebSessionResources with above ChannelPromise to notify listener
webSessionResources = new WebSessionResources(mock(BufferAllocator.class), mock(SocketAddress.class), mock(UserSession.class), closeFuture);
// Add the Test Listener to close future
assertTrue(!listenerComplete);
closeFuture.addListener(closeListener);
// Close the WebSessionResources
webSessionResources.close();
// Verify the states
verify(webSessionResources.getAllocator()).close();
verify(webSessionResources.getSession()).close();
assertTrue(webSessionResources.getCloseFuture() == null);
// Since listener will be invoked so test should not wait forever
latch.await();
assertTrue(listenerComplete);
} catch (Exception e) {
fail();
} finally {
listenerComplete = false;
executor.shutdownGracefully();
}
}
use of io.netty.channel.DefaultChannelPromise in project x-pipe by ctripcorp.
the class DefaultNettyClient method sendRequest.
@Override
public void sendRequest(ByteBuf byteBuf, final ByteBufReceiver byteBufReceiver) {
logger.debug("[sendRequest][begin]{}, {}", byteBufReceiver, this);
DefaultChannelPromise future = new DefaultChannelPromise(channel);
future.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
logger.debug("[operationComplete][add receiver]{}, {}", byteBufReceiver, this);
receivers.offer(byteBufReceiver);
} else {
logger.error("[sendRequest][fail]" + channel, future.cause());
}
}
});
logger.debug("[sendRequest][ end ]{}, {}", byteBufReceiver, this);
channel.writeAndFlush(byteBuf, future);
}
use of io.netty.channel.DefaultChannelPromise in project x-pipe by ctripcorp.
the class DefaultRedisClientTest method beforeDefaultRedisClientTest.
@Before
public void beforeDefaultRedisClientTest() {
when(channel.closeFuture()).thenReturn(new DefaultChannelPromise(channel));
redisClient = new DefaultRedisClient(channel, redisKeeperServer);
}
Aggregations