use of io.netty.channel.local.LocalAddress in project netty by netty.
the class ReentrantChannelTest method testFlushFailure.
@Test
public void testFlushFailure() throws Exception {
LocalAddress addr = new LocalAddress("testFlushFailure");
ServerBootstrap sb = getLocalServerBootstrap();
sb.bind(addr).sync().channel();
Bootstrap cb = getLocalClientBootstrap();
setInterest(Event.WRITE, Event.FLUSH, Event.CLOSE, Event.EXCEPTION);
Channel clientChannel = cb.connect(addr).sync().channel();
clientChannel.pipeline().addLast(new ChannelOutboundHandlerAdapter() {
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
throw new Exception("intentional failure");
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
ctx.close();
}
});
try {
clientChannel.writeAndFlush(createTestBuf(2000)).sync();
fail();
} catch (Throwable cce) {
// FIXME: shouldn't this contain the "intentional failure" exception?
assertEquals(ClosedChannelException.class, cce.getClass());
}
clientChannel.closeFuture().sync();
assertLog("WRITE\nCLOSE\n");
}
use of io.netty.channel.local.LocalAddress in project netty by netty.
the class ReentrantChannelTest method testFlushInWritabilityChanged.
/**
* Similar to {@link #testWritabilityChanged()} with slight variation.
*/
@Test
public void testFlushInWritabilityChanged() throws Exception {
LocalAddress addr = new LocalAddress("testFlushInWritabilityChanged");
ServerBootstrap sb = getLocalServerBootstrap();
sb.bind(addr).sync().channel();
Bootstrap cb = getLocalClientBootstrap();
setInterest(Event.WRITE, Event.FLUSH, Event.WRITABILITY);
Channel clientChannel = cb.connect(addr).sync().channel();
clientChannel.config().setWriteBufferLowWaterMark(512);
clientChannel.config().setWriteBufferHighWaterMark(1024);
clientChannel.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
if (!ctx.channel().isWritable()) {
ctx.channel().flush();
}
ctx.fireChannelWritabilityChanged();
}
});
assertTrue(clientChannel.isWritable());
clientChannel.write(createTestBuf(2000)).sync();
clientChannel.close().sync();
assertLog(// Case 1:
"WRITABILITY: writable=false\n" + "FLUSH\n" + "WRITE\n" + "WRITABILITY: writable=false\n" + "WRITABILITY: writable=false\n" + "FLUSH\n" + "WRITABILITY: writable=true\n", // Case 2:
"WRITABILITY: writable=false\n" + "FLUSH\n" + "WRITE\n" + "WRITABILITY: writable=false\n" + "FLUSH\n" + "WRITABILITY: writable=true\n" + "WRITABILITY: writable=true\n");
}
use of io.netty.channel.local.LocalAddress in project netty by netty.
the class BootstrapTest method testLateRegisterSuccess.
@Test
public void testLateRegisterSuccess() throws Exception {
TestEventLoopGroup group = new TestEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(group);
bootstrap.channel(LocalServerChannel.class);
bootstrap.childHandler(new DummyHandler());
bootstrap.localAddress(new LocalAddress("1"));
ChannelFuture future = bootstrap.bind();
assertFalse(future.isDone());
group.promise.setSuccess();
final BlockingQueue<Boolean> queue = new LinkedBlockingQueue<Boolean>();
future.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
queue.add(future.channel().eventLoop().inEventLoop(Thread.currentThread()));
queue.add(future.isSuccess());
}
});
assertTrue(queue.take());
assertTrue(queue.take());
} finally {
group.shutdownGracefully();
group.terminationFuture().sync();
}
}
use of io.netty.channel.local.LocalAddress in project netty by netty.
the class ServerBootstrapTest method testParentHandler.
private static void testParentHandler(boolean channelInitializer) throws Exception {
final LocalAddress addr = new LocalAddress(UUID.randomUUID().toString());
final CountDownLatch readLatch = new CountDownLatch(1);
final CountDownLatch initLatch = new CountDownLatch(1);
final ChannelHandler handler = new ChannelInboundHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
initLatch.countDown();
super.handlerAdded(ctx);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
readLatch.countDown();
super.channelRead(ctx, msg);
}
};
EventLoopGroup group = new DefaultEventLoopGroup(1);
Channel sch = null;
Channel cch = null;
try {
ServerBootstrap sb = new ServerBootstrap();
sb.channel(LocalServerChannel.class).group(group).childHandler(new ChannelInboundHandlerAdapter());
if (channelInitializer) {
sb.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(handler);
}
});
} else {
sb.handler(handler);
}
Bootstrap cb = new Bootstrap();
cb.group(group).channel(LocalChannel.class).handler(new ChannelInboundHandlerAdapter());
sch = sb.bind(addr).syncUninterruptibly().channel();
cch = cb.connect(addr).syncUninterruptibly().channel();
initLatch.await();
readLatch.await();
} finally {
if (sch != null) {
sch.close().syncUninterruptibly();
}
if (cch != null) {
cch.close().syncUninterruptibly();
}
group.shutdownGracefully();
}
}
use of io.netty.channel.local.LocalAddress in project netty by netty.
the class DefaultChannelPipelineTest method testCancelConnect.
@Test
public void testCancelConnect() throws Exception {
ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel());
ChannelPromise promise = pipeline.channel().newPromise();
assertTrue(promise.cancel(false));
ChannelFuture future = pipeline.connect(new LocalAddress("test"), promise);
assertTrue(future.isCancelled());
}
Aggregations