io.micrometer.core.instrument.MockClock Java Examples

The following examples show how to use io.micrometer.core.instrument.MockClock. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AtlasMeterRegistryCompatibilityTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Override
public MeterRegistry registry() {
    return new AtlasMeterRegistry(new AtlasConfig() {
        @Override
        public boolean enabled() {
            return false;
        }

        @SuppressWarnings("ConstantConditions")
        @Override
        public String get(String k) {
            return null;
        }

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

        @Override
        public Duration lwcStep() {
            return step();
        }
    }, new MockClock());
}
 
Example #2
Source File: SpectatorTimerTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void timerMax() {
    AtlasConfig atlasConfig = new AtlasConfig() {
        @Override
        public String get(String k) {
            return null;
        }

        @Override
        public Duration lwcStep() {
            return step();
        }
    };
    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);
}
 
Example #3
Source File: TimeWindowPercentileHistogramTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void histogramsAreCumulative() {
    try (TimeWindowPercentileHistogram histogram = new TimeWindowPercentileHistogram(new MockClock(),
            DistributionStatisticConfig.builder()
                    .serviceLevelObjectives(3.0, 6, 7)
                    .build()
                    .merge(DistributionStatisticConfig.DEFAULT), false)) {

        histogram.recordDouble(3);

        assertThat(histogram.takeSnapshot(0, 0, 0).histogramCounts()).containsExactly(
                new CountAtBucket(3.0, 1),
                new CountAtBucket(6.0, 1),
                new CountAtBucket(7.0, 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.0, 1),
                new CountAtBucket(6.0, 2),
                new CountAtBucket(7.0, 2)
        );
    }
}
 
Example #4
Source File: TimeWindowPercentileHistogramTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void recordValuesThatExceedTheDynamicRange() {
    try (TimeWindowPercentileHistogram histogram = new TimeWindowPercentileHistogram(new MockClock(),
            DistributionStatisticConfig.builder()
                    .serviceLevelObjectives(Double.POSITIVE_INFINITY)
                    .build()
                    .merge(DistributionStatisticConfig.DEFAULT), false)) {

        // Regardless of the imputed dynamic bound for the underlying histogram, Double.MAX_VALUE is always too
        // large.
        histogram.recordDouble(Double.MAX_VALUE);

        assertThat(histogram.takeSnapshot(0, 0, 0).histogramCounts())
                .containsExactly(new CountAtBucket(Double.POSITIVE_INFINITY, 0));
    }
}
 
Example #5
Source File: TimeWindowPercentileHistogramTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void percentiles() {
    try (TimeWindowPercentileHistogram histogram = new TimeWindowPercentileHistogram(new MockClock(),
            DistributionStatisticConfig.builder()
                    .percentiles(0.5, 0.9, 0.95)
                    .minimumExpectedValue(millisToUnit(1, TimeUnit.NANOSECONDS))
                    .maximumExpectedValue(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));
    }
}
 
Example #6
Source File: WavefrontMeterRegistryCompatibilityTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Override
public MeterRegistry registry() {
    return new WavefrontMeterRegistry(new WavefrontConfig() {
        @Override
        public boolean enabled() {
            return false;
        }

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

        @Override
        public String uri() {
            return WavefrontConfig.DEFAULT_PROXY.uri();
        }
    }, new MockClock());
}
 
Example #7
Source File: HealthMeterRegistryTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void onlyMetricsThatAreServiceLevelIndicatorsAreRegistered() {
    HealthMeterRegistry registry = HealthMeterRegistry.builder(HealthConfig.DEFAULT)
            .clock(new MockClock())
            .serviceLevelObjectives(
                    ServiceLevelObjective
                            .build("counter.throughput")
                            .count(search -> search.name("my.counter"))
                            .isGreaterThan(1)
            )
            .build();

    assertThat(registry.getMeters()).isEmpty();

    registry.counter("my.counter", "k", "v").increment();
    assertThat(registry.getMeters().size()).isEqualTo(1);

    registry.counter("another.counter").increment();
    assertThat(registry.getMeters().size()).isEqualTo(1);
}
 
Example #8
Source File: HealthMeterRegistryTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void applyRequiredBinders() {
    HealthMeterRegistry registry = HealthMeterRegistry.builder(HealthConfig.DEFAULT)
            .clock(new MockClock())
            .serviceLevelObjectives(
                    ServiceLevelObjective
                            .build("counter.throughput")
                            .requires(new JvmMemoryMetrics())
                            .value(search -> search.name("jvm.memory.used"))
                            .isGreaterThan(1)
            )
            .build();

    assertThat(registry.getMeters().stream().map(m -> m.getId().getName()))
            .containsOnly("jvm.memory.used")
            .isNotEmpty();
}
 
