use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class MetricRegistryImplTest method removeByMetricIdRemovesOnlyMetricsWithThatId.
@Test
public void removeByMetricIdRemovesOnlyMetricsWithThatId() {
String name = nextName();
registry.concurrentGauge(withName(name));
ConcurrentGauge remaining1 = registry.concurrentGauge(withName(name), SOME_TAG);
String otherName = nextName();
ConcurrentGauge remaining2 = registry.concurrentGauge(withName(otherName));
assertEquals(3, registry.getConcurrentGauges().size());
assertEquals(new TreeSet<>(asList(name, otherName)), registry.getNames());
assertTrue(registry.remove(new MetricID(name)));
assertEquals(2, registry.getConcurrentGauges().size());
assertEquals(new HashSet<>(asList(remaining1, remaining2)), new HashSet<>(registry.getConcurrentGauges().values()));
assertEquals(new TreeSet<>(asList(name, otherName)), registry.getNames());
assertTrue(registry.remove(new MetricID(name, SOME_TAG)));
assertEquals(1, registry.getConcurrentGauges().size());
assertEquals(new TreeSet<>(asList(otherName)), registry.getNames());
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class MetricIDTest method removalTest.
@SuppressWarnings({ "deprecation", "unused" })
@Test
public void removalTest() {
Tag tagEarth = new Tag("planet", "earth");
Tag tagRed = new Tag("colour", "red");
Tag tagBlue = new Tag("colour", "blue");
String counterName = "org.eclipse.microprofile.metrics.tck.MetricIDTest.counterColour";
Counter counterColour = registry.counter(counterName);
Counter counterRed = registry.counter(counterName, tagEarth, tagRed);
Counter counterBlue = registry.counter(counterName, tagEarth, tagBlue);
MetricID counterColourMID = new MetricID(counterName);
MetricID counterRedMID = new MetricID(counterName, tagEarth, tagRed);
MetricID counterBlueMID = new MetricID(counterName, tagEarth, tagRed);
// check multi-dimensional metrics are registered
assertThat("Counter is not registered correctly", registry.getCounter(counterColourMID), notNullValue());
assertThat("Counter is not registered correctly", registry.getCounter(counterRedMID), notNullValue());
assertThat("Counter is not registered correctly", registry.getCounter(counterBlueMID), notNullValue());
// remove one metric
registry.remove(counterColourMID);
assertThat("Registry did not remove metric", registry.getCounters().size(), equalTo(2));
assertThat("Counter is not registered correctly", registry.getCounter(counterColourMID), nullValue());
// remove all metrics with the given name
registry.remove(counterName);
assertThat("Counter is not registered correctly", registry.getCounter(counterRedMID), nullValue());
assertThat("Counter is not registered correctly", registry.getCounter(counterBlueMID), nullValue());
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class JsonExporterGetTest method exportTimer.
@Test
public void exportTimer() {
Timer timer = mock(Timer.class);
when(timer.getElapsedTime()).thenReturn(Duration.ofMillis(45678L));
when(timer.getCount()).thenReturn(29382L);
when(timer.getMeanRate()).thenReturn(12.185627192860734d);
when(timer.getOneMinuteRate()).thenReturn(12.563d);
when(timer.getFiveMinuteRate()).thenReturn(12.364d);
when(timer.getFifteenMinuteRate()).thenReturn(12.126d);
Snapshot snapshot = mock(Snapshot.class);
when(timer.getSnapshot()).thenReturn(snapshot);
when(snapshot.getMin()).thenReturn(169916L);
when(snapshot.getMax()).thenReturn(5608694L);
when(snapshot.getMean()).thenReturn(415041.00024926325d);
when(snapshot.getStdDev()).thenReturn(652907.9633011606d);
when(snapshot.getMedian()).thenReturn(293324.0d);
when(snapshot.get75thPercentile()).thenReturn(344914d);
when(snapshot.get95thPercentile()).thenReturn(543647d);
when(snapshot.get98thPercentile()).thenReturn(2706543d);
when(snapshot.get99thPercentile()).thenReturn(5608694d);
when(snapshot.get999thPercentile()).thenReturn(5608694d);
// example uses same values for both timers so we can get away with just one
// but conceptually those should be two different timer instances
export(new MetricID("responseTime"), timer);
export(new MetricID("responseTime", new Tag("servlet", "two")), timer);
assertOutputEqualsFile("Timer.json");
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class JsonExporterGetTest method exportCounter.
@Test
public void exportCounter() {
Counter hitCount = mock(Counter.class);
when(hitCount.getCount()).thenReturn(45L);
Counter hitCount2 = mock(Counter.class);
when(hitCount2.getCount()).thenReturn(3L);
Counter hitCount3 = mock(Counter.class);
when(hitCount3.getCount()).thenReturn(4L);
export(new MetricID("hitCount"), hitCount);
export(new MetricID("hitCount", new Tag("servlet", "two")), hitCount2);
export(new MetricID("hitCount", new Tag("store", "webshop"), new Tag("servlet", "three")), hitCount3);
assertOutputEqualsFile("Counter.json");
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class JsonExporterGetTest method exportGauge.
@Test
public void exportGauge() {
Gauge<Double> responsePercentage1 = () -> 48.45632d;
Gauge<Double> responsePercentage2 = () -> 26.23654d;
Gauge<Double> responsePercentage3 = () -> 29.24554d;
export(new MetricID("responsePercentage"), responsePercentage1);
export(new MetricID("responsePercentage", new Tag("servlet", "two")), responsePercentage2);
export(new MetricID("responsePercentage", new Tag("store", "webshop"), new Tag("servlet", "three")), responsePercentage3);
assertOutputEqualsFile("Gauge.json");
}
Aggregations