use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.
the class HttpServerTests method contextShouldBeTransferredFromDownStreamToUpsream.
@Test
public void contextShouldBeTransferredFromDownStreamToUpsream() {
AtomicReference<Context> context = new AtomicReference<>();
NettyContext server = HttpServer.create(0).newHandler((req, res) -> res.status(200).send()).block(Duration.ofSeconds(300));
HttpClient client = HttpClient.create(ops -> ops.connectAddress(() -> server.address()).poolResources(PoolResources.fixed("test", 1)));
try {
Mono<String> content = client.post("/", req -> req.failOnClientError(false).sendString(Mono.just("bodysample").subscriberContext(c -> {
context.set(c);
return c;
}))).flatMap(res -> res.receive().aggregate().asString()).subscriberContext(c -> c.put("Hello", "World"));
StepVerifier.create(content).expectComplete().verify(Duration.ofSeconds(300));
assertThat(context.get().get("Hello").equals("World")).isTrue();
} finally {
server.dispose();
}
}
use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.
the class TcpClientTests method tcpClientHandlesLineFeedDataFixedPool.
@Test
public void tcpClientHandlesLineFeedDataFixedPool() throws InterruptedException {
Consumer<Channel> channelInit = c -> c.pipeline().addBefore(NettyPipeline.ReactiveBridge, "codec", new LineBasedFrameDecoder(8 * 1024));
tcpClientHandlesLineFeedData(opts -> opts.host("localhost").port(echoServerPort).poolResources(PoolResources.fixed("tcpClientHandlesLineFeedDataFixedPool", 1)).afterChannelInit(channelInit));
}
use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.
the class HttpClientTest method closePool.
@Test
public void closePool() {
PoolResources pr = PoolResources.fixed("wstest", 1);
NettyContext httpServer = HttpServer.create(0).newHandler((in, out) -> out.options(opt -> opt.flushOnEach()).sendString(Mono.just("test").delayElement(Duration.ofMillis(100)).repeat())).block(Duration.ofSeconds(30));
Flux<String> ws = HttpClient.create(opts -> opts.port(httpServer.address().getPort()).poolResources(pr)).get("/").flatMapMany(in -> in.receive().asString());
StepVerifier.create(Flux.range(1, 10).concatMap(i -> ws.take(2).log())).expectNextSequence(Flux.range(1, 20).map(v -> "test").toIterable()).expectComplete().verify();
httpServer.dispose();
pr.dispose();
}
use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.
the class HttpClientTest method contentHeader.
@Test
public void contentHeader() throws Exception {
PoolResources fixed = PoolResources.fixed("test", 1);
HttpClientResponse r = HttpClient.create(opts -> opts.poolResources(fixed)).get("http://google.com", c -> c.header("content-length", "1").failOnClientError(false).sendString(Mono.just(" "))).block(Duration.ofSeconds(30));
HttpClientResponse r1 = HttpClient.create(opts -> opts.poolResources(fixed)).get("http://google.com", c -> c.header("content-length", "1").failOnClientError(false).sendString(Mono.just(" "))).block(Duration.ofSeconds(30));
Assert.assertTrue(r.status() == HttpResponseStatus.BAD_REQUEST);
r.dispose();
r1.dispose();
fixed.dispose();
}
use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.
the class HttpClientTest method disableChunkImplicitDefault.
@Test
public void disableChunkImplicitDefault() throws Exception {
PoolResources p = PoolResources.fixed("test", 1);
HttpClientResponse r = HttpClient.create(opts -> opts.poolResources(p)).get("http://google.com/unsupportedURI", c -> c.chunkedTransfer(false).failOnClientError(false)).block(Duration.ofSeconds(30));
HttpClientResponse r2 = HttpClient.create(opts -> opts.poolResources(p)).get("http://google.com/unsupportedURI", c -> c.chunkedTransfer(false).failOnClientError(false)).block(Duration.ofSeconds(30));
Assert.assertTrue(r.context().channel() == r2.context().channel());
Assert.assertTrue(r.status() == HttpResponseStatus.NOT_FOUND);
r.dispose();
r2.dispose();
p.dispose();
}
Aggregations