- * Splitting this code from the finish code allows a subclass to refine the builder before - * using it to construct the builder. - *
- * @return {@code Server.Builder} - */ - static Server.Builder prepareServerBuilder() { - return Server.builder() - .addResourceClass(HelloWorldResource.class) - .host("localhost") - // choose a random available port - .port(-1); + boolean isSyntheticSimpleTimerPresent() { + return !syntheticSimpleTimerRegistry().getSimpleTimers((metricID, metric) -> + metricID.equals(MetricsCdiExtension.SYNTHETIC_SIMPLE_TIMER_METRIC_NAME)) + .isEmpty(); } - /** - * Completes the set-up of the server, using the (possibly refined) builder. - * - * @param builder the {@code Server.Builder} to use in constructing the server - */ - static void finishServerInitialization(Server.Builder builder) { - server = builder.build(); - server.start(); - registry = RegistryFactory.getInstance().getRegistry(MetricRegistry.Type.APPLICATION); - - port = server.port(); - baseUri = "http://localhost:" + port; - } - - @AfterAll - public static void terminateServer() { - server.stop(); - } - - protected String baseUri() { - return baseUri; - } - - protected static void registerCounter(String name) { + protected void registerCounter(String name) { Metadata meta = Metadata.builder() .withName(name) .withDisplayName(name) @@ -96,7 +63,7 @@ public class MetricsMpServiceTest { registry.counter(meta); } - protected static Counter getCounter(String name) { + protected Counter getCounter(String name) { return registry.counter(name); } } diff --git a/microprofile/metrics/src/test/java/io/helidon/microprofile/metrics/ResourceWithReusedMetricForInvocation.java b/microprofile/metrics/src/test/java/io/helidon/microprofile/metrics/ResourceWithReusedMetricForInvocation.java index f03c65253..e7ee8c1df 100644 --- a/microprofile/metrics/src/test/java/io/helidon/microprofile/metrics/ResourceWithReusedMetricForInvocation.java +++ b/microprofile/metrics/src/test/java/io/helidon/microprofile/metrics/ResourceWithReusedMetricForInvocation.java @@ -25,9 +25,9 @@ import org.eclipse.microprofile.metrics.annotation.Counted; @Dependent public class ResourceWithReusedMetricForInvocation { - private static final String TAG_1 = "tag_1=value_1"; - private static final String TAG_2 = "tag_2=value_2"; - private static final String OTHER_REUSED_NAME = "reusedRetrieveDelay"; + static final String TAG_1 = "tag_1=value_1"; + static final String TAG_2 = "tag_2=value_2"; + static final String OTHER_REUSED_NAME = "reusedRetrieveDelay"; @GET @Path("method1") diff --git a/microprofile/metrics/src/test/java/io/helidon/microprofile/metrics/ReusabilityInterceptorTest.java b/microprofile/metrics/src/test/java/io/helidon/microprofile/metrics/ReusabilityInterceptorTest.java index 362898c50..b70333551 100644 --- a/microprofile/metrics/src/test/java/io/helidon/microprofile/metrics/ReusabilityInterceptorTest.java +++ b/microprofile/metrics/src/test/java/io/helidon/microprofile/metrics/ReusabilityInterceptorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2020 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,30 @@ */ package io.helidon.microprofile.metrics; +import io.helidon.microprofile.tests.junit5.HelidonTest; +import org.eclipse.microprofile.metrics.Counter; +import org.eclipse.microprofile.metrics.MetricRegistry; import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import javax.inject.Inject; + +@HelidonTest public class ReusabilityInterceptorTest extends MetricsBaseTest { + @Inject + private MetricRegistry metricRegistry; + @Test public void testReusedMetricWithInterceptor() { ResourceWithReusedMetricForInvocation resource = newBean(ResourceWithReusedMetricForInvocation.class); resource.method1(); + Counter counter = metricRegistry.counter(ResourceWithReusedMetricForInvocation.OTHER_REUSED_NAME, + MetricUtil.tags(new String[] {ResourceWithReusedMetricForInvocation.TAG_1, + ResourceWithReusedMetricForInvocation.TAG_2})); + assertThat(counter.getCount(), is(1L)); } }