You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2018/11/20 16:55:24 UTC
[2/7] tomee git commit: adding new examples
adding new examples
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/07443527
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/07443527
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/07443527
Branch: refs/heads/master
Commit: 0744352730d1435a0a73263439dbf6f1835e0832
Parents: 518a1c6
Author: ivanjunckes <ij...@tomitribe.com>
Authored: Tue Nov 20 10:07:10 2018 -0200
Committer: ivanjunckes <ij...@tomitribe.com>
Committed: Tue Nov 20 10:07:10 2018 -0200
----------------------------------------------------------------------
examples/mp-metrics-counted/README.md | 19 +++++
examples/mp-metrics-counted/pom.xml | 70 ++++++++++++++++++
.../java/org/superbiz/rest/WeatherService.java | 33 +++++++++
.../org/superbiz/rest/WeatherServiceTest.java | 75 ++++++++++++++++++++
.../src/test/resources/arquillian.xml | 30 ++++++++
5 files changed, 227 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/07443527/examples/mp-metrics-counted/README.md
----------------------------------------------------------------------
diff --git a/examples/mp-metrics-counted/README.md b/examples/mp-metrics-counted/README.md
new file mode 100644
index 0000000..9dafe75
--- /dev/null
+++ b/examples/mp-metrics-counted/README.md
@@ -0,0 +1,19 @@
+# Microprofile Metrics
+This is an example on how to use microprofile metrics in TomEE.
+
+The command to run the application the application is:
+
+ mvn clean install tomee:run
+
+Make a call to the greeting endpoint:
+
+ http://localhost:8080/rest-mp-metrics/greeting
+
+Check the metrics in Prometheus format:
+
+ http://localhost:8080/rest-mp-metrics/metrics
+
+
+
+
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/07443527/examples/mp-metrics-counted/pom.xml
----------------------------------------------------------------------
diff --git a/examples/mp-metrics-counted/pom.xml b/examples/mp-metrics-counted/pom.xml
new file mode 100644
index 0000000..c5d10e8
--- /dev/null
+++ b/examples/mp-metrics-counted/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>examples</artifactId>
+ <groupId>org.apache.tomee</groupId>
+ <version>8.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>mp-metrics-counted</artifactId>
+ <packaging>war</packaging>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tomee</groupId>
+ <artifactId>javaee-api</artifactId>
+ <version>8.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.microprofile.metrics</groupId>
+ <artifactId>microprofile-metrics-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomee</groupId>
+ <artifactId>openejb-cxf-rs</artifactId>
+ <version>${tomee.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ <version>1.0.3.Final</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomee</groupId>
+ <artifactId>arquillian-tomee-remote</artifactId>
+ <version>${tomee.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomee</groupId>
+ <artifactId>apache-tomee</artifactId>
+ <version>${tomee.version}</version>
+ <type>zip</type>
+ <classifier>microprofile</classifier>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.tomee.maven</groupId>
+ <artifactId>tomee-maven-plugin</artifactId>
+ <version>8.0.0-SNAPSHOT</version>
+ <configuration>
+ <tomeeClassifier>microprofile</tomeeClassifier>
+ <context>${artifactId}</context>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tomee/blob/07443527/examples/mp-metrics-counted/src/main/java/org/superbiz/rest/WeatherService.java
----------------------------------------------------------------------
diff --git a/examples/mp-metrics-counted/src/main/java/org/superbiz/rest/WeatherService.java b/examples/mp-metrics-counted/src/main/java/org/superbiz/rest/WeatherService.java
new file mode 100644
index 0000000..3475e7b
--- /dev/null
+++ b/examples/mp-metrics-counted/src/main/java/org/superbiz/rest/WeatherService.java
@@ -0,0 +1,33 @@
+package org.superbiz.rest;
+
+import org.eclipse.microprofile.metrics.annotation.Counted;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("/weather")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+@ApplicationScoped
+public class WeatherService {
+
+ @Path("/day/status")
+ @Counted(monotonic = true, name = "weather_day_status", absolute = true)
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String dayStatus() {
+ return "Hi, today is a sunny day!";
+ }
+
+ @Path("/week/status")
+ @Counted(monotonic = true, name = "weather_week_status", absolute = true)
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String weekStatus() {
+ return "Hi, week will be mostly sunny!";
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/07443527/examples/mp-metrics-counted/src/test/java/org/superbiz/rest/WeatherServiceTest.java
----------------------------------------------------------------------
diff --git a/examples/mp-metrics-counted/src/test/java/org/superbiz/rest/WeatherServiceTest.java b/examples/mp-metrics-counted/src/test/java/org/superbiz/rest/WeatherServiceTest.java
new file mode 100644
index 0000000..a2a30b5
--- /dev/null
+++ b/examples/mp-metrics-counted/src/test/java/org/superbiz/rest/WeatherServiceTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.
+ */
+package org.superbiz.rest;
+
+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.ws.rs.core.MediaType;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+@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 testCountedPrometheus() {
+ final String message = WebClient.create(base.toExternalForm())
+ .path("/weather/day/status")
+ .get(String.class);
+ assertEquals("Hi, today is a sunny day!", message);
+
+ final String metric = WebClient.create(base.toExternalForm())
+ .path("/metrics/application/weather_day_status")
+ .accept(MediaType.TEXT_PLAIN)
+ .get(String.class);
+ assertEquals("# TYPE application:weather_day_status counter\napplication:weather_day_status 1.0\n", metric);
+ }
+
+ @Test
+ public void testCountedJson() {
+ final String message = WebClient.create(base.toExternalForm())
+ .path("/weather/week/status")
+ .get(String.class);
+ assertEquals("Hi, week will be mostly sunny!", message);
+
+ final String metric = WebClient.create(base.toExternalForm())
+ .path("/metrics/application/weather_week_status")
+ .accept(MediaType.APPLICATION_JSON)
+ .get(String.class);
+ assertEquals("{\"weather_week_status\":{\"delegate\":{},\"unit\":\"none\",\"count\":1}}", metric);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/07443527/examples/mp-metrics-counted/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/examples/mp-metrics-counted/src/test/resources/arquillian.xml b/examples/mp-metrics-counted/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..3029d48
--- /dev/null
+++ b/examples/mp-metrics-counted/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