use of reactor.ipc.netty.NettyContext 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.NettyContext in project reactor-netty by reactor.
the class HttpClientTest method secureSendFile.
@Test
public void secureSendFile() throws CertificateException, SSLException, URISyntaxException {
Path largeFile = Paths.get(getClass().getResource("/largeFile.txt").toURI());
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
SslContext sslClient = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
AtomicReference<String> uploaded = new AtomicReference<>();
NettyContext context = HttpServer.create(opt -> opt.sslContext(sslServer)).newRouter(r -> r.post("/upload", (req, resp) -> req.receive().aggregate().asString(StandardCharsets.UTF_8).doOnNext(uploaded::set).then(resp.status(201).sendString(Mono.just("Received File")).then()))).block();
HttpClientResponse response = HttpClient.create(opt -> applyHostAndPortFromContext(opt, context).sslContext(sslClient)).post("/upload", r -> r.sendFile(largeFile)).block(Duration.ofSeconds(120));
context.dispose();
context.onClose().block();
String responseBody = response.receive().aggregate().asString().block();
assertThat(response.status().code()).isEqualTo(201);
assertThat(responseBody).isEqualTo("Received File");
assertThat(uploaded.get()).startsWith("This is an UTF-8 file that is larger than 1024 bytes. " + "It contains accents like é.").contains("1024 mark here -><- 1024 mark here").endsWith("End of File");
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpClientTest method sshExchangeRelativeGet.
@Test
public void sshExchangeRelativeGet() 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 backpressured.
@Test
public void backpressured() throws Exception {
Path resource = Paths.get(getClass().getResource("/public").toURI());
NettyContext c = HttpServer.create(0).newRouter(routes -> routes.directory("/test", resource)).block(Duration.ofSeconds(30));
Mono<HttpClientResponse> remote = HttpClient.create(c.address().getPort()).get("/test/test.css");
Mono<String> page = remote.flatMapMany(r -> r.receive().asString().limitRate(1)).reduce(String::concat);
Mono<String> cancelledPage = remote.flatMapMany(r -> r.receive().asString().take(5).limitRate(1)).reduce(String::concat);
page.block(Duration.ofSeconds(30));
cancelledPage.block(Duration.ofSeconds(30));
page.block(Duration.ofSeconds(30));
c.dispose();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpClientTest method chunkedSendFile.
@Test
public void chunkedSendFile() throws URISyntaxException {
Path largeFile = Paths.get(getClass().getResource("/largeFile.txt").toURI());
AtomicReference<String> uploaded = new AtomicReference<>();
NettyContext context = HttpServer.create(opt -> opt.host("localhost")).newRouter(r -> r.post("/upload", (req, resp) -> req.receive().aggregate().asString(StandardCharsets.UTF_8).doOnNext(uploaded::set).then(resp.status(201).sendString(Mono.just("Received File")).then()))).block();
HttpClientResponse response = createHttpClientForContext(context).post("/upload", r -> r.sendFile(largeFile)).block(Duration.ofSeconds(120));
context.dispose();
context.onClose().block();
String responseBody = response.receive().aggregate().asString().block();
assertThat(response.status().code()).isEqualTo(201);
assertThat(responseBody).isEqualTo("Received File");
assertThat(uploaded.get()).startsWith("This is an UTF-8 file that is larger than 1024 bytes. " + "It contains accents like é.").contains("1024 mark here -><- 1024 mark here").endsWith("End of File");
}
Aggregations