Home / Class/ CompositeBufferGatheringWriteTest Class — netty Architecture

CompositeBufferGatheringWriteTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  4c99b978_4cfc_fe0c_8ea0_4ff9c005d46f["CompositeBufferGatheringWriteTest"]
  bb3e12e5_2097_593d_16d7_1d88b601718d["CompositeBufferGatheringWriteTest.java"]
  4c99b978_4cfc_fe0c_8ea0_4ff9c005d46f -->|defined in| bb3e12e5_2097_593d_16d7_1d88b601718d
  96d9b943_df90_32ea_684b_d5bb3e6368d4["testSingleCompositeBufferWrite()"]
  4c99b978_4cfc_fe0c_8ea0_4ff9c005d46f -->|method| 96d9b943_df90_32ea_684b_d5bb3e6368d4
  be7fe362_0800_65df_b12b_92be15d85b7a["testCompositeBufferPartialWriteDoesNotCorruptData()"]
  4c99b978_4cfc_fe0c_8ea0_4ff9c005d46f -->|method| be7fe362_0800_65df_b12b_92be15d85b7a
  72bb55f3_bb56_2fd5_6e44_421dae3f74fc["compositeBufferPartialWriteDoesNotCorruptDataInitServerConfig()"]
  4c99b978_4cfc_fe0c_8ea0_4ff9c005d46f -->|method| 72bb55f3_bb56_2fd5_6e44_421dae3f74fc
  6d1d149e_d083_e9e2_542b_b9056a5e4547["ByteBuf()"]
  4c99b978_4cfc_fe0c_8ea0_4ff9c005d46f -->|method| 6d1d149e_d083_e9e2_542b_b9056a5e4547
  3af08a09_74c8_250d_06c8_d03f30fdaf25["newRandomBytes()"]
  4c99b978_4cfc_fe0c_8ea0_4ff9c005d46f -->|method| 3af08a09_74c8_250d_06c8_d03f30fdaf25

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/CompositeBufferGatheringWriteTest.java lines 43–309

public class CompositeBufferGatheringWriteTest extends AbstractSocketTest {
    private static final int EXPECTED_BYTES = 20;

    @Test
    @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
    public void testSingleCompositeBufferWrite(TestInfo testInfo) throws Throwable {
        run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
            @Override
            public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
                testSingleCompositeBufferWrite(serverBootstrap, bootstrap);
            }
        });
    }

    public void testSingleCompositeBufferWrite(ServerBootstrap sb, Bootstrap cb) throws Throwable {
        Channel serverChannel = null;
        Channel clientChannel = null;
        try {
            final CountDownLatch latch = new CountDownLatch(1);
            final AtomicReference<Object> clientReceived = new AtomicReference<Object>();
            sb.childHandler(new ChannelInitializer<Channel>() {
                @Override
                protected void initChannel(Channel ch) throws Exception {
                    ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                        @Override
                        public void channelActive(ChannelHandlerContext ctx) throws Exception {
                            ctx.writeAndFlush(newCompositeBuffer(ctx.alloc()))
                                    .addListener(ChannelFutureListener.CLOSE);
                        }
                    });
                }
            });
            cb.handler(new ChannelInitializer<Channel>() {
                @Override
                protected void initChannel(Channel ch) throws Exception {
                    ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                        private ByteBuf aggregator;
                        @Override
                        public void handlerAdded(ChannelHandlerContext ctx) {
                            aggregator = ctx.alloc().buffer(EXPECTED_BYTES);
                        }

                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) {
                            try {
                                if (msg instanceof ByteBuf) {
                                    aggregator.writeBytes((ByteBuf) msg);
                                }
                            } finally {
                                ReferenceCountUtil.release(msg);
                            }
                        }

                        @Override
                        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
                            // IOException is fine as it will also close the channel and may just be a connection reset.
                            if (!(cause instanceof IOException)) {
                                clientReceived.set(cause);
                                latch.countDown();
                            }
                        }

                        @Override
                        public void channelInactive(ChannelHandlerContext ctx) throws Exception {
                            if (clientReceived.compareAndSet(null, aggregator)) {
                                try {
                                    assertEquals(EXPECTED_BYTES, aggregator.readableBytes());
                                } catch (Throwable cause) {
                                    aggregator.release();
                                    aggregator = null;
                                    clientReceived.set(cause);
                                } finally {
                                    latch.countDown();
                                }
                            }
                        }
                    });
                }
            });

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

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free