Example usage for io.netty.channel.socket.nio NioSocketChannel shutdown

List of usage examples for io.netty.channel.socket.nio NioSocketChannel shutdown

Introduction

In this page you can find the example usage for io.netty.channel.socket.nio NioSocketChannel shutdown.

Prototype

@Override
    public ChannelFuture shutdown() 

Source Link

Usage

From source file:io.vertx.test.core.Http2Test.java

License:Open Source License

@Test
public void testDiscardConnectionWhenChannelBecomesInactive() throws Exception {
    AtomicInteger count = new AtomicInteger();
    server.requestHandler(req -> {/*from  w ww  .j  av  a2  s .c o m*/
        if (count.getAndIncrement() == 0) {
            Http2ServerConnection a = (Http2ServerConnection) req.connection();
            NioSocketChannel channel = (NioSocketChannel) 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();
    assertWaitUntil(closed::get);
    client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
        testComplete();
    }).exceptionHandler(err -> {
        fail();
    }).end();
    await();
}