Java Code Examples for reactor.netty.DisposableServer#dispose()
The following examples show how to use
reactor.netty.DisposableServer#dispose() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpCompressionClientServerTests.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void trueEnabledIncludeContentEncoding() { HttpServer server = HttpServer.create() .port(0) .compress(true); DisposableServer runningServer = server.handle((in, out) -> out.sendString(Mono.just("reply"))) .wiretap(true) .bindNow(Duration.ofSeconds(10)); HttpClient.create() .remoteAddress(runningServer::address) .wiretap(true) .compress(true) .headers(h -> Assert.assertTrue(h.contains("Accept-Encoding", "gzip", true))) .get() .uri("/test") .responseContent() .blockLast(); runningServer.dispose(); runningServer.onDispose() .block(); }
Example 2
Source File: HttpCompressionClientServerTests.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void compressionActivatedOnClientAddsHeader() { AtomicReference<String> zip = new AtomicReference<>("fail"); HttpServer server = HttpServer.create() .port(0) .compress(true); DisposableServer runningServer = server.handle((in, out) -> out.sendString(Mono.just("reply"))) .wiretap(true) .bindNow(Duration.ofSeconds(10)); HttpClient.create() .remoteAddress(runningServer::address) .wiretap(true) .compress(true) .headers(h -> zip.set(h.get("accept-encoding"))) .get() .uri("/test") .responseContent() .blockLast(); assertThat(zip.get()).isEqualTo("gzip"); runningServer.dispose(); runningServer.onDispose() .block(); }
Example 3
Source File: WebFluxIT.java From glowroot with Apache License 2.0 | 6 votes |
@Override public void executeApp() throws Exception { int port = getAvailablePort(); DisposableServer httpServer = HttpServer.create() .host("localhost") .port(port) .handle(new ReactorHttpHandlerAdapter(new MyHttpHandler())) .bind() .block(); WebClient client = WebClient.create("http://localhost:" + port); client.get() .uri("/webflux/abc") .retrieve() .bodyToMono(String.class) .block(); httpServer.dispose(); }
Example 4
Source File: HttpCompressionClientServerTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void serverCompressionDefault() { HttpServer server = HttpServer.create() .port(0); DisposableServer runningServer = server.handle((in, out) -> out.sendString(Mono.just("reply"))) .wiretap(true) .bindNow(Duration.ofSeconds(10)); HttpClient client = HttpClient.create() .remoteAddress(runningServer::address) .wiretap(true); Tuple2<String, HttpHeaders> resp = client.headers(h -> h.add("Accept-Encoding", "gzip")) .get() .uri("/test") .response((res, buf) -> buf.asString() .zipWith(Mono.just(res.responseHeaders()))) .blockFirst(); assertThat(resp).isNotNull(); assertThat(resp.getT2().get("content-encoding")).isNull(); Assert.assertEquals("reply", resp.getT1()); runningServer.dispose(); runningServer.onDispose() .block(); }
Example 5
Source File: HttpCompressionClientServerTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void serverCompressionDisabled() { HttpServer server = HttpServer.create() .port(0) .compress(false); DisposableServer runningServer = server.handle((in, out) -> out.sendString(Mono.just("reply"))) .wiretap(true) .bindNow(Duration.ofSeconds(10)); //don't activate compression on the client options to avoid auto-handling (which removes the header) HttpClient client = HttpClient.create() .remoteAddress(runningServer::address) .wiretap(true); Tuple2<String, HttpHeaders> resp = //edit the header manually to attempt to trigger compression on server side client.headers(h -> h.add("Accept-Encoding", "gzip")) .get() .uri("/test") .response((res, buf) -> buf.asString() .zipWith(Mono.just(res.responseHeaders()))) .blockFirst(); assertThat(resp).isNotNull(); assertThat(resp.getT2().get("content-encoding")).isNull(); Assert.assertEquals("reply", resp.getT1()); runningServer.dispose(); runningServer.onDispose() .block(); }
Example 6
Source File: HttpCompressionClientServerTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void compressionServerEnabledClientDisabledIsNone() { HttpServer server = HttpServer.create() .port(0) .compress(true); String serverReply = "reply"; DisposableServer runningServer = server.handle((in, out) -> out.sendString(Mono.just(serverReply))) .wiretap(true) .bindNow(Duration.ofSeconds(10)); HttpClient client = HttpClient.create() .remoteAddress(runningServer::address) .wiretap(true) .compress(false); Tuple2<String, HttpHeaders> resp = client.get() .uri("/test") .response((res, buf) -> buf.asString() .zipWith(Mono.just(res.responseHeaders()))) .blockFirst(); assertThat(resp).isNotNull(); assertThat(resp.getT2().get("Content-Encoding")).isNull(); assertThat(resp.getT1()).isEqualTo(serverReply); runningServer.dispose(); runningServer.onDispose() .block(); }
Example 7
Source File: HttpCompressionClientServerTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void compressionServerDefaultClientDefaultIsNone() { HttpServer server = HttpServer.create() .port(0); DisposableServer runningServer = server.handle((in, out) -> out.sendString(Mono.just("reply"))) .wiretap(true) .bindNow(Duration.ofSeconds(10)); HttpClient client = HttpClient.create() .remoteAddress(runningServer::address) .wiretap(true); Tuple2<String, HttpHeaders> resp = client.get() .uri("/test") .response((res, buf) -> buf.asString() .zipWith(Mono.just(res.responseHeaders()))) .blockFirst(); assertThat(resp).isNotNull(); assertThat(resp.getT2().get("Content-Encoding")).isNull(); assertThat(resp.getT1()).isEqualTo("reply"); runningServer.dispose(); runningServer.onDispose() .block(); }
Example 8
Source File: HttpCompressionClientServerTests.java From reactor-netty with Apache License 2.0 | 4 votes |
@Test public void serverCompressionAlwaysEnabled() throws Exception { HttpServer server = HttpServer.create() .port(0) .compress(true); DisposableServer runningServer = server.handle((in, out) -> out.sendString(Mono.just("reply"))) .wiretap(true) .bindNow(Duration.ofSeconds(10)); //don't activate compression on the client options to avoid auto-handling (which removes the header) HttpClient client = HttpClient.create() .remoteAddress(runningServer::address) .compress(false) .wiretap(true); Tuple2<byte[], HttpHeaders> resp = //edit the header manually to attempt to trigger compression on server side client.headers(h -> h.add("Accept-Encoding", "gzip")) .get() .uri("/test") .responseSingle((res, buf) -> buf.asByteArray() .zipWith(Mono.just(res.responseHeaders()))) .block(); assertThat(resp).isNotNull(); assertThat(resp.getT2().get("content-encoding")).isEqualTo("gzip"); assertThat(new String(resp.getT1(), Charset.defaultCharset())).isNotEqualTo("reply"); GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(resp.getT1())); byte[] deflatedBuf = new byte[1024]; int readable = gis.read(deflatedBuf); gis.close(); assertThat(readable).isGreaterThan(0); String deflated = new String(deflatedBuf, 0, readable, Charset.defaultCharset()); assertThat(deflated).isEqualTo("reply"); runningServer.dispose(); runningServer.onDispose() .block(); }
Example 9
Source File: HttpCompressionClientServerTests.java From reactor-netty with Apache License 2.0 | 4 votes |
@Test public void serverCompressionPredicateTrue() throws Exception { HttpServer server = HttpServer.create() .port(0) .compress((req, res) -> true) .wiretap(true); DisposableServer connection = server.handle((in, out) -> out.sendString(Mono.just("reply"))) .bindNow(); //don't activate compression on the client options to avoid auto-handling (which removes the header) HttpClient client = HttpClient.create() .remoteAddress(connection::address); Tuple2<HttpHeaders, byte[]> resp = //edit the header manually to attempt to trigger compression on server side client.headers(h -> h.add("Accept-Encoding", "gzip")) .wiretap(true) .get() .uri("/test") .responseSingle((res, byteBufMono) -> Mono.just(res.responseHeaders()) .zipWith(byteBufMono .asByteArray()) .log()) .block(); assertThat(resp).isNotNull(); assertThat(resp.getT1().get("content-encoding")).isEqualTo("gzip"); byte[] replyBuffer = resp.getT2(); assertThat(new String(replyBuffer, Charset.defaultCharset())).isNotEqualTo("reply"); GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(replyBuffer)); byte[] deflatedBuf = new byte[1024]; int readable = gis.read(deflatedBuf); gis.close(); assertThat(readable).isGreaterThan(0); String deflated = new String(deflatedBuf, 0, readable, Charset.defaultCharset()); assertThat(deflated).isEqualTo("reply"); connection.dispose(); connection.onDispose() .block(); }
Example 10
Source File: HttpCompressionClientServerTests.java From reactor-netty with Apache License 2.0 | 4 votes |
@Test public void serverCompressionEnabledBigResponse() throws Exception { HttpServer server = HttpServer.create() .port(0) .compress(4); DisposableServer runningServer = server.handle((in, out) -> out.sendString(Mono.just("reply"))) .wiretap(true) .bindNow(Duration.ofSeconds(10)); //don't activate compression on the client options to avoid auto-handling (which removes the header) HttpClient client = HttpClient.create() .remoteAddress(runningServer::address) .wiretap(true); Tuple2<byte[], HttpHeaders> resp = //edit the header manually to attempt to trigger compression on server side client.headers(h -> h.add("accept-encoding", "gzip")) .get() .uri("/test") .responseSingle((res, buf) -> buf.asByteArray() .zipWith(Mono.just(res.responseHeaders()))) .block(); assertThat(resp).isNotNull(); assertThat(resp.getT2().get("content-encoding")).isEqualTo("gzip"); assertThat(new String(resp.getT1(), Charset.defaultCharset())).isNotEqualTo("reply"); GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(resp.getT1())); byte[] deflatedBuf = new byte[1024]; int readable = gis.read(deflatedBuf); gis.close(); assertThat(readable).isGreaterThan(0); String deflated = new String(deflatedBuf, 0, readable, Charset.defaultCharset()); assertThat(deflated).isEqualTo("reply"); runningServer.dispose(); runningServer.onDispose() .block(); }