Search in sources :

Example 11 with MockClock

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

the class SpectatorTimerTest method timerMax.

@Test
void timerMax() {
    AtlasConfig atlasConfig = k -> null;
    AtlasMeterRegistry registry = new AtlasMeterRegistry(atlasConfig, new MockClock());
    Timer timer = registry.timer("timer");
    timer.record(1, TimeUnit.SECONDS);
    clock(registry).add(atlasConfig.step());
    assertThat(timer.max(TimeUnit.MILLISECONDS)).isEqualTo(1000);
}
Also used : Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) AtlasConfig(com.netflix.spectator.atlas.AtlasConfig) Timer(io.micrometer.core.instrument.Timer) MockClock(io.micrometer.core.instrument.MockClock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MockClock.clock(io.micrometer.core.instrument.MockClock.clock) Timer(io.micrometer.core.instrument.Timer) AtlasConfig(com.netflix.spectator.atlas.AtlasConfig) MockClock(io.micrometer.core.instrument.MockClock) Test(org.junit.jupiter.api.Test)

Example 12 with MockClock

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

the class TimeWindowFixedBoundaryHistogramTest method histogramsAreCumulative.

@Test
void histogramsAreCumulative() {
    TimeWindowFixedBoundaryHistogram histogram = new TimeWindowFixedBoundaryHistogram(new MockClock(), DistributionStatisticConfig.builder().sla(3, 6, 7).bufferLength(1).build().merge(DistributionStatisticConfig.DEFAULT), false);
    histogram.recordDouble(3);
    assertThat(histogram.takeSnapshot(0, 0, 0).histogramCounts()).contains(new CountAtBucket(3, 1));
    histogram.recordDouble(6);
    // Proves that the accumulated histogram is truly cumulative, and not just a representation
    // of the last snapshot
    assertThat(histogram.takeSnapshot(0, 0, 0).histogramCounts()).containsExactly(new CountAtBucket(3, 1), new CountAtBucket(6, 2), new CountAtBucket(7, 2));
}
Also used : MockClock(io.micrometer.core.instrument.MockClock) Test(org.junit.jupiter.api.Test)

Example 13 with MockClock

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

the class StepFunctionCounterTest method count.

@Test
void count() {
    AtomicInteger n = new AtomicInteger(1);
    MockClock clock = new MockClock();
    StepFunctionCounter<AtomicInteger> counter = new StepFunctionCounter<>(new Meter.Id("my.counter", emptyList(), null, null, Meter.Type.COUNTER), clock, 1, n, AtomicInteger::get);
    assertThat(counter.count()).isEqualTo(0);
    clock.add(1, TimeUnit.MILLISECONDS);
    assertThat(counter.count()).isEqualTo(1);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Meter(io.micrometer.core.instrument.Meter) MockClock(io.micrometer.core.instrument.MockClock) Test(org.junit.jupiter.api.Test)

Example 14 with MockClock

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

the class UptimeMetricsTest method uptimeMetricsMock.

@Test
void uptimeMetricsMock() {
    MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    RuntimeMXBean runtimeMXBean = mock(RuntimeMXBean.class);
    when(runtimeMXBean.getUptime()).thenReturn(1337L);
    when(runtimeMXBean.getStartTime()).thenReturn(4711L);
    new UptimeMetrics(runtimeMXBean, emptyList()).bindTo(registry);
    assertThat(registry.get("process.uptime").timeGauge().value()).isEqualTo(1.337);
    assertThat(registry.get("process.start.time").timeGauge().value()).isEqualTo(4.711);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) RuntimeMXBean(java.lang.management.RuntimeMXBean) MockClock(io.micrometer.core.instrument.MockClock) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 15 with MockClock

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

the class UptimeMetricsTest method uptimeMetricsRuntime.

@Test
void uptimeMetricsRuntime() {
    MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    new UptimeMetrics().bindTo(registry);
    registry.get("process.uptime").timeGauge();
    registry.get("process.start.time").timeGauge();
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MockClock(io.micrometer.core.instrument.MockClock) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

MockClock (io.micrometer.core.instrument.MockClock)19 Test (org.junit.jupiter.api.Test)18 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)5 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)3 TimeUnit (java.util.concurrent.TimeUnit)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Duration (java.time.Duration)2 AtlasConfig (com.netflix.spectator.atlas.AtlasConfig)1 Issue (io.micrometer.core.Issue)1 LongTaskTimer (io.micrometer.core.instrument.LongTaskTimer)1 Meter (io.micrometer.core.instrument.Meter)1 MockClock.clock (io.micrometer.core.instrument.MockClock.clock)1 Timer (io.micrometer.core.instrument.Timer)1 TimeUtils.millisToUnit (io.micrometer.core.instrument.util.TimeUtils.millisToUnit)1 TimeUtils.secondsToUnit (io.micrometer.core.instrument.util.TimeUtils.secondsToUnit)1 Nullable (io.micrometer.core.lang.Nullable)1 ChannelOption (io.netty.channel.ChannelOption)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 InetSocketAddress (java.net.InetSocketAddress)1 Locale (java.util.Locale)1