NioSocketChannelTest Class — netty Architecture
Architecture documentation for the NioSocketChannelTest class in NioSocketChannelTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 6562d13f_0b72_6889_33f9_c7688a2de3fc["NioSocketChannelTest"] 09e7bc45_206c_ddf2_bfd1_1921facf1283["NioSocketChannelTest.java"] 6562d13f_0b72_6889_33f9_c7688a2de3fc -->|defined in| 09e7bc45_206c_ddf2_bfd1_1921facf1283 82d1fba1_2d62_9af4_9df4_fd118b142760["testFlushCloseReentrance()"] 6562d13f_0b72_6889_33f9_c7688a2de3fc -->|method| 82d1fba1_2d62_9af4_9df4_fd118b142760 f4e680dd_c16e_0e80_f6ec_7a4abf24decc["testFlushAfterGatheredFlush()"] 6562d13f_0b72_6889_33f9_c7688a2de3fc -->|method| f4e680dd_c16e_0e80_f6ec_7a4abf24decc 0a1856aa_de13_a9cc_d43e_9a8f7ec33dbe["testChannelReRegisterReadSameEventLoop()"] 6562d13f_0b72_6889_33f9_c7688a2de3fc -->|method| 0a1856aa_de13_a9cc_d43e_9a8f7ec33dbe 07468fee_4564_c65d_7aca_44bcc62707ef["testChannelReRegisterReadDifferentEventLoop()"] 6562d13f_0b72_6889_33f9_c7688a2de3fc -->|method| 07468fee_4564_c65d_7aca_44bcc62707ef 5c181905_1c1d_7eff_38c5_4a59d5e9c413["testChannelReRegisterRead()"] 6562d13f_0b72_6889_33f9_c7688a2de3fc -->|method| 5c181905_1c1d_7eff_38c5_4a59d5e9c413 e17e2fb7_e8ab_64fd_3744_f6ddd86840d5["testShutdownOutputAndClose()"] 6562d13f_0b72_6889_33f9_c7688a2de3fc -->|method| e17e2fb7_e8ab_64fd_3744_f6ddd86840d5 204277bf_a36f_3cdc_444b_7675855930ef["NioSocketChannel()"] 6562d13f_0b72_6889_33f9_c7688a2de3fc -->|method| 204277bf_a36f_3cdc_444b_7675855930ef 8296b0b3_cd4c_781d_9df6_64e56e8ce88e["NetworkChannel()"] 6562d13f_0b72_6889_33f9_c7688a2de3fc -->|method| 8296b0b3_cd4c_781d_9df6_64e56e8ce88e e4779a57_f598_ba7c_dcb0_04e1dfbae890["newInvalidOption()"] 6562d13f_0b72_6889_33f9_c7688a2de3fc -->|method| e4779a57_f598_ba7c_dcb0_04e1dfbae890
Relationship Graph
Source Code
transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelTest.java lines 66–301
public class NioSocketChannelTest extends AbstractNioChannelTest<NioSocketChannel> {
/**
* Reproduces the issue #1600
*/
@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();
}
}
/**
* Reproduces the issue #1679
*/
@Test
public void testFlushAfterGatheredFlush() throws Exception {
EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
try {
ServerBootstrap sb = new ServerBootstrap();
sb.group(group).channel(NioServerSocketChannel.class);
sb.childHandler(new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
// Trigger a gathering write by writing two buffers.
ctx.write(Unpooled.wrappedBuffer(new byte[] { 'a' }));
ChannelFuture f = ctx.write(Unpooled.wrappedBuffer(new byte[] { 'b' }));
f.addListener(future -> {
// This message must be flushed
ctx.writeAndFlush(Unpooled.wrappedBuffer(new byte[]{'c'}));
});
ctx.flush();
}
});
Source
Frequently Asked Questions
What is the NioSocketChannelTest class?
NioSocketChannelTest is a class in the netty codebase, defined in transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelTest.java.
Where is NioSocketChannelTest defined?
NioSocketChannelTest is defined in transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelTest.java at line 66.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free