use of reactor.ipc.netty.ByteBufFlux in project reactor-netty by reactor.
the class HttpServerTests method httpPipelining.
@Test
public void httpPipelining() throws Exception {
AtomicInteger i = new AtomicInteger();
NettyContext server = 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);
NettyContext client = TcpClient.create(server.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();
}
});
return out.sendObject(Flux.just(request.retain(), request.retain(), request.retain())).neverComplete();
}).block(Duration.ofSeconds(30));
Assert.assertTrue(latch.await(45, TimeUnit.SECONDS));
server.dispose();
client.dispose();
}
use of reactor.ipc.netty.ByteBufFlux in project reactor-netty by reactor.
the class HttpServerTests method testConnectionCloseOnServerError.
@Test
public void testConnectionCloseOnServerError() throws Exception {
Flux<String> content = Flux.range(1, 3).doOnNext(i -> {
if (i == 3) {
throw new RuntimeException("test");
}
}).map(i -> "foo " + i);
NettyContext server = HttpServer.create(0).newHandler((req, res) -> res.sendString(content)).block(Duration.ofSeconds(30));
HttpClientResponse r = HttpClient.create(ops -> ops.port(server.address().getPort())).get("/").block(Duration.ofSeconds(30));
ByteBufFlux response = r.receive();
StepVerifier.create(response).expectNextCount(2).expectError(IOException.class).verify(Duration.ofSeconds(30));
FutureMono.from(r.context().channel().closeFuture()).block(Duration.ofSeconds(30));
r.dispose();
server.dispose();
}
Aggregations