Home / Class/ FailureTestHandler Class — netty Architecture

FailureTestHandler Class — netty Architecture

Architecture documentation for the FailureTestHandler class in ProxyHandlerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  4666128d_bb10_bddf_1e70_e3216c05611a["FailureTestHandler"]
  8ee69b4d_9955_829a_96d0_8c943277a68d["ProxyHandlerTest.java"]
  4666128d_bb10_bddf_1e70_e3216c05611a -->|defined in| 8ee69b4d_9955_829a_96d0_8c943277a68d
  d11956a8_ed24_1fe8_fe14_61d9359b2318["channelActive()"]
  4666128d_bb10_bddf_1e70_e3216c05611a -->|method| d11956a8_ed24_1fe8_fe14_61d9359b2318
  903900ec_6acc_aed7_0631_91b64035bad8["channelInactive()"]
  4666128d_bb10_bddf_1e70_e3216c05611a -->|method| 903900ec_6acc_aed7_0631_91b64035bad8
  ada8ad9b_441d_cff7_0ede_7e1fc74a7ee1["userEventTriggered()"]
  4666128d_bb10_bddf_1e70_e3216c05611a -->|method| ada8ad9b_441d_cff7_0ede_7e1fc74a7ee1
  fead0161_e269_a6df_b604_23284b04cb10["channelRead0()"]
  4666128d_bb10_bddf_1e70_e3216c05611a -->|method| fead0161_e269_a6df_b604_23284b04cb10
  448983c2_3fec_90e0_b96b_3a504aafd1ec["exceptionCaught()"]
  4666128d_bb10_bddf_1e70_e3216c05611a -->|method| 448983c2_3fec_90e0_b96b_3a504aafd1ec

Relationship Graph

Source Code

handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java lines 559–606

    private static final class FailureTestHandler extends SimpleChannelInboundHandler<Object> {

        final Queue<Throwable> exceptions = new LinkedBlockingQueue<Throwable>();

        /**
         * A latch that counts down when:
         * - a pending write attempt in {@link #channelActive(ChannelHandlerContext)} finishes, or
         * - the channel is closed.
         * By waiting until the latch goes down to 0, we can make sure all assertion failures related with all write
         * attempts have been recorded.
         */
        final CountDownLatch latch = new CountDownLatch(2);

        @Override
        public void channelActive(ChannelHandlerContext ctx) throws Exception {
            ctx.writeAndFlush(Unpooled.copiedBuffer("A\n", CharsetUtil.US_ASCII)).addListener(
                    future -> {
                        latch.countDown();
                        if (!(future.cause() instanceof ProxyConnectException)) {
                            exceptions.add(new AssertionError(
                                    "Unexpected failure cause for initial write: " + future.cause()));
                        }
                    });
        }

        @Override
        public void channelInactive(ChannelHandlerContext ctx) throws Exception {
            latch.countDown();
        }

        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
            if (evt instanceof ProxyConnectionEvent) {
                fail("Unexpected event: " + evt);
            }
        }

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
            fail("Unexpected message: " + msg);
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            exceptions.add(cause);
            ctx.close();
        }
    }

Frequently Asked Questions

What is the FailureTestHandler class?
FailureTestHandler is a class in the netty codebase, defined in handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java.
Where is FailureTestHandler defined?
FailureTestHandler is defined in handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java at line 559.

Analyze Your Own Codebase

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

Try Supermodel Free