Search in sources :

Example 6 with LongTaskTimer

use of io.micrometer.core.instrument.LongTaskTimer in project micrometer by micrometer-metrics.

the class LongTaskTimerTest method record.

@Test
@DisplayName("total time is preserved for a single timing")
default void record(MeterRegistry registry) {
    LongTaskTimer t = registry.more().longTaskTimer("myTimer");
    LongTaskTimer.Sample sample = t.start();
    clock(registry).add(10, TimeUnit.NANOSECONDS);
    assertAll(() -> assertEquals(10, t.duration(TimeUnit.NANOSECONDS)), () -> assertEquals(0.01, t.duration(TimeUnit.MICROSECONDS)), () -> assertEquals(10, sample.duration(TimeUnit.NANOSECONDS)), () -> assertEquals(0.01, sample.duration(TimeUnit.MICROSECONDS)), () -> assertEquals(1, t.activeTasks()));
    clock(registry).add(10, TimeUnit.NANOSECONDS);
    sample.stop();
    assertAll(() -> assertEquals(0, t.duration(TimeUnit.NANOSECONDS)), () -> assertEquals(-1, sample.duration(TimeUnit.NANOSECONDS)), () -> assertEquals(0, t.activeTasks()));
}
Also used : LongTaskTimer(io.micrometer.core.instrument.LongTaskTimer) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

LongTaskTimer (io.micrometer.core.instrument.LongTaskTimer)6 Timed (io.micrometer.core.annotation.Timed)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2 Timer (io.micrometer.core.instrument.Timer)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 Test (org.junit.jupiter.api.Test)2 Normal (cern.jet.random.Normal)1 MersenneTwister64 (cern.jet.random.engine.MersenneTwister64)1 RandomEngine (cern.jet.random.engine.RandomEngine)1 MockClock (io.micrometer.core.instrument.MockClock)1 SampleConfig (io.micrometer.core.samples.utils.SampleConfig)1 Method (java.lang.reflect.Method)1 Duration (java.time.Duration)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 NotFoundException (javax.ws.rs.NotFoundException)1 Around (org.aspectj.lang.annotation.Around)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1