org.eclipse.microprofile.metrics.SimpleTimer Java Examples

The following examples show how to use org.eclipse.microprofile.metrics.SimpleTimer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricTest.java    From smallrye-graphql with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(101)
public void verifyMetricsAreUpdated() {
    SimpleTimer metricForGetQuery = metricRegistry.getSimpleTimers().get(new MetricID("mp_graphql_Query_get"));
    Assert.assertEquals("The 'get' query was called three times, this should be reflected in metric value",
            3, metricForGetQuery.getCount());
    Assert.assertTrue("Total elapsed time for query should be greater than zero",
            metricForGetQuery.getElapsedTime().toNanos() > 0);

    SimpleTimer metricForMutation = metricRegistry.getSimpleTimers().get(new MetricID("mp_graphql_Mutation_mutate"));
    Assert.assertEquals("The query was called twice, this should be reflected in metric value",
            2, metricForMutation.getCount());
    Assert.assertTrue("Total elapsed time for query should be greater than zero",
            metricForMutation.getElapsedTime().toNanos() > 0);

    SimpleTimer metricForSource = metricRegistry.getSimpleTimers().get(new MetricID("mp_graphql_Foo_description"));
    Assert.assertEquals("The get{description} query was called once, this should be reflected in metric value",
            1, metricForSource.getCount());
    Assert.assertTrue("Total elapsed time for query should be greater than zero",
            metricForSource.getElapsedTime().toNanos() > 0);
}
 
Example #2
Source File: TagsTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(7)
public void simpleTimerTagsTest() {
    
    Tag tagEarth = new Tag("planet", "earth");
    Tag tagRed = new Tag("colour", "red");
    Tag tagBlue = new Tag("colour", "blue");
    
    String simpleTimerName = "org.eclipse.microprofile.metrics.tck.TagTest.simpleTimerColour";
    
    SimpleTimer simpleTimerColour = registry.simpleTimer(simpleTimerName);
    SimpleTimer simpleTimerRed = registry.simpleTimer(simpleTimerName,tagEarth,tagRed);
    SimpleTimer simpleTimerBlue = registry.simpleTimer(simpleTimerName,tagEarth,tagBlue);
    
    MetricID simpleTimerColourMID = new MetricID(simpleTimerName);
    MetricID simpleTimerRedMID = new MetricID(simpleTimerName, tagEarth,tagRed);
    MetricID simpleTimerBlueMID = new MetricID(simpleTimerName, tagEarth,tagBlue);
    
    //check multi-dimensional metrics are registered
    assertThat("SimpleTimer is not registered correctly", registry.getSimpleTimer(simpleTimerColourMID), notNullValue());
    assertThat("SimpleTimer is not registered correctly", registry.getSimpleTimer(simpleTimerRedMID), notNullValue());
    assertThat("SimpleTimer is not registered correctly", registry.getSimpleTimer(simpleTimerBlueMID), notNullValue());
}
 
Example #3
Source File: MetricRegistryTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void registerTest() {
    metrics.register("regCountTemp", countTemp);
    assertExists(Counter.class, new MetricID("regCountTemp"));

    metrics.register("regHistoTemp", histoTemp);
    assertExists(Histogram.class, new MetricID("regHistoTemp"));

    metrics.register("regTimerTemp", timerTemp);
    assertExists(Timer.class, new MetricID("regTimerTemp"));

    metrics.register("regSimpleTimerTemp", simpleTimerTemp);
    assertExists(SimpleTimer.class, new MetricID("regSimpleTimerTemp"));

    metrics.register("regConcurrentGaugeTemp", concurrentGaugeTemp);
    assertExists(ConcurrentGauge.class, new MetricID("regConcurrentGaugeTemp"));

    metrics.register("regMeterTemp", meterTemp);
    assertExists(Meter.class, new MetricID("regMeterTemp"));
}
 
