@Override public NettyOutbound withConnection(Consumer<? super Connection> withConnection) { return source.withConnection(withConnection); }
@Override public NettyOutbound withConnection(Consumer<? super Connection> withConnection) { return source.withConnection(withConnection); }
/** * Provide a new {@link NettyOutbound} scoped configuration for sending. The * {@link NettyPipeline.SendOptions} changes will apply to the next written object or * {@link Publisher}. * * @param configurator the callback invoked to retrieve send configuration * * @return {@code this} instance */ default NettyOutbound options(Consumer<? super NettyPipeline.SendOptions> configurator) { return withConnection(c -> c.channel() .pipeline() .fireUserEventTriggered(new NettyPipeline.SendOptionsChangeEvent(configurator))); }
/** * Provide a new {@link NettyOutbound} scoped configuration for sending. The * {@link NettyPipeline.SendOptions} changes will apply to the next written object or * {@link Publisher}. * * @param configurator the callback invoked to retrieve send configuration * * @return {@code this} instance */ default NettyOutbound options(Consumer<? super NettyPipeline.SendOptions> configurator) { return withConnection(c -> c.channel() .pipeline() .fireUserEventTriggered(new NettyPipeline.SendOptionsChangeEvent(configurator))); }
@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(); }
@Test public void prematureCancel() { DirectProcessor<Void> signal = DirectProcessor.create(); DisposableServer x = TcpServer.create() .host("localhost") .port(0) .handle((in, out) -> { signal.onComplete(); return out.withConnection(c -> c.addHandlerFirst(new HttpResponseEncoder())) .sendObject(Mono.delay(Duration.ofSeconds(2)) .map(t -> new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.PROCESSING))) .neverComplete(); }) .wiretap(true) .bindNow(Duration.ofSeconds(30)); StepVerifier.create( createHttpClientForContextWithAddress(x) .get() .uri("/") .responseContent() .timeout(signal)) .verifyError(TimeoutException.class); }
.take(1) .thenMany(Flux.defer(() -> out.withConnection(c -> c.addHandlerFirst(new HttpResponseEncoder())) .sendObject(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
.port(0) .handle((in, out) -> out.withConnection(c -> c.addHandlerFirst(new HttpResponseEncoder())) .sendObject(Flux.just(response(), response())) .neverComplete())