You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/10/05 10:05:10 UTC

[camel-quarkus] 01/06: Fix failing MicroProfile metrics tests

This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit b6b57772cb5679e5e656898e83365e221d0fb642
Author: James Netherton <ja...@gmail.com>
AuthorDate: Thu Oct 3 14:59:10 2019 +0100

    Fix failing MicroProfile metrics tests
---
 integration-tests/microprofile-metrics/pom.xml     |  4 ++
 .../metrics/it/MicroProfileMetricsResource.java    |  7 +++
 .../metrics/it/MicroProfileMetricsTest.java        | 68 ++++++++++------------
 3 files changed, 43 insertions(+), 36 deletions(-)

diff --git a/integration-tests/microprofile-metrics/pom.xml b/integration-tests/microprofile-metrics/pom.xml
index 0e9f170..a2e3cf3 100644
--- a/integration-tests/microprofile-metrics/pom.xml
+++ b/integration-tests/microprofile-metrics/pom.xml
@@ -39,6 +39,10 @@
             <artifactId>camel-quarkus-direct</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-log</artifactId>
+        </dependency>
+        <dependency>
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-resteasy</artifactId>
         </dependency>
diff --git a/integration-tests/microprofile-metrics/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsResource.java b/integration-tests/microprofile-metrics/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsResource.java
index bcfd8a6..9cf9c3e 100644
--- a/integration-tests/microprofile-metrics/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsResource.java
+++ b/integration-tests/microprofile-metrics/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsResource.java
@@ -73,4 +73,11 @@ public class MicroProfileMetricsResource {
         template.sendBody("direct:timer", null);
         return Response.ok().build();
     }
+
+    @Path("/log")
+    @GET
+    public Response logMessage() throws Exception {
+        template.sendBody("log:message", "Test log message");
+        return Response.ok().build();
+    }
 }
diff --git a/integration-tests/microprofile-metrics/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsTest.java b/integration-tests/microprofile-metrics/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsTest.java
index 62cf2c4..7ace97a 100644
--- a/integration-tests/microprofile-metrics/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsTest.java
+++ b/integration-tests/microprofile-metrics/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsTest.java
@@ -85,62 +85,58 @@ class MicroProfileMetricsTest {
         RestAssured.get("/microprofile-metrics/timer")
             .then()
             .statusCode(200);
-
-        Map<String, Object> routeMetrics = getMetricMapValue("'org.apache.camel.route'");
-        routeMetrics.forEach((k, v) -> {
-            if (k.startsWith("count")) {
-                assertTrue((Integer) v > 0);
-            }
-        });
+        assertTrue(getMetricIntValue("camel.route.exchanges.total", CAMEL_CONTEXT_METRIC_TAG, "routeId=route6") > 0);
     }
 
     @Test
     public void testMicroProfileMetricsMessageHistoryFactory() {
-        Map<String, Object> messageHistoryMetrics = getMetricMapValue("'org.apache.camel.message.history'");
-        messageHistoryMetrics.forEach((k, v) -> {
-            if (k.startsWith("count")) {
+        RestAssured.get("/microprofile-metrics/log")
+            .then()
+            .statusCode(200);
+
+        Map<String, Object> exchangeMetrics = getApplicationMetrics().getMap("'camel.message.history.processing'");
+        exchangeMetrics.forEach((k, v) -> {
+            if (k.startsWith("total")) {
                 assertTrue((Integer) v > 0);
             }
         });
     }
 
     @Test
-    public void testMicroProfileMetricsRouteEventNotifier() {
-        Map<String, Object> routeMetrics = getMetricMapValue("'org.apache.camel.route.total'");
-        routeMetrics.forEach((k, v) -> {
-            if (k.startsWith("current")) {
-                assertEquals(6, v);
-            }
-        });
-
-        Map<String, Object> runningRouteMetrics = getMetricMapValue("'org.apache.camel.route.running.total'");
-        runningRouteMetrics.forEach((k, v) -> {
-            if (k.startsWith("current")) {
-                assertEquals(6, v);
-            }
-        });
+    public void testMicroProfileMetricsRouteEventNotifier() throws InterruptedException {
+        assertEquals(6, getMetricIntValue("camel.route.count"));
+        assertEquals(6, getMetricIntValue("camel.route.running.count"));
     }
 
     @Test
     public void testMicroProfileMetricsExchangeEventNotifier() {
-        Map<String, Object> exchangeMetrics = getMetricMapValue("'org.apache.camel.exchange'");
-        exchangeMetrics.forEach((k, v) -> {
-            if (k.startsWith("total")) {
-                assertTrue((Integer) v > 0);
-            }
-        });
+        RestAssured.get("/microprofile-metrics/log")
+            .then()
+            .statusCode(200);
+        assertTrue(getMetricIntValue("camel.context.exchanges.total") > 0);
+    }
+
+    private int getMetricIntValue(String metricName, String... tags) {
+        return getApplicationMetrics().getInt(sanitizeMetricName(metricName, tags));
     }
 
-    private int getMetricIntValue(String metricName) {
-        return getApplicationMetrics().getInt(metricName + CAMEL_CONTEXT_METRIC_TAG);
+    private float getMetricFloatValue(String metricName, String... tags) {
+        return getApplicationMetrics().getFloat(sanitizeMetricName(metricName, tags));
     }
 
-    private float getMetricFloatValue(String metricName) {
-        return getApplicationMetrics().getFloat(metricName + CAMEL_CONTEXT_METRIC_TAG);
+    private Map<String, Object> getMetricMapValue(String metricName, String... tags) {
+        return getApplicationMetrics().getMap(sanitizeMetricName(metricName, tags));
     }
 
-    private Map<String, Object> getMetricMapValue(String metricName) {
-        return getApplicationMetrics().getMap(metricName);
+    private String sanitizeMetricName(String metricName, String... tags) {
+        if (tags.length == 0) {
+            tags = new String[] {CAMEL_CONTEXT_METRIC_TAG};
+        }
+
+        if (metricName.contains(".") && metricName.split("\\.").length > 2) {
+            return String.format("'%s%s'", metricName, String.join(";", tags));
+        }
+        return metricName + String.join(";", tags);
     }
 
     private JsonPath getApplicationMetrics() {