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);
}
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));
}
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);
}
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);
}
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();
}
Aggregations