use of io.netty.util.concurrent.DefaultEventExecutor 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.util.concurrent.DefaultEventExecutor 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.util.concurrent.DefaultEventExecutor 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();
}
Aggregations