use of reactor.ipc.netty.NettyContext in project spring-framework by spring-projects.
the class ReactorHttpServer method startInternal.
@Override
protected void startInternal() {
NettyContext nettyContext = this.reactorServer.newHandler(this.reactorHandler).block();
setPort(nettyContext.address().getPort());
this.nettyContext.set(nettyContext);
}
use of reactor.ipc.netty.NettyContext in project spring-boot by spring-projects.
the class NettyWebServer method stop.
@Override
public void stop() throws WebServerException {
NettyContext context = this.nettyContext.getAndSet(null);
if (context != null) {
context.dispose();
}
latch.countDown();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class TcpClientTests method consumerSpecAssignsEventHandlers.
@Test
public void consumerSpecAssignsEventHandlers() throws InterruptedException, IOException {
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(opts -> opts.host("localhost").port(timeoutServerPort));
NettyContext s = client.newHandler((in, out) -> {
in.onReadIdle(500, () -> {
totalDelay.addAndGet(System.currentTimeMillis() - start);
latch.countDown();
}).context().onClose(close::countDown);
out.onWriteIdle(500, () -> {
totalDelay.addAndGet(System.currentTimeMillis() - start);
latch.countDown();
});
return Mono.delay(Duration.ofSeconds(3)).then().log();
}).block(Duration.ofSeconds(30));
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.dispose();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class TcpClientTests method readIdleDoesNotFireWhileDataIsBeingRead.
@Test
public void readIdleDoesNotFireWhileDataIsBeingRead() throws InterruptedException, IOException {
final CountDownLatch latch = new CountDownLatch(1);
long start = System.currentTimeMillis();
TcpClient client = TcpClient.create("localhost", heartbeatServerPort);
NettyContext s = client.newHandler((in, out) -> {
in.onReadIdle(500, latch::countDown);
return Flux.never();
}).block(Duration.ofSeconds(30));
assertTrue(latch.await(15, TimeUnit.SECONDS));
heartbeatServer.close();
long duration = System.currentTimeMillis() - start;
assertThat(duration, is(greaterThanOrEqualTo(500L)));
s.dispose();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class TcpClientTests method writeIdleDoesNotFireWhileDataIsBeingSent.
@Test
public void writeIdleDoesNotFireWhileDataIsBeingSent() throws InterruptedException, IOException {
final CountDownLatch latch = new CountDownLatch(1);
long start = System.currentTimeMillis();
NettyContext client = TcpClient.create("localhost", echoServerPort).newHandler((in, out) -> {
System.out.println("hello");
out.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);
}).block(Duration.ofSeconds(30));
System.out.println("Started");
assertTrue(latch.await(5, TimeUnit.SECONDS));
long duration = System.currentTimeMillis() - start;
assertThat(duration, is(greaterThanOrEqualTo(500l)));
client.dispose();
}
Aggregations