@Override @SuppressWarnings("deprecation") public void onWriteInactivity(Runnable runnable, long inactivityDuration) { this.inbound.withConnection(conn -> conn.onWriteIdle(inactivityDuration, runnable)); }
@Override @SuppressWarnings("deprecation") public void onWriteInactivity(Runnable runnable, long inactivityDuration) { this.inbound.withConnection(conn -> conn.onWriteIdle(inactivityDuration, runnable)); }
@Override @SuppressWarnings("deprecation") public void onWriteInactivity(Runnable runnable, long inactivityDuration) { this.inbound.withConnection(conn -> conn.onWriteIdle(inactivityDuration, runnable)); }
@Override @SuppressWarnings("deprecation") public void onWriteInactivity(Runnable runnable, long inactivityDuration) { this.inbound.withConnection(conn -> conn.onWriteIdle(inactivityDuration, runnable)); }
@Test public void onWriteIdleReplaces() { EmbeddedChannel channel = new EmbeddedChannel(); Connection mockContext = () -> channel; AtomicLong idle1 = new AtomicLong(); AtomicLong idle2 = new AtomicLong(); mockContext.onWriteIdle(100, idle1::incrementAndGet); mockContext.onWriteIdle(150, idle2::incrementAndGet); ReactorNetty.OutboundIdleStateHandler idleStateHandler = (ReactorNetty.OutboundIdleStateHandler) channel.pipeline().get(NettyPipeline.OnChannelWriteIdle); idleStateHandler.onWriteIdle.run(); assertThat(channel.pipeline().names()).containsExactly( NettyPipeline.OnChannelWriteIdle, "DefaultChannelPipeline$TailContext#0"); assertThat(idle1.intValue()).isZero(); assertThat(idle2.intValue()).isEqualTo(1); } }
@Test public void writeIdleDoesNotFireWhileDataIsBeingSent() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); long start = System.currentTimeMillis(); Connection client = TcpClient.create() .host("localhost") .port(echoServerPort) .handle((in, out) -> { System.out.println("hello"); out.withConnection(c -> c.onWriteIdle(500, latch::countDown)); List<Publisher<Void>> allWrites = new ArrayList<>(); for (int i = 0; i < 5; i++) { allWrites.add(out.sendString(Flux.just("a") .delayElements(Duration.ofMillis(750)))); } return Flux.merge(allWrites); }) .wiretap(true) .connectNow(); System.out.println("Started"); assertTrue(latch.await(5, TimeUnit.SECONDS)); long duration = System.currentTimeMillis() - start; assertThat(duration, is(greaterThanOrEqualTo(500L))); client.disposeNow(); }
@Ignore public void consumerSpecAssignsEventHandlers() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(2); final CountDownLatch close = new CountDownLatch(1); final AtomicLong totalDelay = new AtomicLong(); final long start = System.currentTimeMillis(); TcpClient client = TcpClient.create() .host("localhost") .port(timeoutServerPort); Connection s = client.handle((in, out) -> { in.withConnection(c -> c.onDispose(close::countDown)); out.withConnection(c -> c.onWriteIdle(500, () -> { totalDelay.addAndGet(System.currentTimeMillis() - start); latch.countDown(); })); return Mono.delay(Duration.ofSeconds(3)) .then() .log(); }) .wiretap(true) .connectNow(); assertTrue("latch was counted down", latch.await(5, TimeUnit.SECONDS)); assertTrue("close was counted down", close.await(30, TimeUnit.SECONDS)); assertThat("totalDelay was >500ms", totalDelay.get(), greaterThanOrEqualTo(500L)); s.disposeNow(); }