use of reactor.netty.DisposableServer in project reactor-netty by reactor.
the class TcpClientTests method doTestIssue600.
private void doTestIssue600(boolean withLoop) {
DisposableServer server = TcpServer.create().port(0).handle((req, res) -> res.send(req.receive().retain().delaySubscription(Duration.ofSeconds(1)))).wiretap(true).bindNow();
ConnectionProvider pool = ConnectionProvider.create("doTestIssue600", 10);
LoopResources loop = LoopResources.create("test", 4, true);
TcpClient client;
if (withLoop) {
client = TcpClient.create(pool).remoteAddress(server::address).runOn(loop);
} else {
client = TcpClient.create(pool).remoteAddress(server::address);
}
Set<String> threadNames = new ConcurrentSkipListSet<>();
Flux.range(1, 4).flatMap(i -> client.handle((in, out) -> {
threadNames.add(Thread.currentThread().getName());
return out.send(Flux.empty());
}).connect()).as(StepVerifier::create).expectNextCount(4).expectComplete().verify(Duration.ofSeconds(30));
pool.dispose();
loop.dispose();
server.disposeNow();
assertThat(threadNames.size()).isGreaterThan(1);
}
use of reactor.netty.DisposableServer in project reactor-netty by reactor.
the class TcpClientTests method testIssue585_2.
@Test
void testIssue585_2() throws Exception {
DisposableServer server = TcpServer.create().port(0).handle((req, res) -> res.send(req.receive().retain())).wiretap(true).bindNow();
byte[] bytes = "test".getBytes(Charset.defaultCharset());
ByteBuf b1 = Unpooled.wrappedBuffer(bytes);
ByteBuf b2 = Unpooled.wrappedBuffer(bytes);
ByteBuf b3 = Unpooled.wrappedBuffer(bytes);
WeakReference<ByteBuf> refCheck1 = new WeakReference<>(b1);
WeakReference<ByteBuf> refCheck2 = new WeakReference<>(b2);
WeakReference<ByteBuf> refCheck3 = new WeakReference<>(b3);
Connection conn = TcpClient.create().remoteAddress(server::address).wiretap(true).connectNow();
NettyOutbound out = conn.outbound();
out.sendObject(b1).then().block(Duration.ofSeconds(30));
assertThat(b1.refCnt()).isEqualTo(0);
b1 = null;
checkReference(refCheck1);
out.sendObject(b2).then().block(Duration.ofSeconds(30));
assertThat(b2.refCnt()).isEqualTo(0);
b2 = null;
checkReference(refCheck2);
out.sendObject(b3).then().block(Duration.ofSeconds(30));
assertThat(b3.refCnt()).isEqualTo(0);
b3 = null;
checkReference(refCheck3);
server.disposeNow();
conn.disposeNow();
}
use of reactor.netty.DisposableServer 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.DisposableServer 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.DisposableServer in project reactor-netty by reactor.
the class TcpClientTests method testIssue585_1.
@Test
void testIssue585_1() throws Exception {
DisposableServer server = TcpServer.create().port(0).handle((req, res) -> res.send(req.receive().retain())).wiretap(true).bindNow();
CountDownLatch latch = new CountDownLatch(1);
byte[] bytes = "test".getBytes(Charset.defaultCharset());
ByteBuf b1 = Unpooled.wrappedBuffer(bytes);
ByteBuf b2 = Unpooled.wrappedBuffer(bytes);
ByteBuf b3 = Unpooled.wrappedBuffer(bytes);
WeakReference<ByteBuf> refCheck1 = new WeakReference<>(b1);
WeakReference<ByteBuf> refCheck2 = new WeakReference<>(b2);
WeakReference<ByteBuf> refCheck3 = new WeakReference<>(b3);
Connection conn = TcpClient.create().remoteAddress(server::address).wiretap(true).connectNow();
NettyOutbound out = conn.outbound();
Flux.concatDelayError(out.sendObject(Mono.error(new RuntimeException("test"))).sendObject(b1).then(), out.sendObject(Mono.error(new RuntimeException("test"))).sendObject(b2).then(), out.sendObject(Mono.error(new RuntimeException("test"))).sendObject(b3).then()).doOnError(t -> latch.countDown()).subscribe(conn.disposeSubscriber());
assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
assertThat(b1.refCnt()).isEqualTo(0);
b1 = null;
checkReference(refCheck1);
assertThat(b2.refCnt()).isEqualTo(0);
b2 = null;
checkReference(refCheck2);
assertThat(b3.refCnt()).isEqualTo(0);
b3 = null;
checkReference(refCheck3);
server.disposeNow();
conn.disposeNow();
}
Aggregations