Search in sources :

Example 16 with MockClock

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

the class TimeWindowPercentileHistogramTest method percentilesWithNoSamples.

@Test
void percentilesWithNoSamples() {
    DistributionStatisticConfig config = DistributionStatisticConfig.builder().percentiles(0.5).build().merge(DistributionStatisticConfig.DEFAULT);
    TimeWindowPercentileHistogram histogram = new TimeWindowPercentileHistogram(new MockClock(), config, false);
    assertThat(histogram.takeSnapshot(0, 0, 0).percentileValues()).containsExactly(new ValueAtPercentile(0.5, 0));
}
Also used : MockClock(io.micrometer.core.instrument.MockClock) Test(org.junit.jupiter.api.Test)

Example 17 with MockClock

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

the class TimeWindowPercentileHistogramTest method percentiles.

@Test
void percentiles() {
    TimeWindowPercentileHistogram histogram = new TimeWindowPercentileHistogram(new MockClock(), DistributionStatisticConfig.builder().percentiles(0.5, 0.9, 0.95).minimumExpectedValue((long) millisToUnit(1, TimeUnit.NANOSECONDS)).maximumExpectedValue((long) secondsToUnit(30, TimeUnit.NANOSECONDS)).build().merge(DistributionStatisticConfig.DEFAULT), false);
    for (long i = 1; i <= 10; i++) {
        histogram.recordLong((long) millisToUnit(i, TimeUnit.NANOSECONDS));
    }
    assertThat(histogram.takeSnapshot(0, 0, 0).percentileValues()).anyMatch(p -> percentileValueIsApproximately(p, 0.5, 5e6)).anyMatch(p -> percentileValueIsApproximately(p, 0.9, 9e6)).anyMatch(p -> percentileValueIsApproximately(p, 0.95, 10e6));
}
Also used : Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) TimeUtils.secondsToUnit(io.micrometer.core.instrument.util.TimeUtils.secondsToUnit) MockClock(io.micrometer.core.instrument.MockClock) Duration(java.time.Duration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeUtils.millisToUnit(io.micrometer.core.instrument.util.TimeUtils.millisToUnit) MockClock(io.micrometer.core.instrument.MockClock) Test(org.junit.jupiter.api.Test)

Example 18 with MockClock

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

the class InfluxMeterRegistryFieldToStringTest method testWithEnglishLocale.

@Test
void testWithEnglishLocale() {
    Locale.setDefault(Locale.ENGLISH);
    InfluxMeterRegistry instance = new InfluxMeterRegistry(k -> null, new MockClock());
    InfluxMeterRegistry.Field field = instance.new Field("value", 0.01);
    assertThat(field.toString()).isEqualTo("value=0.01");
}
Also used : MockClock(io.micrometer.core.instrument.MockClock) Test(org.junit.jupiter.api.Test)

Example 19 with MockClock

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

the class InfluxMeterRegistryFieldToStringTest method testWithSwedishLocale.

@Test
void testWithSwedishLocale() {
    Locale.setDefault(new Locale("sv", "SE"));
    InfluxMeterRegistry instance = new InfluxMeterRegistry(k -> null, new MockClock());
    InfluxMeterRegistry.Field field = instance.new Field("value", 0.01);
    assertThat(field.toString()).isEqualTo("value=0.01");
}
Also used : Locale(java.util.Locale) MockClock(io.micrometer.core.instrument.MockClock) 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