You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/01/25 13:54:38 UTC

[4/4] camel git commit: Metrics CDI example automated tests

Metrics CDI example automated tests


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

Branch: refs/heads/master
Commit: 60068a90324e0d2f43fd15677cb5fb0eec7d3557
Parents: 6300194
Author: Antonin Stefanutti <an...@stefanutti.fr>
Authored: Mon Jan 25 10:35:56 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jan 25 13:53:39 2016 +0100

----------------------------------------------------------------------
 examples/camel-example-metrics-cdi/pom.xml      | 32 ++++++++
 .../example/metrics/cdi/MetricsSampleTest.java  | 81 ++++++++++++++++++++
 2 files changed, 113 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/60068a90/examples/camel-example-metrics-cdi/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-metrics-cdi/pom.xml b/examples/camel-example-metrics-cdi/pom.xml
index c2958d6..293927a 100755
--- a/examples/camel-example-metrics-cdi/pom.xml
+++ b/examples/camel-example-metrics-cdi/pom.xml
@@ -96,6 +96,38 @@
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
     </dependency>
+
+    <!-- test -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.hamcrest</groupId>
+      <artifactId>java-hamcrest</artifactId>
+      <version>${hamcrest-version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.arquillian.junit</groupId>
+      <artifactId>arquillian-junit-container</artifactId>
+      <version>${arquillian-version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.shrinkwrap.descriptors</groupId>
+      <artifactId>shrinkwrap-descriptors-depchain</artifactId>
+      <version>${shrinkwrap-descriptors-version}</version>
+      <type>pom</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.arquillian.container</groupId>
+      <artifactId>arquillian-weld-se-embedded-1.1</artifactId>
+      <version>${arquillian-weld-se-embedded-version}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>

http://git-wip-us.apache.org/repos/asf/camel/blob/60068a90/examples/camel-example-metrics-cdi/src/test/java/org/apache/camel/example/metrics/cdi/MetricsSampleTest.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-metrics-cdi/src/test/java/org/apache/camel/example/metrics/cdi/MetricsSampleTest.java b/examples/camel-example-metrics-cdi/src/test/java/org/apache/camel/example/metrics/cdi/MetricsSampleTest.java
new file mode 100644
index 0000000..b9d41d4
--- /dev/null
+++ b/examples/camel-example-metrics-cdi/src/test/java/org/apache/camel/example/metrics/cdi/MetricsSampleTest.java
@@ -0,0 +1,81 @@
+/**
+ * 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.
+ */
+package org.apache.camel.example.metrics.cdi;
+
+import javax.inject.Inject;
+import com.codahale.metrics.Gauge;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.annotation.Metric;
+import io.astefanutti.metrics.cdi.MetricsExtension;
+import org.apache.camel.CamelContext;
+import org.apache.camel.cdi.CdiCamelExtension;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+@RunWith(Arquillian.class)
+public class MetricsSampleTest {
+
+    @Inject
+    private Meter generated;
+    @Inject
+    private Meter attempt;
+    @Inject
+    private Meter success;
+    @Inject
+    private Meter redelivery;
+    @Inject
+    private Meter error;
+    @Inject
+    @Metric(name = "success-ratio")
+    private Gauge<Double> ratio;
+
+    @Deployment
+    public static Archive<?> deployment() {
+        return ShrinkWrap.create(JavaArchive.class)
+            // Camel CDI
+            .addPackage(CdiCamelExtension.class.getPackage())
+            // Metrics CDI
+            .addPackage(MetricsExtension.class.getPackage())
+            // Test classes
+            .addPackage(MetricsSampleTest.class.getPackage())
+            // Bean archive deployment descriptor
+            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+    }
+
+    @Test
+    public void testMetricsValues(CamelContext context) throws Exception {
+        // Wait a while so that the timer can kick in
+        Thread.sleep(5000);
+
+        // And stop the Camel context so that inflight exchanges get completed
+        context.stop();
+
+        assertThat("Meter counts are not consistent!", attempt.getCount() - redelivery.getCount() - success.getCount() - error.getCount(), is(equalTo(0L)));
+
+        assertThat("Success rate gauge value is incorrect!", ratio.getValue(), is(equalTo(success.getOneMinuteRate() / generated.getOneMinuteRate())));
+    }
+}