use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.
the class TcpClientTests method tcpClientHandlesLineFeedDataElasticPool.
@Test
public void tcpClientHandlesLineFeedDataElasticPool() throws InterruptedException {
Consumer<Channel> channelInit = c -> c.pipeline().addBefore(NettyPipeline.ReactiveBridge, "codec", new LineBasedFrameDecoder(8 * 1024));
tcpClientHandlesLineFeedData(opts -> opts.host("localhost").port(echoServerPort).poolResources(PoolResources.elastic("tcpClientHandlesLineFeedDataElasticPool")).afterChannelInit(channelInit));
}
use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.
the class TcpResourcesTest method before.
@Before
public void before() {
loopDisposed = new AtomicBoolean();
poolDisposed = new AtomicBoolean();
loopResources = new LoopResources() {
@Override
public EventLoopGroup onServer(boolean useNative) {
return null;
}
@Override
public Mono<Void> disposeLater() {
return Mono.<Void>empty().doOnSuccess(c -> loopDisposed.set(true));
}
@Override
public boolean isDisposed() {
return loopDisposed.get();
}
};
poolResources = new PoolResources() {
@Override
public ChannelPool selectOrCreate(SocketAddress address, Supplier<? extends Bootstrap> bootstrap, Consumer<? super Channel> onChannelCreate, EventLoopGroup group) {
return null;
}
public Mono<Void> disposeLater() {
return Mono.<Void>empty().doOnSuccess(c -> poolDisposed.set(true));
}
@Override
public boolean isDisposed() {
return poolDisposed.get();
}
};
tcpResources = new TcpResources(loopResources, poolResources);
}
use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.
the class HttpClientTest method pipelined.
@Test
@Ignore
public void pipelined() throws Exception {
NettyContext x = TcpServer.create("localhost", 0).newHandler((in, out) -> out.context(c -> c.addHandlerFirst(new HttpResponseEncoder())).sendObject(Flux.just(response(), response())).neverComplete()).block(Duration.ofSeconds(30));
PoolResources pool = PoolResources.fixed("test", 1);
HttpClient.create(opts -> opts.host("localhost").port(x.address().getPort()).poolResources(pool)).get("/").flatMap(r -> {
r.dispose();
return Mono.just(r.status().code());
}).log().block(Duration.ofSeconds(30));
try {
HttpClient.create(opts -> opts.host("localhost").port(x.address().getPort()).poolResources(pool)).get("/").log().block(Duration.ofSeconds(30));
} catch (AbortedException ae) {
return;
}
x.dispose();
pool.dispose();
Assert.fail("Not aborted");
}
use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.
the class HttpClientTest method disableChunkImplicit.
@Test
public void disableChunkImplicit() throws Exception {
PoolResources p = PoolResources.fixed("test", 1);
HttpClientResponse r = HttpClient.create(opts -> opts.poolResources(p)).get("http://google.com/unsupportedURI", c -> c.failOnClientError(false).sendHeaders()).block(Duration.ofSeconds(30));
HttpClientResponse r2 = HttpClient.create(opts -> opts.poolResources(p)).get("http://google.com/unsupportedURI", c -> c.failOnClientError(false).sendHeaders()).block(Duration.ofSeconds(30));
Assert.assertTrue(r.context().channel() == r2.context().channel());
Assert.assertTrue(r.status() == HttpResponseStatus.NOT_FOUND);
r.dispose();
r2.dispose();
p.dispose();
}
use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.
the class HttpClientTest method userIssue.
@Test
public void userIssue() throws Exception {
final PoolResources pool = PoolResources.fixed("local", 1);
CountDownLatch latch = new CountDownLatch(3);
Set<String> localAddresses = ConcurrentHashMap.newKeySet();
NettyContext serverContext = HttpServer.create(8080).newRouter(r -> r.post("/", (req, resp) -> req.receive().asString().flatMap(data -> {
latch.countDown();
return resp.status(200).send();
}))).block();
final HttpClient client = HttpClient.create(options -> {
options.poolResources(pool);
options.connectAddress(() -> new InetSocketAddress(8080));
});
Flux.just("1", "2", "3").concatMap(data -> client.post("/", req -> req.sendString(Flux.just(data))).doOnNext(r -> r.receive().subscribe())).subscribe(response -> {
localAddresses.add(response.channel().localAddress().toString());
});
latch.await();
pool.dispose();
serverContext.dispose();
System.out.println("Local Addresses used: " + localAddresses);
}
Aggregations