Example #4
Source File: SimplyTimedMethodBeanLookupTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(3)
public void removeSimplyTimedFromRegistry() throws InterruptedException {
    // Get a contextual instance of the bean
    SimplyTimedMethodBean1 bean = instance.get();

    SimpleTimer simpleTimer = registry.getSimpleTimer(simpleTimerMID);
    assertThat("SimplyTimed is not registered correctly", simpleTimer, notNullValue());

    // Remove the simpleTimer from metrics registry
    registry.remove(simpleTimerMID);

    try {
        // Call the simplyTimed method and assert an exception is thrown
        bean.simplyTimedMethod();
    }
    catch (RuntimeException cause) {
        assertThat(cause, is(instanceOf(IllegalStateException.class)));
        // Make sure that the simpleTimer hasn't been called
        assertThat("SimplyTimed count is incorrect", simpleTimer.getCount(), is(equalTo(SIMPLE_TIMER_COUNT.get())));
        return;
    }

    fail("No exception has been re-thrown!");
}
 
Example #5
Source File: SimplyTimedMethodBeanLookupTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void callSimplyTimedMethodOnce() throws InterruptedException {
    // Get a contextual instance of the bean
    SimplyTimedMethodBean1 bean = instance.get();

    SimpleTimer simpleTimer = registry.getSimpleTimer(simpleTimerMID);
    assertThat("SimplyTimed is not registered correctly", simpleTimer, notNullValue());

    // Call the simplyTimed method and assert it's been simplyTimed
    bean.simplyTimedMethod();

    // Make sure that the simpleTimer has been called
    assertThat("SimplyTimed count is incorrect", simpleTimer.getCount(), is(equalTo(SIMPLE_TIMER_COUNT.incrementAndGet())));
    TestUtils.assertEqualsWithTolerance(2000000000L,  simpleTimer.getElapsedTime().toNanos());
}
 
Example #6
Source File: SimplyTimedMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(3)
public void removeSimpleTimerFromRegistry() throws InterruptedException {
    SimpleTimer simpleTimer = registry.getSimpleTimer(simpleTimerMID);
    assertThat("SimpleTimer is not registered correctly", simpleTimer, notNullValue());

    // Remove the simpleTimer from metrics registry
    registry.remove(simpleTimerMID);

    try {
        // Call the simplyTimed method and assert an exception is thrown
        bean.simplyTimedMethod();
    }
    catch (RuntimeException cause) {
        assertThat(cause, is(instanceOf(IllegalStateException.class)));
        // Make sure that the simpleTimer hasn't been called
        assertThat("SimpleTimer count is incorrect", simpleTimer.getCount(), is(equalTo(SIMPLE_TIMER_COUNT.get())));
        return;
    }

    fail("No exception has been re-thrown!");
}
 
Example #7
Source File: SimplyTimedClassBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void callSimplyTimedMethodsOnce() {
    assertThat("SimpleTimers are not registered correctly", registry.getSimpleTimers().keySet(), is(equalTo(simpleTimerMIDsIncludingToString)));
    
    assertThat("Constructor simple timer count is incorrect", registry.getSimpleTimer(constructorMID).getCount(), is(equalTo(1L)));

    // Call the simplyTimed methods and assert they've been simplyTimed
    bean.simplyTimedMethodOne();
    bean.simplyTimedMethodTwo();
    // Let's call the non-public methods as well
    bean.simplyTimedMethodProtected();
    bean.simplyTimedMethodPackagedPrivate();

    // Make sure that the method timers have been simplyTimed
    assertThat("Method simple timer counts are incorrect", registry.getSimpleTimers(METHOD_SIMPLE_TIMERS).values(),
            everyItem(Matchers.<SimpleTimer> hasProperty("count", equalTo(METHOD_COUNT.incrementAndGet()))));
}
 
