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/09/22 11:23:07 UTC
[1/2] camel git commit: CAMEL-9151: camel-metrics route policy should
be per route and so they work when using sub routes.
Repository: camel
Updated Branches:
refs/heads/camel-2.15.x 9300f50e1 -> d7cea3adf
refs/heads/master bfb5b9e37 -> 95fad505c
CAMEL-9151: camel-metrics route policy should be per route and so they work when using sub routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/95fad505
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/95fad505
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/95fad505
Branch: refs/heads/master
Commit: 95fad505c460acfa7ce40c4a89dffd9299bbe55d
Parents: bfb5b9e
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Sep 22 11:23:47 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Sep 22 11:23:47 2015 +0200
----------------------------------------------------------------------
.../metrics/routepolicy/MetricsRoutePolicy.java | 12 ++--
.../MetricsRoutePolicySubRouteTest.java | 71 ++++++++++++++++++++
2 files changed, 78 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/95fad505/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
index 179b17e..74ae017 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
@@ -44,19 +44,21 @@ public class MetricsRoutePolicy extends RoutePolicySupport {
private Route route;
private static final class MetricsStatistics {
- private Timer responses;
+ private final String routeId;
+ private final Timer responses;
- private MetricsStatistics(Timer responses) {
+ private MetricsStatistics(Route route, Timer responses) {
+ this.routeId = route.getId();
this.responses = responses;
}
public void onExchangeBegin(Exchange exchange) {
Timer.Context context = responses.time();
- exchange.setProperty("MetricsRoutePolicy", context);
+ exchange.setProperty("MetricsRoutePolicy-" + routeId, context);
}
public void onExchangeDone(Exchange exchange) {
- Timer.Context context = exchange.getProperty("MetricsRoutePolicy", Timer.Context.class);
+ Timer.Context context = (Timer.Context) exchange.removeProperty("MetricsRoutePolicy-" + routeId);
if (context != null) {
context.stop();
}
@@ -136,7 +138,7 @@ public class MetricsRoutePolicy extends RoutePolicySupport {
// for know we record only all the timings of a complete exchange (responses)
// we have in-flight / total statistics already from camel-core
Timer responses = registryService.getMetricsRegistry().timer(createName("responses"));
- statistics = new MetricsStatistics(responses);
+ statistics = new MetricsStatistics(route, responses);
}
private String createName(String type) {
http://git-wip-us.apache.org/repos/asf/camel/blob/95fad505/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicySubRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicySubRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicySubRouteTest.java
new file mode 100644
index 0000000..61762d2
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicySubRouteTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.routepolicy;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class MetricsRoutePolicySubRouteTest extends CamelTestSupport {
+
+ private MetricRegistry registry = new MetricRegistry();
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ MetricsRoutePolicyFactory factory = new MetricsRoutePolicyFactory();
+ factory.setUseJmx(false);
+ factory.setMetricsRegistry(registry);
+ context.addRoutePolicyFactory(factory);
+
+ return context;
+ }
+
+ @Test
+ public void testMetricsRoutePolicy() throws Exception {
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+
+ template.sendBody("seda:foo", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // there should be 2 names
+ assertEquals(2, registry.getNames().size());
+
+ // there should be 2 timers
+ assertEquals(2, registry.getTimers().size());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("seda:foo").routeId("foo")
+ .to("direct:bar")
+ .to("mock:foo");
+
+ from("direct:bar").routeId("bar")
+ .to("mock:bar");
+ }
+ };
+ }
+}
[2/2] camel git commit: CAMEL-9151: camel-metrics route policy should
be per route and so they work when using sub routes.
Posted by da...@apache.org.
CAMEL-9151: camel-metrics route policy should be per route and so they work when using sub routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d7cea3ad
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d7cea3ad
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d7cea3ad
Branch: refs/heads/camel-2.15.x
Commit: d7cea3adfbe1cf30a149fd785fca925606d06375
Parents: 9300f50
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Sep 22 11:23:47 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Sep 22 11:24:32 2015 +0200
----------------------------------------------------------------------
.../metrics/routepolicy/MetricsRoutePolicy.java | 12 ++--
.../MetricsRoutePolicySubRouteTest.java | 71 ++++++++++++++++++++
2 files changed, 78 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d7cea3ad/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
index 179b17e..74ae017 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
@@ -44,19 +44,21 @@ public class MetricsRoutePolicy extends RoutePolicySupport {
private Route route;
private static final class MetricsStatistics {
- private Timer responses;
+ private final String routeId;
+ private final Timer responses;
- private MetricsStatistics(Timer responses) {
+ private MetricsStatistics(Route route, Timer responses) {
+ this.routeId = route.getId();
this.responses = responses;
}
public void onExchangeBegin(Exchange exchange) {
Timer.Context context = responses.time();
- exchange.setProperty("MetricsRoutePolicy", context);
+ exchange.setProperty("MetricsRoutePolicy-" + routeId, context);
}
public void onExchangeDone(Exchange exchange) {
- Timer.Context context = exchange.getProperty("MetricsRoutePolicy", Timer.Context.class);
+ Timer.Context context = (Timer.Context) exchange.removeProperty("MetricsRoutePolicy-" + routeId);
if (context != null) {
context.stop();
}
@@ -136,7 +138,7 @@ public class MetricsRoutePolicy extends RoutePolicySupport {
// for know we record only all the timings of a complete exchange (responses)
// we have in-flight / total statistics already from camel-core
Timer responses = registryService.getMetricsRegistry().timer(createName("responses"));
- statistics = new MetricsStatistics(responses);
+ statistics = new MetricsStatistics(route, responses);
}
private String createName(String type) {
http://git-wip-us.apache.org/repos/asf/camel/blob/d7cea3ad/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicySubRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicySubRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicySubRouteTest.java
new file mode 100644
index 0000000..61762d2
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicySubRouteTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.routepolicy;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class MetricsRoutePolicySubRouteTest extends CamelTestSupport {
+
+ private MetricRegistry registry = new MetricRegistry();
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ MetricsRoutePolicyFactory factory = new MetricsRoutePolicyFactory();
+ factory.setUseJmx(false);
+ factory.setMetricsRegistry(registry);
+ context.addRoutePolicyFactory(factory);
+
+ return context;
+ }
+
+ @Test
+ public void testMetricsRoutePolicy() throws Exception {
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+
+ template.sendBody("seda:foo", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // there should be 2 names
+ assertEquals(2, registry.getNames().size());
+
+ // there should be 2 timers
+ assertEquals(2, registry.getTimers().size());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("seda:foo").routeId("foo")
+ .to("direct:bar")
+ .to("mock:foo");
+
+ from("direct:bar").routeId("bar")
+ .to("mock:bar");
+ }
+ };
+ }
+}