Home / Function/ testClientHandshakeTimeout() — netty Function Reference

testClientHandshakeTimeout() — netty Function Reference

Architecture documentation for the testClientHandshakeTimeout() function in WebSocketHandshakeHandOverTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  dd9e5ef2_79fa_2034_1449_21cd8d663c13["testClientHandshakeTimeout()"]
  f9cd3101_4b2b_a61c_41fe_b9876a6a0902["WebSocketHandshakeHandOverTest"]
  dd9e5ef2_79fa_2034_1449_21cd8d663c13 -->|defined in| f9cd3101_4b2b_a61c_41fe_b9876a6a0902
  8e12a079_6d1e_af18_a1a8_3016f84016ff["transferAllDataWithMerge()"]
  dd9e5ef2_79fa_2034_1449_21cd8d663c13 -->|calls| 8e12a079_6d1e_af18_a1a8_3016f84016ff
  style dd9e5ef2_79fa_2034_1449_21cd8d663c13 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java lines 132–195

    @Test
    public void testClientHandshakeTimeout() throws Throwable {
        EmbeddedChannel serverChannel = createServerChannel(new SimpleChannelInboundHandler<Object>() {
            @Override
            public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
                if (evt == ServerHandshakeStateEvent.HANDSHAKE_COMPLETE) {
                    serverReceivedHandshake = true;
                    // immediately send a message to the client on connect
                    ctx.writeAndFlush(new TextWebSocketFrame("abc"));
                } else if (evt instanceof WebSocketServerProtocolHandler.HandshakeComplete) {
                    serverHandshakeComplete = (WebSocketServerProtocolHandler.HandshakeComplete) evt;
                }
            }

            @Override
            protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
            }
        });

        EmbeddedChannel clientChannel = createClientChannel(new SimpleChannelInboundHandler<Object>() {
            @Override
            public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
                if (evt == ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) {
                    clientReceivedHandshake = true;
                } else if (evt == ClientHandshakeStateEvent.HANDSHAKE_TIMEOUT) {
                    clientHandshakeTimeout = true;
                }
            }

            @Override
            protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
                if (msg instanceof TextWebSocketFrame) {
                    clientReceivedMessage = true;
                }
            }
        }, 100);
        // Client send the handshake request to server
        transferAllDataWithMerge(clientChannel, serverChannel);
        // Server do not send the response back
        // transferAllDataWithMerge(serverChannel, clientChannel);
        final WebSocketClientProtocolHandshakeHandler handshakeHandler =
                (WebSocketClientProtocolHandshakeHandler) clientChannel
                        .pipeline().get(WebSocketClientProtocolHandshakeHandler.class.getName());

        while (!handshakeHandler.getHandshakeFuture().isDone()) {
            Thread.sleep(10);
            // We need to run all pending tasks as the handshake timeout is scheduled on the EventLoop.
            clientChannel.runScheduledPendingTasks();
        }
        assertTrue(clientHandshakeTimeout);
        assertFalse(clientReceivedHandshake);
        assertFalse(clientReceivedMessage);
        // Should throw WebSocketHandshakeException
        try {
            assertThrows(WebSocketHandshakeException.class, new Executable() {
                @Override
                public void execute() {
                    handshakeHandler.getHandshakeFuture().syncUninterruptibly();
                }
            });
        } finally {
            serverChannel.finishAndReleaseAll();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testClientHandshakeTimeout() do?
testClientHandshakeTimeout() is a function in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java.
Where is testClientHandshakeTimeout() defined?
testClientHandshakeTimeout() is defined in codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java at line 132.
What does testClientHandshakeTimeout() call?
testClientHandshakeTimeout() calls 1 function(s): transferAllDataWithMerge.

Analyze Your Own Codebase

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

Try Supermodel Free