.receive() .retain() .subscribe( byteBuf -> {
@Test public void testTcpClientWithInetSocketAddress() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); TcpClient client = TcpClient.create().port(echoServerPort); Connection s = client.handle((in, out) -> { in.receive() .subscribe(d -> latch.countDown()); return out.sendString(Flux.just("Hello")) .neverComplete(); }) .wiretap(true) .connectNow(Duration.ofSeconds(5)); latch.await(5, TimeUnit.SECONDS); s.disposeNow(); assertThat("latch was counted down", latch.getCount(), is(0L)); }
@Test public void connectionWillAttemptToReconnectWhenItIsDropped() throws InterruptedException { final CountDownLatch connectionLatch = new CountDownLatch(1); final CountDownLatch reconnectionLatch = new CountDownLatch(1); try { TcpClient tcpClient = TcpClient.newConnection() .host("localhost") .port(abortServerPort); Mono<? extends Connection> handler = tcpClient.handle((in, out) -> { System.out.println("Start"); connectionLatch.countDown(); in.receive() .subscribe(); return Flux.never(); }) .wiretap(true) .connect(); handler.log() .then(handler.doOnSuccess(s -> reconnectionLatch.countDown())) .block(Duration.ofSeconds(30)) .onDispose(); assertTrue("Initial connection is made", connectionLatch.await(5, TimeUnit.SECONDS)); assertTrue("A reconnect attempt was made", reconnectionLatch.await(5, TimeUnit.SECONDS)); } catch (AbortedException ise){ return; } }
.handle((in, out) -> { in.receive() .subscribe(b -> { System.out.println("Client1 received " + b.readCharSequence(b.readableBytes(), CharsetUtil.UTF_8)); latch.countDown(); .handle((in, out) -> { in.receive() .subscribe(b -> { System.out.println("Client2 received " + b.readCharSequence(b.readableBytes(), CharsetUtil.UTF_8)); latch.countDown();