Search in sources :

Example 51 with MetricID

use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.

the class BulkheadMetricTckTest method bulkheadMetricAsyncTest.

/**
 * Scenario is equivalent to the TCK test of same name but not 100% identical
 */
@Test(timeout = 3000)
public void bulkheadMetricAsyncTest() {
    callMethodWithNewThreadAndWaitFor(commonWaiter);
    callMethodWithNewThreadAndWaitFor(commonWaiter);
    waitUntilPermitsAquired(2, 0);
    callMethodWithNewThreadAndWaitFor(commonWaiter);
    callMethodWithNewThreadAndWaitFor(commonWaiter);
    waitUntilPermitsAquired(2, 2);
    assertFurtherThreadThrowsBulkheadException(1);
    commonWaiter.complete(null);
    waitUntilPermitsAquired(0, 0);
    String methodName = "fish.payara.microprofile.faulttolerance.policy.BulkheadMetricTckTest.bulkheadMetricAsyncTest_Method";
    Counter successfulInvocations = registry.getCounter(new MetricID("ft.invocations.total", new Tag("method", methodName), new Tag("fallback", "notDefined"), new Tag("result", "valueReturned")));
    Counter failedInvocations = registry.getCounter(new MetricID("ft.invocations.total", new Tag("method", methodName), new Tag("fallback", "notDefined"), new Tag("result", "exceptionThrown")));
    assertEquals(4, successfulInvocations.getCount());
    assertEquals(1, failedInvocations.getCount());
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Counter(org.eclipse.microprofile.metrics.Counter) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 52 with MetricID

use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.

the class BulkheadMetricTckTest method bulkheadMetricRejectionTest.

/**
 * Scenario is equivalent to the TCK test of same name but not 100% identical
 */
@Test(timeout = 3000)
public void bulkheadMetricRejectionTest() {
    callMethodWithNewThreadAndWaitFor(commonWaiter);
    callMethodWithNewThreadAndWaitFor(commonWaiter);
    waitUntilPermitsAquired(2, 0);
    assertFurtherThreadThrowsBulkheadException(1);
    commonWaiter.complete(null);
    waitUntilPermitsAquired(0, 0);
    String methodName = "fish.payara.microprofile.faulttolerance.policy.BulkheadMetricTckTest.bulkheadMetricRejectionTest_Method";
    @SuppressWarnings("unchecked") Gauge<Long> excutionsRunning = (Gauge<Long>) registry.getGauge(new MetricID("ft.bulkhead.executionsRunning", new Tag("method", methodName)));
    assertNotNull(excutionsRunning);
    assertEquals(0, excutionsRunning.getValue().intValue());
    Counter acceptedCalls = registry.getCounter(new MetricID("ft.bulkhead.calls.total", new Tag("method", methodName), new Tag("bulkheadResult", "accepted")));
    assertNotNull(acceptedCalls);
    assertEquals(2, acceptedCalls.getCount());
    Counter rejectedCalls = registry.getCounter(new MetricID("ft.bulkhead.calls.total", new Tag("method", methodName), new Tag("bulkheadResult", "rejected")));
    assertNotNull(rejectedCalls);
    assertEquals(1, rejectedCalls.getCount());
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Counter(org.eclipse.microprofile.metrics.Counter) Tag(org.eclipse.microprofile.metrics.Tag) Gauge(org.eclipse.microprofile.metrics.Gauge) Test(org.junit.Test)

Example 53 with MetricID

use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.

the class MetricUtils method getGauge.

@SuppressWarnings("unchecked")
private static Gauge<?> getGauge(MetricRegistry registry, String name, Tag[] tags) {
    MetricID metricID = new MetricID(name, tags);
    Gauge<?> gauge = registry.getGauges().get(metricID);
    return gauge != null ? gauge : new LazyGauge<>(() -> registry.getGauges().get(metricID));
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID)

Aggregations

MetricID (org.eclipse.microprofile.metrics.MetricID)53 Test (org.junit.Test)41 Metadata (org.eclipse.microprofile.metrics.Metadata)31 Tag (org.eclipse.microprofile.metrics.Tag)25 Counter (org.eclipse.microprofile.metrics.Counter)10 Metric (org.eclipse.microprofile.metrics.Metric)6 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)6 Snapshot (org.eclipse.microprofile.metrics.Snapshot)6 Histogram (org.eclipse.microprofile.metrics.Histogram)5 ConcurrentGauge (org.eclipse.microprofile.metrics.ConcurrentGauge)4 Timer (org.eclipse.microprofile.metrics.Timer)4 Gauge (org.eclipse.microprofile.metrics.Gauge)3 MonitoringDataCollector (fish.payara.monitoring.collect.MonitoringDataCollector)2 ArrayList (java.util.ArrayList)2 Meter (org.eclipse.microprofile.metrics.Meter)2 NoSuchRegistryException (fish.payara.microprofile.metrics.exception.NoSuchRegistryException)1 TimerImpl (fish.payara.microprofile.metrics.impl.TimerImpl)1 MBeanMetadata (fish.payara.microprofile.metrics.jmx.MBeanMetadata)1 FileNotFoundException (java.io.FileNotFoundException)1 Collections.emptyMap (java.util.Collections.emptyMap)1