Example #8
Source File: InheritedSimplyTimedMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void callSimplyTimedMethodsOnce() { 
    assertThat("SimpleTimer are not registered correctly", registry.getSimpleTimers().keySet(),
        is(equalTo(MetricsUtil.createMetricIDs(absoluteMetricNames()))));

    // Call the simplyTimed methods and assert they've all been simplyTimed once
    bean.publicSimplyTimedMethod();
    bean.protectedSimplyTimedMethod();
    bean.packagePrivateSimplyTimedMethod();

    // Call the methods of the parent and assert they've also been simplyTimed once
    bean.simplyTimedMethodOne();
    bean.simplyTimedMethodTwo();
    bean.simplyTimedMethodProtected();
    bean.simplyTimedMethodPackagedPrivate();

    assertThat("SimpleTimer counts are incorrect", registry.getSimpleTimers().values(),
            everyItem(Matchers.<SimpleTimer>hasProperty("count", equalTo(1L))));
}
 
Example #9
Source File: MetricsTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testQuery() {
    SimpleTimer metric = metricRegistry.getSimpleTimers().get(new MetricID("mp_graphql_Query_ping"));
    assertNotNull(metric, "Metrics should be registered eagerly");

    String pingRequest = getPayload("{\n" +
            "  ping {\n" +
            "    message\n" +
            "  }\n" +
            "}");

    RestAssured.given().when()
            .accept("application/json")
            .contentType("application/json")
            .body(pingRequest)
            .post("/graphql")
            .then()
            .assertThat()
            .statusCode(200)
            .and()
            .body(CoreMatchers.containsString("{\"data\":{\"ping\":{\"message\":\"pong\"}}}"));

    assertEquals(1L, metric.getCount(), "Metric should be updated after querying");
}
 
Example #10
Source File: OpenMetricsExporter.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
private void writeSimpleTimerValues(StringBuilder sb, MetricRegistry.Type scope, SimpleTimer simpleTimer, Metadata md,
        Map<String, String> tags) {
    String unit = OpenMetricsUnit.getBaseUnitAsOpenMetricsString(md.unit());
    if (unit.equals(NONE))
        unit = "seconds";

    String theUnit = USCORE + unit;

    // 'total' value plus the help line
    writeHelpLine(sb, scope, md.getName(), md, "_total");
    writeTypeAndValue(sb, scope, "_total", simpleTimer.getCount(), COUNTER, md, false, tags);
    writeTypeAndValue(sb, scope, "_elapsedTime" + theUnit, simpleTimer.getElapsedTime().toNanos(), GAUGE, md, true, tags);
    Duration min = simpleTimer.getMinTimeDuration();
    Duration max = simpleTimer.getMaxTimeDuration();
    if (min != null) {
        writeTypeAndValue(sb, scope, "_minTimeDuration" + theUnit, min.toNanos(), GAUGE, md, true, tags);
    } else {
        writeTypeAndValue(sb, scope, "_minTimeDuration" + theUnit, Double.NaN, GAUGE, md, true, tags);
    }
    if (max != null) {
        writeTypeAndValue(sb, scope, "_maxTimeDuration" + theUnit, max.toNanos(), GAUGE, md, true, tags);
    } else {
        writeTypeAndValue(sb, scope, "_maxTimeDuration" + theUnit, Double.NaN, GAUGE, md, true, tags);
    }

}
 
Example #11
Source File: JsonExporter.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
private JsonObject exportSimpleTimer(SimpleTimer timer, String unit, String tags) {
    JsonObjectBuilder builder = JsonProviderHolder.get().createObjectBuilder();
    builder.add("count" + tags, timer.getCount());
    builder.add("elapsedTime" + tags, toBase(timer.getElapsedTime().toNanos(), unit));
    Duration minTimeDuration = timer.getMinTimeDuration();
    if (minTimeDuration != null) {
        builder.add("minTimeDuration" + tags, toBase(minTimeDuration.toNanos(), unit));
    } else {
        builder.add("minTimeDuration" + tags, JsonValue.NULL);
    }
    Duration maxTimeDuration = timer.getMaxTimeDuration();
    if (maxTimeDuration != null) {
        builder.add("maxTimeDuration" + tags, toBase(maxTimeDuration.toNanos(), unit));
    } else {
        builder.add("maxTimeDuration" + tags, JsonValue.NULL);
    }
    return builder.build();
}
 
