Source:
public void testClientHandshakeTimeout() throws Exception { EmbeddedChannel serverChannel = createServerChannel(new SimpleChannelInboundHandler<Object>() { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { if (evt == ServerHandshakeStateEvent.HANDSHAKE_COMPLETE) { serverReceivedHandshake = true; 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; } if (evt == ClientHandshakeStateEvent.HANDSHAKE_TIMEOUT) { clientHandshakeTimeout = true; } } @Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof TextWebSocketFrame) { clientReceivedMessage = true; } } }, 100); transferAllDataWithMerge(clientChannel, serverChannel); WebSocketClientProtocolHandshakeHandler handshakeHandler = (WebSocketClientProtocolHandshakeHandler) clientChannel .pipeline().get(WebSocketClientProtocolHandshakeHandler.class.getName()); while (!handshakeHandler.getHandshakeFuture().isDone()) { Thread.sleep(10); clientChannel.runScheduledPendingTasks(); } assertTrue(clientHandshakeTimeout); assertFalse(clientReceivedHandshake); assertFalse(clientReceivedMessage); try { handshakeHandler.getHandshakeFuture().syncUninterruptibly(); } finally { cleanChannelData(serverChannel); } }

Target:
public void testClientHandshakeTimeout() throws Exception { EmbeddedChannel serverChannel = createServerChannel(new SimpleChannelInboundHandler<Object>() { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { if (evt == ServerHandshakeStateEvent.HANDSHAKE_COMPLETE) { serverReceivedHandshake = true; 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); transferAllDataWithMerge(clientChannel, serverChannel); WebSocketClientProtocolHandshakeHandler handshakeHandler = (WebSocketClientProtocolHandshakeHandler) clientChannel .pipeline().get(WebSocketClientProtocolHandshakeHandler.class.getName()); while (!handshakeHandler.getHandshakeFuture().isDone()) { Thread.sleep(10); clientChannel.runScheduledPendingTasks(); } assertTrue(clientHandshakeTimeout); assertFalse(clientReceivedHandshake); assertFalse(clientReceivedMessage); try { handshakeHandler.getHandshakeFuture().syncUninterruptibly(); } finally { serverChannel.finishAndReleaseAll(); } }