use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class JsonExporterGetTest method exportSimpleTimer.
@Test
public void exportSimpleTimer() {
SimpleTimer timer = mock(SimpleTimer.class);
when(timer.getCount()).thenReturn(1L);
when(timer.getElapsedTime()).thenReturn(Duration.ofMillis(12300000000L));
when(timer.getMaxTimeDuration()).thenReturn(Duration.ofMillis(3231000000L));
when(timer.getMinTimeDuration()).thenReturn(Duration.ofMillis(25600000L));
export(new MetricID("simple_responseTime"), timer);
assertOutputEqualsFile("SimpleTimer.json");
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class OpenMetricsExporterTest method gaugesThatThrowIllegalStateExceptionWhenReadAreNotExported.
@Test
public void gaugesThatThrowIllegalStateExceptionWhenReadAreNotExported() {
Gauge<Long> gauge = () -> {
throw new IllegalStateException("test");
};
MetricID metricID = new MetricID("test4");
Metadata metadata = Metadata.builder().withName(metricID.getName()).build();
assertOutputEquals("", metricID, gauge, metadata);
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class OpenMetricsExporterTest method namesAreadyEndingWithSuffixAvoidAppendingSuffixAgain.
@Test
public void namesAreadyEndingWithSuffixAvoidAppendingSuffixAgain() {
Counter counter = mock(Counter.class);
when(counter.getCount()).thenReturn(13L);
MetricID metricID = new MetricID("my_total");
Metadata metadata = Metadata.builder().withName(metricID.getName()).build();
assertOutputEquals("# TYPE application_my_total counter\n" + "application_my_total 13\n", metricID, counter, metadata);
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class OpenMetricsExporterTest method quantilesAreAppendedOtherTags.
@Test
public void quantilesAreAppendedOtherTags() {
Histogram histogram = mock(Histogram.class);
Snapshot snapshot = mock(Snapshot.class);
when(histogram.getSnapshot()).thenReturn(snapshot);
MetricID metricID = new MetricID("test6", new Tag("custom", "tag-value"));
Metadata metadata = Metadata.builder().withName(metricID.getName()).withUnit(MetricUnits.MILLISECONDS).build();
exporter.export(metricID, histogram, metadata);
String actualOutput = actual.getBuffer().toString();
assertTrue(actualOutput.contains("application_test6_seconds{custom=\"tag-value\",quantile=\"0.5\"} 0"));
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class OpenMetricsExporterTest method assertUnitConversion.
private void assertUnitConversion(String inputUnit, Number inputValue, String expectedUnit, String expectedValue) {
Gauge<Number> gauge = () -> inputValue;
String name = "test" + nextNameId.incrementAndGet();
MetricID metricID = new MetricID(name);
Metadata metadata = Metadata.builder().withName(metricID.getName()).withUnit(inputUnit).build();
assertOutputEquals("# TYPE application_" + name + "_" + expectedUnit + " gauge\n" + "application_" + name + "_" + expectedUnit + " " + expectedValue + "\n", metricID, gauge, metadata);
// clean output so far to allow multiple usages of this in a single test
actual.getBuffer().setLength(0);
}
Aggregations