Example #12
Source File: SimplyTimedInterceptor.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
private <E extends Member & AnnotatedElement> Object timedCallable(InvocationContext invocationContext, E element)
        throws Exception {
    Set<MetricID> ids = ((MetricsRegistryImpl) registry).getMemberToMetricMappings()
            .getSimpleTimers(new CDIMemberInfoAdapter<>().convert(element));
    if (ids == null || ids.isEmpty()) {
        throw SmallRyeMetricsMessages.msg.noMetricMappedForMember(element);
    }
    List<SimpleTimer.Context> contexts = ids.stream()
            .map(metricID -> {
                SimpleTimer metric = registry.getSimpleTimers().get(metricID);
                if (metric == null) {
                    throw SmallRyeMetricsMessages.msg.noMetricFoundInRegistry(MetricType.SIMPLE_TIMER, metricID);
                }
                return metric;
            })
            .map(SimpleTimer::time)
            .collect(Collectors.toList());
    try {
        return invocationContext.proceed();
    } finally {
        for (SimpleTimer.Context timeContext : contexts) {
            timeContext.stop();
        }
    }
}
 
Example #13
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
private MetricType metricTypeFromClass(Class<?> in) {
    if (in.equals(Counter.class)) {
        return MetricType.COUNTER;
    } else if (in.equals(Gauge.class)) {
        return MetricType.GAUGE;
    } else if (in.equals(ConcurrentGauge.class)) {
        return MetricType.CONCURRENT_GAUGE;
    } else if (in.equals(Meter.class)) {
        return MetricType.METERED;
    } else if (in.equals(Timer.class)) {
        return MetricType.TIMER;
    } else if (in.equals(SimpleTimer.class)) {
        return MetricType.SIMPLE_TIMER;
    } else if (in.equals(Histogram.class)) {
        return MetricType.HISTOGRAM;
    }
    return null;
}
 
Example #14
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
private boolean isSameType(Metric metricInstance, MetricType type) {
    switch (type) {
        case CONCURRENT_GAUGE:
            return metricInstance instanceof ConcurrentGauge;
        case GAUGE:
            return metricInstance instanceof Gauge;
        case HISTOGRAM:
            return metricInstance instanceof Histogram;
        case TIMER:
            return metricInstance instanceof Timer;
        case METERED:
            return metricInstance instanceof Meter;
        case COUNTER:
            return metricInstance instanceof Counter;
        case SIMPLE_TIMER:
            return metricInstance instanceof SimpleTimer;
        default:
            throw new IllegalArgumentException();
    }
}
 
Example #15
Source File: JaxRsMetricsTestCase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testAsyncMethod() {
    when()
            .get("/async")
            .then()
            .statusCode(200);
    SimpleTimer metric = metricRegistry.simpleTimer("REST.request",
            new Tag("class", METRIC_RESOURCE_CLASS_NAME),
            new Tag("method", "async"));
    assertEquals(1, metric.getCount());
    assertTrue(metric.getElapsedTime().toNanos() > 0);
}
 
Example #16
Source File: MetricAppBean.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
public void simpleTimeMe() {

        SimpleTimer simpleTimer = metrics.simpleTimer("metricTest.test1.simpleTimer");

        SimpleTimer.Context context = simpleTimer.time();
        try {
            Thread.sleep((long) (Math.random() * 1000));
        }
        catch (InterruptedException e) {
        } finally {
            context.stop();
        }

    }
 
