Search in sources :

Example 1 with EVENT_LOOP_PREFIX

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));
        }
    }
}
Also used : LoopResources(reactor.netty.resources.LoopResources) IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) EVENT_LOOP_PREFIX(reactor.netty.Metrics.EVENT_LOOP_PREFIX) SimpleMeterRegistry(io.micrometer.api.instrument.simple.SimpleMeterRegistry) SingleThreadEventExecutor(io.netty.util.concurrent.SingleThreadEventExecutor) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NAME(reactor.netty.Metrics.NAME) EventLoop(io.netty.channel.EventLoop) Test(org.junit.jupiter.api.Test) TcpClient(reactor.netty.tcp.TcpClient) TimeUnit(java.util.concurrent.TimeUnit) PENDING_TASKS(reactor.netty.Metrics.PENDING_TASKS) CountDownLatch(java.util.concurrent.CountDownLatch) AfterEach(org.junit.jupiter.api.AfterEach) MeterRegistry(io.micrometer.api.instrument.MeterRegistry) Duration(java.time.Duration) Metrics(io.micrometer.api.instrument.Metrics) TcpServer(reactor.netty.tcp.TcpServer) Connection(reactor.netty.Connection) DisposableServer(reactor.netty.DisposableServer) Gauge(io.micrometer.api.instrument.Gauge) EventLoop(io.netty.channel.EventLoop) DisposableServer(reactor.netty.DisposableServer) SingleThreadEventExecutor(io.netty.util.concurrent.SingleThreadEventExecutor) LoopResources(reactor.netty.resources.LoopResources) Connection(reactor.netty.Connection) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

Gauge (io.micrometer.api.instrument.Gauge)1 MeterRegistry (io.micrometer.api.instrument.MeterRegistry)1 Metrics (io.micrometer.api.instrument.Metrics)1 SimpleMeterRegistry (io.micrometer.api.instrument.simple.SimpleMeterRegistry)1 EventLoop (io.netty.channel.EventLoop)1 SingleThreadEventExecutor (io.netty.util.concurrent.SingleThreadEventExecutor)1 Duration (java.time.Duration)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 IntStream (java.util.stream.IntStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 AfterEach (org.junit.jupiter.api.AfterEach)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 Connection (reactor.netty.Connection)1 DisposableServer (reactor.netty.DisposableServer)1 EVENT_LOOP_PREFIX (reactor.netty.Metrics.EVENT_LOOP_PREFIX)1 NAME (reactor.netty.Metrics.NAME)1 PENDING_TASKS (reactor.netty.Metrics.PENDING_TASKS)1 LoopResources (reactor.netty.resources.LoopResources)1