Home / Function/ testFlushNotDiscarded() — netty Function Reference

testFlushNotDiscarded() — netty Function Reference

Architecture documentation for the testFlushNotDiscarded() function in Http2MultiplexTransportTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  6c6962d0_e341_4a30_fb29_8ef81f526f7a["testFlushNotDiscarded()"]
  91fc51f7_5bfd_40ef_a0e8_b98c3ed99f48["Http2MultiplexTransportTest"]
  6c6962d0_e341_4a30_fb29_8ef81f526f7a -->|defined in| 91fc51f7_5bfd_40ef_a0e8_b98c3ed99f48
  ddc09e7c_92de_4aa4_bf62_25ac0d49ef36["channelRead()"]
  6c6962d0_e341_4a30_fb29_8ef81f526f7a -->|calls| ddc09e7c_92de_4aa4_bf62_25ac0d49ef36
  style 6c6962d0_e341_4a30_fb29_8ef81f526f7a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTransportTest.java lines 274–349

    @Test
    @Timeout(value = 5000L, unit = MILLISECONDS)
    public void testFlushNotDiscarded()
            throws InterruptedException {
        final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);

        try {
            ServerBootstrap sb = new ServerBootstrap();
            sb.group(eventLoopGroup);
            sb.channel(NioServerSocketChannel.class);
            sb.childHandler(new ChannelInitializer<Channel>() {
                @Override
                protected void initChannel(Channel ch) {
                    ch.pipeline().addLast(new Http2FrameCodecBuilder(true).build());
                    ch.pipeline().addLast(new Http2MultiplexHandler(new ChannelInboundHandlerAdapter() {
                        @Override
                        public void channelRead(final ChannelHandlerContext ctx, Object msg) {
                            if (msg instanceof Http2HeadersFrame && ((Http2HeadersFrame) msg).isEndStream()) {
                                executorService.schedule(new Runnable() {
                                    @Override
                                    public void run() {
                                        ctx.writeAndFlush(new DefaultHttp2HeadersFrame(
                                                new DefaultHttp2Headers(), false)).addListener(
                                                (ChannelFutureListener) future -> {
                                                    ctx.write(new DefaultHttp2DataFrame(
                                                            Unpooled.copiedBuffer(
                                                                    "Hello World", CharsetUtil.US_ASCII),
                                                            true));
                                                    ctx.channel().eventLoop().execute(new Runnable() {
                                                        @Override
                                                        public void run() {
                                                            ctx.flush();
                                                        }
                                                    });
                                                });
                                    }
                                }, 500, MILLISECONDS);
                            }
                            ReferenceCountUtil.release(msg);
                        }
                    }));
                }
            });
            serverChannel = sb.bind(new InetSocketAddress(NetUtil.LOCALHOST, 0)).syncUninterruptibly().channel();

            final CountDownLatch latch = new CountDownLatch(1);
            Bootstrap bs = new Bootstrap();
            bs.group(eventLoopGroup);
            bs.channel(NioSocketChannel.class);
            bs.handler(new ChannelInitializer<Channel>() {
                @Override
                protected void initChannel(Channel ch) {
                    ch.pipeline().addLast(new Http2FrameCodecBuilder(false).build());
                    ch.pipeline().addLast(new Http2MultiplexHandler(DISCARD_HANDLER));
                }
            });
            clientChannel = bs.connect(serverChannel.localAddress()).syncUninterruptibly().channel();
            Http2StreamChannelBootstrap h2Bootstrap = new Http2StreamChannelBootstrap(clientChannel);
            h2Bootstrap.handler(new ChannelInboundHandlerAdapter() {
                @Override
                public void channelRead(ChannelHandlerContext ctx, Object msg) {
                    if (msg instanceof Http2DataFrame && ((Http2DataFrame) msg).isEndStream()) {
                        latch.countDown();
                    }
                    ReferenceCountUtil.release(msg);
                }
            });
            Http2StreamChannel streamChannel = h2Bootstrap.open().syncUninterruptibly().getNow();
            streamChannel.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers(), true))
                    .syncUninterruptibly();

            latch.await();
        } finally {
            executorService.shutdown();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testFlushNotDiscarded() do?
testFlushNotDiscarded() is a function in the netty codebase, defined in codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTransportTest.java.
Where is testFlushNotDiscarded() defined?
testFlushNotDiscarded() is defined in codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTransportTest.java at line 274.
What does testFlushNotDiscarded() call?
testFlushNotDiscarded() calls 1 function(s): channelRead.

Analyze Your Own Codebase

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

Try Supermodel Free