Example #17
Source File: MetricTest.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(99)
public void verifyMetricsAreRegisteredEagerly() {
    SimpleTimer metricForHelloQuery = metricRegistry.getSimpleTimers().get(new MetricID("mp_graphql_Query_get"));
    Assert.assertNotNull("Metric should be registered eagerly", metricForHelloQuery);

    SimpleTimer metricForMutation = metricRegistry.getSimpleTimers().get(new MetricID("mp_graphql_Mutation_mutate"));
    Assert.assertNotNull("Metric should be registered eagerly", metricForMutation);

    SimpleTimer metricForSource = metricRegistry.getSimpleTimers().get(new MetricID("mp_graphql_Foo_description"));
    Assert.assertNotNull("Metric should be registered eagerly", metricForSource);
}
 
Example #18
Source File: SimplyTimedMethodBeanLookupTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(1)
public void simplyTimedMethodNotCalledYet() {
    // Get a contextual instance of the bean
    SimplyTimedMethodBean1 bean = instance.get();

    SimpleTimer simpleTimer = registry.getSimpleTimer(simpleTimerMID);
    assertThat("SimplyTimed is not registered correctly", simpleTimer, notNullValue());

    // Make sure that the simpleTimer hasn't been called yet
    assertThat("SimplyTimed count is incorrect", simpleTimer.getCount(), is(equalTo(SIMPLE_TIMER_COUNT.get())));
}
 
Example #19
Source File: SimplyTimedMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(2)
public void callSimplyTimedMethodOnce() throws InterruptedException {
    SimpleTimer simpleTimer = registry.getSimpleTimer(simpleTimerMID);
    assertThat("SimpleTimer is not registered correctly", simpleTimer, notNullValue());

    // Call the simplyTimed method and assert it's been simplyTimed
    bean.simplyTimedMethod();

    // Make sure that the simpleTimer has been called
    assertThat("SimpleTimer count is incorrect", simpleTimer.getCount(), is(equalTo(SIMPLE_TIMER_COUNT.incrementAndGet())));
    TestUtils.assertEqualsWithTolerance(2000000000L,  simpleTimer.getElapsedTime().toNanos());
}
 
Example #20
Source File: SimplyTimedMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(1)
public void simplyTimedMethodNotCalledYet() {
    SimpleTimer simpleTimer = registry.getSimpleTimer(simpleTimerMID);
    assertThat("SimpleTimer is not registered correctly", simpleTimer, notNullValue());

    // Make sure that the simpleTimer hasn't been called yet
    assertThat("SimpleTimer count is incorrect", simpleTimer.getCount(), is(equalTo(SIMPLE_TIMER_COUNT.get())));

}
 
Example #21
Source File: SimplyTimedClassBeanTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(1)
public void simplyTimedMethodsNotCalledYet() {
    assertThat("SimpleTimers are not registered correctly", registry.getSimpleTimers().keySet(), is(equalTo(simpleTimerMIDsIncludingToString)));
    
    assertThat("Constructor timer count is incorrect", registry.getSimpleTimer(constructorMID).getCount(), is(equalTo(1L)));

    // Make sure that the method timers haven't been simplyTimed yet
    assertThat("Method simple timer counts are incorrect", registry.getSimpleTimers(METHOD_SIMPLE_TIMERS).values(),
            everyItem(Matchers.<SimpleTimer> hasProperty("count", equalTo(METHOD_COUNT.get()))));
}
 
Example #22
Source File: SimplyTimedConstructorBeanTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(1)
public void simpleTimerConstructorCalled() {
    long count = 1L + Math.round(Math.random() * 10);
    for (int i = 0; i < count; i++) {
        instance.get();
    }

    SimpleTimer simpleTimer = registry.getSimpleTimer(simpleTimerMID);
    assertThat("SimpleTimer is not registered correctly", simpleTimer, notNullValue());

    // Make sure that the simpleTimer has been called
    assertThat("SimpleTimer count is incorrect", simpleTimer.getCount(), is(equalTo(count)));
}
 
Example #23
Source File: SimpleTimerTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(4)
public void timesRunnableInstances() throws Exception {
    SimpleTimer simpleTimer = registry.simpleTimer("testRunnable");
    final AtomicBoolean called = new AtomicBoolean();
    simpleTimer.time(() -> called.set(true));

    Assert.assertEquals(simpleTimer.getCount(), 1);

    Assert.assertEquals(called.get(), true);
}
 
