reactor.netty.ByteBufFlux Java Examples
The following examples show how to use
reactor.netty.ByteBufFlux.
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: EchoClient.java From reactor-netty with Apache License 2.0 | 6 votes |
public static void main(String[] args) { TcpClient client = TcpClient.create() .port(PORT) .wiretap(WIRETAP); if (SECURE) { client = client.secure( spec -> spec.sslContext(SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE))); } Connection connection = client.handle((in, out) -> out.send(Flux.concat(ByteBufFlux.fromString(Mono.just("echo")), in.receive().retain()))) .connectNow(); connection.onDispose() .block(); }
Example #2
Source File: EchoClient.java From reactor-netty with Apache License 2.0 | 6 votes |
public static void main(String[] args) { HttpClient client = HttpClient.create() .port(PORT) .wiretap(WIRETAP) .compress(COMPRESS); if (SECURE) { client = client.secure( spec -> spec.sslContext(SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE))); } String response = client.post() .uri("/echo") .send(ByteBufFlux.fromString(Mono.just("echo"))) .responseContent() .aggregate() .asString() .block(); System.out.println("Response: " + response); }
Example #3
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void testIssue303() { disposableServer = HttpServer.create() .port(0) .handle((req, resp) -> resp.sendString(Mono.just("OK"))) .wiretap(true) .bindNow(); Mono<String> content = createHttpClientForContextWithPort() .request(HttpMethod.GET) .uri("/") .send(ByteBufFlux.fromInbound(Mono.defer(() -> Mono.just("Hello".getBytes(Charset.defaultCharset()))))) .responseContent() .aggregate() .asString(); StepVerifier.create(content) .expectNextMatches("OK"::equals) .expectComplete() .verify(Duration.ofSeconds(30)); }
Example #4
Source File: HttpsMetricsHandlerTests.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void testIssue896() throws Exception { disposableServer = httpServer.noSSL() .bindNow(); CountDownLatch latch = new CountDownLatch(1); httpClient.observe((conn, state) -> conn.channel() .closeFuture() .addListener(f -> latch.countDown())) .post() .uri("/1") .send(ByteBufFlux.fromString(Mono.just("hello"))) .responseContent() .subscribe(); assertTrue(latch.await(30, TimeUnit.SECONDS)); InetSocketAddress sa = (InetSocketAddress) disposableServer.channel().localAddress(); String serverAddress = sa.getHostString() + ":" + sa.getPort(); String[] summaryTags = new String[]{REMOTE_ADDRESS, serverAddress, URI, "unknown"}; checkCounter(CLIENT_ERRORS, summaryTags, true, 2); }
Example #5
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void testIssue719() throws Exception { doTestIssue719(ByteBufFlux.fromString(Mono.just("test")), h -> h.set("Transfer-Encoding", "chunked"), false); doTestIssue719(ByteBufFlux.fromString(Mono.just("test")), h -> h.set("Content-Length", "4"), false); doTestIssue719(ByteBufFlux.fromString(Mono.just("")), h -> h.set("Transfer-Encoding", "chunked"), false); doTestIssue719(ByteBufFlux.fromString(Mono.just("")), h -> h.set("Content-Length", "0"), false); doTestIssue719(ByteBufFlux.fromString(Mono.just("test")), h -> h.set("Transfer-Encoding", "chunked"), true); doTestIssue719(ByteBufFlux.fromString(Mono.just("test")), h -> h.set("Content-Length", "4"), true); doTestIssue719(ByteBufFlux.fromString(Mono.just("")), h -> h.set("Transfer-Encoding", "chunked"), true); doTestIssue719(ByteBufFlux.fromString(Mono.just("")), h -> h.set("Content-Length", "0"), true); }
Example #6
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 6 votes |
private ChannelId[] doTestConnectionLifeTime(ConnectionProvider provider) throws Exception { disposableServer = HttpServer.create() .port(0) .handle((req, resp) -> resp.sendObject(ByteBufFlux.fromString(Mono.delay(Duration.ofMillis(30)) .map(Objects::toString)))) .wiretap(true) .bindNow(); Flux<ChannelId> id = createHttpClientForContextWithAddress(provider) .get() .uri("/") .responseConnection((res, conn) -> Mono.just(conn.channel().id()) .delayUntil(ch -> conn.inbound().receive())); ChannelId id1 = id.blockLast(Duration.ofSeconds(30)); Thread.sleep(10); ChannelId id2 = id.blockLast(Duration.ofSeconds(30)); assertThat(id1).isNotNull(); assertThat(id2).isNotNull(); provider.dispose(); return new ChannelId[] {id1, id2}; }
Example #7
Source File: HttpServerTests.java From reactor-netty with Apache License 2.0 | 6 votes |
private void doTestTcpConfiguration(HttpServer server, HttpClient client) { disposableServer = server.bindNow(); String response = client.post() .uri("/") .send(ByteBufFlux.fromString(Mono.just("testTcpConfiguration"))) .responseContent() .aggregate() .asString() .block(Duration.ofSeconds(30)); disposableServer.disposeNow(); assertThat(response).isEqualTo("testTcpConfiguration"); }
Example #8
Source File: HttpClientWithTomcatTest.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void disableChunkForced() { AtomicReference<HttpHeaders> headers = new AtomicReference<>(); Tuple2<HttpResponseStatus, String> r = HttpClient.newConnection() .host("localhost") .port(getPort()) .headers(h -> h.set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED)) .wiretap(true) .doAfterRequest((req, connection) -> headers.set(req.requestHeaders())) .request(HttpMethod.GET) .uri("/status/400") .send(ByteBufFlux.fromString(Flux.just("hello"))) .responseSingle((res, conn) -> Mono.just(res.status()) .zipWith(conn.asString())) .block(Duration.ofSeconds(30)); assertThat(r).isNotNull(); assertThat(r.getT1()).isEqualTo(HttpResponseStatus.BAD_REQUEST); assertThat(headers.get().get("Content-Length")).isEqualTo("5"); assertThat(headers.get().get("Transfer-Encoding")).isNull(); }
Example #9
Source File: HttpClientWithTomcatTest.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void contentHeader() { ConnectionProvider fixed = ConnectionProvider.create("contentHeader", 1); HttpClient client = HttpClient.create(fixed) .wiretap(true) .headers(h -> h.add("content-length", "1")); HttpResponseStatus r = client.request(HttpMethod.GET) .uri(getURL()) .send(ByteBufFlux.fromString(Mono.just(" "))) .responseSingle((res, buf) -> Mono.just(res.status())) .block(Duration.ofSeconds(30)); client.request(HttpMethod.GET) .uri(getURL()) .send(ByteBufFlux.fromString(Mono.just(" "))) .responseSingle((res, buf) -> Mono.just(res.status())) .block(Duration.ofSeconds(30)); Assert.assertEquals(r, HttpResponseStatus.BAD_REQUEST); fixed.dispose(); }
Example #10
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void backpressured() throws Exception { Path resource = Paths.get(getClass().getResource("/public").toURI()); disposableServer = HttpServer.create() .port(0) .route(routes -> routes.directory("/test", resource)) .wiretap(true) .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)); }
Example #11
Source File: ReactorNettyHttpClientBraveTests.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Override Mono<Integer> postMono(AnnotationConfigApplicationContext context, String pathIncludingQuery, String body) { return context.getBean(HttpClient.class).post() .send(ByteBufFlux.fromString(Mono.just(body))).uri(pathIncludingQuery) .response().map(r -> r.status().code()); }
Example #12
Source File: HttpServerTests.java From reactor-netty with Apache License 2.0 | 5 votes |
private void doTestIssue186(HttpClient client) { Mono<String> content = client.post() .uri("/") .send(ByteBufFlux.fromString(Mono.just("bodysample"))) .responseContent() .aggregate() .asString(); StepVerifier.create(content) .expectComplete() .verify(Duration.ofSeconds(30)); }
Example #13
Source File: HttpServerTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void contextShouldBeTransferredFromDownStreamToUpStream() { AtomicReference<Context> context = new AtomicReference<>(); disposableServer = HttpServer.create() .port(0) .handle((req, res) -> res.status(200).send()) .bindNow(); HttpClient client = HttpClient.create(ConnectionProvider.create("contextShouldBeTransferredFromDownStreamToUpStream", 1)) .remoteAddress(disposableServer::address); Mono<String> content = client.post() .uri("/") .send(ByteBufFlux.fromString(Mono.just("bodysample") .subscriberContext(c -> { context.set(c); return c; }))) .responseContent() .aggregate() .asString() .subscriberContext(c -> c.put("Hello", "World")); StepVerifier.create(content) .expectComplete() .verify(Duration.ofSeconds(30)); assertThat(context.get().get("Hello").equals("World")).isTrue(); }
Example #14
Source File: HttpServerTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void httpServerRequestConfigInjectAttributes() { AtomicReference<Channel> channelRef = new AtomicReference<>(); AtomicReference<Boolean> validate = new AtomicReference<>(); AtomicReference<Integer> chunkSize = new AtomicReference<>(); HttpServer server = HttpServer.create() .httpRequestDecoder(opt -> opt.maxInitialLineLength(123) .maxHeaderSize(456) .maxChunkSize(789) .validateHeaders(false) .initialBufferSize(10)) .handle((req, resp) -> req.receive().then(resp.sendNotFound())) .doOnConnection(c -> { channelRef.set(c.channel()); HttpServerCodec codec = c.channel() .pipeline() .get(HttpServerCodec.class); HttpObjectDecoder decoder = (HttpObjectDecoder) getValueReflection(codec, "inboundHandler", 1); chunkSize.set((Integer) getValueReflection(decoder, "maxChunkSize", 2)); validate.set((Boolean) getValueReflection(decoder, "validateHeaders", 2)); }) .wiretap(true); disposableServer = server.bindNow(); HttpClient.create() .remoteAddress(disposableServer::address) .post() .uri("/") .send(ByteBufFlux.fromString(Mono.just("bodysample"))) .responseContent() .aggregate() .asString() .block(); assertThat(channelRef.get()).isNotNull(); assertThat(chunkSize.get()).as("line length").isEqualTo(789); assertThat(validate.get()).as("validate headers").isFalse(); }
Example #15
Source File: HttpServerTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void testIssue630() { disposableServer = HttpServer.create() .port(0) .handle((req, res) -> // Not consuming the incoming data is deliberate res.sendString(Flux.just("OK") .delayElements(Duration.ofSeconds(3)))) .bindNow(); Flux.range(0, 70) .flatMap(i -> HttpClient.create() .remoteAddress(disposableServer::address) .post() .uri("/") .send(ByteBufFlux.fromString(Mono.just("test"))) .responseConnection((res, conn) -> { int status = res.status().code(); conn.dispose(); return Mono.just(status); })) .blockLast(Duration.ofSeconds(30)); }
Example #16
Source File: HttpServerTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void testIssue825() throws Exception { disposableServer = HttpServer.create() .port(0) .handle((req, resp) -> resp.sendString(Mono.just("test"))) .wiretap(true) .bindNow(); DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"); CountDownLatch latch = new CountDownLatch(1); Connection client = TcpClient.create() .port(disposableServer.port()) .handle((in, out) -> { in.withConnection(x -> x.addHandlerFirst(new HttpClientCodec())) .receiveObject() .ofType(DefaultHttpContent.class) .as(ByteBufFlux::fromInbound) // ReferenceCounted::release is deliberately invoked // so that .release() in FluxReceive.drainReceiver will fail .subscribe(ReferenceCounted::release, t -> latch.countDown(), null); return out.sendObject(Flux.just(request)) .neverComplete(); }) .wiretap(true) .connectNow(); assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue(); client.disposeNow(); }
Example #17
Source File: HttpServerTests.java From reactor-netty with Apache License 2.0 | 5 votes |
private void doTestHttpServerWithDomainSockets(HttpServer server, HttpClient client) { assumeTrue(LoopResources.hasNativeSupport()); try { disposableServer = server.bindAddress(() -> new DomainSocketAddress("/tmp/test.sock")) .wiretap(true) .handle((req, res) -> { req.withConnection(conn -> { assertThat(conn.channel().localAddress()).isNull(); assertThat(conn.channel().remoteAddress()).isNull(); assertThat(req.hostAddress()).isNull(); assertThat(req.remoteAddress()).isNull(); }); assertThat(req.requestHeaders().get(HttpHeaderNames.HOST)).isEqualTo("localhost"); return res.send(req.receive().retain()); }) .bindNow(); String response = client.remoteAddress(disposableServer::address) .wiretap(true) .post() .uri("/") .send(ByteBufFlux.fromString(Flux.just("1", "2", "3"))) .responseContent() .aggregate() .asString() .block(Duration.ofSeconds(30)); assertEquals("123", response); } finally { assertThat(disposableServer).isNotNull(); disposableServer.disposeNow(); } }
Example #18
Source File: HttpResponseStatusCodesHandlingTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void httpStatusCode404IsHandledByTheClient() { DisposableServer server = HttpServer.create() .port(0) .route(r -> r.post("/test", (req, res) -> res.send(req.receive() .log("server-received")))) .wiretap(true) .bindNow(); HttpClient client = HttpClient.create() .port(server.port()) .wiretap(true); Mono<Integer> content = client.headers(h -> h.add("Content-Type", "text/plain")) .request(HttpMethod.GET) .uri("/status/404") .send(ByteBufFlux.fromString(Flux.just("Hello") .log("client-send"))) .responseSingle((res, buf) -> Mono.just(res.status().code())) .doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage())); StepVerifier.create(content) .expectNext(404) .verifyComplete(); server.disposeNow(); }
Example #19
Source File: Http2Tests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void testCustomConnectionProvider() { disposableServer = HttpServer.create() .protocol(HttpProtocol.H2C) .route(routes -> routes.post("/echo", (req, res) -> res.send(req.receive().retain()))) .port(0) .wiretap(true) .bindNow(); ConnectionProvider provider = ConnectionProvider.create("testCustomConnectionProvider", 1); String response = HttpClient.create(provider, 1) .port(disposableServer.port()) .protocol(HttpProtocol.H2C) .wiretap(true) .post() .uri("/echo") .send(ByteBufFlux.fromString(Mono.just("testCustomConnectionProvider"))) .responseContent() .aggregate() .asString() .block(Duration.ofSeconds(30)); assertThat(response).isEqualTo("testCustomConnectionProvider"); provider.disposeLater() .block(Duration.ofSeconds(30)); }
Example #20
Source File: JacksonWriterStrategy.java From Discord4J with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Mono<HttpClient.ResponseReceiver<?>> write(HttpClient.RequestSender sender, @Nullable Object body) { if (body == null) { return Mono.error(new RuntimeException("Missing body")); } Mono<String> source = Mono.fromCallable(() -> mapToString(body)) .doOnNext(json -> { if (log.isTraceEnabled()) { log.trace("{}", json); } }); return Mono.fromCallable(() -> sender.send( ByteBufFlux.fromString(source, StandardCharsets.UTF_8, ByteBufAllocator.DEFAULT))); }
Example #21
Source File: SeparatedTransport.java From etherjar with Apache License 2.0 | 5 votes |
/** * Read response * @param resp HTTP Response headers * @param data HTTP Response data * @return publisher of read bytes * @throws RpcException if status code is not 200 of an error happened on reading data */ protected Publisher<byte[]> read(HttpClientResponse resp, ByteBufFlux data) { if (resp.status() == HttpResponseStatus.OK) { return data.aggregate() .asByteArray() .onErrorResume((t) -> Mono.error(new RpcException(RpcResponseError.CODE_UPSTREAM_INVALID_RESPONSE, "Upstream connection error. Failed to read response")) ); } else { throw new RpcException(RpcResponseError.CODE_UPSTREAM_INVALID_RESPONSE, "Upstream connection error. Status: " + resp.status().code()); } }
Example #22
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 5 votes |
/** This ensures that non-default values for the HTTP request line are visible for parsing. */ @Test public void postVisibleToOnRequest() { disposableServer = HttpServer.create() .port(0) .route(r -> r.post("/foo", (in, out) -> out.sendString(Flux.just("bar")))) .bindNow(); final AtomicReference<HttpMethod> method = new AtomicReference<>(); final AtomicReference<String> path = new AtomicReference<>(); final HttpClientResponse response = createHttpClientForContextWithPort() .doOnRequest((req, con) -> { method.set(req.method()); path.set(req.path()); }) .post() .uri("/foo") .send(ByteBufFlux.fromString(Mono.just("bar"))) .response() .block(Duration.ofSeconds(30)); assertThat(response).isNotNull(); assertThat(response.status()).isEqualTo(HttpResponseStatus.OK); assertThat(method.get()).isEqualTo(HttpMethod.POST); // req.path() returns the decoded path, without a leading "/" assertThat(path.get()).isEqualTo("foo"); }
Example #23
Source File: WebsocketFinalizer.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override public ByteBufFlux receive() { ByteBufAllocator alloc = (ByteBufAllocator) configuration().options() .get(ChannelOption.ALLOCATOR); if (alloc == null) { alloc = ByteBufAllocator.DEFAULT; } @SuppressWarnings("unchecked") Mono<ChannelOperations<?, ?>> connector = (Mono<ChannelOperations<?, ?>>) connect(); return ByteBufFlux.fromInbound(connector.flatMapMany(contentReceiver), alloc); }
Example #24
Source File: HttpClientFinalizer.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override public ByteBufFlux responseContent() { ByteBufAllocator alloc = (ByteBufAllocator) configuration().options() .get(ChannelOption.ALLOCATOR); if (alloc == null) { alloc = ByteBufAllocator.DEFAULT; } @SuppressWarnings("unchecked") Mono<ChannelOperations<?, ?>> connector = (Mono<ChannelOperations<?, ?>>) connect(); return ByteBufFlux.fromInbound(connector.flatMapMany(contentReceiver), alloc); }
Example #25
Source File: HttpServerRoutes.java From reactor-netty with Apache License 2.0 | 5 votes |
/** * Listens for HTTP GET on the passed path to be used as a routing condition. The * file on the provided {@link Path} is served. * <p>Additional regex matching is available e.g. * "/test/{param}". Params are resolved using {@link HttpServerRequest#param(CharSequence)}</p> * * @param uri The {@link HttpPredicate} to use to trigger the route, pattern matching * and capture are supported * @param path the Path to the file to serve * @param interceptor a channel pre-intercepting handler e.g. for content type header * * @return this {@link HttpServerRoutes} */ default HttpServerRoutes file(Predicate<HttpServerRequest> uri, Path path, @Nullable Function<HttpServerResponse, HttpServerResponse> interceptor) { Objects.requireNonNull(path, "path"); return route(uri, (req, resp) -> { if (!Files.isReadable(path)) { return resp.send(ByteBufFlux.fromPath(path)); } if (interceptor != null) { return interceptor.apply(resp) .sendFile(path); } return resp.sendFile(path); }); }
Example #26
Source File: ChannelOperationsHandlerTest.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public 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 = HttpClient.create() .port(abortServerPort) .wiretap(true) .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(); }
Example #27
Source File: HttpTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void httpRespondsEmpty() { DisposableServer server = HttpServer.create() .port(0) .route(r -> r.post("/test/{param}", (req, res) -> Mono.empty())) .wiretap(true) .bindNow(); HttpClient client = HttpClient.create() .port(server.port()) .wiretap(true); Mono<ByteBuf> content = client.headers(h -> h.add("Content-Type", "text/plain")) .post() .uri("/test/World") .send(ByteBufFlux.fromString(Mono.just("Hello") .log("client-send"))) .responseContent() .log("client-received") .next() .doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage())); StepVerifier.create(content) .expectComplete() .verify(Duration.ofSeconds(30)); server.disposeNow(); }
Example #28
Source File: HttpTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void httpRespondsToRequestsFromClients() { DisposableServer server = HttpServer.create() .port(0) .route(r -> r.post("/test/{param}", (req, res) -> res.sendString(req.receive() .asString() .log("server-received") .map(it -> it + ' ' + req.param("param") + '!') .log("server-reply")))) .wiretap(true) .bindNow(); HttpClient client = HttpClient.create() .port(server.port()) .wiretap(true); Mono<String> content = client.headers(h -> h.add("Content-Type", "text/plain")) .post() .uri("/test/World") .send(ByteBufFlux.fromString(Flux.just("Hello") .log("client-send"))) .responseContent() .aggregate() .asString() .log("client-received") .doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage())); StepVerifier.create(content) .expectNextMatches(s -> s.equals("Hello World!")) .expectComplete() .verify(Duration.ofSeconds(30)); server.disposeNow(); }
Example #29
Source File: HttpTests.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void test100Continue() throws Exception { CountDownLatch latch = new CountDownLatch(1); DisposableServer server = HttpServer.create() .port(0) .handle((req, res) -> req.receive() .aggregate() .asString() .flatMap(s -> { latch.countDown(); return res.sendString(Mono.just(s)) .then(); })) .wiretap(true) .bindNow(); String content = HttpClient.create() .port(server.port()) .headers(h -> h.add("Expect", "100-continue")) .post() .uri("/") .send(ByteBufFlux.fromString(Flux.just("1", "2", "3", "4", "5"))) .responseContent() .aggregate() .asString() .block(); System.out.println(content); Assertions.assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue(); server.disposeNow(); }
Example #30
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void userIssue() throws Exception { final ConnectionProvider pool = ConnectionProvider.create("userIssue", 1); CountDownLatch latch = new CountDownLatch(3); Set<String> localAddresses = ConcurrentHashMap.newKeySet(); disposableServer = HttpServer.create() .port(8080) .route(r -> r.post("/", (req, resp) -> req.receive() .asString() .flatMap(data -> { latch.countDown(); return resp.status(200) .send(); }))) .wiretap(true) .bindNow(); final HttpClient client = createHttpClientForContextWithAddress(pool); Flux.just("1", "2", "3") .concatMap(data -> client.doOnResponse((res, conn) -> localAddresses.add(conn.channel() .localAddress() .toString())) .post() .uri("/") .send(ByteBufFlux.fromString(Flux.just(data))) .responseContent()) .subscribe(); latch.await(); pool.dispose(); System.out.println("Local Addresses used: " + localAddresses); }