Example #9
Source File: StepTimerTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Issue("#1814")
@Test
void meanShouldWorkIfTotalTimeNotCalled() {
    Duration stepDuration = Duration.ofMillis(10);
    MockClock clock = new MockClock();
    StepTimer timer = new StepTimer(
            mock(Meter.Id.class),
            clock,
            DistributionStatisticConfig.builder().expiry(stepDuration).bufferLength(2).build(),
            mock(PauseDetector.class),
            TimeUnit.MILLISECONDS,
            stepDuration.toMillis(),
            false
    );

    clock.add(stepDuration);
    assertThat(timer.mean(TimeUnit.MILLISECONDS)).isEqualTo(0.0);

    clock.add(Duration.ofMillis(1));
    timer.record(Duration.ofMillis(50));
    timer.record(Duration.ofMillis(100));

    clock.add(stepDuration);
    assertThat(timer.mean(TimeUnit.MILLISECONDS)).isEqualTo(75.0);
}
 
Example #10
Source File: StepDistributionSummaryTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Issue("#1814")
@Test
void meanShouldWorkIfTotalNotCalled() {
    Duration stepDuration = Duration.ofMillis(10);
    MockClock clock = new MockClock();
    StepDistributionSummary summary = new StepDistributionSummary(
            mock(Meter.Id.class),
            clock,
            DistributionStatisticConfig.builder().expiry(stepDuration).bufferLength(2).build(),
            1.0,
            stepDuration.toMillis(),
            false
    );

    clock.add(stepDuration);
    assertThat(summary.mean()).isEqualTo(0.0);

    clock.add(Duration.ofMillis(1));
    summary.record(50);
    summary.record(100);

    clock.add(stepDuration);
    assertThat(summary.mean()).isEqualTo(75.0);
}
 
Example #11
Source File: HealthMeterRegistryTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void meterFiltersAffectServiceLevelObjectives() {
    HealthMeterRegistry registry = HealthMeterRegistry.builder(HealthConfig.DEFAULT)
            .clock(new MockClock())
            .serviceLevelObjectives(JvmServiceLevelObjectives.MEMORY)
            .serviceLevelObjectiveFilter(MeterFilter.denyNameStartsWith("jvm.pool"))
            .serviceLevelObjectiveFilter(new MeterFilter() {
                @Override
                public Meter.Id map(Meter.Id id) {
                    return id.getName().equals("jvm.gc.load") ? id.withName("jvm.collection.load") : id;
                }
            })
            .build();

    assertThat(registry.getServiceLevelObjectives().stream().map(ServiceLevelObjective::getName))
            .contains("jvm.collection.load")
            .doesNotContain("jvm.pool.memory")
            .isNotEmpty();
}
 
Example #12
Source File: TimeWindowPercentileHistogramTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void percentilesChangeWithMoreRecentSamples() {
    DistributionStatisticConfig config = DistributionStatisticConfig.builder()
            .percentiles(0.5)
            .build()
            .merge(DistributionStatisticConfig.DEFAULT);

    try (TimeWindowPercentileHistogram histogram = new TimeWindowPercentileHistogram(new MockClock(),
            config, false)) {

        for (int i = 1; i <= 10; i++) {
            histogram.recordLong((long) millisToUnit(i, TimeUnit.NANOSECONDS));
        }

        // baseline median
        assertThat(histogram.takeSnapshot(0, 0, 0).percentileValues())
                .anyMatch(p -> percentileValueIsApproximately(p, 0.5, 5e6));

        for (int i = 11; i <= 20; i++) {
            histogram.recordLong((long) millisToUnit(i, TimeUnit.NANOSECONDS));
        }

        // median should have moved after seeing 10 more samples
        assertThat(histogram.takeSnapshot(0, 0, 0).percentileValues())
                .anyMatch(p -> percentileValueIsApproximately(p, 0.5, 10e6));
    }
}
 
