Example usage for io.netty.handler.codec.http DefaultFullHttpRequest retain

List of usage examples for io.netty.handler.codec.http DefaultFullHttpRequest retain

Introduction

In this page you can find the example usage for io.netty.handler.codec.http DefaultFullHttpRequest retain.

Prototype

@Override
    public FullHttpRequest retain() 

Source Link

Usage

From source file:reactor.ipc.netty.http.HttpServerTests.java

License:Open Source License

@Test
public void httpPipelining() throws Exception {

    AtomicInteger i = new AtomicInteger();

    NettyContext c = HttpServer.create(0)
            .newHandler(/*  w w w  . j ava2  s . c o  m*/
                    (req, resp) -> resp.header(HttpHeaderNames.CONTENT_LENGTH, "1")
                            .sendString(Mono.just(i.incrementAndGet())
                                    .then(d -> Mono.delay(Duration.ofSeconds(4 - d)).map(x -> d + "\n"))))
            .block();

    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            "/plaintext");

    CountDownLatch latch = new CountDownLatch(6);

    TcpClient.create(c.address().getPort()).newHandler((in, out) -> {
        in.context().addHandler(new HttpClientCodec());

        in.receiveObject().ofType(DefaultHttpContent.class).as(ByteBufFlux::fromInbound).asString().log()
                .map(Integer::parseInt).subscribe(d -> {
                    for (int x = 0; x < d; x++) {
                        latch.countDown();
                    }
                });

        return out.sendObject(Flux.just(request.retain(), request.retain(), request.retain())).neverComplete();
    }).block();

    Assert.assertTrue(latch.await(10000, TimeUnit.SECONDS));

}

From source file:reactor.ipc.netty.http.server.HttpServerTests.java

License:Open Source License

@Test
public void httpPipelining() throws Exception {

    AtomicInteger i = new AtomicInteger();

    NettyContext c = HttpServer.create(0)
            .newHandler((req, resp) -> resp.header(HttpHeaderNames.CONTENT_LENGTH, "1")
                    .sendString(Mono.just(i.incrementAndGet())
                            .flatMap(d -> Mono.delay(Duration.ofSeconds(4 - d)).map(x -> d + "\n"))))
            .block(Duration.ofSeconds(30));

    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            "/plaintext");

    CountDownLatch latch = new CountDownLatch(6);

    TcpClient.create(c.address().getPort()).newHandler((in, out) -> {
        in.context().addHandlerFirst(new HttpClientCodec());

        in.receiveObject().ofType(DefaultHttpContent.class).as(ByteBufFlux::fromInbound).asString().log()
                .map(Integer::parseInt).subscribe(d -> {
                    for (int x = 0; x < d; x++) {
                        latch.countDown();
                    }/*  www.  j  a va 2 s .c o m*/
                });

        return out.sendObject(Flux.just(request.retain(), request.retain(), request.retain())).neverComplete();
    }).block(Duration.ofSeconds(30));

    Assert.assertTrue(latch.await(45, TimeUnit.SECONDS));

}