use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpClientTest method pipelined.
@Test
@Ignore
public void pipelined() throws Exception {
NettyContext x = TcpServer.create("localhost", 0).newHandler((in, out) -> out.context(c -> c.addHandlerFirst(new HttpResponseEncoder())).sendObject(Flux.just(response(), response())).neverComplete()).block(Duration.ofSeconds(30));
PoolResources pool = PoolResources.fixed("test", 1);
HttpClient.create(opts -> opts.host("localhost").port(x.address().getPort()).poolResources(pool)).get("/").flatMap(r -> {
r.dispose();
return Mono.just(r.status().code());
}).log().block(Duration.ofSeconds(30));
try {
HttpClient.create(opts -> opts.host("localhost").port(x.address().getPort()).poolResources(pool)).get("/").log().block(Duration.ofSeconds(30));
} catch (AbortedException ae) {
return;
}
x.dispose();
pool.dispose();
Assert.fail("Not aborted");
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpClientTest method sshExchangeAbsoluteGet.
@Test
public void sshExchangeAbsoluteGet() throws CertificateException, SSLException {
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
SslContext sslClient = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
NettyContext context = HttpServer.create(opt -> opt.sslContext(sslServer)).newHandler((req, resp) -> resp.sendString(Flux.just("hello ", req.uri()))).block();
HttpClientResponse response = HttpClient.create(opt -> applyHostAndPortFromContext(opt, context).sslContext(sslClient)).get("/foo").block();
context.dispose();
context.onClose().block();
String responseString = response.receive().aggregate().asString(CharsetUtil.UTF_8).block();
assertThat(responseString).isEqualTo("hello /foo");
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpClientTest method test.
@Test
public void test() {
NettyContext context = HttpServer.create(opt -> opt.host("localhost")).newRouter(r -> r.put("/201", (req, res) -> res.addHeader("Content-Length", "0").status(HttpResponseStatus.CREATED).sendHeaders()).put("/204", (req, res) -> res.status(HttpResponseStatus.NO_CONTENT).sendHeaders()).get("/200", (req, res) -> res.addHeader("Content-Length", "0").sendHeaders())).block(Duration.ofSeconds(30));
HttpClientResponse response1 = createHttpClientForContext(context).put("/201", req -> req.sendHeaders()).block();
HttpClientResponse response2 = createHttpClientForContext(context).put("/204", req -> req.sendHeaders()).block(Duration.ofSeconds(30));
HttpClientResponse response3 = createHttpClientForContext(context).get("/200", req -> req.sendHeaders()).block(Duration.ofSeconds(30));
response1.dispose();
response2.dispose();
response3.dispose();
context.dispose();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpClientTest method userIssue.
@Test
public void userIssue() throws Exception {
final PoolResources pool = PoolResources.fixed("local", 1);
CountDownLatch latch = new CountDownLatch(3);
Set<String> localAddresses = ConcurrentHashMap.newKeySet();
NettyContext serverContext = HttpServer.create(8080).newRouter(r -> r.post("/", (req, resp) -> req.receive().asString().flatMap(data -> {
latch.countDown();
return resp.status(200).send();
}))).block();
final HttpClient client = HttpClient.create(options -> {
options.poolResources(pool);
options.connectAddress(() -> new InetSocketAddress(8080));
});
Flux.just("1", "2", "3").concatMap(data -> client.post("/", req -> req.sendString(Flux.just(data))).doOnNext(r -> r.receive().subscribe())).subscribe(response -> {
localAddresses.add(response.channel().localAddress().toString());
});
latch.await();
pool.dispose();
serverContext.dispose();
System.out.println("Local Addresses used: " + localAddresses);
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpClientTest method serverInfiniteClientClose.
@Test
public void serverInfiniteClientClose() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
NettyContext c = HttpServer.create(0).newHandler((req, resp) -> {
req.context().onClose(latch::countDown);
return Flux.interval(Duration.ofSeconds(1)).flatMap(d -> {
req.context().channel().config().setAutoRead(true);
return resp.sendObject(Unpooled.EMPTY_BUFFER).then().doOnSuccess(x -> req.context().channel().config().setAutoRead(false));
});
}).block(Duration.ofSeconds(30));
Mono<HttpClientResponse> remote = HttpClient.create(c.address().getPort()).get("/");
HttpClientResponse r = remote.block();
r.dispose();
while (r.channel().isActive()) {
}
latch.await();
c.dispose();
}
Aggregations