Example #13
Source File: CompositeCounterTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: TimeWindowPercentileHistogramTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void percentilesWithNoSamples() {
    DistributionStatisticConfig config = DistributionStatisticConfig.builder()
            .percentiles(0.5)
            .build()
            .merge(DistributionStatisticConfig.DEFAULT);

    try (TimeWindowPercentileHistogram histogram = new TimeWindowPercentileHistogram(new MockClock(),
            config, false)) {

        ValueAtPercentile expectedPercentile = new ValueAtPercentile(0.5, 0);
        HistogramSnapshot snapshot = histogram.takeSnapshot(0, 0, 0);
        assertThat(snapshot.percentileValues()).containsExactly(expectedPercentile);
    }
}
 
Example #15
Source File: StepFunctionTimerTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Issue("#1814")
@Test
void meanShouldWorkIfTotalNotCalled() {
    Queue<Long> counts = new LinkedList<>();
    counts.add(2L);
    counts.add(5L);
    counts.add(10L);

    Queue<Double> totalTimes = new LinkedList<>();
    totalTimes.add(150.0);
    totalTimes.add(300.0);
    totalTimes.add(1000.0);

    Duration stepDuration = Duration.ofMillis(10);
    MockClock clock = new MockClock();
    StepFunctionTimer<Object> ft = new StepFunctionTimer<>(
            mock(Meter.Id.class),
            clock,
            stepDuration.toMillis(),
            new Object(),
            (o) -> counts.poll(),
            (o) -> totalTimes.poll(),
            TimeUnit.SECONDS,
            TimeUnit.SECONDS
    );

    assertThat(ft.count()).isEqualTo(0.0);

    clock.add(stepDuration);
    assertThat(ft.mean(TimeUnit.SECONDS)).isEqualTo(300.0 / 5L);

    clock.add(stepDuration);
    assertThat(ft.mean(TimeUnit.SECONDS)).isEqualTo(700.0 / 5L);
}
 
Example #16
Source File: StepFunctionTimerTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void totalTimeWhenStateObjectChangedToNullShouldWorkWithChangedTimeUnit() {
    MockClock clock = new MockClock();
    StepFunctionTimer<Object> functionTimer = new StepFunctionTimer<>(
            mock(Meter.Id.class), clock, 1000L, new Object(), (o) -> 1L, (o) -> 1d, TimeUnit.SECONDS, TimeUnit.SECONDS
    );
    clock.add(Duration.ofSeconds(1));
    assertThat(functionTimer.totalTime(TimeUnit.SECONDS)).isEqualTo(1d);
    assertThat(functionTimer.totalTime(TimeUnit.MILLISECONDS)).isEqualTo(1000d);
    System.gc();
    assertThat(functionTimer.totalTime(TimeUnit.MILLISECONDS)).isEqualTo(1000d);
    assertThat(functionTimer.totalTime(TimeUnit.SECONDS)).isEqualTo(1d);
}
 
Example #17
Source File: UptimeMetricsTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #18
Source File: MonoMetricsFuseableTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void queuePollError() {
	//prepare registry with mock clock
	MockClock clock = new MockClock();
	removeRegistry();
	registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
	Metrics.globalRegistry.add(registry);

	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new MetricsFuseableSubscriber<>(testSubscriber,
					registry, clock, Tags.empty());

	FluxPeekFuseableTest.AssertQueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	testQueue.setCompleteWithError(true);
	testQueue.offer(1);

	fuseableSubscriber.onSubscribe(testQueue);
	fuseableSubscriber.requestFusion(Fuseable.SYNC);

	clock.add(Duration.ofMillis(200));
	Integer val1 = fuseableSubscriber.poll();
	assertThat(val1).isEqualTo(1);

	clock.add(Duration.ofMillis(123));
	assertThatIllegalStateException().isThrownBy(fuseableSubscriber::poll)
	                                 .withMessage("AssertQueueSubscriber poll error");

	//test meters
	Timer terminationTimer = registry.find(METER_FLOW_DURATION)
	                          .tags(Tags.of(TAG_ON_ERROR))
	                          .timer();

	assertThat(terminationTimer).isNotNull();
	assertThat(terminationTimer.max(TimeUnit.MILLISECONDS)).as("terminate max delay").isEqualTo(323);
}
 
