private Histogram histogramOf(String name) { Histogram histogram = registry.getHistograms().get(name); if (histogram == null) { synchronized (operation) { histogram = registry.getHistograms().get(name); if (histogram == null) { histogram = registry.histogram(MetricsCollectorFactory.metadataOf(name, MetricType.HISTOGRAM)); } } } return histogram; }
private Histogram histogramOf(String name) { Histogram histogram = registry.getHistograms().get(name); if (histogram == null) { synchronized (operation) { histogram = registry.getHistograms().get(name); if (histogram == null) { histogram = registry.histogram(metadataOf(name, MetricType.HISTOGRAM)); } } } return histogram; }
@Test @InSequence(2) public void updateHistogramField() { assertThat("Histogram is not registered correctly", registry.getHistograms(), hasKey(HISTOGRAM_NAME)); Histogram histogram = registry.getHistograms().get(HISTOGRAM_NAME); // Call the update method and assert the histogram is up-to-date long value = Math.round(Math.random() * Long.MAX_VALUE); bean.update(value); assertThat("Histogram count is incorrect", histogram.getCount(), is(equalTo(1L))); assertThat("Histogram size is incorrect", histogram.getSnapshot().size(), is(equalTo(1))); assertThat("Histogram min value is incorrect", histogram.getSnapshot().getMin(), is(equalTo(value))); assertThat("Histogram max value is incorrect", histogram.getSnapshot().getMax(), is(equalTo(value))); } }
@Test public void testMetricRegistry() throws Exception { String histogramIntName = "org.eclipse.microprofile.metrics.tck.HistogramTest.histogramInt"; String histogramLongName = "test.longData.histogram"; SortedMap<String, Histogram> histograms = metrics.getHistograms(); Assert.assertTrue(histograms.size() == 2); Assert.assertTrue(histograms.containsKey(histogramIntName)); Assert.assertTrue(histograms.containsKey(histogramLongName)); TestUtils.assertEqualsWithTolerance(48, histograms.get(histogramIntName).getSnapshot().getValue(0.5)); TestUtils.assertEqualsWithTolerance(480, histograms.get(histogramLongName).getSnapshot().getValue(0.5)); }
@Test @InSequence(1) public void histogramFieldRegistered() { assertThat("Histogram is not registered correctly", registry.getHistograms(), hasKey(HISTOGRAM_NAME)); }
@Test @InSequence(2) public void registerTest() { metrics.register("regCountTemp", countTemp); Assert.assertTrue(metrics.getCounters().containsKey("regCountTemp")); metrics.register("regHistoTemp", histoTemp); Assert.assertTrue(metrics.getHistograms().containsKey("regHistoTemp")); metrics.register("regTimerTemp", timerTemp); Assert.assertTrue(metrics.getTimers().containsKey("regTimerTemp")); metrics.register("regMeterTemp", meterTemp); Assert.assertTrue(metrics.getMeters().containsKey("regMeterTemp")); }