tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject [04/14] tomee git commit: Adding test and a few changes
Date Wed, 28 Nov 2018 22:52:01 GMT
Adding test and a few changes


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/a87cf682
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/a87cf682
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/a87cf682

Branch: refs/heads/master
Commit: a87cf682cef5e6ae4c0f46409a9df5f8f4453bef
Parents: 1b7bacc
Author: ivanjunckes <ijunckes@tomitribe.com>
Authored: Fri Nov 23 16:08:47 2018 -0200
Committer: ivanjunckes <ijunckes@tomitribe.com>
Committed: Fri Nov 23 16:08:47 2018 -0200

----------------------------------------------------------------------
 .../src/main/java/WeatherService.java           |   4 +-
 .../src/test/java/WeatherServiceTest.java       | 151 +++++++++++++++++++
 .../src/test/resources/arquillian.xml           |  30 ++++
 examples/pom.xml                                |   1 +
 pom.xml                                         |   2 +-
 5 files changed, 185 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/a87cf682/examples/mp-metrics-timed/src/main/java/WeatherService.java
----------------------------------------------------------------------
diff --git a/examples/mp-metrics-timed/src/main/java/WeatherService.java b/examples/mp-metrics-timed/src/main/java/WeatherService.java
index a0f058e..e117800 100644
--- a/examples/mp-metrics-timed/src/main/java/WeatherService.java
+++ b/examples/mp-metrics-timed/src/main/java/WeatherService.java
@@ -14,8 +14,8 @@ import javax.ws.rs.core.MediaType;
 public class WeatherService {
 
     @Path("/day/status")
-    @Timed(name = "weather_day_timed", absolute = true,
-            displayName = "Weather Day Timed",
+    @Timed(name = "weather_day_status", absolute = true,
+            displayName = "Weather Day Status",
             description = "This metric shows the weather status of the day.")
     @GET
     @Produces(MediaType.TEXT_PLAIN)

http://git-wip-us.apache.org/repos/asf/tomee/blob/a87cf682/examples/mp-metrics-timed/src/test/java/WeatherServiceTest.java
----------------------------------------------------------------------
diff --git a/examples/mp-metrics-timed/src/test/java/WeatherServiceTest.java b/examples/mp-metrics-timed/src/test/java/WeatherServiceTest.java
new file mode 100644
index 0000000..b119ede
--- /dev/null
+++ b/examples/mp-metrics-timed/src/test/java/WeatherServiceTest.java
@@ -0,0 +1,151 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.json.Json;
+import javax.json.JsonObject;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.StringReader;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+public class WeatherServiceTest {
+
+    @Deployment(testable = false)
+    public static WebArchive createDeployment() {
+        final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test.war")
+                .addClass(WeatherService.class)
+                .addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml");
+        return webArchive;
+    }
+
+    @ArquillianResource
+    private URL base;
+
+    @Test
+    public void testTimedMetric() {
+        WebClient.create(base.toExternalForm())
+                .path("/weather/day/status")
+                .get(String.class);
+
+        final String metricPath = "/metrics/application/weather_day_status";
+        assertPrometheusFormat(metricPath);
+        assertJsonFormat(metricPath);
+    }
+
+    private void assertPrometheusFormat(final String metricPath) {
+        final String metric = WebClient.create(base.toExternalForm())
+                .path(metricPath)
+                .accept(MediaType.TEXT_PLAIN)
+                .get(String.class);
+
+        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds summary
timer"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds_count timer"));
+        assertTrue(metric.contains("application:weather_day_status_seconds_count 1.0"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_rate_per_second
timer"));
+        assertTrue(metric.contains("application:weather_day_status_rate_per_second"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_one_min_rate_per_second
timer"));
+        assertTrue(metric.contains("application:weather_day_status_one_min_rate_per_second"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_five_min_rate_per_second
timer"));
+        assertTrue(metric.contains("application:weather_day_status_five_min_rate_per_second"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_fifteen_min_rate_per_second
time"));
+        assertTrue(metric.contains("application:weather_day_status_fifteen_min_rate_per_second"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_min_seconds timer"));
+        assertTrue(metric.contains("application:weather_day_status_min_seconds"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_max_seconds timer"));
+        assertTrue(metric.contains("application:weather_day_status_max_seconds"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_mean_seconds timer"));
+        assertTrue(metric.contains("application:weather_day_status_mean_seconds"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_stddev_seconds
timer"));
+        assertTrue(metric.contains("application:weather_day_status_stddev_seconds"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
+        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.5\"}"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
+        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.75\"}"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
+        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.95\"}"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
+        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.98\"}"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
+        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.99\"}"));
+        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
+        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.999\"}"));
+    }
+
+    private void assertJsonFormat(final String metricPath) {
+        final String metric = WebClient.create(base.toExternalForm())
+                .path(metricPath)
+                .accept(MediaType.APPLICATION_JSON)
+                .get(String.class);
+
+        assertTrue(metric.contains("count"));
+        assertTrue(metric.contains("meanRate"));
+        assertTrue(metric.contains("fifteenMinRate"));
+        assertTrue(metric.contains("fiveMinRate"));
+        assertTrue(metric.contains("oneMinRate"));
+        assertTrue(metric.contains("min"));
+        assertTrue(metric.contains("max"));
+        assertTrue(metric.contains("mean"));
+        assertTrue(metric.contains("stddev"));
+        assertTrue(metric.contains("p50"));
+        assertTrue(metric.contains("p75"));
+        assertTrue(metric.contains("p95"));
+        assertTrue(metric.contains("p98"));
+        assertTrue(metric.contains("p99"));
+        assertTrue(metric.contains("p999"));
+
+    }
+
+    @Test
+    public void testTimedMetricMetadata() {
+        final Response response = WebClient.create(base.toExternalForm())
+                .path("/metrics/application/weather_day_status")
+                .accept(MediaType.APPLICATION_JSON)
+                .options();
+        final String metaData = response.readEntity(String.class);
+        JsonObject metadataJson = Json.createReader(new StringReader(metaData)).readObject();
+
+        final String expected = "{\n" +
+                "  \"weather_day_status\": {\n" +
+                "    \"description\": \"This metric shows the weather status of the day.\",\n"
+
+                "    \"displayName\": \"Weather Day Status\",\n" +
+                "    \"name\": \"weather_day_status\",\n" +
+                "    \"reusable\": false,\n" +
+                "    \"tags\": \"\",\n" +
+                "    \"type\": \"timer\",\n" +
+                "    \"typeRaw\": \"TIMER\",\n" +
+                "    \"unit\": \"nanoseconds\"\n" +
+                "  }\n" +
+                "}";
+
+        JsonObject expectedJson = Json.createReader(new StringReader(expected)).readObject();
+        assertEquals(expectedJson, metadataJson);
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/a87cf682/examples/mp-metrics-timed/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/examples/mp-metrics-timed/src/test/resources/arquillian.xml b/examples/mp-metrics-timed/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..3029d48
--- /dev/null
+++ b/examples/mp-metrics-timed/src/test/resources/arquillian.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+  <container qualifier="tomee" default="true">
+    <configuration>
+      <property name="httpPort">-1</property>
+      <property name="stopPort">-1</property>
+      <property name="classifier">microprofile</property>
+      <property name="dir">target/apache-tomee-remote</property>
+      <property name="appWorkingDir">target/arquillian-test-working-dir</property>
+    </configuration>
+  </container>
+</arquillian>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tomee/blob/a87cf682/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 92518e3..2e670a9 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -172,6 +172,7 @@ BROKEN, see TOMEE-2140
     <module>moviefun-rest</module>
     <module>resources-jmx-example</module>
     <module>mp-metrics-counted</module>
+    <module>mp-metrics-timed</module>
   </modules>
 
   <dependencies>

http://git-wip-us.apache.org/repos/asf/tomee/blob/a87cf682/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index c446d34..778b110 100644
--- a/pom.xml
+++ b/pom.xml
@@ -208,7 +208,7 @@
     <microprofile.health.version>1.0</microprofile.health.version>
     <microprofile.health.impl.version>1.0.0</microprofile.health.impl.version>
     <microprofile.metrics.version>1.1</microprofile.metrics.version>
-    <microprofile.metrics.impl.version>1.0.0</microprofile.metrics.impl.version>
+    <microprofile.metrics.impl.version>1.0.1-SNAPSHOT</microprofile.metrics.impl.version>
     <microprofile.rest-client.version>1.0</microprofile.rest-client.version>
     <microprofile.rest-client.impl.version>${cxf.version}</microprofile.rest-client.impl.version>
     <microprofile.openapi.version>1.0.1</microprofile.openapi.version>


Mime
View raw message