Search in sources :

Example 6 with MockClock

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

the class CompositeLongTaskTimerTest method mapIdsToEachLongTaskTimerInComposite.

@Test
void mapIdsToEachLongTaskTimerInComposite() {
    MockClock clock = new MockClock();
    MeterRegistry s1 = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
    LongTaskTimer anotherTimer = s1.more().longTaskTimer("long.task");
    LongTaskTimer.Sample anotherSample = anotherTimer.start();
    clock.add(10, TimeUnit.NANOSECONDS);
    CompositeMeterRegistry registry = new CompositeMeterRegistry(clock);
    registry.add(s1);
    LongTaskTimer longTaskTimer = registry.more().longTaskTimer("long.task");
    LongTaskTimer.Sample sample = longTaskTimer.start();
    clock.add(100, TimeUnit.NANOSECONDS);
    assertThat(anotherSample.stop()).isEqualTo(110);
    // if this fails, the composite is using a timer ID that overlaps with a separate timer in a member
    // of the composite rather than mapping the ID to a separate ID in the composite member.
    assertThat(sample.stop()).isEqualTo(100);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) LongTaskTimer(io.micrometer.core.instrument.LongTaskTimer) 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 7 with MockClock

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

the class JettyStatisticsMetricsTest method setup.

@BeforeEach
void setup() {
    this.registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    this.handler = new StatisticsHandler();
    JettyStatisticsMetrics.monitor(registry, handler);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler) MockClock(io.micrometer.core.instrument.MockClock) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with MockClock

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

the class CompositeCounterTest method increment.

@Test
@Issue("#119")
void increment() {
    SimpleMeterRegistry simple = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    CompositeMeterRegistry registry = new CompositeMeterRegistry();
    registry.add(simple);
    registry.counter("counter").increment(2.0);
    assertThat(simple.get("counter").counter().count()).isEqualTo(2.0);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MockClock(io.micrometer.core.instrument.MockClock) Issue(io.micrometer.core.Issue) Test(org.junit.jupiter.api.Test)

Example 9 with MockClock

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

the class InfluxMeterRegistryFieldToStringTest method testWithEnglishLocaleWithLargerResolution.

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

Example 10 with MockClock

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

the class GraphiteMeterRegistryTest method metricPrefixes.

@Test
void metricPrefixes() {
    final CountDownLatch bindLatch = new CountDownLatch(1);
    final CountDownLatch receiveLatch = new CountDownLatch(1);
    final CountDownLatch terminateLatch = new CountDownLatch(1);
    final GraphiteMeterRegistry registry = new GraphiteMeterRegistry(new GraphiteConfig() {

        @Override
        @Nullable
        public String get(String key) {
            return null;
        }

        @Override
        public Duration step() {
            return Duration.ofSeconds(1);
        }

        @Override
        public GraphiteProtocol protocol() {
            return GraphiteProtocol.UDP;
        }

        @Override
        public int port() {
            return 8127;
        }

        @Override
        public String[] tagsAsPrefix() {
            return new String[] { "application" };
        }
    }, mockClock);
    final Disposable.Swap server = Disposables.swap();
    Consumer<ClientOptions.Builder<?>> opts = builder -> builder.option(ChannelOption.SO_REUSEADDR, true).connectAddress(() -> new InetSocketAddress(PORT));
    UdpServer.create(opts).newHandler((in, out) -> {
        in.receive().asString().log().subscribe(line -> {
            assertThat(line).startsWith("APPNAME.myTimer");
            receiveLatch.countDown();
        });
        return Flux.never();
    }).doOnSuccess(v -> bindLatch.countDown()).doOnTerminate(terminateLatch::countDown).subscribe(server::replace);
    try {
        assertTrue(bindLatch.await(10, TimeUnit.SECONDS));
        registry.timer("my.timer", "application", "APPNAME");
        assertTrue(receiveLatch.await(10, TimeUnit.SECONDS));
    } catch (InterruptedException e) {
        fail("Failed to wait for line", e);
    } finally {
        server.dispose();
        registry.stop();
        try {
            terminateLatch.await(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            fail("Failed to terminate UDP server listening for Graphite metrics", e);
        }
    }
}
Also used : Disposable(reactor.core.Disposable) Nullable(io.micrometer.core.lang.Nullable) Disposable(reactor.core.Disposable) ChannelOption(io.netty.channel.ChannelOption) MockClock(io.micrometer.core.instrument.MockClock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Flux(reactor.core.publisher.Flux) CountDownLatch(java.util.concurrent.CountDownLatch) Assertions.fail(org.assertj.core.api.Assertions.fail) Duration(java.time.Duration) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UdpServer(reactor.ipc.netty.udp.UdpServer) ClientOptions(reactor.ipc.netty.options.ClientOptions) Disposables(reactor.core.Disposables) InetSocketAddress(java.net.InetSocketAddress) Duration(java.time.Duration) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(io.micrometer.core.lang.Nullable) 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