use of reactor.netty.ByteBufFlux in project reactor-netty by reactor.
the class HttpServerTests method httpPipelining.
@Test
void httpPipelining() throws Exception {
AtomicInteger i = new AtomicInteger();
disposableServer = createServer().handle((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")))).bindNow();
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/plaintext");
CountDownLatch latch = new CountDownLatch(6);
Connection client = TcpClient.create().port(disposableServer.port()).handle((in, out) -> {
in.withConnection(x -> x.addHandlerFirst(new HttpClientCodec())).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();
}).wiretap(true).connectNow();
assertThat(latch.await(45, TimeUnit.SECONDS)).as("latch await").isTrue();
client.disposeNow();
}
use of reactor.netty.ByteBufFlux in project reactor-netty by reactor.
the class HttpClientTest method backpressured.
@Test
void backpressured() throws Exception {
Path resource = Paths.get(getClass().getResource("/public").toURI());
disposableServer = createServer().route(routes -> routes.directory("/test", resource)).bindNow();
ByteBufFlux remote = createHttpClientForContextWithPort().get().uri("/test/test.css").responseContent();
Mono<String> page = remote.asString().limitRate(1).reduce(String::concat);
Mono<String> cancelledPage = remote.asString().take(5).limitRate(1).reduce(String::concat);
page.block(Duration.ofSeconds(30));
cancelledPage.block(Duration.ofSeconds(30));
page.block(Duration.ofSeconds(30));
}
use of reactor.netty.ByteBufFlux in project reactor-netty by reactor.
the class ChannelOperationsHandlerTest method testChannelInactiveThrowsIOException.
// @Test
// public void keepPrefetchSizeConstantEqualsWriteBufferLowHighWaterMark() {
// doTestPrefetchSize(1024, 1024);
// }
//
// @Test
// public void keepPrefetchSizeConstantDifferentWriteBufferLowHighWaterMark() {
// doTestPrefetchSize(0, 1024);
// }
//
// private void doTestPrefetchSize(int writeBufferLowWaterMark, int writeBufferHighWaterMark) {
// EmbeddedChannel channel = new EmbeddedChannel();
// channel.config()
// .setWriteBufferLowWaterMark(writeBufferLowWaterMark)
// .setWriteBufferHighWaterMark(writeBufferHighWaterMark);
//
// StepVerifier.create(FutureMono.deferFuture(() -> channel.writeAndFlush(MonoSendMany.objectSource(Flux.range(0, 70), channel, null))))
// .expectComplete()
// .verify(Duration.ofSeconds(30));
//
// }
@Test
void testChannelInactiveThrowsIOException() throws Exception {
ExecutorService threadPool = Executors.newCachedThreadPool();
int abortServerPort = SocketUtils.findAvailableTcpPort();
ConnectionAbortServer abortServer = new ConnectionAbortServer(abortServerPort);
Future<?> f = threadPool.submit(abortServer);
if (!abortServer.await(10, TimeUnit.SECONDS)) {
throw new IOException("Fail to start test server");
}
ByteBufFlux response = createClient(abortServerPort).request(HttpMethod.GET).uri("/").send((req, out) -> out.sendString(Flux.just("a", "b", "c"))).responseContent();
StepVerifier.create(response.log()).expectError(IOException.class).verify();
abortServer.close();
assertThat(f.get()).isNull();
}
Aggregations