@Override public Snapshot getSnapshot() { return histogram.getSnapshot(); }
@Override public Snapshot getSnapshot() { return delegate.getSnapshot(); }
@Override @JsonbTransient public Snapshot getSnapshot() { return histogram.getSnapshot(); }
@Test public void testSnapshotMax() throws Exception { Assert.assertEquals(99, histogramInt.getSnapshot().getMax()); Assert.assertEquals(990, histogramLong.getSnapshot().getMax()); }
@Test public void testSnapshotValues() throws Exception { Assert.assertArrayEquals( "The histogramInt does not contain the expected values: " + Arrays.toString(SAMPLE_INT_DATA), Arrays.stream(SAMPLE_INT_DATA).asLongStream().toArray(), histogramInt.getSnapshot().getValues()); Assert.assertArrayEquals( "The histogramLong does not contain the expected values: " + Arrays.toString(SAMPLE_LONG_DATA), SAMPLE_LONG_DATA, histogramLong.getSnapshot().getValues()); }
@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 public void testSnapshot99thPercentile() throws Exception { TestUtils.assertEqualsWithTolerance(98, histogramInt.getSnapshot().get99thPercentile()); TestUtils.assertEqualsWithTolerance(980, histogramLong.getSnapshot().get99thPercentile()); }
@Test public void testSnapshot75thPercentile() throws Exception { TestUtils.assertEqualsWithTolerance(75, histogramInt.getSnapshot().get75thPercentile()); TestUtils.assertEqualsWithTolerance(750, histogramLong.getSnapshot().get75thPercentile()); }
@Test public void testSnapshot98thPercentile() throws Exception { TestUtils.assertEqualsWithTolerance(98, histogramInt.getSnapshot().get98thPercentile()); TestUtils.assertEqualsWithTolerance(980, histogramLong.getSnapshot().get98thPercentile()); }
@Test public void testSnapshot999thPercentile() throws Exception { TestUtils.assertEqualsWithTolerance(99, histogramInt.getSnapshot().get999thPercentile()); TestUtils.assertEqualsWithTolerance(990, histogramLong.getSnapshot().get999thPercentile()); }
@Test public void testSnapshotMin() throws Exception { Assert.assertEquals(0, histogramInt.getSnapshot().getMin()); Assert.assertEquals(0, histogramLong.getSnapshot().getMin()); }
@Test public void testSnapshot95thPercentile() throws Exception { TestUtils.assertEqualsWithTolerance(96, histogramInt.getSnapshot().get95thPercentile()); TestUtils.assertEqualsWithTolerance(960, histogramLong.getSnapshot().get95thPercentile()); }
@Test public void testSnapshotMean() throws Exception { TestUtils.assertEqualsWithTolerance(50.6, histogramInt.getSnapshot().getMean()); TestUtils.assertEqualsWithTolerance(506.3, histogramLong.getSnapshot().getMean()); }
@Test public void testSnapshotMedian() throws Exception { TestUtils.assertEqualsWithTolerance(48, histogramInt.getSnapshot().getMedian()); TestUtils.assertEqualsWithTolerance(480, histogramLong.getSnapshot().getMedian()); }
@Test public void testSnapshotStdDev() throws Exception { TestUtils.assertEqualsWithTolerance(29.4, histogramInt.getSnapshot().getStdDev()); TestUtils.assertEqualsWithTolerance(294.3, histogramLong.getSnapshot().getStdDev()); }
@Test public void testSnapshotSize() throws Exception { Assert.assertEquals(200, histogramInt.getSnapshot().size()); Assert.assertEquals(200, histogramLong.getSnapshot().size()); }
@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))); } }
Snapshot snap = executionTimes.getSnapshot(); snap = executionTimes.getSnapshot(); assertThat("histogram count", executionTimes.getCount(), is(12L)); assertThat("median", snap.getMedian(), approxMillis(0));
.append(type(registryKey, keyBase + keyUnit + " summary", entry.metadata)) .append(value(registryKey, keyBase + keyUnit + "_count", histogram.getCount(), entry.metadata)) .append(toPrometheus(registryKey, keyBase, keyUnit, histogram.getSnapshot(), entry.metadata)); default: return new StringBuilder();
@Test public void testTimeoutHistogram() { MetricGetter m = new MetricGetter(TimeoutMetricBean.class, "histogramTestWorkForMillis"); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); // 50th Percentile timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(1000); timeoutBean.histogramTestWorkForMillis(1000); // 75th Percentile expectTimeout(() -> timeoutBean.histogramTestWorkForMillis(5000)); // Will timeout after 2000 expectTimeout(() -> timeoutBean.histogramTestWorkForMillis(5000)); // Will timeout after 2000 Histogram histogram = m.getTimeoutExecutionDuration().get(); Snapshot snapshot = histogram.getSnapshot(); assertThat("Histogram count", histogram.getCount(), is(10L)); assertThat("Median", snapshot.getMedian(), MetricComparator.approxMillis(100)); assertThat("75th percentile", snapshot.get75thPercentile(), MetricComparator.approxMillis(1000)); assertThat("99th percentile", snapshot.get99thPercentile(), MetricComparator.approxMillis(2000)); assertThat("99.9th percentile", snapshot.get999thPercentile(), MetricComparator.approxMillis(2000)); }