Home / Class/ SocketConditionalWritabilityTest Class — netty Architecture

SocketConditionalWritabilityTest Class — netty Architecture

Architecture documentation for the SocketConditionalWritabilityTest class in SocketConditionalWritabilityTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  66f975b4_4247_80d0_8000_e9b5b9c6b975["SocketConditionalWritabilityTest"]
  c791b361_fd39_6638_d370_c918a92435e1["SocketConditionalWritabilityTest.java"]
  66f975b4_4247_80d0_8000_e9b5b9c6b975 -->|defined in| c791b361_fd39_6638_d370_c918a92435e1
  dceaece3_9ced_9e88_7619_f909698b4a47["testConditionalWritability()"]
  66f975b4_4247_80d0_8000_e9b5b9c6b975 -->|method| dceaece3_9ced_9e88_7619_f909698b4a47

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketConditionalWritabilityTest.java lines 36–133

public class SocketConditionalWritabilityTest extends AbstractSocketTest {
    @Test
    @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
    public void testConditionalWritability(TestInfo testInfo) throws Throwable {
        run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
            @Override
            public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
                testConditionalWritability(serverBootstrap, bootstrap);
            }
        });
    }

    public void testConditionalWritability(ServerBootstrap sb, Bootstrap cb) throws Throwable {
        Channel serverChannel = null;
        Channel clientChannel = null;
        try {
            final int expectedBytes = 100 * 1024 * 1024;
            final int maxWriteChunkSize = 16 * 1024;
            final CountDownLatch latch = new CountDownLatch(1);
            sb.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 16 * 1024));
            sb.childHandler(new ChannelInitializer<Channel>() {
                @Override
                protected void initChannel(Channel ch) {
                    ch.pipeline().addLast(new ChannelDuplexHandler() {
                        private int bytesWritten;

                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) {
                            ReferenceCountUtil.release(msg);
                            writeRemainingBytes(ctx);
                        }

                        @Override
                        public void flush(ChannelHandlerContext ctx) {
                            if (ctx.channel().isWritable()) {
                                writeRemainingBytes(ctx);
                            } else {
                                ctx.flush();
                            }
                        }

                        @Override
                        public void channelWritabilityChanged(ChannelHandlerContext ctx) {
                            if (ctx.channel().isWritable()) {
                                writeRemainingBytes(ctx);
                            }
                            ctx.fireChannelWritabilityChanged();
                        }

                        private void writeRemainingBytes(ChannelHandlerContext ctx) {
                            while (ctx.channel().isWritable() && bytesWritten < expectedBytes) {
                                int chunkSize = Math.min(expectedBytes - bytesWritten, maxWriteChunkSize);
                                bytesWritten += chunkSize;
                                ctx.write(ctx.alloc().buffer(chunkSize).writeZero(chunkSize));
                            }
                            ctx.flush();
                        }
                    });
                }
            });

            serverChannel = sb.bind().syncUninterruptibly().channel();

            cb.handler(new ChannelInitializer<Channel>() {
                @Override
                protected void initChannel(Channel ch) {
                    ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                        private int totalRead;
                        @Override
                        public void channelActive(ChannelHandlerContext ctx) {
                            ctx.writeAndFlush(ctx.alloc().buffer(1).writeByte(0));
                        }

                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) {
                            if (msg instanceof ByteBuf) {
                                totalRead += ((ByteBuf) msg).readableBytes();
                                if (totalRead == expectedBytes) {
                                    latch.countDown();
                                }
                            }

Frequently Asked Questions

What is the SocketConditionalWritabilityTest class?
SocketConditionalWritabilityTest is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketConditionalWritabilityTest.java.
Where is SocketConditionalWritabilityTest defined?
SocketConditionalWritabilityTest is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketConditionalWritabilityTest.java at line 36.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free