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