use of reactor.netty.Connection in project reactor-netty by reactor.
the class TcpClientTests method testCancelSend.
@Test
void testCancelSend() throws InterruptedException {
final CountDownLatch connectionLatch = new CountDownLatch(3);
TcpClient tcpClient = TcpClient.newConnection().host("localhost").port(echoServerPort);
Connection c;
c = tcpClient.handle((i, o) -> {
o.sendObject(Mono.never().doOnCancel(connectionLatch::countDown).log("uno")).then().subscribe().dispose();
Schedulers.parallel().schedule(() -> o.sendObject(Mono.never().doOnCancel(connectionLatch::countDown).log("dos")).then().subscribe().dispose());
o.sendObject(Mono.never().doOnCancel(connectionLatch::countDown).log("tres")).then().subscribe().dispose();
return Mono.never();
}).connectNow();
assertThat(connectionLatch.await(30, TimeUnit.SECONDS)).as("Cancel not propagated").isTrue();
c.disposeNow();
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class TcpClientTests method testBootstrap.
@Test
@SuppressWarnings("deprecation")
void testBootstrap() {
DisposableServer server = TcpServer.create().port(0).handle((req, res) -> res.send(req.receive().retain())).wiretap(true).bindNow();
AtomicInteger invoked = new AtomicInteger();
Connection conn = TcpClient.create().bootstrap(b -> b.attr(AttributeKey.valueOf("testBootstrap"), "testBootstrap").group(new NioEventLoopGroup()).option(ChannelOption.valueOf("testBootstrap"), "testBootstrap").remoteAddress(server.address()).resolver(DefaultAddressResolverGroup.INSTANCE).handler(new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
invoked.set(1);
super.channelActive(ctx);
}
})).connectNow();
conn.outbound().sendString(Mono.just("testBootstrap")).then().subscribe();
String result = conn.inbound().receive().asString().blockFirst();
assertThat(result).isEqualTo("testBootstrap");
assertThat(invoked.get()).isEqualTo(1);
conn.disposeNow();
server.disposeNow();
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class TcpClientTests method testAddressSupplier.
@Test
@SuppressWarnings("deprecation")
void testAddressSupplier() {
DisposableServer server = TcpServer.create().port(0).handle((req, res) -> res.send(req.receive().retain())).wiretap(true).bindNow();
Connection conn = TcpClient.create().addressSupplier(server::address).connectNow();
conn.outbound().sendString(Mono.just("testAddressSupplier")).then().subscribe();
String result = conn.inbound().receive().asString().blockFirst();
assertThat(result).isEqualTo("testAddressSupplier");
conn.disposeNow();
server.disposeNow();
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class TcpClientTests method readIdleDoesNotFireWhileDataIsBeingRead.
@Test
void readIdleDoesNotFireWhileDataIsBeingRead() throws InterruptedException, IOException {
final CountDownLatch latch = new CountDownLatch(1);
long start = System.currentTimeMillis();
TcpClient client = TcpClient.create().port(heartbeatServerPort);
Connection s = client.handle((in, out) -> {
in.withConnection(c -> c.onReadIdle(200, latch::countDown));
return Flux.never();
}).wiretap(true).connectNow();
assertThat(latch.await(5, TimeUnit.SECONDS)).as("latch await").isTrue();
heartbeatServer.close();
long duration = System.currentTimeMillis() - start;
assertThat(duration).isGreaterThanOrEqualTo(200L);
s.disposeNow();
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class TcpClientTests method testTcpClient1ThreadAcquire.
@Test
void testTcpClient1ThreadAcquire() {
LoopResources resources = LoopResources.create("test", 1, true);
Connection client = TcpClient.create().host("localhost").port(echoServerPort).runOn(resources).wiretap(true).connectNow();
client.disposeNow();
resources.dispose();
assertThat(client).as("client was configured").isInstanceOf(ChannelOperations.class);
}
Aggregations