Example #19
Source File: TimeWindowFixedBoundaryHistogramTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void histogramsAreCumulative() {
    try (TimeWindowFixedBoundaryHistogram histogram = new TimeWindowFixedBoundaryHistogram(new MockClock(),
            DistributionStatisticConfig.builder()
                    .serviceLevelObjectives(3.0, 6, 7)
                    .bufferLength(1)
                    .build()
                    .merge(DistributionStatisticConfig.DEFAULT), false)) {

        histogram.recordDouble(3);

        assertThat(histogram.takeSnapshot(0, 0, 0).histogramCounts()).containsExactly(
                new CountAtBucket(3.0, 1),
                new CountAtBucket(6.0, 1),
                new CountAtBucket(7.0, 1));

        histogram.recordDouble(6);

        histogram.recordDouble(7);

        // 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.0, 1),
                new CountAtBucket(6.0, 2),
                new CountAtBucket(7.0, 3)
        );
    }
}
 
Example #20
Source File: MicrometerCapabilityTest.java    From feign with Apache License 2.0 5 votes vote down vote up
@Test
public void addMetricsCapability() {
  SimpleMeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());

  final SimpleSource source = Feign.builder()
      .client(new MockClient()
          .ok(HttpMethod.GET, "/get", "1234567890abcde"))
      .addCapability(new MicrometerCapability(registry))
      .target(new MockTarget<>(MicrometerCapabilityTest.SimpleSource.class));

  source.get("0x3456789");

  List<Meter> metrics = new ArrayList<>();
  registry.forEachMeter(metrics::add);
  metrics.removeIf(meter -> !meter.getId().getName().startsWith("feign."));

  metrics.forEach(meter -> assertThat(
      "Expect all metric names to include client name:" + meter.getId(),
      meter.getId().getTag("client"),
      equalTo("feign.micrometer.MicrometerCapabilityTest$SimpleSource")));
  metrics.forEach(meter -> assertThat(
      "Expect all metric names to include method name:" + meter.getId(),
      meter.getId().getTag("method"),
      equalTo("get")));
  metrics.forEach(meter -> assertThat(
      "Expect all metric names to include host name:" + meter.getId(),
      meter.getId().getTag("host"),
      // hostname is blank due to feign-mock shortfalls
      equalTo("")));
}
 
Example #21
Source File: DefaultLongTaskTimerTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("supports sending histograms of active task duration")
void histogram() {
    MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());

    LongTaskTimer t = LongTaskTimer.builder("my.timer")
            .serviceLevelObjectives(Duration.ofSeconds(10), Duration.ofSeconds(40), Duration.ofMinutes(1))
            .register(registry);

    List<Integer> samples = Arrays.asList(48, 42, 40, 35, 22, 16, 13, 8, 6, 4, 2);
    int prior = samples.get(0);
    for (Integer value : samples) {
        clock(registry).add(prior - value, TimeUnit.SECONDS);
        t.start();
        prior = value;
    }
    clock(registry).add(samples.get(samples.size() - 1), TimeUnit.SECONDS);

    CountAtBucket[] countAtBuckets = t.takeSnapshot().histogramCounts();

    assertThat(countAtBuckets[0].bucket(TimeUnit.SECONDS)).isEqualTo(10);
    assertThat(countAtBuckets[0].count()).isEqualTo(4);

    assertThat(countAtBuckets[1].bucket(TimeUnit.SECONDS)).isEqualTo(40);
    assertThat(countAtBuckets[1].count()).isEqualTo(9);

    assertThat(countAtBuckets[2].bucket(TimeUnit.MINUTES)).isEqualTo(1);
    assertThat(countAtBuckets[2].count()).isEqualTo(11);
}
 
Example #22
Source File: FluxMetricsFuseableTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void queuePollSyncTracksOnComplete() {
	//prepare registry with mock clock
	MockClock clock = new MockClock();
	removeRegistry();
	registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
	Metrics.globalRegistry.add(registry);

	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	FluxMetricsFuseable.MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new FluxMetricsFuseable.MetricsFuseableSubscriber<>(testSubscriber,
					registry, clock, "foo", Tags.empty());

	Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	testQueue.offer(1);

	fuseableSubscriber.onSubscribe(testQueue);
	fuseableSubscriber.requestFusion(Fuseable.SYNC);

	clock.add(Duration.ofMillis(200));
	Integer val1 = fuseableSubscriber.poll();
	clock.add(Duration.ofMillis(123));
	Integer val2 = fuseableSubscriber.poll();

	assertThat(val1).isEqualTo(1);
	assertThat(val2).isNull();

	//test meters
	Timer terminationTimer = registry.find(METER_FLOW_DURATION)
	                          .tags(Tags.of(TAG_ON_COMPLETE))
	                          .timer();

	assertThat(terminationTimer).isNotNull();
	assertThat(terminationTimer.max(TimeUnit.MILLISECONDS)).as("terminate max delay").isEqualTo(323);
}
 
