use of io.netty.channel.group.DefaultChannelGroup in project reactor-netty by reactor.
the class ITTracingHttpServerDecoratorTest method init.
@Override
@SuppressWarnings("deprecation")
protected void init() {
HttpServerRoutes routes = HttpServerRoutes.newRoutes().options("/", (req, res) -> res.send()).get("/foo", (req, res) -> res.sendString(Mono.just("bar"))).get("/baggage", (req, res) -> res.sendString(Mono.just(req.requestHeaders().getAsString(BAGGAGE_FIELD_KEY)))).get("/exception", (req, res) -> Mono.error(NOT_READY_ISE)).get("/badrequest", (req, res) -> res.status(400).send()).get("/async", (req, res) -> res.sendString(Mono.just("body").publishOn(Schedulers.boundedElastic()))).get("/exceptionAsync", (req, res) -> Mono.error(NOT_READY_ISE).publishOn(Schedulers.boundedElastic()).then()).get("/items/{itemId}", (req, res) -> res.sendString(Mono.justOrEmpty(req.param("itemId")))).get("/async_items/{itemId}", (req, res) -> res.sendString(Mono.justOrEmpty(req.param("itemId")).publishOn(Schedulers.boundedElastic()))).get("/nested/items/{itemId}", (req, res) -> res.sendString(Mono.justOrEmpty(req.param("itemId")))).get("/child", (req, res) -> {
httpTracing.tracing().tracer().nextSpan().name("child").start().finish();
return res.send();
});
ReactorNettyHttpTracing reactorNettyHttpTracing = ReactorNettyHttpTracing.create(httpTracing, s -> {
if ("/foo/bark".equals(s)) {
return "not_found";
}
int ind = s.lastIndexOf('/');
if (s.length() > 1 && ind > -1) {
return s.substring(0, ind);
}
return s;
});
group = new DefaultChannelGroup(executor);
disposableServer = reactorNettyHttpTracing.decorateHttpServer(HttpServer.create().port(0).wiretap(true).forwarded(true).channelGroup(group).handle(routes)).bindNow();
}
use of io.netty.channel.group.DefaultChannelGroup in project reactor-netty by reactor.
the class TcpServerTests method testChannelGroupClosesAllConnections.
@Test
void testChannelGroupClosesAllConnections() throws Exception {
ChannelGroup group = new DefaultChannelGroup(new DefaultEventExecutor());
CountDownLatch latch1 = new CountDownLatch(1);
CountDownLatch latch2 = new CountDownLatch(1);
DisposableServer boundServer = TcpServer.create().port(0).doOnConnection(c -> {
c.onDispose().subscribe(null, null, latch2::countDown);
group.add(c.channel());
latch1.countDown();
}).wiretap(true).bindNow();
TcpClient.create().remoteAddress(boundServer::address).wiretap(true).connect().subscribe();
assertThat(latch1.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
boundServer.disposeNow();
FutureMono.from(group.close()).block(Duration.ofSeconds(30));
assertThat(latch2.await(5, TimeUnit.SECONDS)).as("latch await").isTrue();
}
use of io.netty.channel.group.DefaultChannelGroup in project reactor-netty by reactor.
the class TcpServerTests method testIssue688.
@Test
void testIssue688() throws Exception {
CountDownLatch connected = new CountDownLatch(1);
CountDownLatch configured = new CountDownLatch(1);
CountDownLatch disconnected = new CountDownLatch(1);
ChannelGroup group = new DefaultChannelGroup(new DefaultEventExecutor());
DisposableServer server = TcpServer.create().port(0).childObserve((connection, newState) -> {
if (newState == ConnectionObserver.State.CONNECTED) {
group.add(connection.channel());
connected.countDown();
} else if (newState == ConnectionObserver.State.CONFIGURED) {
configured.countDown();
} else if (newState == ConnectionObserver.State.DISCONNECTING) {
disconnected.countDown();
}
}).wiretap(true).bindNow();
TcpClient.create().remoteAddress(server::address).wiretap(true).connect().subscribe();
assertThat(connected.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
assertThat(configured.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
FutureMono.from(group.close()).block(Duration.ofSeconds(30));
assertThat(disconnected.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
server.disposeNow();
}
use of io.netty.channel.group.DefaultChannelGroup in project reactor-netty by reactor.
the class HttpClientTest method testChannelGroupClosesAllConnections.
@Test
void testChannelGroupClosesAllConnections() throws Exception {
disposableServer = createServer().route(r -> r.get("/never", (req, res) -> res.sendString(Mono.never())).get("/delay10", (req, res) -> res.sendString(Mono.just("test").delayElement(Duration.ofSeconds(10)))).get("/delay1", (req, res) -> res.sendString(Mono.just("test").delayElement(Duration.ofSeconds(1))))).bindNow(Duration.ofSeconds(30));
ConnectionProvider connectionProvider = ConnectionProvider.create("testChannelGroupClosesAllConnections", Integer.MAX_VALUE);
ChannelGroup group = new DefaultChannelGroup(new DefaultEventExecutor());
CountDownLatch latch1 = new CountDownLatch(3);
CountDownLatch latch2 = new CountDownLatch(3);
HttpClient client = createHttpClientForContextWithAddress(connectionProvider);
Flux.just("/never", "/delay10", "/delay1").flatMap(s -> client.doOnConnected(c -> {
c.onDispose().subscribe(null, null, latch2::countDown);
group.add(c.channel());
latch1.countDown();
}).get().uri(s).responseContent().aggregate().asString()).subscribe();
assertThat(latch1.await(30, TimeUnit.SECONDS)).isTrue();
Mono.whenDelayError(FutureMono.from(group.close()), connectionProvider.disposeLater()).block(Duration.ofSeconds(30));
assertThat(latch2.await(30, TimeUnit.SECONDS)).isTrue();
}
use of io.netty.channel.group.DefaultChannelGroup in project reactor-netty by reactor.
the class HttpServerTests method testTcpConfiguration_1.
@Test
@SuppressWarnings("deprecation")
void testTcpConfiguration_1() throws Exception {
CountDownLatch latch = new CountDownLatch(10);
LoopResources loop = LoopResources.create("testTcpConfiguration");
ChannelGroup group = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
doTestTcpConfiguration(HttpServer.create().tcpConfiguration(tcp -> configureTcpServer(tcp, loop, group, latch)), HttpClient.create().tcpConfiguration(tcp -> configureTcpClient(tcp, loop, group, latch)));
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
FutureMono.from(group.close()).then(loop.disposeLater()).block(Duration.ofSeconds(30));
}
Aggregations