testFlushCloseReentrance() — netty Function Reference
Architecture documentation for the testFlushCloseReentrance() function in NioSocketChannelTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 82d1fba1_2d62_9af4_9df4_fd118b142760["testFlushCloseReentrance()"] 6562d13f_0b72_6889_33f9_c7688a2de3fc["NioSocketChannelTest"] 82d1fba1_2d62_9af4_9df4_fd118b142760 -->|defined in| 6562d13f_0b72_6889_33f9_c7688a2de3fc style 82d1fba1_2d62_9af4_9df4_fd118b142760 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelTest.java lines 71–123
@Test
public void testFlushCloseReentrance() throws Exception {
EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
try {
final Queue<ChannelFuture> futures = new LinkedBlockingQueue<ChannelFuture>();
ServerBootstrap sb = new ServerBootstrap();
sb.group(group).channel(NioServerSocketChannel.class);
sb.childOption(ChannelOption.SO_SNDBUF, 1024);
sb.childHandler(new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
// Write a large enough data so that it is split into two loops.
futures.add(ctx.write(
ctx.alloc().buffer().writeZero(1048576)).addListener(ChannelFutureListener.CLOSE));
futures.add(ctx.write(ctx.alloc().buffer().writeZero(1048576)));
ctx.flush();
futures.add(ctx.write(ctx.alloc().buffer().writeZero(1048576)));
ctx.flush();
}
});
SocketAddress address = sb.bind(0).sync().channel().localAddress();
Socket s = new Socket(NetUtil.LOCALHOST, ((InetSocketAddress) address).getPort());
InputStream in = s.getInputStream();
byte[] buf = new byte[8192];
for (;;) {
if (in.read(buf) == -1) {
break;
}
// Wait a little bit so that the write attempts are split into multiple flush attempts.
Thread.sleep(10);
}
s.close();
assertEquals(3, futures.size());
ChannelFuture f1 = futures.poll();
ChannelFuture f2 = futures.poll();
ChannelFuture f3 = futures.poll();
assertTrue(f1.isSuccess());
assertTrue(f2.isDone());
assertFalse(f2.isSuccess());
assertInstanceOf(ClosedChannelException.class, f2.cause());
assertTrue(f3.isDone());
assertFalse(f3.isSuccess());
assertInstanceOf(ClosedChannelException.class, f3.cause());
} finally {
group.shutdownGracefully().sync();
}
}
Domain
Subdomains
Source
Frequently Asked Questions
What does testFlushCloseReentrance() do?
testFlushCloseReentrance() is a function in the netty codebase, defined in transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelTest.java.
Where is testFlushCloseReentrance() defined?
testFlushCloseReentrance() is defined in transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelTest.java at line 71.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free