@Test public void testDiscardConnectionWhenChannelBecomesInactive() throws Exception { AtomicInteger count = new AtomicInteger(); server.requestHandler(req -> { if (count.getAndIncrement() == 0) { Http2ServerConnection a = (Http2ServerConnection) req.connection(); SocketChannel channel = (SocketChannel) a.channel(); channel.shutdown(); } else { req.response().end(); } }); startServer(); AtomicBoolean closed = new AtomicBoolean(); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onFailure(err -> {})) .connectionHandler(conn -> conn.closeHandler(v -> closed.set(true))) .end(); AsyncTestBase.assertWaitUntil(closed::get); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { testComplete(); }).exceptionHandler(err -> { fail(); }).end(); await(); }
private void testShutdownSoLingerNoAssertError0(Bootstrap cb, boolean output) throws Throwable { ServerSocket ss = new ServerSocket(); Socket s = null; ChannelFuture cf = null; try { ss.bind(newSocketAddress()); cf = cb.option(ChannelOption.SO_LINGER, 1).handler(new ChannelInboundHandlerAdapter()) .connect(ss.getLocalSocketAddress()).sync(); s = ss.accept(); cf.sync(); if (output) { ((SocketChannel) cf.channel()).shutdownOutput().sync(); } else { ((SocketChannel) cf.channel()).shutdown().sync(); } } finally { if (s != null) { s.close(); } if (cf != null) { cf.channel().close(); } ss.close(); } } private static void checkThrowable(Throwable cause) throws Throwable {
@Test public void testDiscardConnectionWhenChannelBecomesInactive() throws Exception { AtomicInteger count = new AtomicInteger(); server.requestHandler(req -> { if (count.getAndIncrement() == 0) { Http2ServerConnection a = (Http2ServerConnection) req.connection(); SocketChannel channel = (SocketChannel) a.channel(); channel.shutdown(); } else { req.response().end(); } }); startServer(); AtomicBoolean closed = new AtomicBoolean(); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { fail(); }).connectionHandler(conn -> conn.closeHandler(v -> closed.set(true))).end(); AsyncTestBase.assertWaitUntil(closed::get); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { testComplete(); }).exceptionHandler(err -> { fail(); }).end(); await(); }