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 2015/12/05 09:29:25 UTC

[2/6] camel git commit: CAMEL-9389: camel-metrics - Allow to capture message history easily

CAMEL-9389: camel-metrics - Allow to capture message history easily


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

Branch: refs/heads/master
Commit: bde39551d8edcdc3cabe06262073a0cfc78acf27
Parents: 8fb44bb
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Dec 5 08:56:44 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Dec 5 08:56:44 2015 +0100

----------------------------------------------------------------------
 .../MetricsMessageHistoryTest.java              |  2 +-
 .../SpringMetricsMessageHistoryTest.java        | 53 ++++++++++++++++++++
 .../SpringMetricsMessageHistoryTest.xml         | 46 +++++++++++++++++
 3 files changed, 100 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bde39551/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryTest.java
index 17279c6..0467812 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryTest.java
@@ -39,7 +39,7 @@ public class MetricsMessageHistoryTest extends CamelTestSupport {
     }
 
     @Test
-    public void testMetricsRoutePolicy() throws Exception {
+    public void testMetricsHistory() throws Exception {
         getMockEndpoint("mock:foo").expectedMessageCount(5);
         getMockEndpoint("mock:bar").expectedMessageCount(5);
         getMockEndpoint("mock:baz").expectedMessageCount(5);

http://git-wip-us.apache.org/repos/asf/camel/blob/bde39551/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/SpringMetricsMessageHistoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/SpringMetricsMessageHistoryTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/SpringMetricsMessageHistoryTest.java
new file mode 100644
index 0000000..a57ffe0
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/SpringMetricsMessageHistoryTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.component.metrics.messagehistory;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringMetricsMessageHistoryTest extends CamelSpringTestSupport {
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/metrics/messagehistory/SpringMetricsMessageHistoryTest.xml");
+    }
+
+    @Test
+    public void testMetricsHistory() throws Exception {
+        getMockEndpoint("mock:foo").expectedMessageCount(5);
+        getMockEndpoint("mock:bar").expectedMessageCount(5);
+        getMockEndpoint("mock:baz").expectedMessageCount(5);
+
+        for (int i = 0; i < 10; i++) {
+            if (i % 2 == 0) {
+                template.sendBody("seda:foo", "Hello " + i);
+            } else {
+                template.sendBody("seda:bar", "Hello " + i);
+            }
+        }
+
+        assertMockEndpointsSatisfied();
+
+        // there should be 3 names
+        MetricRegistry registry = context.getRegistry().findByType(MetricRegistry.class).iterator().next();
+        assertEquals(3, registry.getNames().size());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/bde39551/components/camel-metrics/src/test/resources/org/apache/camel/component/metrics/messagehistory/SpringMetricsMessageHistoryTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/resources/org/apache/camel/component/metrics/messagehistory/SpringMetricsMessageHistoryTest.xml b/components/camel-metrics/src/test/resources/org/apache/camel/component/metrics/messagehistory/SpringMetricsMessageHistoryTest.xml
new file mode 100644
index 0000000..d3694cb
--- /dev/null
+++ b/components/camel-metrics/src/test/resources/org/apache/camel/component/metrics/messagehistory/SpringMetricsMessageHistoryTest.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:aop="http://www.springframework.org/schema/aop"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <bean id="registry" class="com.codahale.metrics.MetricRegistry"/>
+
+  <bean id="history" class="org.apache.camel.component.metrics.messagehistory.MetricsMessageHistoryFactory">
+    <property name="metricsRegistry" ref="registry"/>
+    <property name="useJmx" value="false"/>
+  </bean>
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+    <route>
+      <from uri="seda:foo"/>
+      <to uri="mock:foo"/>
+    </route>
+    <route>
+      <from uri="seda:bar"/>
+      <to uri="mock:bar"/>
+      <to uri="mock:baz"/>
+    </route>
+  </camelContext>
+
+</beans>