Example #24
Source File: SimpleTimerTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(3)
public void timesCallableInstances() throws Exception {
    SimpleTimer simpleTimer = registry.simpleTimer("testCallable");
    final String value = simpleTimer.time(() -> "one");

    Assert.assertEquals(simpleTimer.getCount(), 1);

    Assert.assertEquals(value, "one");
}
 
Example #25
Source File: InheritedSimplyTimedMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(1)
public void simplyTimedMethodsNotCalledYet() {
    assertThat("SimpleTimer are not registered correctly", registry.getSimpleTimers().keySet(),
        is(equalTo(MetricsUtil.createMetricIDs(absoluteMetricNames()))));

    // Make sure that all the timers haven't been called yet
    assertThat("SimpleTimer counts are incorrect", registry.getSimpleTimers().values(), 
            everyItem(Matchers.<SimpleTimer>hasProperty("count", equalTo(0L))));
}
 
Example #26
Source File: VisibilitySimplyTimedMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(2)
public void callSimplyTimedMethodsOnce() {
    assertThat("SimpleTimers are not registered correctly", registry.getSimpleTimers().keySet(), 
        is(equalTo(MetricsUtil.createMetricIDs(absoluteMetricNames()))));
    
    // Call the simplyTimed methods and assert they've all been timed once
    bean.publicSimplyTimedMethod();
    bean.protectedSimplyTimedMethod();
    bean.packagePrivateSimplyTimedMethod();

    assertThat("SimpleTimer counts are incorrect", registry.getSimpleTimers().values(),
            everyItem(Matchers.<SimpleTimer>hasProperty("count", equalTo(1L))));
}
 
Example #27
Source File: VisibilitySimplyTimedMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(1)
public void simplyTimedMethodsNotCalledYet() {
    assertThat("SimpleTimers are not registered correctly", registry.getSimpleTimers().keySet(), 
        is(equalTo(MetricsUtil.createMetricIDs(absoluteMetricNames()))));
    
    // Make sure that all the SimpleTimers haven't been called yet
    assertThat("SimpleTimer counts are incorrect", registry.getSimpleTimers().values(),
            everyItem(Matchers.<SimpleTimer>hasProperty("count", equalTo(0L))));
}
 
Example #28
Source File: JaxRsMetricsTestCase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testMethodTakingVarargs() {
    when()
            .get("/a/b/c/varargs")
            .then()
            .statusCode(200);
    SimpleTimer metric = metricRegistry.simpleTimer("REST.request",
            new Tag("class", METRIC_RESOURCE_CLASS_NAME),
            new Tag("method", "varargs_javax.ws.rs.core.PathSegment[]"));
    assertEquals(1, metric.getCount());
    assertTrue(metric.getElapsedTime().toNanos() > 0);
}
 
Example #29
Source File: JaxRsMetricsTestCase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testMethodTakingArray() {
    when()
            .get("/a/b/c/array")
            .then()
            .statusCode(200);
    SimpleTimer metric = metricRegistry.simpleTimer("REST.request",
            new Tag("class", METRIC_RESOURCE_CLASS_NAME),
            new Tag("method", "array_javax.ws.rs.core.PathSegment[]"));
    assertEquals(1, metric.getCount());
    assertTrue(metric.getElapsedTime().toNanos() > 0);
}
 
Example #30
Source File: JaxRsMetricsTestCase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testMethodThrowingException() {
    when()
            .get("/exception")
            .then()
            .statusCode(500);
    SimpleTimer metric = metricRegistry.simpleTimer("REST.request",
            new Tag("class", METRIC_RESOURCE_CLASS_NAME),
            new Tag("method", "exception"));
    assertEquals(1, metric.getCount());
    assertTrue(metric.getElapsedTime().toNanos() > 0);
}