use of reactor.netty.Metrics.EVENT_LOOP_PREFIX in project reactor-netty by reactor.
the class TransportEventLoopMetricsTest method testEventLoopMetrics.
@Test
void testEventLoopMetrics() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
DisposableServer server = null;
Connection client = null;
LoopResources loop = null;
try {
loop = LoopResources.create(TransportEventLoopMetricsTest.class.getName(), 3, true);
server = TcpServer.create().port(0).metrics(true).runOn(loop).doOnConnection(c -> {
EventLoop eventLoop = c.channel().eventLoop();
IntStream.range(0, 10).forEach(i -> eventLoop.execute(() -> {
}));
if (eventLoop instanceof SingleThreadEventExecutor) {
SingleThreadEventExecutor singleThreadEventExecutor = (SingleThreadEventExecutor) eventLoop;
String[] tags = new String[] { NAME, singleThreadEventExecutor.threadProperties().name() };
assertThat(getGaugeValue(EVENT_LOOP_PREFIX + PENDING_TASKS, tags)).isEqualTo(10);
latch.countDown();
}
}).wiretap(true).bindNow();
assertThat(server).isNotNull();
client = TcpClient.create().port(server.port()).wiretap(true).connectNow();
assertThat(client).isNotNull();
assertThat(latch.await(5, TimeUnit.SECONDS)).as("Did not find 10 pending tasks from meter").isTrue();
} finally {
if (client != null) {
client.disposeNow();
}
if (server != null) {
server.disposeNow();
}
if (loop != null) {
loop.disposeLater().block(Duration.ofSeconds(10));
}
}
}
Aggregations