Example #23
Source File: FluxMetricsFuseableTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void queuePollTracksOnNext() {
	//prepare registry with mock clock
	MockClock clock = new MockClock();
	removeRegistry();
	registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
	Metrics.globalRegistry.add(registry);

	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	FluxMetricsFuseable.MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new FluxMetricsFuseable.MetricsFuseableSubscriber<>(testSubscriber,
					registry, clock, "foo", Tags.empty());

	Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	testQueue.offer(1);

	fuseableSubscriber.onSubscribe(testQueue);
	clock.add(Duration.ofMillis(200));

	Integer val1 = fuseableSubscriber.poll();
	Integer val2 = fuseableSubscriber.poll();

	assertThat(val1).isEqualTo(1);
	assertThat(val2).isNull();

	//test meters
	Timer nextTimer = registry.find(METER_ON_NEXT_DELAY)
			.timer();

	assertThat(nextTimer).isNotNull();
	assertThat(nextTimer.max(TimeUnit.MILLISECONDS)).as("onNext max delay").isEqualTo(200);
}
 
Example #24
Source File: HealthMeterRegistryTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void unmatchedServiceLevelObjectiveReportsHealthy() {
    HealthMeterRegistry registry = HealthMeterRegistry.builder(HealthConfig.DEFAULT)
            .clock(new MockClock())
            .serviceLevelObjectives(
                    ServiceLevelObjective
                            .build("counter.throughput")
                            .count(search -> search.name("my.counter"))
                            .isGreaterThan(1)
            )
            .build();

    assertThat(registry.getServiceLevelObjectives().iterator().next().healthy(registry)).isTrue();
}
 
Example #25
Source File: DropwizardFunctionTimerTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void totalTimeWhenStateObjectChangedToNullShouldWorkWithChangedTimeUnit() {
    DropwizardFunctionTimer<Object> functionTimer = new DropwizardFunctionTimer<>(
            null, new MockClock(), new Object(), (o) -> 1L, (o) -> 1d, TimeUnit.SECONDS, TimeUnit.SECONDS);
    assertThat(functionTimer.totalTime(TimeUnit.SECONDS)).isEqualTo(1d);
    assertThat(functionTimer.totalTime(TimeUnit.MILLISECONDS)).isEqualTo(1000d);
    System.gc();
    assertThat(functionTimer.totalTime(TimeUnit.MILLISECONDS)).isEqualTo(1000d);
    assertThat(functionTimer.totalTime(TimeUnit.SECONDS)).isEqualTo(1d);
}
 
Example #26
Source File: ElasticMeterRegistryCompatibilityTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
public MeterRegistry registry() {
    return new ElasticMeterRegistry(new ElasticConfig() {
        @Override
        public boolean enabled() {
            return false;
        }

        @Override
        @Nullable
        public String get(String key) {
            return null;
        }
    }, new MockClock());
}
 
Example #27
Source File: KairosMeterRegistryCompatibilityTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
public MeterRegistry registry() {
    return new KairosMeterRegistry(new KairosConfig() {
        @Override
        public boolean enabled() {
            return false;
        }

        @Override
        @Nullable
        public String get(String key) {
            return null;
        }
    }, new MockClock());
}
 
Example #28
Source File: GraphiteMeterRegistryCompatibilityTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
public MeterRegistry registry() {
    return new GraphiteMeterRegistry(new GraphiteConfig() {
        @Override
        public boolean enabled() {
            return false;
        }

        @Override
        @Nullable
        public String get(String key) {
            return null;
        }
    }, new MockClock(), HierarchicalNameMapper.DEFAULT);
}
 
Example #29
Source File: InfluxMeterRegistryCompatibilityTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
public MeterRegistry registry() {
    return new InfluxMeterRegistry(new InfluxConfig() {
        @Override
        public boolean enabled() {
            return false;
        }

        @Override
        @Nullable
        public String get(String key) {
            return null;
        }
    }, new MockClock());
}
 
Example #30
Source File: GangliaMeterRegistryCompatibilityTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
public MeterRegistry registry() {
    return GangliaMeterRegistry.builder(new GangliaConfig() {
        @Override
        public boolean enabled() {
            return false;
        }

        @Override
        @Nullable
        public String get(String key) {
            return null;
        }
    }).clock(new MockClock()).build();
}