use of reactor.netty.NettyInbound in project reactor-netty by reactor.
the class TcpServerTests method exposesNettyPipelineConfiguration.
@Test
void exposesNettyPipelineConfiguration() throws InterruptedException {
final int port = SocketUtils.findAvailableTcpPort();
final CountDownLatch latch = new CountDownLatch(2);
final TcpClient client = TcpClient.create().port(port);
BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> serverHandler = (in, out) -> {
in.receive().asString().subscribe(data -> {
log.info("data " + data + " on " + in);
latch.countDown();
});
return Flux.never();
};
TcpServer server = TcpServer.create().doOnConnection(c -> c.addHandlerLast("codec", new LineBasedFrameDecoder(8 * 1024))).port(port);
DisposableServer connected = server.handle(serverHandler).wiretap(true).bindNow();
assertThat(connected).isNotNull();
Connection clientContext = client.handle((in, out) -> out.sendString(Flux.just("Hello World!\n", "Hello 11!\n"))).wiretap(true).connectNow();
assertThat(clientContext).isNotNull();
assertThat(latch.await(10, TimeUnit.SECONDS)).as("Latch was counted down").isTrue();
connected.disposeNow();
clientContext.disposeNow();
}
Aggregations