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 2014/07/30 15:00:44 UTC
[01/34] git commit: Initial commit
Repository: camel
Updated Branches:
refs/heads/master d98a45e84 -> ca67967e0
Initial commit
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/375f13ee
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/375f13ee
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/375f13ee
Branch: refs/heads/master
Commit: 375f13eed7be48abb3f548209b87ba45501559a9
Parents:
Author: Lauri Kimmel <la...@gmx.com>
Authored: Tue May 6 20:44:21 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Tue May 6 20:44:21 2014 +1000
----------------------------------------------------------------------
.gitignore | 8 ++
pom.xml | 95 ++++++++++++++++++++
.../java/org/apache/camel/MetricsComponent.java | 18 ++++
.../java/org/apache/camel/MetricsConsumer.java | 39 ++++++++
.../java/org/apache/camel/MetricsEndpoint.java | 35 ++++++++
.../java/org/apache/camel/MetricsProducer.java | 24 +++++
.../services/org/apache/camel/component/metrics | 1 +
.../org/apache/camel/MetricsComponentTest.java | 28 ++++++
src/test/resources/log4j.properties | 14 +++
9 files changed, 262 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9365f3c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+# Maven
+target
+
+# Eclipse
+
+.classpath
+.project
+.settings/
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..ae5ac4a
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,95 @@
+<?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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-metrics</artifactId>
+ <packaging>bundle</packaging>
+ <version>2.13.0</version>
+
+ <name>Camel Metrics Component</name>
+ <url>http://www.myorganization.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <version>2.13.0</version>
+ </dependency>
+
+ <!-- logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.17</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <version>2.13.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.5.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.6</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+
+ <!-- to generate the MANIFEST-FILE of the bundle -->
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.3.7</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>org.apache.camel.camel-metrics</Bundle-SymbolicName>
+ <Export-Service>org.apache.camel.spi.ComponentResolver;component=metrics</Export-Service>
+ </instructions>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/main/java/org/apache/camel/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsComponent.java b/src/main/java/org/apache/camel/MetricsComponent.java
new file mode 100644
index 0000000..2690fdb
--- /dev/null
+++ b/src/main/java/org/apache/camel/MetricsComponent.java
@@ -0,0 +1,18 @@
+package org.apache.camel;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * Represents the component that manages {@link MetricsEndpoint}.
+ */
+public class MetricsComponent extends DefaultComponent {
+
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ Endpoint endpoint = new MetricsEndpoint(uri, this);
+ setProperties(endpoint, parameters);
+ return endpoint;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/main/java/org/apache/camel/MetricsConsumer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsConsumer.java b/src/main/java/org/apache/camel/MetricsConsumer.java
new file mode 100644
index 0000000..26199ea
--- /dev/null
+++ b/src/main/java/org/apache/camel/MetricsConsumer.java
@@ -0,0 +1,39 @@
+package org.apache.camel;
+
+import java.util.Date;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.ScheduledPollConsumer;
+
+/**
+ * The Metrics consumer.
+ */
+public class MetricsConsumer extends ScheduledPollConsumer {
+ private final MetricsEndpoint endpoint;
+
+ public MetricsConsumer(MetricsEndpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ this.endpoint = endpoint;
+ }
+
+ @Override
+ protected int poll() throws Exception {
+ Exchange exchange = endpoint.createExchange();
+
+ // create a message body
+ Date now = new Date();
+ exchange.getIn().setBody("Hello World! The time is " + now);
+
+ try {
+ // send message to next processor in the route
+ getProcessor().process(exchange);
+ return 1; // number of messages polled
+ } finally {
+ // log exception if an exception occurred and was not handled
+ if (exchange.getException() != null) {
+ getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/main/java/org/apache/camel/MetricsEndpoint.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsEndpoint.java b/src/main/java/org/apache/camel/MetricsEndpoint.java
new file mode 100644
index 0000000..4327a03
--- /dev/null
+++ b/src/main/java/org/apache/camel/MetricsEndpoint.java
@@ -0,0 +1,35 @@
+package org.apache.camel;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * Represents a Metrics endpoint.
+ */
+public class MetricsEndpoint extends DefaultEndpoint {
+
+ public MetricsEndpoint() {
+ }
+
+ public MetricsEndpoint(String uri, MetricsComponent component) {
+ super(uri, component);
+ }
+
+ public MetricsEndpoint(String endpointUri) {
+ super(endpointUri);
+ }
+
+ public Producer createProducer() throws Exception {
+ return new MetricsProducer(this);
+ }
+
+ public Consumer createConsumer(Processor processor) throws Exception {
+ return new MetricsConsumer(this, processor);
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/main/java/org/apache/camel/MetricsProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsProducer.java b/src/main/java/org/apache/camel/MetricsProducer.java
new file mode 100644
index 0000000..4d6a1cd
--- /dev/null
+++ b/src/main/java/org/apache/camel/MetricsProducer.java
@@ -0,0 +1,24 @@
+package org.apache.camel;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Metrics producer.
+ */
+public class MetricsProducer extends DefaultProducer {
+ private static final Logger LOG = LoggerFactory.getLogger(MetricsProducer.class);
+ private MetricsEndpoint endpoint;
+
+ public MetricsProducer(MetricsEndpoint endpoint) {
+ super(endpoint);
+ this.endpoint = endpoint;
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ System.out.println(exchange.getIn().getBody());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/main/resources/META-INF/services/org/apache/camel/component/metrics
----------------------------------------------------------------------
diff --git a/src/main/resources/META-INF/services/org/apache/camel/component/metrics b/src/main/resources/META-INF/services/org/apache/camel/component/metrics
new file mode 100644
index 0000000..e7239ec
--- /dev/null
+++ b/src/main/resources/META-INF/services/org/apache/camel/component/metrics
@@ -0,0 +1 @@
+class=org.apache.camel.MetricsComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/test/java/org/apache/camel/MetricsComponentTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/MetricsComponentTest.java b/src/test/java/org/apache/camel/MetricsComponentTest.java
new file mode 100644
index 0000000..2fb5926
--- /dev/null
+++ b/src/test/java/org/apache/camel/MetricsComponentTest.java
@@ -0,0 +1,28 @@
+package org.apache.camel;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class MetricsComponentTest extends CamelTestSupport {
+
+ @Test
+ public void testMetrics() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("metrics://foo")
+ .to("metrics://bar")
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties
new file mode 100644
index 0000000..3b1bd38
--- /dev/null
+++ b/src/test/resources/log4j.properties
@@ -0,0 +1,14 @@
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following line to turn on Camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
[29/34] CAMEL-7554: Renamed package to include component which is the
way we do in Camel.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsEndpointTest.java
new file mode 100644
index 0000000..e663153
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsEndpointTest.java
@@ -0,0 +1,105 @@
+/**
+ * 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;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AbstractMetricsEndpointTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+
+ @Mock
+ private MetricRegistry registry;
+
+ @Mock
+ private Processor processor;
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private Message in;
+
+ private AbstractMetricsEndpoint endpoint;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ endpoint = new AbstractMetricsEndpoint(registry, METRICS_NAME) {
+ @Override
+ public Producer createProducer() throws Exception {
+ return null;
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return "not real endpoint";
+ }
+ };
+ inOrder = Mockito.inOrder(registry, processor, exchange, in);
+ when(exchange.getIn()).thenReturn(in);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testAbstractMetricsEndpoint() throws Exception {
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ assertThat(endpoint.getRegistry(), is(registry));
+ }
+
+ @Test(expected = RuntimeCamelException.class)
+ public void testCreateConsumer() throws Exception {
+ endpoint.createConsumer(processor);
+ }
+
+ @Test
+ public void testIsSingleton() throws Exception {
+ assertThat(endpoint.isSingleton(), is(false));
+ }
+
+ @Test
+ public void testGetRegistry() throws Exception {
+ assertThat(endpoint.getRegistry(), is(registry));
+ }
+
+ @Test
+ public void testGetMetricsName() throws Exception {
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsProducerTest.java
new file mode 100644
index 0000000..f651389
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsProducerTest.java
@@ -0,0 +1,186 @@
+/**
+ * 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;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.impl.DefaultMessage;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.apache.camel.component.metrics.AbstractMetricsProducer.HEADER_PATTERN;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AbstractMetricsProducerTest {
+
+ public static final String METRIC_NAME = "a metric";
+
+ @Mock
+ private AbstractMetricsEndpoint endpoint;
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private Message in;
+
+ @Mock
+ private MetricRegistry registry;
+
+ private AbstractMetricsProducer<AbstractMetricsEndpoint> okProducer;
+
+ private AbstractMetricsProducer<AbstractMetricsEndpoint> failProducer;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ okProducer = new AbstractMetricsProducer<AbstractMetricsEndpoint>(endpoint) {
+ @Override
+ protected void doProcess(Exchange exchange, AbstractMetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ }
+ };
+ failProducer = new AbstractMetricsProducer<AbstractMetricsEndpoint>(endpoint) {
+
+ @Override
+ protected void doProcess(Exchange exchange, AbstractMetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ throw new Exception("Muchos problemos");
+ }
+ };
+ inOrder = Mockito.inOrder(endpoint, exchange, in, registry);
+ when(exchange.getIn()).thenReturn(in);
+ when(endpoint.getMetricsName()).thenReturn(METRIC_NAME);
+ when(endpoint.getRegistry()).thenReturn(registry);
+ }
+
+ @Test
+ public void testDoProcess() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
+ when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
+ okProducer.process(exchange);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testDoProcessWithException() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
+ when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
+ failProducer.process(exchange);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetMetricsName() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("A");
+ assertThat(okProducer.getMetricsName(in, "value"), is("A"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetMetricsNameNotSet() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
+ assertThat(okProducer.getMetricsName(in, "name"), is("name"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetStringHeader() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("A");
+ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("A"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetStringHeaderWithNullValue() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
+ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetStringHeaderWithWhiteSpaces() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(" ");
+ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetStringHeaderWithEmptySrting() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("");
+ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetLongHeader() throws Exception {
+ when(in.getHeader(HEADER_HISTOGRAM_VALUE, 19L, Long.class)).thenReturn(201L);
+ assertThat(okProducer.getLongHeader(in, HEADER_HISTOGRAM_VALUE, 19L), is(201L));
+ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, 19L, Long.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testClearMetricsHeaders() throws Exception {
+ when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
+ assertThat(okProducer.clearMetricsHeaders(in), is(true));
+ inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testClearRealHeaders() throws Exception {
+ Message msg = new DefaultMessage();
+ Object val = new Object();
+ msg.setHeader(HEADER_HISTOGRAM_VALUE, 109L);
+ msg.setHeader(HEADER_METRIC_NAME, "the metric");
+ msg.setHeader("notRemoved", val);
+ assertThat(msg.getHeaders().size(), is(3));
+ assertThat(msg.getHeader(HEADER_HISTOGRAM_VALUE, Long.class), is(109L));
+ assertThat(msg.getHeader(HEADER_METRIC_NAME, String.class), is("the metric"));
+ assertThat(msg.getHeader("notRemoved"), is(val));
+ okProducer.clearMetricsHeaders(msg);
+ assertThat(msg.getHeaders().size(), is(1));
+ assertThat(msg.getHeader("notRemoved"), is(val));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricComponentSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricComponentSpringTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricComponentSpringTest.java
new file mode 100644
index 0000000..2cd5335
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricComponentSpringTest.java
@@ -0,0 +1,91 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
+import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(CamelSpringJUnit4ClassRunner.class)
+@ContextConfiguration(
+ classes = { MetricComponentSpringTest.TestConfig.class },
+ loader = CamelSpringDelegatingTestContextLoader.class)
+@MockEndpoints
+public class MetricComponentSpringTest {
+
+ @EndpointInject(uri = "mock:out")
+ private MockEndpoint endpoint;
+
+ @Produce(uri = "direct:in")
+ private ProducerTemplate producer;
+
+ @Configuration
+ public static class TestConfig extends SingleRouteCamelConfiguration {
+
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:in")
+ .to("metrics:counter:A?increment=512")
+ .to("mock:out");
+ }
+ };
+ }
+
+ @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
+ public MetricRegistry getMetricRegistry() {
+ return Mockito.mock(MetricRegistry.class);
+ }
+ }
+
+ @Test
+ public void testMetricsRegistryFromCamelRegistry() throws Exception {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
+ Counter mockCounter = Mockito.mock(Counter.class);
+ InOrder inOrder = Mockito.inOrder(mockRegistry, mockCounter);
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+
+ endpoint.expectedMessageCount(1);
+ producer.sendBody(new Object());
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).inc(512L);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentRouteTest.java
new file mode 100644
index 0000000..9fed201
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentRouteTest.java
@@ -0,0 +1,113 @@
+/**
+ * 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;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_PERFIX;
+
+public class MetricsComponentRouteTest extends CamelTestSupport {
+
+ @Produce(uri = "direct:start-1")
+ protected ProducerTemplate template1;
+
+ @Produce(uri = "direct:start-2")
+ protected ProducerTemplate template2;
+
+ @Test
+ public void testMetrics() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+ template1.sendBody(new Object());
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testMessageContentDelivery() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ String body = "Message Body";
+ String header1 = "Header 1";
+ String header2 = "Header 2";
+ Object value1 = new Date();
+ Object value2 = System.currentTimeMillis();
+ mock.expectedBodiesReceived(body);
+ mock.expectedHeaderReceived(header1, value1);
+ mock.expectedHeaderReceived(header2, value2);
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(header1, value1);
+ headers.put(header2, value2);
+ template1.sendBodyAndHeaders(body, headers);
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testHeaderRemoval() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ Object body = new Object();
+ Date now = new Date();
+
+ mock.expectedBodiesReceived(body);
+ mock.expectedHeaderReceived("." + HEADER_PERFIX, "value");
+ mock.expectedHeaderReceived("date", now);
+
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(HEADER_METRIC_NAME, "a name");
+ headers.put(HEADER_HISTOGRAM_VALUE, 34L);
+ headers.put(HEADER_PERFIX + "notExistingHeader", "?");
+ headers.put("." + HEADER_PERFIX, "value");
+ headers.put("date", now);
+
+ template2.sendBodyAndHeaders(body, headers);
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start-1")
+ .to("metrics:timer:T?action=start")
+ .to("metrics:A")
+ .to("metrics:counter://B")
+ .to("metrics:counter:C?increment=19291")
+ .to("metrics:counter:C?decrement=19292")
+ .to("metrics:counter:C")
+ .to("metrics:meter:D")
+ .to("metrics:meter:D?mark=90001")
+ .to("metrics:histogram:E")
+ .to("metrics:timer:T")
+ .to("metrics:histogram:E?value=12000000031")
+ .to("metrics:timer:T?action=stop")
+ .to("mock:result");
+
+ from("direct:start-2")
+ .to("metrics:meter:F?mark=88")
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentTest.java
new file mode 100644
index 0000000..fd4b4a2
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentTest.java
@@ -0,0 +1,217 @@
+/**
+ * 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;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.metrics.counter.CounterEndpoint;
+import org.apache.camel.component.metrics.histogram.HistogramEndpoint;
+import org.apache.camel.component.metrics.meter.MeterEndpoint;
+import org.apache.camel.component.metrics.timer.TimerEndpoint;
+import org.apache.camel.spi.Registry;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MetricsComponentTest {
+
+ @Mock
+ private CamelContext camelContext;
+
+ @Mock
+ private Registry camelRegistry;
+
+ @Mock
+ private MetricRegistry metricRegistry;
+
+ private InOrder inOrder;
+
+ private MetricsComponent component;
+
+ @Before
+ public void setUp() throws Exception {
+ component = new MetricsComponent();
+ inOrder = Mockito.inOrder(camelContext, camelRegistry, metricRegistry);
+
+ }
+
+ @Test
+ public void testCreateEndpoint() throws Exception {
+ component.setCamelContext(camelContext);
+ when(camelContext.getRegistry()).thenReturn(camelRegistry);
+ when(camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class)).thenReturn(metricRegistry);
+ Map<String, Object> params = new HashMap<String, Object>();
+ Long value = System.currentTimeMillis();
+ params.put("mark", value);
+ Endpoint result = component.createEndpoint("metrics:meter:long.meter", "meter:long.meter", params);
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(instanceOf(MeterEndpoint.class)));
+ MeterEndpoint me = (MeterEndpoint) result;
+ assertThat(me.getMark(), is(value));
+ assertThat(me.getMetricsName(), is("long.meter"));
+ assertThat(me.getRegistry(), is(metricRegistry));
+ inOrder.verify(camelContext, times(1)).getRegistry();
+ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
+ inOrder.verify(camelContext, times(1)).getTypeConverter();
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testCreateEndpoints() throws Exception {
+ component.setCamelContext(camelContext);
+ when(camelContext.getRegistry()).thenReturn(camelRegistry);
+ when(camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class)).thenReturn(metricRegistry);
+ Map<String, Object> params = new HashMap<String, Object>();
+ Long value = System.currentTimeMillis();
+ params.put("mark", value);
+ Endpoint result = component.createEndpoint("metrics:meter:long.meter", "meter:long.meter", params);
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(instanceOf(MeterEndpoint.class)));
+ MeterEndpoint me = (MeterEndpoint) result;
+ assertThat(me.getMark(), is(value));
+ assertThat(me.getMetricsName(), is("long.meter"));
+ assertThat(me.getRegistry(), is(metricRegistry));
+
+ params = new HashMap<String, Object>();
+ params.put("increment", value + 1);
+ params.put("decrement", value - 1);
+
+ result = component.createEndpoint("metrics:counter:long.counter", "counter:long.counter", params);
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(instanceOf(CounterEndpoint.class)));
+ CounterEndpoint ce = (CounterEndpoint) result;
+ assertThat(ce.getIncrement(), is(value + 1));
+ assertThat(ce.getDecrement(), is(value - 1));
+ assertThat(ce.getMetricsName(), is("long.counter"));
+ assertThat(ce.getRegistry(), is(metricRegistry));
+
+ inOrder.verify(camelContext, times(1)).getRegistry();
+ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
+ inOrder.verify(camelContext, times(2)).getTypeConverter();
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetMetricsName() throws Exception {
+ assertThat(component.getMetricsName("meter:metric-a"), is("metric-a"));
+ assertThat(component.getMetricsName("meter:metric-a:sub-b"), is("metric-a:sub-b"));
+ assertThat(component.getMetricsName("metric-a"), is("metric-a"));
+ assertThat(component.getMetricsName("//metric-a"), is("//metric-a"));
+ assertThat(component.getMetricsName("meter://metric-a"), is("//metric-a"));
+ }
+
+ @Test
+ public void testCreateNewEndpointForCounter() throws Exception {
+ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.COUNTER, "a name");
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint, is(instanceOf(CounterEndpoint.class)));
+ }
+
+ @Test
+ public void testCreateNewEndpointForMeter() throws Exception {
+ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.METER, "a name");
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint, is(instanceOf(MeterEndpoint.class)));
+ }
+
+ @Test(expected = RuntimeCamelException.class)
+ public void testCreateNewEndpointForGauge() throws Exception {
+ component.createNewEndpoint(metricRegistry, MetricsType.GAUGE, "a name");
+ }
+
+ @Test
+ public void testCreateNewEndpointForHistogram() throws Exception {
+ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.HISTOGRAM, "a name");
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint, is(instanceOf(HistogramEndpoint.class)));
+ }
+
+ @Test
+ public void testCreateNewEndpointForTimer() throws Exception {
+ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.TIMER, "a name");
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint, is(instanceOf(TimerEndpoint.class)));
+ }
+
+ @Test
+ public void testGetMetricsType() throws Exception {
+ for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
+ assertThat(component.getMetricsType(type.toString() + ":metrics-name"), is(type));
+ }
+ }
+
+ @Test
+ public void testGetMetricsTypeNotSet() throws Exception {
+ assertThat(component.getMetricsType("no-metrics-type"), is(MetricsComponent.DEFAULT_METRICS_TYPE));
+ }
+
+ @Test(expected = RuntimeCamelException.class)
+ public void testGetMetricsTypeNotFound() throws Exception {
+ component.getMetricsType("unknown-metrics:metrics-name");
+ }
+
+ @Test
+ public void testGetOrCreateMetricRegistryFoundInCamelRegistry() throws Exception {
+ when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(metricRegistry);
+ MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
+ assertThat(result, is(metricRegistry));
+ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetOrCreateMetricRegistryNotFoundInCamelRegistry() throws Exception {
+ when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(null);
+ MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(not(metricRegistry)));
+ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetMetricRegistryFromCamelRegistry() throws Exception {
+ when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(metricRegistry);
+ MetricRegistry result = component.getMetricRegistryFromCamelRegistry(camelRegistry, "name");
+ assertThat(result, is(metricRegistry));
+ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testCreateMetricRegistry() throws Exception {
+ MetricRegistry registry = component.createMetricRegistry();
+ assertThat(registry, is(notNullValue()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsTypeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsTypeTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsTypeTest.java
new file mode 100644
index 0000000..145a1db
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsTypeTest.java
@@ -0,0 +1,34 @@
+/**
+ * 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;
+
+import java.util.EnumSet;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class MetricsTypeTest {
+
+ @Test
+ public void testGetByName() throws Exception {
+ for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
+ MetricsType t = MetricsType.getByName(type.toString());
+ assertThat(t, is(type));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterEndpointTest.java
new file mode 100644
index 0000000..c5da95e
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterEndpointTest.java
@@ -0,0 +1,102 @@
+/**
+ * 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.counter;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Producer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CounterEndpointTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final Long VALUE = System.currentTimeMillis();
+
+ @Mock
+ private MetricRegistry registry;
+
+ private CounterEndpoint endpoint;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ endpoint = new CounterEndpoint(registry, METRICS_NAME);
+ inOrder = Mockito.inOrder(registry);
+ }
+
+ @After
+ public void tearDown() {
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testCounterEndpoint() throws Exception {
+ assertThat(endpoint.getRegistry(), is(registry));
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ assertThat(endpoint.getIncrement(), is(nullValue()));
+ assertThat(endpoint.getDecrement(), is(nullValue()));
+ }
+
+ @Test
+ public void testCreateProducer() throws Exception {
+ Producer producer = endpoint.createProducer();
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer, is(instanceOf(CounterProducer.class)));
+ }
+
+ @Test
+ public void testGetIncrement() throws Exception {
+ assertThat(endpoint.getIncrement(), is(nullValue()));
+ }
+
+ @Test
+ public void testSetIncrement() throws Exception {
+ assertThat(endpoint.getIncrement(), is(nullValue()));
+ endpoint.setIncrement(VALUE);
+ assertThat(endpoint.getIncrement(), is(VALUE));
+ }
+
+ @Test
+ public void testGetDecrement() throws Exception {
+ assertThat(endpoint.getDecrement(), is(nullValue()));
+ }
+
+ @Test
+ public void testSetDecrement() throws Exception {
+ assertThat(endpoint.getDecrement(), is(nullValue()));
+ endpoint.setDecrement(VALUE);
+ assertThat(endpoint.getDecrement(), is(VALUE));
+ }
+
+ @Test
+ public void testCreateEndpointUri() throws Exception {
+ assertThat(endpoint.createEndpointUri(), is(CounterEndpoint.ENDPOINT_URI));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterProducerTest.java
new file mode 100644
index 0000000..005ae65
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterProducerTest.java
@@ -0,0 +1,195 @@
+/**
+ * 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.counter;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CounterProducerTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final Long INCREMENT = 100000L;
+ private static final Long DECREMENT = 91929199L;
+
+ @Mock
+ private CounterEndpoint endpoint;
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private MetricRegistry registry;
+
+ @Mock
+ private Counter counter;
+
+ @Mock
+ private Message in;
+
+ private CounterProducer producer;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ producer = new CounterProducer(endpoint);
+ inOrder = Mockito.inOrder(endpoint, exchange, registry, counter, in);
+ when(endpoint.getRegistry()).thenReturn(registry);
+ when(registry.counter(METRICS_NAME)).thenReturn(counter);
+ when(exchange.getIn()).thenReturn(in);
+ }
+
+ @Test
+ public void testCounterProducer() throws Exception {
+ assertThat(producer.getEndpoint().equals(endpoint), is(true));
+ }
+
+ @Test
+ public void testProcessWithIncrementOnly() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(INCREMENT);
+ when(endpoint.getDecrement()).thenReturn(null);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
+ inOrder.verify(counter, times(1)).inc(INCREMENT);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessWithDecrementOnly() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(null);
+ when(endpoint.getDecrement()).thenReturn(DECREMENT);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
+ inOrder.verify(counter, times(1)).dec(DECREMENT);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testDoProcessWithIncrementAndDecrement() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(INCREMENT);
+ when(endpoint.getDecrement()).thenReturn(DECREMENT);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
+ inOrder.verify(counter, times(1)).inc(INCREMENT);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessWithOutIncrementAndDecrement() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(null);
+ when(endpoint.getDecrement()).thenReturn(null);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
+ inOrder.verify(counter, times(1)).inc();
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessWithHeaderValuesOnly() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(null);
+ when(endpoint.getDecrement()).thenReturn(null);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(INCREMENT + 1);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(DECREMENT - 1);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
+ inOrder.verify(counter, times(1)).inc(INCREMENT + 1);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessOverridingIncrement() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(INCREMENT);
+ when(endpoint.getDecrement()).thenReturn(DECREMENT);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT + 1);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
+ inOrder.verify(counter, times(1)).inc(INCREMENT + 1);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessOverridingDecrement() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(null);
+ when(endpoint.getDecrement()).thenReturn(DECREMENT);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT - 1);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
+ inOrder.verify(counter, times(1)).dec(DECREMENT - 1);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterRouteTest.java
new file mode 100644
index 0000000..c33ec39
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterRouteTest.java
@@ -0,0 +1,209 @@
+/**
+ * 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.counter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
+import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.component.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(CamelSpringJUnit4ClassRunner.class)
+@ContextConfiguration(
+ classes = { CounterRouteTest.TestConfig.class },
+ loader = CamelSpringDelegatingTestContextLoader.class)
+@MockEndpoints
+public class CounterRouteTest {
+
+ @EndpointInject(uri = "mock:out")
+ private MockEndpoint endpoint;
+
+ @Produce(uri = "direct:in-1")
+ private ProducerTemplate producer1;
+
+ @Produce(uri = "direct:in-2")
+ private ProducerTemplate producer2;
+
+ @Produce(uri = "direct:in-3")
+ private ProducerTemplate producer3;
+
+ @Produce(uri = "direct:in-4")
+ private ProducerTemplate producer4;
+
+ private MetricRegistry mockRegistry;
+
+ private Counter mockCounter;
+
+ private InOrder inOrder;
+
+ @Configuration
+ public static class TestConfig extends SingleRouteCamelConfiguration {
+
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:in-1")
+ .to("metrics:counter:A?increment=5")
+ .to("mock:out");
+
+ from("direct:in-2")
+ .to("metrics:counter:A?decrement=9")
+ .to("mock:out");
+
+ from("direct:in-3")
+ .setHeader(HEADER_COUNTER_INCREMENT, constant(417L))
+ .to("metrics:counter:A")
+ .to("mock:out");
+
+ from("direct:in-4")
+ .setHeader(HEADER_COUNTER_INCREMENT, simple("${body.length}"))
+ .to("metrics:counter:A")
+ .to("mock:out");
+ }
+ };
+ }
+
+ @Bean(name = METRIC_REGISTRY_NAME)
+ public MetricRegistry getMetricRegistry() {
+ return Mockito.mock(MetricRegistry.class);
+ }
+ }
+
+ @Before
+ public void setup() {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
+ mockCounter = mock(Counter.class);
+ inOrder = Mockito.inOrder(mockRegistry, mockCounter);
+ }
+
+ @After
+ public void tearDown() {
+ endpoint.reset();
+ reset(mockRegistry, mockCounter);
+ }
+
+ @Test
+ public void testOverrideMetricsName() throws Exception {
+ when(mockRegistry.counter("B")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ producer1.sendBodyAndHeader(new Object(), HEADER_METRIC_NAME, "B");
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("B");
+ inOrder.verify(mockCounter, times(1)).inc(5L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideIncrement() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ producer1.sendBodyAndHeader(new Object(), HEADER_COUNTER_INCREMENT, 14L);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).inc(14L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideIncrementAndDecrement() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(HEADER_COUNTER_INCREMENT, 912L);
+ headers.put(HEADER_COUNTER_DECREMENT, 43219L);
+ producer1.sendBodyAndHeaders(new Object(), headers);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).inc(912L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideDecrement() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ producer2.sendBodyAndHeader(new Object(), HEADER_COUNTER_DECREMENT, 7L);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).dec(7L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideIncrementWithWrongType() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ producer1.sendBodyAndHeader(new Object(), HEADER_COUNTER_INCREMENT, "this is not a valid long value");
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideUsingConstantValue() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ producer3.sendBody(new Object());
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).inc(417L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideUsingScriptEvaluation() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ String message = "Hello from Camel Metrics!";
+ producer4.sendBody(message);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).inc(message.length());
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramEndpointTest.java
new file mode 100644
index 0000000..86049d5
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramEndpointTest.java
@@ -0,0 +1,88 @@
+/**
+ * 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.histogram;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Producer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+@RunWith(MockitoJUnitRunner.class)
+public class HistogramEndpointTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final Long VALUE = System.currentTimeMillis();
+
+ @Mock
+ private MetricRegistry registry;
+
+ private HistogramEndpoint endpoint;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ endpoint = new HistogramEndpoint(registry, METRICS_NAME);
+ inOrder = Mockito.inOrder(registry);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testHistogramEndpoint() throws Exception {
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint.getRegistry(), is(registry));
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ }
+
+ @Test
+ public void testCreateProducer() throws Exception {
+ Producer producer = endpoint.createProducer();
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer, is(HistogramProducer.class));
+ }
+
+ @Test
+ public void testGetValue() throws Exception {
+ assertThat(endpoint.getValue(), is(nullValue()));
+ }
+
+ @Test
+ public void testSetValue() throws Exception {
+ assertThat(endpoint.getValue(), is(nullValue()));
+ endpoint.setValue(VALUE);
+ assertThat(endpoint.getValue(), is(VALUE));
+ }
+
+ @Test
+ public void testCreateEndpointUri() throws Exception {
+ assertThat(endpoint.createEndpointUri(), is(HistogramEndpoint.ENDPOINT_URI));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramProducerTest.java
new file mode 100644
index 0000000..6665796
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramProducerTest.java
@@ -0,0 +1,125 @@
+/**
+ * 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.histogram;
+
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class HistogramProducerTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final Long VALUE = System.currentTimeMillis();
+
+ @Mock
+ private HistogramEndpoint endpoint;
+
+ @Mock
+ private MetricRegistry registry;
+
+ @Mock
+ private Histogram histogram;
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private Message in;
+
+ private HistogramProducer producer;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ producer = new HistogramProducer(endpoint);
+ inOrder = Mockito.inOrder(endpoint, registry, histogram, exchange, in);
+ when(endpoint.getRegistry()).thenReturn(registry);
+ when(registry.histogram(METRICS_NAME)).thenReturn(histogram);
+ when(exchange.getIn()).thenReturn(in);
+ }
+
+ @Test
+ public void testHistogramProducer() throws Exception {
+ assertThat(producer.getEndpoint().equals(endpoint), is(true));
+ }
+
+ @Test
+ public void testProcessValueSet() throws Exception {
+ when(endpoint.getValue()).thenReturn(VALUE);
+ when(in.getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class)).thenReturn(VALUE);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getValue();
+ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class);
+ inOrder.verify(histogram, times(1)).update(VALUE);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessValueNotSet() throws Exception {
+ when(endpoint.getValue()).thenReturn(null);
+ when(in.getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getValue();
+ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessOverrideValue() throws Exception {
+ when(endpoint.getValue()).thenReturn(VALUE);
+ when(in.getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class)).thenReturn(VALUE + 3);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getValue();
+ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class);
+ inOrder.verify(histogram, times(1)).update(VALUE + 3);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessOverrideUriValueNotSet() throws Exception {
+ when(endpoint.getValue()).thenReturn(null);
+ when(in.getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class)).thenReturn(VALUE + 2);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getValue();
+ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class);
+ inOrder.verify(histogram, times(1)).update(VALUE + 2);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramRouteTest.java
new file mode 100644
index 0000000..ee5dad8
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramRouteTest.java
@@ -0,0 +1,123 @@
+/**
+ * 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.histogram;
+
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
+import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.component.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(CamelSpringJUnit4ClassRunner.class)
+@ContextConfiguration(
+ classes = { HistogramRouteTest.TestConfig.class },
+ loader = CamelSpringDelegatingTestContextLoader.class)
+@MockEndpoints
+public class HistogramRouteTest {
+
+ @EndpointInject(uri = "mock:out")
+ private MockEndpoint endpoint;
+
+ @Produce(uri = "direct:in")
+ private ProducerTemplate producer;
+
+ private MetricRegistry mockRegistry;
+
+ private Histogram mockHistogram;
+
+ private InOrder inOrder;
+
+ @Configuration
+ public static class TestConfig extends SingleRouteCamelConfiguration {
+
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:in")
+ .to("metrics:histogram:A?value=332491")
+ .to("mock:out");
+ }
+ };
+ }
+
+ @Bean(name = METRIC_REGISTRY_NAME)
+ public MetricRegistry getMetricRegistry() {
+ return Mockito.mock(MetricRegistry.class);
+ }
+ }
+
+ @Before
+ public void setup() {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
+ mockHistogram = Mockito.mock(Histogram.class);
+ inOrder = Mockito.inOrder(mockRegistry, mockHistogram);
+ }
+
+ @After
+ public void tearDown() {
+ endpoint.reset();
+ reset(mockRegistry);
+ }
+
+ @Test
+ public void testOverrideMetricsName() throws Exception {
+ when(mockRegistry.histogram("B")).thenReturn(mockHistogram);
+ endpoint.expectedMessageCount(1);
+ producer.sendBodyAndHeader(new Object(), HEADER_METRIC_NAME, "B");
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).histogram("B");
+ inOrder.verify(mockHistogram, times(1)).update(332491L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideValue() throws Exception {
+ when(mockRegistry.histogram("A")).thenReturn(mockHistogram);
+ endpoint.expectedMessageCount(1);
+ producer.sendBodyAndHeader(new Object(), HEADER_HISTOGRAM_VALUE, 181L);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).histogram("A");
+ inOrder.verify(mockHistogram, times(1)).update(181L);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterEndpointTest.java
new file mode 100644
index 0000000..e2fb8c1
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterEndpointTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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.meter;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Producer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MeterEndpointTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final Long VALUE = System.currentTimeMillis();
+
+ @Mock
+ private MetricRegistry registry;
+
+ private MeterEndpoint endpoint;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ endpoint = new MeterEndpoint(registry, METRICS_NAME);
+ inOrder = Mockito.inOrder(registry);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testMeterEndpoint() throws Exception {
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint.getRegistry(), is(registry));
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ }
+
+ @Test
+ public void testCreateProducer() throws Exception {
+ Producer producer = endpoint.createProducer();
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer, is(instanceOf(MeterProducer.class)));
+ }
+
+ @Test
+ public void testGetMark() throws Exception {
+ assertThat(endpoint.getMark(), is(nullValue()));
+ }
+
+ @Test
+ public void testSetMark() throws Exception {
+ assertThat(endpoint.getMark(), is(nullValue()));
+ endpoint.setMark(VALUE);
+ assertThat(endpoint.getMark(), is(VALUE));
+ }
+
+ @Test
+ public void testCreateEndpointUri() throws Exception {
+ assertThat(endpoint.createEndpointUri(), is(MeterEndpoint.ENDPOINT_URI));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterProducerTest.java
new file mode 100644
index 0000000..1392768
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterProducerTest.java
@@ -0,0 +1,126 @@
+/**
+ * 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.meter;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METER_MARK;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MeterProducerTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final Long MARK = 9919120L;
+
+ @Mock
+ private MeterEndpoint endpoint;
+
+ @Mock
+ private MetricRegistry registry;
+
+ @Mock
+ private Meter meter;
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private Message in;
+
+ private MeterProducer producer;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ producer = new MeterProducer(endpoint);
+ inOrder = Mockito.inOrder(endpoint, registry, meter, exchange, in);
+ when(endpoint.getRegistry()).thenReturn(registry);
+ when(registry.meter(METRICS_NAME)).thenReturn(meter);
+ when(exchange.getIn()).thenReturn(in);
+ }
+
+ @Test
+ public void testMeterProducer() throws Exception {
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer.getEndpoint().equals(endpoint), is(true));
+ }
+
+ @Test
+ public void testProcessMarkSet() throws Exception {
+ when(endpoint.getMark()).thenReturn(MARK);
+ when(in.getHeader(HEADER_METER_MARK, MARK, Long.class)).thenReturn(MARK);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getMark();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, MARK, Long.class);
+ inOrder.verify(meter, times(1)).mark(MARK);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessMarkSetOverrideByHeaderValue() throws Exception {
+ when(endpoint.getMark()).thenReturn(MARK);
+ when(in.getHeader(HEADER_METER_MARK, MARK, Long.class)).thenReturn(MARK + 101);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getMark();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, MARK, Long.class);
+ inOrder.verify(meter, times(1)).mark(MARK + 101);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessMarkNotSet() throws Exception {
+ when(endpoint.getMark()).thenReturn(null);
+ when(in.getHeader(HEADER_METER_MARK, null, Long.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getMark();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, null, Long.class);
+ inOrder.verify(meter, times(1)).mark();
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessMarkNotSetOverrideByHeaderValue() throws Exception {
+ when(endpoint.getMark()).thenReturn(null);
+ when(in.getHeader(HEADER_METER_MARK, null, Long.class)).thenReturn(MARK);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getMark();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, null, Long.class);
+ inOrder.verify(meter, times(1)).mark(MARK);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
[23/34] git commit: Merge branch 'master' into camel-metrics
Posted by da...@apache.org.
Merge branch 'master' into camel-metrics
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/85cc550f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/85cc550f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/85cc550f
Branch: refs/heads/master
Commit: 85cc550fd73a6809b07d43686ddad1e9f004d242
Parents: 838eb59 e8fb927
Author: Lauri Kimmel <la...@gmx.com>
Authored: Wed Jul 30 20:29:57 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Wed Jul 30 20:29:57 2014 +1000
----------------------------------------------------------------------
apache-camel/pom.xml | 24 ++-
.../src/main/descriptors/common-bin.xml | 1 +
.../camel/FailedToCreateRouteException.java | 10 +-
.../camel/component/rest/RestEndpoint.java | 12 +-
.../apache/camel/impl/DefaultCamelContext.java | 2 +-
.../apache/camel/impl/DefaultRouteContext.java | 7 +
.../apache/camel/impl/DefaultUnitOfWork.java | 17 ++
.../language/tokenizer/XMLTokenizeLanguage.java | 1 +
.../model/language/XMLTokenizerExpression.java | 6 +
.../camel/model/rest/RestBindingDefinition.java | 169 ++++++++-------
.../model/rest/RestConfigurationDefinition.java | 79 ++++++++
.../apache/camel/model/rest/RestDefinition.java | 114 ++++++++---
.../apache/camel/model/rest/VerbDefinition.java | 38 ++--
.../camel/processor/CamelInternalProcessor.java | 29 +++
.../processor/binding/RestBindingProcessor.java | 186 +++++++++++++----
.../org/apache/camel/spi/RestConfiguration.java | 59 +++++-
.../apache/camel/spi/RestConsumerFactory.java | 7 +-
.../camel/spi/SynchronizationRouteAware.java | 58 ++++++
.../java/org/apache/camel/spi/UnitOfWork.java | 17 ++
.../camel/support/SynchronizationAdapter.java | 12 +-
.../org/apache/camel/util/UnitOfWorkHelper.java | 52 +++++
.../mock/MockEndpointTimeClauseTest.java | 36 +++-
.../rest/DummyRestConsumerFactory.java | 4 +-
.../rest/FromRestGetEmbeddedRouteTest.java | 4 +-
.../component/rest/FromRestGetEndPathTest.java | 2 +-
.../camel/component/rest/FromRestGetTest.java | 3 +-
.../management/ManagedFromRestGetTest.java | 3 +-
.../RouteAwareSynchronizationTest.java | 97 +++++++++
.../websocket/CamelWebSocketServlet.java | 2 +-
.../handler/CamelNamespaceHandler.java | 54 ++++-
.../camel/core/osgi/OsgiCamelContextHelper.java | 2 +-
.../camel/core/osgi/OsgiClassResolver.java | 20 +-
.../camel/core/osgi/CamelOsgiTestSupport.java | 2 +-
.../camel/component/http/CamelServlet.java | 41 ++--
.../HttpServletResolveConsumerStrategy.java | 46 +++++
.../http/ServletResolveConsumerStrategy.java | 37 ++++
.../component/jackson/JacksonDataFormat.java | 13 ++
.../jackson/JacksonMarshalAllowJMSTypeTest.java | 2 +-
.../JacksonMarshalUnmarshalTypeHeaderTest.java | 2 +-
components/camel-jetty/pom.xml | 11 +
.../jetty/CamelContinuationServlet.java | 2 +-
.../component/jetty/CamelFilterWrapper.java | 1 -
.../component/jetty/CamelMultipartFilter.java | 1 +
.../component/jetty/JettyHttpComponent.java | 78 ++++++-
.../component/jetty/JettyRestHttpBinding.java | 68 +++++++
...JettyRestServletResolveConsumerStrategy.java | 103 ++++++++++
.../camel/component/jetty/rest/CountryPojo.java | 40 ++++
.../RestJettyBindingModeAutoWithJsonTest.java | 59 ++++++
.../RestJettyBindingModeAutoWithXmlTest.java | 59 ++++++
.../rest/RestJettyBindingModeJsonTest.java | 75 +++++++
.../jetty/rest/RestJettyBindingModeXmlTest.java | 75 +++++++
.../component/jetty/rest/RestJettyGetTest.java | 56 +++++
.../jetty/rest/RestJettyPojoInOutTest.java | 53 +++++
.../rest/RestJettyPostJsonJaxbPojoTest.java | 61 ++++++
.../rest/RestJettyPostJsonPojoListTest.java | 67 ++++++
.../jetty/rest/RestJettyPostJsonPojoTest.java | 61 ++++++
.../rest/RestJettyPostXmlJaxbPojoTest.java | 79 ++++++++
.../jetty/rest/RestPathMatchingTest.java | 55 +++++
.../component/jetty/rest/UserJaxbPojo.java | 48 +++++
.../camel/component/jetty/rest/UserPojo.java | 40 ++++
.../camel/component/jetty/rest/UserService.java | 33 +++
.../jms/reply/CorrelationTimeoutMap.java | 8 +-
.../apache/camel/component/jpa/JpaConsumer.java | 2 +
components/camel-netty-http/pom.xml | 11 +
.../netty/http/DefaultContextPathMatcher.java | 4 +
.../netty/http/DefaultNettyHttpBinding.java | 32 +--
.../netty/http/NettyHttpComponent.java | 86 +++++++-
.../netty/http/NettyHttpConverter.java | 2 +-
.../component/netty/http/NettyHttpHelper.java | 4 +-
.../netty/http/RestContextPathMatcher.java | 95 +++++++++
.../netty/http/RestNettyHttpBinding.java | 91 +++++++++
.../http/SecurityAuthenticatorSupport.java | 2 +-
.../http/handlers/HttpClientChannelHandler.java | 6 +-
.../http/handlers/HttpServerChannelHandler.java | 29 +--
.../HttpServerMultiplexChannelHandler.java | 23 ++-
...ttpAccessHttpRequestAndResponseBeanTest.java | 2 +-
...ponentConfigurationAndDocumentationTest.java | 1 -
.../NettyHttpGetWithInvalidMessageTest.java | 104 ++++++++++
.../http/NettyHttpMapHeadersFalseTest.java | 6 +-
.../netty/http/NettyUseRawHttpResponseTest.java | 2 +-
.../component/netty/http/rest/CountryPojo.java | 40 ++++
...estNettyHttpBindingModeAutoWithJsonTest.java | 59 ++++++
...RestNettyHttpBindingModeAutoWithXmlTest.java | 59 ++++++
.../rest/RestNettyHttpBindingModeJsonTest.java | 76 +++++++
.../rest/RestNettyHttpBindingModeXmlTest.java | 77 +++++++
.../netty/http/rest/RestNettyHttpGetTest.java | 56 +++++
.../http/rest/RestNettyHttpPojoInOutTest.java | 55 +++++
.../rest/RestNettyHttpPostJsonJaxbPojoTest.java | 63 ++++++
.../rest/RestNettyHttpPostJsonPojoListTest.java | 68 +++++++
.../rest/RestNettyHttpPostJsonPojoTest.java | 63 ++++++
.../rest/RestNettyHttpPostXmlJaxbPojoTest.java | 79 ++++++++
.../component/netty/http/rest/UserJaxbPojo.java | 48 +++++
.../component/netty/http/rest/UserPojo.java | 40 ++++
.../component/netty/http/rest/UserService.java | 33 +++
.../component/netty/ClientPipelineFactory.java | 2 +-
.../component/netty/ServerPipelineFactory.java | 6 +-
.../netty/handlers/ClientChannelHandler.java | 1 +
.../netty/handlers/ServerChannelHandler.java | 2 +-
.../component/netty4/ClientPipelineFactory.java | 2 +-
.../camel/component/netty4/NettyProducer.java | 3 +-
.../component/netty4/ServerPipelineFactory.java | 4 +-
.../SingleUDPNettyServerBootstrapFactory.java | 1 -
.../netty4/handlers/ServerChannelHandler.java | 2 +-
.../component/netty4/NettyConverterTest.java | 1 -
.../component/restlet/RestletComponent.java | 15 +-
.../RestRestletBindingModeAutoWithJsonTest.java | 60 ++++++
.../RestRestletBindingModeAutoWithXmlTest.java | 60 ++++++
.../restlet/RestRestletBindingModeJsonTest.java | 1 -
.../restlet/RestRestletBindingModeXmlTest.java | 1 -
.../restlet/RestRestletPojoInOutTest.java | 6 +-
.../RestRestletPostJsonJaxbPojoTest.java | 4 +-
.../RestRestletPostJsonPojoListTest.java | 4 +-
.../restlet/RestRestletPostJsonPojoTest.java | 4 +-
.../restlet/RestRestletPostXmlJaxbPojoTest.java | 4 +-
.../restlet/SpringRestRestletPojoInOutTest.java | 53 +++++
.../restlet/SpringRestRestletPojoInOutTest.xml | 46 +++++
components/camel-scala/pom.xml | 11 +
components/camel-servlet/pom.xml | 11 +
.../servlet/CamelHttpTransportServlet.java | 3 +
.../component/servlet/ServletComponent.java | 54 ++++-
.../servlet/ServletRestHttpBinding.java | 67 ++++++
...rvletRestServletResolveConsumerStrategy.java | 102 ++++++++++
.../component/servlet/rest/CountryPojo.java | 40 ++++
.../RestServletBindingModeAutoWithJsonTest.java | 71 +++++++
.../RestServletBindingModeAutoWithXmlTest.java | 71 +++++++
.../rest/RestServletBindingModeJsonTest.java | 86 ++++++++
.../rest/RestServletBindingModeXmlTest.java | 87 ++++++++
.../servlet/rest/RestServletGetTest.java | 66 ++++++
.../servlet/rest/RestServletPojoInOutTest.java | 65 ++++++
.../rest/RestServletPostJsonJaxbPojoTest.java | 70 +++++++
.../rest/RestServletPostJsonPojoListTest.java | 76 +++++++
.../rest/RestServletPostJsonPojoTest.java | 70 +++++++
.../rest/RestServletPostXmlJaxbPojoTest.java | 92 +++++++++
.../component/servlet/rest/UserJaxbPojo.java | 48 +++++
.../camel/component/servlet/rest/UserPojo.java | 40 ++++
.../component/servlet/rest/UserService.java | 33 +++
components/camel-spark-rest/pom.xml | 13 ++
.../sparkrest/DefaultSparkBinding.java | 2 +
.../component/sparkrest/SparkComponent.java | 4 +-
.../camel/component/sparkrest/CountryPojo.java | 40 ++++
.../sparkrest/RestCamelSparkPojoInOutTest.java | 52 +++++
.../camel/component/sparkrest/UserPojo.java | 40 ++++
.../camel/component/sparkrest/UserService.java | 33 +++
.../component/splunk/SplunkConfiguration.java | 26 +++
.../camel/component/splunk/SplunkConsumer.java | 39 +++-
.../splunk/support/SplunkDataReader.java | 41 ++--
.../splunk/support/SplunkResultProcessor.java | 26 +++
.../component/splunk/ConsumerStreamingTest.java | 68 +++++++
.../component/rest/SpringFromRestGetTest.xml | 2 +-
.../rest/DummyRestConsumerFactory.java | 4 +-
.../rest/FromRestGetEmbeddedRouteTest.java | 4 +-
.../component/rest/FromRestGetTest.java | 1 -
.../component/rest/FromRestGetTest.xml | 2 +-
.../component/xmlsecurity/SantuarioUtil.java | 83 --------
.../xmlsecurity/processor/SantuarioUtil.java | 83 ++++++++
.../processor/XmlSignatureProcessor.java | 2 -
.../zookeeper/ZooKeeperConfiguration.java | 4 +-
components/pom.xml | 1 +
examples/camel-example-restlet-jdbc/pom.xml | 8 +-
.../README.txt | 36 ++++
.../camel-example-servlet-rest-tomcat/pom.xml | 84 ++++++++
.../org/apache/camel/example/rest/User.java | 47 +++++
.../camel/example/rest/UserRouteBuilder.java | 49 +++++
.../apache/camel/example/rest/UserService.java | 64 ++++++
.../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++++++++++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../src/main/resources/camel-config-xml.xml | 59 ++++++
.../src/main/resources/camel-config.xml | 36 ++++
.../src/main/resources/log4j.properties | 28 +++
.../src/main/webapp/WEB-INF/web.xml | 55 +++++
.../src/main/webapp/index.html | 72 +++++++
.../camel-example-spark-rest-tomcat/README.txt | 7 +
.../camel-example-spark-rest-tomcat/pom.xml | 6 +
.../example/spark/MySparkRouteBuilder.java | 48 -----
.../org/apache/camel/example/spark/User.java | 47 +++++
.../camel/example/spark/UserRouteBuilder.java | 49 +++++
.../apache/camel/example/spark/UserService.java | 64 ++++++
.../src/main/resources/camel-config.xml | 10 +-
.../src/main/webapp/index.html | 36 ++--
examples/pom.xml | 1 +
parent/pom.xml | 17 +-
tests/camel-itest-osgi/pom.xml | 5 +
.../OSGiBlueprintQuarz2SchedulerTest.java | 86 ++++++++
.../camel/itest/osgi/blueprint/blueprint-28.xml | 28 +++
184 files changed, 6387 insertions(+), 505 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/85cc550f/components/pom.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/85cc550f/parent/pom.xml
----------------------------------------------------------------------
[28/34] CAMEL-7554: Renamed package to include component which is the
way we do in Camel.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterRouteTest.java
new file mode 100644
index 0000000..86076e7
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterRouteTest.java
@@ -0,0 +1,165 @@
+/**
+ * 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.meter;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
+import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METER_MARK;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.component.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(CamelSpringJUnit4ClassRunner.class)
+@ContextConfiguration(
+ classes = { MeterRouteTest.TestConfig.class },
+ loader = CamelSpringDelegatingTestContextLoader.class)
+@MockEndpoints
+public class MeterRouteTest {
+
+ @EndpointInject(uri = "mock:out")
+ private MockEndpoint endpoint;
+
+ @Produce(uri = "direct:in-1")
+ private ProducerTemplate producer1;
+
+ @Produce(uri = "direct:in-2")
+ private ProducerTemplate producer2;
+
+ private MetricRegistry mockRegistry;
+
+ private Meter mockMeter;
+
+ private InOrder inOrder;
+
+ @Configuration
+ public static class TestConfig extends SingleRouteCamelConfiguration {
+
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:in-1")
+ .to("metrics:meter:A?mark=3179")
+ .to("mock:out");
+
+ from("direct:in-2")
+ .to("metrics:meter:A")
+ .to("mock:out");
+ }
+ };
+ }
+
+ @Bean(name = METRIC_REGISTRY_NAME)
+ public MetricRegistry getMetricRegistry() {
+ return Mockito.mock(MetricRegistry.class);
+ }
+ }
+
+ @Before
+ public void setup() {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
+ mockMeter = Mockito.mock(Meter.class);
+ inOrder = Mockito.inOrder(mockRegistry, mockMeter);
+ when(mockRegistry.meter("A")).thenReturn(mockMeter);
+ }
+
+ @After
+ public void tearDown() {
+ endpoint.reset();
+ reset(mockRegistry, mockMeter);
+ }
+
+ @Test
+ public void testValueSetInUri() throws Exception {
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer1.sendBody(body);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).meter("A");
+ inOrder.verify(mockMeter, times(1)).mark(3179L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testValueNoSetInUri() throws Exception {
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer2.sendBody(body);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).meter("A");
+ inOrder.verify(mockMeter, times(1)).mark();
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideMetricsName() throws Exception {
+ when(mockRegistry.meter("B")).thenReturn(mockMeter);
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer1.sendBodyAndHeader(body, HEADER_METRIC_NAME, "B");
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).meter("B");
+ inOrder.verify(mockMeter, times(1)).mark(3179L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideValueWithHeader() throws Exception {
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer1.sendBodyAndHeader(body, HEADER_METER_MARK, 9926L);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).meter("A");
+ inOrder.verify(mockMeter, times(1)).mark(9926L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testValueNoSetInUriOverrideWithHeader() throws Exception {
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer2.sendBodyAndHeader(body, HEADER_METER_MARK, 7707370L);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).meter("A");
+ inOrder.verify(mockMeter, times(1)).mark(7707370L);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerEndpointTest.java
new file mode 100644
index 0000000..5bc1138
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerEndpointTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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.timer;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Producer;
+import org.apache.camel.component.metrics.timer.TimerEndpoint.TimerAction;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TimerEndpointTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+
+ @Mock
+ private MetricRegistry registry;
+
+ private TimerEndpoint endpoint;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ endpoint = new TimerEndpoint(registry, METRICS_NAME);
+ inOrder = Mockito.inOrder(registry);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testTimerEndpoint() throws Exception {
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint.getRegistry(), is(registry));
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ }
+
+ @Test
+ public void testCreateProducer() throws Exception {
+ Producer producer = endpoint.createProducer();
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer, is(instanceOf(TimerProducer.class)));
+ }
+
+ @Test
+ public void testGetAction() throws Exception {
+ assertThat(endpoint.getAction(), is(nullValue()));
+ }
+
+ @Test
+ public void testSetAction() throws Exception {
+ assertThat(endpoint.getAction(), is(nullValue()));
+ endpoint.setAction(TimerAction.start);
+ assertThat(endpoint.getAction(), is(TimerAction.start));
+ }
+
+ @Test
+ public void testCreateEndpointUri() throws Exception {
+ assertThat(endpoint.createEndpointUri(), is(TimerEndpoint.ENDPOINT_URI));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerProducerTest.java
new file mode 100644
index 0000000..df94fef
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerProducerTest.java
@@ -0,0 +1,229 @@
+/**
+ * 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.timer;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.metrics.timer.TimerEndpoint.TimerAction;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_TIMER_ACTION;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TimerProducerTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final String PROPERTY_NAME = TimerEndpoint.ENDPOINT_URI + ":" + METRICS_NAME;
+
+ @Mock
+ private TimerEndpoint endpoint;
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private MetricRegistry registry;
+
+ @Mock
+ private Timer timer;
+
+ @Mock
+ private Timer.Context context;
+
+ @Mock
+ private Message in;
+
+ private TimerProducer producer;
+
+ @Mock
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ producer = new TimerProducer(endpoint);
+ inOrder = Mockito.inOrder(endpoint, exchange, registry, timer, context, in);
+ when(endpoint.getRegistry()).thenReturn(registry);
+ when(registry.timer(METRICS_NAME)).thenReturn(timer);
+ when(timer.time()).thenReturn(context);
+ when(exchange.getIn()).thenReturn(in);
+ }
+
+ @Test
+ public void testTimerProducer() throws Exception {
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer.getEndpoint().equals(endpoint), is(true));
+ }
+
+ @Test
+ public void testProcessStart() throws Exception {
+ when(endpoint.getAction()).thenReturn(TimerAction.start);
+ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class)).thenReturn(TimerAction.start);
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
+ inOrder.verify(timer, times(1)).time();
+ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessStartWithOverride() throws Exception {
+ when(endpoint.getAction()).thenReturn(TimerAction.start);
+ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class)).thenReturn(TimerAction.stop);
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(context, times(1)).stop();
+ inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessStop() throws Exception {
+ when(endpoint.getAction()).thenReturn(TimerAction.stop);
+ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class)).thenReturn(TimerAction.stop);
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(context, times(1)).stop();
+ inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessStopWithOverride() throws Exception {
+ when(endpoint.getAction()).thenReturn(TimerAction.stop);
+ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class)).thenReturn(TimerAction.start);
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
+ inOrder.verify(timer, times(1)).time();
+ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessNoAction() throws Exception {
+ when(endpoint.getAction()).thenReturn(null);
+ when(in.getHeader(HEADER_TIMER_ACTION, null, TimerAction.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, null, TimerAction.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessNoActionOverride() throws Exception {
+ when(endpoint.getAction()).thenReturn(null);
+ when(in.getHeader(HEADER_TIMER_ACTION, null, TimerAction.class)).thenReturn(TimerAction.start);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, null, TimerAction.class);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
+ inOrder.verify(timer, times(1)).time();
+ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testHandleStart() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
+ producer.handleStart(exchange, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
+ inOrder.verify(timer, times(1)).time();
+ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testHandleStartAlreadyRunning() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
+ producer.handleStart(exchange, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testHandleStop() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
+ producer.handleStop(exchange, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(context, times(1)).stop();
+ inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testHandleStopContextNotFound() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
+ producer.handleStop(exchange, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetPropertyName() throws Exception {
+ assertThat(producer.getPropertyName(METRICS_NAME), is(TimerEndpoint.ENDPOINT_URI + ":" + METRICS_NAME));
+ }
+
+ @Test
+ public void testGetTimerContextFromExchange() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
+ assertThat(producer.getTimerContextFromExchange(exchange, PROPERTY_NAME), is(context));
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetTimerContextFromExchangeNotFound() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
+ assertThat(producer.getTimerContextFromExchange(exchange, PROPERTY_NAME), is(nullValue()));
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerRouteTest.java
new file mode 100644
index 0000000..b6941b5
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerRouteTest.java
@@ -0,0 +1,144 @@
+/**
+ * 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.timer;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.metrics.timer.TimerEndpoint.TimerAction;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
+import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_TIMER_ACTION;
+import static org.apache.camel.component.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(CamelSpringJUnit4ClassRunner.class)
+@ContextConfiguration(
+ classes = { TimerRouteTest.TestConfig.class },
+ loader = CamelSpringDelegatingTestContextLoader.class)
+@MockEndpoints
+public class TimerRouteTest {
+
+ @EndpointInject(uri = "mock:out")
+ private MockEndpoint endpoint;
+
+ @Produce(uri = "direct:in-1")
+ private ProducerTemplate producer1;
+
+ @Produce(uri = "direct:in-2")
+ private ProducerTemplate producer2;
+
+ private MetricRegistry mockRegistry;
+
+ private Timer mockTimer;
+
+ private InOrder inOrder;
+
+ @Configuration
+ public static class TestConfig extends SingleRouteCamelConfiguration {
+
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:in-1")
+ .to("metrics:timer:A?action=start")
+ .to("mock:out");
+
+ from("direct:in-2")
+ .to("metrics:timer:A")
+ .to("mock:out");
+ }
+ };
+ }
+
+ @Bean(name = METRIC_REGISTRY_NAME)
+ public MetricRegistry getMetricRegistry() {
+ return Mockito.mock(MetricRegistry.class);
+ }
+ }
+
+ @Before
+ public void setup() {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
+ mockTimer = Mockito.mock(Timer.class);
+ inOrder = Mockito.inOrder(mockRegistry, mockTimer);
+ }
+
+ @After
+ public void tearDown() {
+ endpoint.reset();
+ reset(mockRegistry, mockTimer);
+ }
+
+ @Test
+ public void testOverrideMetricsName() throws Exception {
+ when(mockRegistry.timer("B")).thenReturn(mockTimer);
+
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer1.sendBodyAndHeader(body, HEADER_METRIC_NAME, "B");
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).timer("B");
+ inOrder.verify(mockTimer, times(1)).time();
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideExistingAction() throws Exception {
+ when(mockRegistry.timer("A")).thenReturn(mockTimer);
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer1.sendBodyAndHeader(body, HEADER_TIMER_ACTION, TimerAction.stop);
+ endpoint.assertIsSatisfied();
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideNoAction() throws Exception {
+ when(mockRegistry.timer("A")).thenReturn(mockTimer);
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer2.sendBodyAndHeader(body, HEADER_TIMER_ACTION, TimerAction.start);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).timer("A");
+ inOrder.verify(mockTimer, times(1)).time();
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
deleted file mode 100644
index a4e1218..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * 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.metrics;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.Producer;
-import org.apache.camel.RuntimeCamelException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class AbstractMetricsEndpointTest {
-
- private static final String METRICS_NAME = "metrics.name";
-
- @Mock
- private MetricRegistry registry;
-
- @Mock
- private Processor processor;
-
- @Mock
- private Exchange exchange;
-
- @Mock
- private Message in;
-
- private AbstractMetricsEndpoint endpoint;
-
- private InOrder inOrder;
-
- @Before
- public void setUp() throws Exception {
- endpoint = new AbstractMetricsEndpoint(registry, METRICS_NAME) {
- @Override
- public Producer createProducer() throws Exception {
- return null;
- }
-
- @Override
- protected String createEndpointUri() {
- return "not real endpoint";
- }
- };
- inOrder = Mockito.inOrder(registry, processor, exchange, in);
- when(exchange.getIn()).thenReturn(in);
- }
-
- @After
- public void tearDown() throws Exception {
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testAbstractMetricsEndpoint() throws Exception {
- assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
- assertThat(endpoint.getRegistry(), is(registry));
- }
-
- @Test(expected = RuntimeCamelException.class)
- public void testCreateConsumer() throws Exception {
- endpoint.createConsumer(processor);
- }
-
- @Test
- public void testIsSingleton() throws Exception {
- assertThat(endpoint.isSingleton(), is(false));
- }
-
- @Test
- public void testGetRegistry() throws Exception {
- assertThat(endpoint.getRegistry(), is(registry));
- }
-
- @Test
- public void testGetMetricsName() throws Exception {
- assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
deleted file mode 100644
index b740634..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/**
- * 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.metrics;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.impl.DefaultMessage;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import static org.apache.camel.metrics.AbstractMetricsProducer.HEADER_PATTERN;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class AbstractMetricsProducerTest {
-
- public static final String METRIC_NAME = "a metric";
-
- @Mock
- private AbstractMetricsEndpoint endpoint;
-
- @Mock
- private Exchange exchange;
-
- @Mock
- private Message in;
-
- @Mock
- private MetricRegistry registry;
-
- private AbstractMetricsProducer<AbstractMetricsEndpoint> okProducer;
-
- private AbstractMetricsProducer<AbstractMetricsEndpoint> failProducer;
-
- private InOrder inOrder;
-
- @Before
- public void setUp() throws Exception {
- okProducer = new AbstractMetricsProducer<AbstractMetricsEndpoint>(endpoint) {
- @Override
- protected void doProcess(Exchange exchange, AbstractMetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
- }
- };
- failProducer = new AbstractMetricsProducer<AbstractMetricsEndpoint>(endpoint) {
-
- @Override
- protected void doProcess(Exchange exchange, AbstractMetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
- throw new Exception("Muchos problemos");
- }
- };
- inOrder = Mockito.inOrder(endpoint, exchange, in, registry);
- when(exchange.getIn()).thenReturn(in);
- when(endpoint.getMetricsName()).thenReturn(METRIC_NAME);
- when(endpoint.getRegistry()).thenReturn(registry);
- }
-
- @Test
- public void testDoProcess() throws Exception {
- when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
- when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
- okProducer.process(exchange);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(endpoint, times(1)).getMetricsName();
- inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testDoProcessWithException() throws Exception {
- when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
- when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
- failProducer.process(exchange);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(endpoint, times(1)).getMetricsName();
- inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetMetricsName() throws Exception {
- when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("A");
- assertThat(okProducer.getMetricsName(in, "value"), is("A"));
- inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetMetricsNameNotSet() throws Exception {
- when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
- assertThat(okProducer.getMetricsName(in, "name"), is("name"));
- inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetStringHeader() throws Exception {
- when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("A");
- assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("A"));
- inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetStringHeaderWithNullValue() throws Exception {
- when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
- assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
- inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetStringHeaderWithWhiteSpaces() throws Exception {
- when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(" ");
- assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
- inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetStringHeaderWithEmptySrting() throws Exception {
- when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("");
- assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
- inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetLongHeader() throws Exception {
- when(in.getHeader(HEADER_HISTOGRAM_VALUE, 19L, Long.class)).thenReturn(201L);
- assertThat(okProducer.getLongHeader(in, HEADER_HISTOGRAM_VALUE, 19L), is(201L));
- inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, 19L, Long.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testClearMetricsHeaders() throws Exception {
- when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
- assertThat(okProducer.clearMetricsHeaders(in), is(true));
- inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testClearRealHeaders() throws Exception {
- Message msg = new DefaultMessage();
- Object val = new Object();
- msg.setHeader(HEADER_HISTOGRAM_VALUE, 109L);
- msg.setHeader(HEADER_METRIC_NAME, "the metric");
- msg.setHeader("notRemoved", val);
- assertThat(msg.getHeaders().size(), is(3));
- assertThat(msg.getHeader(HEADER_HISTOGRAM_VALUE, Long.class), is(109L));
- assertThat(msg.getHeader(HEADER_METRIC_NAME, String.class), is("the metric"));
- assertThat(msg.getHeader("notRemoved"), is(val));
- okProducer.clearMetricsHeaders(msg);
- assertThat(msg.getHeaders().size(), is(1));
- assertThat(msg.getHeader("notRemoved"), is(val));
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
deleted file mode 100644
index 417cab6..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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.metrics;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.EndpointInject;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
-import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
-import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
-import org.apache.camel.test.spring.MockEndpoints;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mockito;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.context.ContextConfiguration;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-@RunWith(CamelSpringJUnit4ClassRunner.class)
-@ContextConfiguration(
- classes = { MetricComponentSpringTest.TestConfig.class },
- loader = CamelSpringDelegatingTestContextLoader.class)
-@MockEndpoints
-public class MetricComponentSpringTest {
-
- @EndpointInject(uri = "mock:out")
- private MockEndpoint endpoint;
-
- @Produce(uri = "direct:in")
- private ProducerTemplate producer;
-
- @Configuration
- public static class TestConfig extends SingleRouteCamelConfiguration {
-
- @Bean
- @Override
- public RouteBuilder route() {
- return new RouteBuilder() {
-
- @Override
- public void configure() throws Exception {
- from("direct:in")
- .to("metrics:counter:A?increment=512")
- .to("mock:out");
- }
- };
- }
-
- @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
- public MetricRegistry getMetricRegistry() {
- return Mockito.mock(MetricRegistry.class);
- }
- }
-
- @Test
- public void testMetricsRegistryFromCamelRegistry() throws Exception {
- // TODO - 12.05.2014, Lauri - is there any better way to set this up?
- MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
- Counter mockCounter = Mockito.mock(Counter.class);
- InOrder inOrder = Mockito.inOrder(mockRegistry, mockCounter);
- when(mockRegistry.counter("A")).thenReturn(mockCounter);
-
- endpoint.expectedMessageCount(1);
- producer.sendBody(new Object());
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).counter("A");
- inOrder.verify(mockCounter, times(1)).inc(512L);
- inOrder.verifyNoMoreInteractions();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
deleted file mode 100644
index 09270c1..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * 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.metrics;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_PERFIX;
-
-public class MetricsComponentRouteTest extends CamelTestSupport {
-
- @Produce(uri = "direct:start-1")
- protected ProducerTemplate template1;
-
- @Produce(uri = "direct:start-2")
- protected ProducerTemplate template2;
-
- @Test
- public void testMetrics() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMinimumMessageCount(1);
- template1.sendBody(new Object());
- assertMockEndpointsSatisfied();
- }
-
- @Test
- public void testMessageContentDelivery() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- String body = "Message Body";
- String header1 = "Header 1";
- String header2 = "Header 2";
- Object value1 = new Date();
- Object value2 = System.currentTimeMillis();
- mock.expectedBodiesReceived(body);
- mock.expectedHeaderReceived(header1, value1);
- mock.expectedHeaderReceived(header2, value2);
- Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(header1, value1);
- headers.put(header2, value2);
- template1.sendBodyAndHeaders(body, headers);
- assertMockEndpointsSatisfied();
- }
-
- @Test
- public void testHeaderRemoval() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- Object body = new Object();
- Date now = new Date();
-
- mock.expectedBodiesReceived(body);
- mock.expectedHeaderReceived("." + HEADER_PERFIX, "value");
- mock.expectedHeaderReceived("date", now);
-
- Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(HEADER_METRIC_NAME, "a name");
- headers.put(HEADER_HISTOGRAM_VALUE, 34L);
- headers.put(HEADER_PERFIX + "notExistingHeader", "?");
- headers.put("." + HEADER_PERFIX, "value");
- headers.put("date", now);
-
- template2.sendBodyAndHeaders(body, headers);
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() {
- from("direct:start-1")
- .to("metrics:timer:T?action=start")
- .to("metrics:A")
- .to("metrics:counter://B")
- .to("metrics:counter:C?increment=19291")
- .to("metrics:counter:C?decrement=19292")
- .to("metrics:counter:C")
- .to("metrics:meter:D")
- .to("metrics:meter:D?mark=90001")
- .to("metrics:histogram:E")
- .to("metrics:timer:T")
- .to("metrics:histogram:E?value=12000000031")
- .to("metrics:timer:T?action=stop")
- .to("mock:result");
-
- from("direct:start-2")
- .to("metrics:meter:F?mark=88")
- .to("mock:result");
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
deleted file mode 100644
index 8fd02ce..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/**
- * 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.metrics;
-
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.Map;
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.CamelContext;
-import org.apache.camel.Endpoint;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.metrics.counter.CounterEndpoint;
-import org.apache.camel.metrics.histogram.HistogramEndpoint;
-import org.apache.camel.metrics.meter.MeterEndpoint;
-import org.apache.camel.metrics.timer.TimerEndpoint;
-import org.apache.camel.spi.Registry;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class MetricsComponentTest {
-
- @Mock
- private CamelContext camelContext;
-
- @Mock
- private Registry camelRegistry;
-
- @Mock
- private MetricRegistry metricRegistry;
-
- private InOrder inOrder;
-
- private MetricsComponent component;
-
- @Before
- public void setUp() throws Exception {
- component = new MetricsComponent();
- inOrder = Mockito.inOrder(camelContext, camelRegistry, metricRegistry);
-
- }
-
- @Test
- public void testCreateEndpoint() throws Exception {
- component.setCamelContext(camelContext);
- when(camelContext.getRegistry()).thenReturn(camelRegistry);
- when(camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class)).thenReturn(metricRegistry);
- Map<String, Object> params = new HashMap<String, Object>();
- Long value = System.currentTimeMillis();
- params.put("mark", value);
- Endpoint result = component.createEndpoint("metrics:meter:long.meter", "meter:long.meter", params);
- assertThat(result, is(notNullValue()));
- assertThat(result, is(instanceOf(MeterEndpoint.class)));
- MeterEndpoint me = (MeterEndpoint) result;
- assertThat(me.getMark(), is(value));
- assertThat(me.getMetricsName(), is("long.meter"));
- assertThat(me.getRegistry(), is(metricRegistry));
- inOrder.verify(camelContext, times(1)).getRegistry();
- inOrder.verify(camelRegistry, times(1)).lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
- inOrder.verify(camelContext, times(1)).getTypeConverter();
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testCreateEndpoints() throws Exception {
- component.setCamelContext(camelContext);
- when(camelContext.getRegistry()).thenReturn(camelRegistry);
- when(camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class)).thenReturn(metricRegistry);
- Map<String, Object> params = new HashMap<String, Object>();
- Long value = System.currentTimeMillis();
- params.put("mark", value);
- Endpoint result = component.createEndpoint("metrics:meter:long.meter", "meter:long.meter", params);
- assertThat(result, is(notNullValue()));
- assertThat(result, is(instanceOf(MeterEndpoint.class)));
- MeterEndpoint me = (MeterEndpoint) result;
- assertThat(me.getMark(), is(value));
- assertThat(me.getMetricsName(), is("long.meter"));
- assertThat(me.getRegistry(), is(metricRegistry));
-
- params = new HashMap<String, Object>();
- params.put("increment", value + 1);
- params.put("decrement", value - 1);
-
- result = component.createEndpoint("metrics:counter:long.counter", "counter:long.counter", params);
- assertThat(result, is(notNullValue()));
- assertThat(result, is(instanceOf(CounterEndpoint.class)));
- CounterEndpoint ce = (CounterEndpoint) result;
- assertThat(ce.getIncrement(), is(value + 1));
- assertThat(ce.getDecrement(), is(value - 1));
- assertThat(ce.getMetricsName(), is("long.counter"));
- assertThat(ce.getRegistry(), is(metricRegistry));
-
- inOrder.verify(camelContext, times(1)).getRegistry();
- inOrder.verify(camelRegistry, times(1)).lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
- inOrder.verify(camelContext, times(2)).getTypeConverter();
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetMetricsName() throws Exception {
- assertThat(component.getMetricsName("meter:metric-a"), is("metric-a"));
- assertThat(component.getMetricsName("meter:metric-a:sub-b"), is("metric-a:sub-b"));
- assertThat(component.getMetricsName("metric-a"), is("metric-a"));
- assertThat(component.getMetricsName("//metric-a"), is("//metric-a"));
- assertThat(component.getMetricsName("meter://metric-a"), is("//metric-a"));
- }
-
- @Test
- public void testCreateNewEndpointForCounter() throws Exception {
- Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.COUNTER, "a name");
- assertThat(endpoint, is(notNullValue()));
- assertThat(endpoint, is(instanceOf(CounterEndpoint.class)));
- }
-
- @Test
- public void testCreateNewEndpointForMeter() throws Exception {
- Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.METER, "a name");
- assertThat(endpoint, is(notNullValue()));
- assertThat(endpoint, is(instanceOf(MeterEndpoint.class)));
- }
-
- @Test(expected = RuntimeCamelException.class)
- public void testCreateNewEndpointForGauge() throws Exception {
- component.createNewEndpoint(metricRegistry, MetricsType.GAUGE, "a name");
- }
-
- @Test
- public void testCreateNewEndpointForHistogram() throws Exception {
- Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.HISTOGRAM, "a name");
- assertThat(endpoint, is(notNullValue()));
- assertThat(endpoint, is(instanceOf(HistogramEndpoint.class)));
- }
-
- @Test
- public void testCreateNewEndpointForTimer() throws Exception {
- Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.TIMER, "a name");
- assertThat(endpoint, is(notNullValue()));
- assertThat(endpoint, is(instanceOf(TimerEndpoint.class)));
- }
-
- @Test
- public void testGetMetricsType() throws Exception {
- for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
- assertThat(component.getMetricsType(type.toString() + ":metrics-name"), is(type));
- }
- }
-
- @Test
- public void testGetMetricsTypeNotSet() throws Exception {
- assertThat(component.getMetricsType("no-metrics-type"), is(MetricsComponent.DEFAULT_METRICS_TYPE));
- }
-
- @Test(expected = RuntimeCamelException.class)
- public void testGetMetricsTypeNotFound() throws Exception {
- component.getMetricsType("unknown-metrics:metrics-name");
- }
-
- @Test
- public void testGetOrCreateMetricRegistryFoundInCamelRegistry() throws Exception {
- when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(metricRegistry);
- MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
- assertThat(result, is(metricRegistry));
- inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetOrCreateMetricRegistryNotFoundInCamelRegistry() throws Exception {
- when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(null);
- MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
- assertThat(result, is(notNullValue()));
- assertThat(result, is(not(metricRegistry)));
- inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetMetricRegistryFromCamelRegistry() throws Exception {
- when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(metricRegistry);
- MetricRegistry result = component.getMetricRegistryFromCamelRegistry(camelRegistry, "name");
- assertThat(result, is(metricRegistry));
- inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testCreateMetricRegistry() throws Exception {
- MetricRegistry registry = component.createMetricRegistry();
- assertThat(registry, is(notNullValue()));
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
deleted file mode 100644
index 9a3129a..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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.metrics;
-
-import java.util.EnumSet;
-import org.junit.Test;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public class MetricsTypeTest {
-
- @Test
- public void testGetByName() throws Exception {
- for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
- MetricsType t = MetricsType.getByName(type.toString());
- assertThat(t, is(type));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
deleted file mode 100644
index 0d5c015..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * 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.metrics.counter;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Producer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-
-@RunWith(MockitoJUnitRunner.class)
-public class CounterEndpointTest {
-
- private static final String METRICS_NAME = "metrics.name";
- private static final Long VALUE = System.currentTimeMillis();
-
- @Mock
- private MetricRegistry registry;
-
- private CounterEndpoint endpoint;
-
- private InOrder inOrder;
-
- @Before
- public void setUp() throws Exception {
- endpoint = new CounterEndpoint(registry, METRICS_NAME);
- inOrder = Mockito.inOrder(registry);
- }
-
- @After
- public void tearDown() {
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testCounterEndpoint() throws Exception {
- assertThat(endpoint.getRegistry(), is(registry));
- assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
- assertThat(endpoint.getIncrement(), is(nullValue()));
- assertThat(endpoint.getDecrement(), is(nullValue()));
- }
-
- @Test
- public void testCreateProducer() throws Exception {
- Producer producer = endpoint.createProducer();
- assertThat(producer, is(notNullValue()));
- assertThat(producer, is(instanceOf(CounterProducer.class)));
- }
-
- @Test
- public void testGetIncrement() throws Exception {
- assertThat(endpoint.getIncrement(), is(nullValue()));
- }
-
- @Test
- public void testSetIncrement() throws Exception {
- assertThat(endpoint.getIncrement(), is(nullValue()));
- endpoint.setIncrement(VALUE);
- assertThat(endpoint.getIncrement(), is(VALUE));
- }
-
- @Test
- public void testGetDecrement() throws Exception {
- assertThat(endpoint.getDecrement(), is(nullValue()));
- }
-
- @Test
- public void testSetDecrement() throws Exception {
- assertThat(endpoint.getDecrement(), is(nullValue()));
- endpoint.setDecrement(VALUE);
- assertThat(endpoint.getDecrement(), is(VALUE));
- }
-
- @Test
- public void testCreateEndpointUri() throws Exception {
- assertThat(endpoint.createEndpointUri(), is(CounterEndpoint.ENDPOINT_URI));
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
deleted file mode 100644
index e33429d..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/**
- * 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.metrics.counter;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class CounterProducerTest {
-
- private static final String METRICS_NAME = "metrics.name";
- private static final Long INCREMENT = 100000L;
- private static final Long DECREMENT = 91929199L;
-
- @Mock
- private CounterEndpoint endpoint;
-
- @Mock
- private Exchange exchange;
-
- @Mock
- private MetricRegistry registry;
-
- @Mock
- private Counter counter;
-
- @Mock
- private Message in;
-
- private CounterProducer producer;
-
- private InOrder inOrder;
-
- @Before
- public void setUp() throws Exception {
- producer = new CounterProducer(endpoint);
- inOrder = Mockito.inOrder(endpoint, exchange, registry, counter, in);
- when(endpoint.getRegistry()).thenReturn(registry);
- when(registry.counter(METRICS_NAME)).thenReturn(counter);
- when(exchange.getIn()).thenReturn(in);
- }
-
- @Test
- public void testCounterProducer() throws Exception {
- assertThat(producer.getEndpoint().equals(endpoint), is(true));
- }
-
- @Test
- public void testProcessWithIncrementOnly() throws Exception {
- when(endpoint.getIncrement()).thenReturn(INCREMENT);
- when(endpoint.getDecrement()).thenReturn(null);
- when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT);
- when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(null);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).counter(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getIncrement();
- inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
- inOrder.verify(counter, times(1)).inc(INCREMENT);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessWithDecrementOnly() throws Exception {
- when(endpoint.getIncrement()).thenReturn(null);
- when(endpoint.getDecrement()).thenReturn(DECREMENT);
- when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
- when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).counter(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getIncrement();
- inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
- inOrder.verify(counter, times(1)).dec(DECREMENT);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testDoProcessWithIncrementAndDecrement() throws Exception {
- when(endpoint.getIncrement()).thenReturn(INCREMENT);
- when(endpoint.getDecrement()).thenReturn(DECREMENT);
- when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT);
- when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).counter(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getIncrement();
- inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
- inOrder.verify(counter, times(1)).inc(INCREMENT);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessWithOutIncrementAndDecrement() throws Exception {
- when(endpoint.getIncrement()).thenReturn(null);
- when(endpoint.getDecrement()).thenReturn(null);
- when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
- when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(null);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).counter(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getIncrement();
- inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
- inOrder.verify(counter, times(1)).inc();
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessWithHeaderValuesOnly() throws Exception {
- when(endpoint.getIncrement()).thenReturn(null);
- when(endpoint.getDecrement()).thenReturn(null);
- when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(INCREMENT + 1);
- when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(DECREMENT - 1);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).counter(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getIncrement();
- inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
- inOrder.verify(counter, times(1)).inc(INCREMENT + 1);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessOverridingIncrement() throws Exception {
- when(endpoint.getIncrement()).thenReturn(INCREMENT);
- when(endpoint.getDecrement()).thenReturn(DECREMENT);
- when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT + 1);
- when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).counter(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getIncrement();
- inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
- inOrder.verify(counter, times(1)).inc(INCREMENT + 1);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessOverridingDecrement() throws Exception {
- when(endpoint.getIncrement()).thenReturn(null);
- when(endpoint.getDecrement()).thenReturn(DECREMENT);
- when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
- when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT - 1);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).counter(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getIncrement();
- inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
- inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
- inOrder.verify(counter, times(1)).dec(DECREMENT - 1);
- inOrder.verifyNoMoreInteractions();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
deleted file mode 100644
index 246f11e..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/**
- * 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.metrics.counter;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.EndpointInject;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
-import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
-import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
-import org.apache.camel.test.spring.MockEndpoints;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mockito;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.context.ContextConfiguration;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-@RunWith(CamelSpringJUnit4ClassRunner.class)
-@ContextConfiguration(
- classes = { CounterRouteTest.TestConfig.class },
- loader = CamelSpringDelegatingTestContextLoader.class)
-@MockEndpoints
-public class CounterRouteTest {
-
- @EndpointInject(uri = "mock:out")
- private MockEndpoint endpoint;
-
- @Produce(uri = "direct:in-1")
- private ProducerTemplate producer1;
-
- @Produce(uri = "direct:in-2")
- private ProducerTemplate producer2;
-
- @Produce(uri = "direct:in-3")
- private ProducerTemplate producer3;
-
- @Produce(uri = "direct:in-4")
- private ProducerTemplate producer4;
-
- private MetricRegistry mockRegistry;
-
- private Counter mockCounter;
-
- private InOrder inOrder;
-
- @Configuration
- public static class TestConfig extends SingleRouteCamelConfiguration {
-
- @Bean
- @Override
- public RouteBuilder route() {
- return new RouteBuilder() {
-
- @Override
- public void configure() throws Exception {
- from("direct:in-1")
- .to("metrics:counter:A?increment=5")
- .to("mock:out");
-
- from("direct:in-2")
- .to("metrics:counter:A?decrement=9")
- .to("mock:out");
-
- from("direct:in-3")
- .setHeader(HEADER_COUNTER_INCREMENT, constant(417L))
- .to("metrics:counter:A")
- .to("mock:out");
-
- from("direct:in-4")
- .setHeader(HEADER_COUNTER_INCREMENT, simple("${body.length}"))
- .to("metrics:counter:A")
- .to("mock:out");
- }
- };
- }
-
- @Bean(name = METRIC_REGISTRY_NAME)
- public MetricRegistry getMetricRegistry() {
- return Mockito.mock(MetricRegistry.class);
- }
- }
-
- @Before
- public void setup() {
- // TODO - 12.05.2014, Lauri - is there any better way to set this up?
- mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
- mockCounter = mock(Counter.class);
- inOrder = Mockito.inOrder(mockRegistry, mockCounter);
- }
-
- @After
- public void tearDown() {
- endpoint.reset();
- reset(mockRegistry, mockCounter);
- }
-
- @Test
- public void testOverrideMetricsName() throws Exception {
- when(mockRegistry.counter("B")).thenReturn(mockCounter);
- endpoint.expectedMessageCount(1);
- producer1.sendBodyAndHeader(new Object(), HEADER_METRIC_NAME, "B");
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).counter("B");
- inOrder.verify(mockCounter, times(1)).inc(5L);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testOverrideIncrement() throws Exception {
- when(mockRegistry.counter("A")).thenReturn(mockCounter);
- endpoint.expectedMessageCount(1);
- producer1.sendBodyAndHeader(new Object(), HEADER_COUNTER_INCREMENT, 14L);
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).counter("A");
- inOrder.verify(mockCounter, times(1)).inc(14L);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testOverrideIncrementAndDecrement() throws Exception {
- when(mockRegistry.counter("A")).thenReturn(mockCounter);
- endpoint.expectedMessageCount(1);
- Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(HEADER_COUNTER_INCREMENT, 912L);
- headers.put(HEADER_COUNTER_DECREMENT, 43219L);
- producer1.sendBodyAndHeaders(new Object(), headers);
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).counter("A");
- inOrder.verify(mockCounter, times(1)).inc(912L);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testOverrideDecrement() throws Exception {
- when(mockRegistry.counter("A")).thenReturn(mockCounter);
- endpoint.expectedMessageCount(1);
- producer2.sendBodyAndHeader(new Object(), HEADER_COUNTER_DECREMENT, 7L);
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).counter("A");
- inOrder.verify(mockCounter, times(1)).dec(7L);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testOverrideIncrementWithWrongType() throws Exception {
- when(mockRegistry.counter("A")).thenReturn(mockCounter);
- endpoint.expectedMessageCount(1);
- producer1.sendBodyAndHeader(new Object(), HEADER_COUNTER_INCREMENT, "this is not a valid long value");
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).counter("A");
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testOverrideUsingConstantValue() throws Exception {
- when(mockRegistry.counter("A")).thenReturn(mockCounter);
- endpoint.expectedMessageCount(1);
- producer3.sendBody(new Object());
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).counter("A");
- inOrder.verify(mockCounter, times(1)).inc(417L);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testOverrideUsingScriptEvaluation() throws Exception {
- when(mockRegistry.counter("A")).thenReturn(mockCounter);
- endpoint.expectedMessageCount(1);
- String message = "Hello from Camel Metrics!";
- producer4.sendBody(message);
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).counter("A");
- inOrder.verify(mockCounter, times(1)).inc(message.length());
- inOrder.verifyNoMoreInteractions();
- }
-}
[14/34] git commit: Added header to enable overriding meter mark in
the URI.
Posted by da...@apache.org.
Added header to enable overriding meter mark in the URI.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/10f5c7c4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/10f5c7c4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/10f5c7c4
Branch: refs/heads/master
Commit: 10f5c7c4ad0b47532ecb134001c7caea11815bdb
Parents: ddec990
Author: Lauri Kimmel <la...@gmx.com>
Authored: Sun Jun 1 17:31:46 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Mon Jun 16 21:04:22 2014 +1000
----------------------------------------------------------------------
README.md | 50 +++++++---
.../apache/camel/metrics/MetricsComponent.java | 1 +
.../camel/metrics/meter/MeterProducer.java | 9 +-
.../camel/metrics/meter/MeterProducerTest.java | 38 +++++++-
.../camel/metrics/meter/MeterRouteTest.java | 97 +++++++++++++++++---
5 files changed, 165 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/10f5c7c4/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 35f9f89..10a1e4c 100644
--- a/README.md
+++ b/README.md
@@ -26,8 +26,8 @@ metrics:[ meter | counter | histogram | timer ]:metricname[?options]
# Metric Registry
-If MetricRegistry instance for name ```metricRegistry``` is not found from Camel registry default one is used. Default MetricRegistry uses Slf4jReporter and 60 second reporting interval.
-MetricRegistry instance can be configured by adding bean with name ```metricRegistry``` to Camel registry. For example using Spring Java Configuration.
+If MetricRegistry instance for name `metricRegistry` is not found from Camel registry default one is used. Default MetricRegistry uses Slf4jReporter and 60 second reporting interval.
+MetricRegistry instance can be configured by adding bean with name `metricRegistry` to Camel registry. For example using Spring Java Configuration.
```java
@@ -57,11 +57,11 @@ MetricRegistry instance can be configured by adding bean with name ```metricRegi
# Usage
-Each metric has type and name. Supported types are ```counter```, ```meter```, ```histogram``` and ```timer```. Metric name is simple string. If metric type is not provided then type ```meter``` is used by default.
+Each metric has type and name. Supported types are `counter`, `meter`, `histogram` and `timer`. Metric name is simple string. If metric type is not provided then type `meter` is used by default.
### Headers
-Metric name defined in URI can be overridden by using Header with name ```CamelMetricsName```.
+Metric name defined in URI can be overridden by using header with name `CamelMetricsName`.
For example
@@ -72,10 +72,10 @@ from("direct:in")
.to("direct:out")
```
-will update counter with name ```new.name``` instead of ```name.not.used```.
+will update counter with name `new.name` instead of `name.not.used`.
All Metrics specific headers are removed from the message once Metrics endpoint finishes processing of exchange.
-While processing exchange Metrics endpoint will catch all exceptions and write log entry using level warn.
+While processing exchange Metrics endpoint will catch all exceptions and write log entry using level `warn`.
## Metrics type counter
@@ -91,7 +91,7 @@ Where options are
| increment | - | Long value to add to the counter |
| decrement | - | Long value to subtract from the counter |
-If neither ```increment``` or ```decrement``` is defined counter value will be incremented by one. If ```increment``` and ```decrement``` are both defined only increment operation is called.
+If neither `increment` or `decrement` is defined counter value will be incremented by one. If `increment` and `decrement` are both defined only increment operation is called.
```java
// update counter simple.counter by 7
@@ -116,6 +116,8 @@ from("direct:in")
### Headers
+Message headers can be used to override `increment` and `decrement` values specified in Metrics component URI.
+
| Name | Description | Expected type |
|------------------------------|---------------------------------|---------------|
| CamelMetricsCounterIncrement | Override increment value in URI | Long |
@@ -150,7 +152,7 @@ Where options are
|-------|---------|---------------------------|
| value | - | Value to use in histogram |
-If no ```value``` is not set nothing is added to histogram and warning is logged.
+If no `value` is not set nothing is added to histogram and warning is logged.
```java
// adds value 9923 to simple.histogram
@@ -168,9 +170,11 @@ from("direct:in")
### Headers
+Message header can be used to override `value` specified in Metrics component URI.
+
| Name | Description | Expected type |
|----------------------------|---------------------------------|---------------|
-| CamelMetricsHistogramValue | Override increment value in URI | Long |
+| CamelMetricsHistogramValue | Override histogram value in URI | Long |
```java
// adds value 992 to simple.histogram
@@ -193,7 +197,7 @@ Where options are
|------|---------|---------------------------|
| mark | - | Long value to use as mark |
-If ```mark``` is not set ```meter.mark()``` is called without argument.
+If `mark` is not set `meter.mark()` is called without argument.
```java
// marks simple.meter without value
@@ -209,6 +213,22 @@ from("direct:in")
.to("direct:out")
```
+### Headers
+
+Message header can be used to override `mark` value specified in Metrics component URI.
+
+| Name | Description | Expected type |
+|-----------------------|----------------------------|---------------|
+| CamelMetricsMeterMark | Override mark value in URI | Long |
+
+```java
+// updates meter simple.meter with value 345
+from("direct:in")
+ .setHeader(MetricsComponent.HEADER_METER_MARK, constant(345L))
+ .to("metric:meter:simple.meter?mark=123")
+ .to("direct:out")
+```
+
## Metrics type timer
@@ -218,11 +238,11 @@ metrics:timer:metricname[?options]
Where options are
-| Name | Default | Description |
-|--------|---------|---------------------------|
-| action | - | ```start``` or ```stop``` |
+| Name | Default | Description |
+|--------|---------|-------------------|
+| action | - | `start` or `stop` |
-If no ```action``` or invalid value is provided warning is logged and no timer is updated. If ```action``` ```start``` is called on already running timer or ```stop``` is called on not running timer nothing is updated and warning is logged.
+If no `action` or invalid value is provided warning is logged and no timer is updated. If `action` `start` is called on already running timer or `stop` is called on not running timer nothing is updated and warning is logged.
```java
// measure time taken by route calculate
@@ -232,4 +252,4 @@ from("direct:in")
.to("metrics:timer:simple.timer?action=stop");
```
-`Timer Context` objects are stored as `Exchange` properties.
+`Timer Context` objects are stored as `Exchange` properties between different Metrics component calls.
http://git-wip-us.apache.org/repos/asf/camel/blob/10f5c7c4/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index 1ff175d..ba04c23 100644
--- a/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -31,6 +31,7 @@ public class MetricsComponent extends DefaultComponent {
public static final String HEADER_COUNTER_INCREMENT = HEADER_PERFIX + "CounterIncrement";
public static final String HEADER_COUNTER_DECREMENT = HEADER_PERFIX + "CounterDecrement";
public static final String HEADER_HISTOGRAM_VALUE = HEADER_PERFIX + "HistogramValue";
+ public static final String HEADER_METER_MARK = HEADER_PERFIX + "MeterMark";
private static final Logger LOG = LoggerFactory.getLogger(MetricsComponent.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/10f5c7c4/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java b/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
index 5777134..7622112 100644
--- a/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
+++ b/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
@@ -1,6 +1,9 @@
package org.apache.camel.metrics.meter;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
+
import org.apache.camel.Exchange;
+import org.apache.camel.Message;
import org.apache.camel.metrics.AbstractMetricsProducer;
import com.codahale.metrics.Meter;
@@ -14,13 +17,15 @@ public class MeterProducer extends AbstractMetricsProducer<MeterEndpoint> {
@Override
protected void doProcess(Exchange exchange, MeterEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ Message in = exchange.getIn();
Meter meter = registry.meter(metricsName);
Long mark = endpoint.getMark();
- if (mark == null) {
+ Long finalMark = getLongHeader(in, HEADER_METER_MARK, mark);
+ if (finalMark == null) {
meter.mark();
}
else {
- meter.mark(mark);
+ meter.mark(finalMark);
}
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/10f5c7c4/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java b/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
index ffa8224..66dcce2 100644
--- a/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
@@ -1,5 +1,6 @@
package org.apache.camel.metrics.meter;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
@@ -7,6 +8,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
import org.apache.camel.Exchange;
+import org.apache.camel.Message;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,6 +38,9 @@ public class MeterProducerTest {
@Mock
private Exchange exchange;
+ @Mock
+ private Message in;
+
private MeterProducer producer;
private InOrder inOrder;
@@ -43,9 +48,10 @@ public class MeterProducerTest {
@Before
public void setUp() throws Exception {
producer = new MeterProducer(endpoint);
- inOrder = Mockito.inOrder(endpoint, registry, meter, exchange);
+ inOrder = Mockito.inOrder(endpoint, registry, meter, exchange, in);
when(endpoint.getRegistry()).thenReturn(registry);
when(registry.meter(METRICS_NAME)).thenReturn(meter);
+ when(exchange.getIn()).thenReturn(in);
}
@Test
@@ -57,20 +63,50 @@ public class MeterProducerTest {
@Test
public void testProcessMarkSet() throws Exception {
when(endpoint.getMark()).thenReturn(MARK);
+ when(in.getHeader(HEADER_METER_MARK, MARK, Long.class)).thenReturn(MARK);
producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
inOrder.verify(registry, times(1)).meter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getMark();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, MARK, Long.class);
inOrder.verify(meter, times(1)).mark(MARK);
inOrder.verifyNoMoreInteractions();
}
@Test
+ public void testProcessMarkSetOverrideByHeaderValue() throws Exception {
+ when(endpoint.getMark()).thenReturn(MARK);
+ when(in.getHeader(HEADER_METER_MARK, MARK, Long.class)).thenReturn(MARK + 101);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getMark();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, MARK, Long.class);
+ inOrder.verify(meter, times(1)).mark(MARK + 101);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
public void testProcessMarkNotSet() throws Exception {
when(endpoint.getMark()).thenReturn(null);
+ when(in.getHeader(HEADER_METER_MARK, null, Long.class)).thenReturn(null);
producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
inOrder.verify(registry, times(1)).meter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getMark();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, null, Long.class);
inOrder.verify(meter, times(1)).mark();
inOrder.verifyNoMoreInteractions();
}
+
+ @Test
+ public void testProcessMarkNotSetOverrideByHeaderValue() throws Exception {
+ when(endpoint.getMark()).thenReturn(null);
+ when(in.getHeader(HEADER_METER_MARK, null, Long.class)).thenReturn(MARK);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getMark();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, null, Long.class);
+ inOrder.verify(meter, times(1)).mark(MARK);
+ inOrder.verifyNoMoreInteractions();
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/10f5c7c4/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java b/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
index d6daf33..6bd5b59 100644
--- a/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
+++ b/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
@@ -1,5 +1,9 @@
package org.apache.camel.metrics.meter;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
@@ -8,11 +12,12 @@ import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.metrics.MetricsComponent;
import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
@@ -34,8 +39,17 @@ public class MeterRouteTest {
@EndpointInject(uri = "mock:out")
private MockEndpoint endpoint;
- @Produce(uri = "direct:in")
- private ProducerTemplate producer;
+ @Produce(uri = "direct:in-1")
+ private ProducerTemplate producer1;
+
+ @Produce(uri = "direct:in-2")
+ private ProducerTemplate producer2;
+
+ private MetricRegistry mockRegistry;
+
+ private Meter mockMeter;
+
+ private InOrder inOrder;
@Configuration
public static class TestConfig extends SingleRouteCamelConfiguration {
@@ -47,32 +61,91 @@ public class MeterRouteTest {
@Override
public void configure() throws Exception {
- from("direct:in")
+ from("direct:in-1")
.to("metrics:meter:A?mark=3179")
.to("mock:out");
+
+ from("direct:in-2")
+ .to("metrics:meter:A")
+ .to("mock:out");
}
};
}
- @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
+ @Bean(name = METRIC_REGISTRY_NAME)
public MetricRegistry getMetricRegistry() {
return Mockito.mock(MetricRegistry.class);
}
}
+ @Before
+ public void setup() {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
+ mockMeter = Mockito.mock(Meter.class);
+ inOrder = Mockito.inOrder(mockRegistry, mockMeter);
+ when(mockRegistry.meter("A")).thenReturn(mockMeter);
+ }
+
+ @After
+ public void tearDown() {
+ endpoint.reset();
+ reset(mockRegistry, mockMeter);
+ }
+
+ @Test
+ public void testValueSetInUri() throws Exception {
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer1.sendBody(body);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).meter("A");
+ inOrder.verify(mockMeter, times(1)).mark(3179L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testValueNoSetInUri() throws Exception {
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer2.sendBody(body);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).meter("A");
+ inOrder.verify(mockMeter, times(1)).mark();
+ inOrder.verifyNoMoreInteractions();
+ }
+
@Test
public void testOverrideMetricsName() throws Exception {
- // TODO - 12.05.2014, Lauri - is there any better way to set this up?
- MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
- Meter mockMeter = Mockito.mock(Meter.class);
- InOrder inOrder = Mockito.inOrder(mockRegistry, mockMeter);
when(mockRegistry.meter("B")).thenReturn(mockMeter);
-
- endpoint.expectedMessageCount(1);
- producer.sendBodyAndHeader(new Object(), MetricsComponent.HEADER_METRIC_NAME, "B");
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer1.sendBodyAndHeader(body, HEADER_METRIC_NAME, "B");
endpoint.assertIsSatisfied();
inOrder.verify(mockRegistry, times(1)).meter("B");
inOrder.verify(mockMeter, times(1)).mark(3179L);
inOrder.verifyNoMoreInteractions();
}
+
+ @Test
+ public void testOverrideValueWithHeader() throws Exception {
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer1.sendBodyAndHeader(body, HEADER_METER_MARK, 9926L);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).meter("A");
+ inOrder.verify(mockMeter, times(1)).mark(9926L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testValueNoSetInUriOverrideWithHeader() throws Exception {
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer2.sendBodyAndHeader(body, HEADER_METER_MARK, 7707370L);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).meter("A");
+ inOrder.verify(mockMeter, times(1)).mark(7707370L);
+ inOrder.verifyNoMoreInteractions();
+ }
}
[21/34] git commit: CAMEL-7554 - camel-metrics
Posted by da...@apache.org.
CAMEL-7554 - camel-metrics
* Externalized dependency versions.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1ff159ac
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1ff159ac
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1ff159ac
Branch: refs/heads/master
Commit: 1ff159ac7164d2cc2591ea44104eed581f8389a5
Parents: 4ea79b1
Author: Lauri Kimmel <la...@gmx.com>
Authored: Thu Jul 3 22:41:34 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Thu Jul 3 22:41:34 2014 +1000
----------------------------------------------------------------------
components/camel-metrics/pom.xml | 7 +++----
parent/pom.xml | 1 +
2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1ff159ac/components/camel-metrics/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-metrics/pom.xml b/components/camel-metrics/pom.xml
index bf3fdc8..e449e7e 100644
--- a/components/camel-metrics/pom.xml
+++ b/components/camel-metrics/pom.xml
@@ -43,7 +43,7 @@
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-core</artifactId>
- <version>3.0.1</version>
+ <version>${metrics-version}</version>
</dependency>
<!-- testing -->
@@ -80,16 +80,15 @@
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
- <version>1.3</version>
+ <version>${hamcrest-version}</version>
<scope>test</scope>
</dependency>
+
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
-
</dependencies>
-
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/1ff159ac/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 714fb4c..2a1f33f 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -296,6 +296,7 @@
<maven-surefire-report-plugin-version>2.13</maven-surefire-report-plugin-version>
<maven-war-plugin-version>2.4</maven-war-plugin-version>
<maven-version>2.0</maven-version>
+ <metrics-version>3.0.1</metrics-version>
<mina-bundle-version>1.1.7_6</mina-bundle-version>
<mina-version>1.1.7</mina-version>
<mina2-version>2.0.7</mina2-version>
[04/34] git commit: Implemented metrics:histogram endpoint.
Posted by da...@apache.org.
Implemented metrics:histogram endpoint.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0ad223ee
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0ad223ee
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0ad223ee
Branch: refs/heads/master
Commit: 0ad223eeec339e636f5ffd8bf9f4523b90d00ae3
Parents: 225d11d
Author: Lauri Kimmel <la...@gmx.com>
Authored: Tue May 13 23:23:02 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Tue May 13 23:23:02 2014 +1000
----------------------------------------------------------------------
.../apache/camel/metrics/MetricsComponent.java | 4 +
.../metrics/histogram/HistogramEndpoint.java | 39 ++++++++++
.../metrics/histogram/HistogramProducer.java | 34 +++++++++
.../metrics/MetricsComponentRouteTest.java | 2 +
.../camel/metrics/MetricsComponentTest.java | 7 +-
.../histogram/HistogramEndpointTest.java | 74 +++++++++++++++++++
.../histogram/HistogramProducerTest.java | 78 ++++++++++++++++++++
7 files changed, 236 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0ad223ee/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index b6af8af..7d7d5ef 100644
--- a/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -7,6 +7,7 @@ import org.apache.camel.Endpoint;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.metrics.counter.CounterEndpoint;
+import org.apache.camel.metrics.histogram.HistogramEndpoint;
import org.apache.camel.metrics.meter.MeterEndpoint;
import org.apache.camel.spi.Registry;
import org.apache.camel.util.ObjectHelper;
@@ -57,6 +58,9 @@ public class MetricsComponent extends DefaultComponent {
case METER:
endpoint = new MeterEndpoint(registry, metricsName);
break;
+ case HISTOGRAM:
+ endpoint = new HistogramEndpoint(registry, metricsName);
+ break;
default:
throw new RuntimeCamelException("Metrics type \"" + type.toString() + "\" not supported");
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0ad223ee/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java b/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
new file mode 100644
index 0000000..8024289
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
@@ -0,0 +1,39 @@
+package org.apache.camel.metrics.histogram;
+
+import org.apache.camel.Producer;
+import org.apache.camel.metrics.AbstractMetricsEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+
+import com.codahale.metrics.MetricRegistry;
+
+@UriEndpoint(scheme = "metrics:histogram")
+public class HistogramEndpoint extends AbstractMetricsEndpoint {
+
+ public static String ENDPOINT_URI = "metrics:histogram";
+
+ @UriParam
+ private Long value;
+
+ public HistogramEndpoint(MetricRegistry registry, String metricsName) {
+ super(registry, metricsName);
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new HistogramProducer(this);
+ }
+
+ public Long getValue() {
+ return value;
+ }
+
+ public void setValue(Long value) {
+ this.value = value;
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return ENDPOINT_URI;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0ad223ee/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java b/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
new file mode 100644
index 0000000..9a15607
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
@@ -0,0 +1,34 @@
+package org.apache.camel.metrics.histogram;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.MetricRegistry;
+
+public class HistogramProducer extends DefaultProducer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(HistogramProducer.class);
+
+ public HistogramProducer(Endpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ HistogramEndpoint endpoint = (HistogramEndpoint) getEndpoint();
+ MetricRegistry registry = endpoint.getRegistry();
+ String metricsName = endpoint.getMetricsName();
+ Histogram histogram = registry.histogram(metricsName);
+ Long value = endpoint.getValue();
+ if (value != null) {
+ histogram.update(value);
+ }
+ else {
+ LOG.warn("Cannot update histogram \"{}\" with null value", metricsName);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0ad223ee/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java b/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
index b005b93..5ff0ed4 100644
--- a/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
+++ b/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
@@ -35,6 +35,8 @@ public class MetricsComponentRouteTest extends CamelTestSupport {
.to("metrics:counter:C")
.to("metrics:meter:D")
.to("metrics:meter:D?mark=90001")
+ .to("metrics:histogram:E")
+ .to("metrics:histogram:E?value=12000000031")
.to("mock:result");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/0ad223ee/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java b/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
index f8dd013..7c1c189 100644
--- a/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
+++ b/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
@@ -16,6 +16,7 @@ import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.metrics.counter.CounterEndpoint;
+import org.apache.camel.metrics.histogram.HistogramEndpoint;
import org.apache.camel.metrics.meter.MeterEndpoint;
import org.apache.camel.spi.Registry;
import org.junit.Before;
@@ -135,9 +136,11 @@ public class MetricsComponentTest {
component.createNewEndpoint(metricRegistry, MetricsType.GAUGE, "a name");
}
- @Test(expected = RuntimeCamelException.class)
+ @Test
public void testCreateNewEndpointForHistogram() throws Exception {
- component.createNewEndpoint(metricRegistry, MetricsType.HISTOGRAM, "a name");
+ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.HISTOGRAM, "a name");
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint, is(instanceOf(HistogramEndpoint.class)));
}
@Test(expected = RuntimeCamelException.class)
http://git-wip-us.apache.org/repos/asf/camel/blob/0ad223ee/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java b/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
new file mode 100644
index 0000000..3ba9ea1
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
@@ -0,0 +1,74 @@
+package org.apache.camel.metrics.histogram;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+import org.apache.camel.Producer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(MockitoJUnitRunner.class)
+public class HistogramEndpointTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final Long VALUE = System.currentTimeMillis();
+
+ @Mock
+ private MetricRegistry registry;
+
+ private HistogramEndpoint endpoint;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ endpoint = new HistogramEndpoint(registry, METRICS_NAME);
+ inOrder = Mockito.inOrder(registry);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testHistogramEndpoint() throws Exception {
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint.getRegistry(), is(registry));
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ }
+
+ @Test
+ public void testCreateProducer() throws Exception {
+ Producer producer = endpoint.createProducer();
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer, is(HistogramProducer.class));
+ }
+
+ @Test
+ public void testGetValue() throws Exception {
+ assertThat(endpoint.getValue(), is(nullValue()));
+ }
+
+ @Test
+ public void testSetValue() throws Exception {
+ assertThat(endpoint.getValue(), is(nullValue()));
+ endpoint.setValue(VALUE);
+ assertThat(endpoint.getValue(), is(VALUE));
+ }
+
+ @Test
+ public void testCreateEndpointUri() throws Exception {
+ assertThat(endpoint.createEndpointUri(), is(HistogramEndpoint.ENDPOINT_URI));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0ad223ee/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java b/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
new file mode 100644
index 0000000..296c52c
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
@@ -0,0 +1,78 @@
+package org.apache.camel.metrics.histogram;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.Exchange;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(MockitoJUnitRunner.class)
+public class HistogramProducerTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final Long VALUE = System.currentTimeMillis();
+
+ @Mock
+ private HistogramEndpoint endpoint;
+
+ @Mock
+ private MetricRegistry registry;
+
+ @Mock
+ private Histogram histogram;
+
+ @Mock
+ private Exchange exchange;
+
+ private HistogramProducer producer;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ producer = new HistogramProducer(endpoint);
+ inOrder = Mockito.inOrder(endpoint, registry, histogram, exchange);
+ when(endpoint.getRegistry()).thenReturn(registry);
+ when(endpoint.getMetricsName()).thenReturn(METRICS_NAME);
+ when(registry.histogram(METRICS_NAME)).thenReturn(histogram);
+ }
+
+ @Test
+ public void testHistogramProducer() throws Exception {
+ assertThat(producer.getEndpoint().equals(endpoint), is(true));
+ }
+
+ @Test
+ public void testProcessValueSet() throws Exception {
+ when(endpoint.getValue()).thenReturn(VALUE);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getValue();
+ inOrder.verify(histogram, times(1)).update(VALUE);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessValueNotSet() throws Exception {
+ when(endpoint.getValue()).thenReturn(null);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getValue();
+ inOrder.verifyNoMoreInteractions();
+ }
+}
[31/34] git commit: CAMEL-7554: Introduced constants class for
constants. Fixed CS.
Posted by da...@apache.org.
CAMEL-7554: Introduced constants class for constants. Fixed CS.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3373b6f3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3373b6f3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3373b6f3
Branch: refs/heads/master
Commit: 3373b6f357a512bc9dd323f87ffd70563a906c5d
Parents: acf0fa3
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 30 14:23:45 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 30 14:23:45 2014 +0200
----------------------------------------------------------------------
.../metrics/AbstractMetricsProducer.java | 4 +--
.../component/metrics/MetricsComponent.java | 12 ++------
.../component/metrics/MetricsConstants.java | 32 ++++++++++++++++++++
.../metrics/counter/CounterProducer.java | 5 +--
.../metrics/histogram/HistogramProducer.java | 3 +-
.../component/metrics/meter/MeterProducer.java | 3 +-
.../component/metrics/timer/TimerProducer.java | 3 +-
.../metrics/AbstractMetricsProducerTest.java | 4 +--
.../metrics/MetricsComponentRouteTest.java | 6 ++--
.../metrics/counter/CounterProducerTest.java | 4 +--
.../metrics/counter/CounterRouteTest.java | 7 +++--
.../histogram/HistogramProducerTest.java | 2 +-
.../metrics/histogram/HistogramRouteTest.java | 5 +--
.../metrics/meter/MeterProducerTest.java | 2 +-
.../component/metrics/meter/MeterRouteTest.java | 5 +--
.../metrics/timer/TimerProducerTest.java | 2 +-
.../component/metrics/timer/TimerRouteTest.java | 7 +++--
17 files changed, 70 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsProducer.java
index 539847a..4ee8b21 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsProducer.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsProducer.java
@@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory;
public abstract class AbstractMetricsProducer<T extends AbstractMetricsEndpoint> extends DefaultProducer {
- public static final String HEADER_PATTERN = MetricsComponent.HEADER_PERFIX + "*";
+ public static final String HEADER_PATTERN = MetricsConstants.HEADER_PERFIX + "*";
private static final Logger LOG = LoggerFactory.getLogger(AbstractMetricsProducer.class);
public AbstractMetricsProducer(T endpoint) {
@@ -54,7 +54,7 @@ public abstract class AbstractMetricsProducer<T extends AbstractMetricsEndpoint>
protected abstract void doProcess(Exchange exchange, T endpoint, MetricRegistry registry, String metricsName) throws Exception;
public String getMetricsName(Message in, String defaultValue) {
- return getStringHeader(in, MetricsComponent.HEADER_METRIC_NAME, defaultValue);
+ return getStringHeader(in, MetricsConstants.HEADER_METRIC_NAME, defaultValue);
}
public String getStringHeader(Message in, String header, String defaultValue) {
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java
index bb2813a..962721e 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java
@@ -18,35 +18,29 @@ package org.apache.camel.component.metrics;
import java.util.Map;
import java.util.concurrent.TimeUnit;
+
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Slf4jReporter;
import org.apache.camel.Endpoint;
import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.component.metrics.counter.CounterEndpoint;
import org.apache.camel.component.metrics.histogram.HistogramEndpoint;
import org.apache.camel.component.metrics.meter.MeterEndpoint;
import org.apache.camel.component.metrics.timer.TimerEndpoint;
+import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.spi.Registry;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Represents the component that manages {@link MetricsEndpoint}.
+ * Represents the component that manages metrics endpoints.
*/
public class MetricsComponent extends DefaultComponent {
public static final String METRIC_REGISTRY_NAME = "metricRegistry";
public static final MetricsType DEFAULT_METRICS_TYPE = MetricsType.METER;
public static final long DEFAULT_REPORTING_INTERVAL_SECONDS = 60L;
- public static final String HEADER_PERFIX = "CamelMetrics";
- public static final String HEADER_METRIC_NAME = HEADER_PERFIX + "Name";
- public static final String HEADER_COUNTER_INCREMENT = HEADER_PERFIX + "CounterIncrement";
- public static final String HEADER_COUNTER_DECREMENT = HEADER_PERFIX + "CounterDecrement";
- public static final String HEADER_HISTOGRAM_VALUE = HEADER_PERFIX + "HistogramValue";
- public static final String HEADER_METER_MARK = HEADER_PERFIX + "MeterMark";
- public static final String HEADER_TIMER_ACTION = HEADER_PERFIX + "TimerAction";
private static final Logger LOG = LoggerFactory.getLogger(MetricsComponent.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsConstants.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsConstants.java
new file mode 100644
index 0000000..0bfe35f
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsConstants.java
@@ -0,0 +1,32 @@
+/**
+ * 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;
+
+public final class MetricsConstants {
+
+ public static final String HEADER_PERFIX = "CamelMetrics";
+ public static final String HEADER_TIMER_ACTION = HEADER_PERFIX + "TimerAction";
+ public static final String HEADER_METER_MARK = HEADER_PERFIX + "MeterMark";
+ public static final String HEADER_HISTOGRAM_VALUE = HEADER_PERFIX + "HistogramValue";
+ public static final String HEADER_COUNTER_DECREMENT = HEADER_PERFIX + "CounterDecrement";
+ public static final String HEADER_COUNTER_INCREMENT = HEADER_PERFIX + "CounterIncrement";
+ public static final String HEADER_METRIC_NAME = HEADER_PERFIX + "Name";
+
+ private MetricsConstants() {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterProducer.java
index 5a9dd42..7525866 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterProducer.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterProducer.java
@@ -22,8 +22,9 @@ import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.component.metrics.AbstractMetricsProducer;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
+
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_COUNTER_INCREMENT;
public class CounterProducer extends AbstractMetricsProducer<CounterEndpoint> {
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramProducer.java
index 161da92..530e934 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramProducer.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramProducer.java
@@ -24,7 +24,8 @@ import org.apache.camel.Message;
import org.apache.camel.component.metrics.AbstractMetricsProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_HISTOGRAM_VALUE;
public class HistogramProducer extends AbstractMetricsProducer<HistogramEndpoint> {
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterProducer.java
index b3474bb..f6becca 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterProducer.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterProducer.java
@@ -21,7 +21,8 @@ import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.component.metrics.AbstractMetricsProducer;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METER_MARK;
+
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_METER_MARK;
public class MeterProducer extends AbstractMetricsProducer<MeterEndpoint> {
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerProducer.java
index 57cf471..1254cbe 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerProducer.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerProducer.java
@@ -24,7 +24,8 @@ import org.apache.camel.component.metrics.AbstractMetricsProducer;
import org.apache.camel.component.metrics.timer.TimerEndpoint.TimerAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_TIMER_ACTION;
+
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_TIMER_ACTION;
import static org.apache.camel.component.metrics.timer.TimerEndpoint.ENDPOINT_URI;
public class TimerProducer extends AbstractMetricsProducer<TimerEndpoint> {
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsProducerTest.java
index f651389..d441c24 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsProducerTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/AbstractMetricsProducerTest.java
@@ -28,8 +28,8 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import static org.apache.camel.component.metrics.AbstractMetricsProducer.HEADER_PATTERN;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_METRIC_NAME;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.times;
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentRouteTest.java
index 9fed201..7b14213 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentRouteTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentRouteTest.java
@@ -25,9 +25,9 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_PERFIX;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_METRIC_NAME;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_PERFIX;
public class MetricsComponentRouteTest extends CamelTestSupport {
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterProducerTest.java
index 005ae65..4878cde 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterProducerTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterProducerTest.java
@@ -27,8 +27,8 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_COUNTER_INCREMENT;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.times;
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterRouteTest.java
index c33ec39..0540822 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterRouteTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/counter/CounterRouteTest.java
@@ -39,10 +39,11 @@ import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
+
import static org.apache.camel.component.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_COUNTER_INCREMENT;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_METRIC_NAME;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramProducerTest.java
index 6665796..e048979 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramProducerTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramProducerTest.java
@@ -27,7 +27,7 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_HISTOGRAM_VALUE;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.times;
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramRouteTest.java
index ee5dad8..a27107d 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramRouteTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/histogram/HistogramRouteTest.java
@@ -36,9 +36,10 @@ import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
+
import static org.apache.camel.component.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_METRIC_NAME;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterProducerTest.java
index 1392768..7e6e910 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterProducerTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterProducerTest.java
@@ -27,7 +27,7 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METER_MARK;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_METER_MARK;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterRouteTest.java
index 86076e7..382d29a 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterRouteTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/meter/MeterRouteTest.java
@@ -36,9 +36,10 @@ import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METER_MARK;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
+
import static org.apache.camel.component.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_METER_MARK;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_METRIC_NAME;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerProducerTest.java
index df94fef..3a09f8b 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerProducerTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerProducerTest.java
@@ -28,7 +28,7 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_TIMER_ACTION;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_TIMER_ACTION;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
http://git-wip-us.apache.org/repos/asf/camel/blob/3373b6f3/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerRouteTest.java
index b6941b5..1fc46b1 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerRouteTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/timer/TimerRouteTest.java
@@ -22,8 +22,8 @@ import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.component.metrics.timer.TimerEndpoint.TimerAction;
+import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
@@ -37,9 +37,10 @@ import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.component.metrics.MetricsComponent.HEADER_TIMER_ACTION;
+
import static org.apache.camel.component.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_METRIC_NAME;
+import static org.apache.camel.component.metrics.MetricsConstants.HEADER_TIMER_ACTION;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
[03/34] git commit: Added unit tests.
Posted by da...@apache.org.
Added unit tests.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/225d11d9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/225d11d9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/225d11d9
Branch: refs/heads/master
Commit: 225d11d9df8c4b4aa7af5068c60c007b27b853ee
Parents: 98560c8
Author: Lauri Kimmel <la...@gmx.com>
Authored: Tue May 13 22:47:26 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Tue May 13 22:47:26 2014 +1000
----------------------------------------------------------------------
pom.xml | 41 +++-
.../apache/camel/metrics/MetricsComponent.java | 31 ++-
.../metrics/AbstractMetricsEndpointTest.java | 81 +++++++
.../metrics/MetricComponentSpringTest.java | 77 +++++++
.../metrics/MetricsComponentRouteTest.java | 42 ++++
.../camel/metrics/MetricsComponentTest.java | 228 ++++++++++++++++---
.../apache/camel/metrics/MetricsTypeTest.java | 19 ++
.../metrics/counter/CounterEndpointTest.java | 88 +++++++
.../metrics/counter/CounterProducerTest.java | 112 +++++++++
.../camel/metrics/meter/MeterEndpointTest.java | 75 ++++++
.../camel/metrics/meter/MeterProducerTest.java | 81 +++++++
11 files changed, 821 insertions(+), 54 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/225d11d9/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2407292..0f65ab5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,13 +54,50 @@
<version>2.13.0</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ <version>2.13.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring-javaconfig</artifactId>
+ <version>2.13.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-spring</artifactId>
+ <version>2.13.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
-
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@@ -70,7 +107,7 @@
<target>1.6</target>
</configuration>
</plugin>
-
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
http://git-wip-us.apache.org/repos/asf/camel/blob/225d11d9/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index 14e93cb..b6af8af 100644
--- a/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -9,6 +9,7 @@ import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.metrics.counter.CounterEndpoint;
import org.apache.camel.metrics.meter.MeterEndpoint;
import org.apache.camel.spi.Registry;
+import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -20,7 +21,7 @@ import com.codahale.metrics.Slf4jReporter;
*/
public class MetricsComponent extends DefaultComponent {
- public static final String NAME_METRIC_REGISTRY = "metricRegistry";
+ public static final String METRIC_REGISTRY_NAME = "metricRegistry";
public static final MetricsType DEFAULT_METRICS_TYPE = MetricsType.METER;
public static final long DEFAULT_REPORTING_INTERVAL_SECONDS = 60L;
@@ -30,8 +31,10 @@ public class MetricsComponent extends DefaultComponent {
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- Registry camelRegistry = getCamelContext().getRegistry();
- getOrCreateMetricRegistry(camelRegistry, NAME_METRIC_REGISTRY);
+ if (metricRegistry == null) {
+ Registry camelRegistry = getCamelContext().getRegistry();
+ metricRegistry = getOrCreateMetricRegistry(camelRegistry, METRIC_REGISTRY_NAME);
+ }
String metricsName = getMetricsName(remaining);
MetricsType metricsType = getMetricsType(remaining);
LOG.info("Metrics type: {}; name: {}", metricsType, metricsName);
@@ -41,8 +44,8 @@ public class MetricsComponent extends DefaultComponent {
}
String getMetricsName(String remaining) {
- int index = remaining.indexOf(":");
- return index < 0 ? remaining : remaining.substring(index + 1);
+ String name = ObjectHelper.after(remaining, ":");
+ return name == null ? remaining : name;
}
Endpoint createNewEndpoint(MetricRegistry registry, MetricsType type, String metricsName) {
@@ -61,14 +64,12 @@ public class MetricsComponent extends DefaultComponent {
}
MetricsType getMetricsType(String remaining) {
- int index = remaining.indexOf(":");
- String name = null;
+ String name = ObjectHelper.before(remaining, ":");
MetricsType type;
- if (index < 0) {
+ if (name == null) {
type = DEFAULT_METRICS_TYPE;
}
else {
- name = remaining.substring(0, index);
type = MetricsType.getByName(name);
}
if (type == null) {
@@ -78,16 +79,14 @@ public class MetricsComponent extends DefaultComponent {
}
MetricRegistry getOrCreateMetricRegistry(Registry camelRegistry, String registryName) {
- if (metricRegistry == null) {
- LOG.debug("Looking up MetricRegistry from Camel Registry for name \"{}\"", registryName);
- metricRegistry = getMetricRegistryFromCamelRegistry(camelRegistry, registryName);
- }
- if (metricRegistry == null) {
+ LOG.debug("Looking up MetricRegistry from Camel Registry for name \"{}\"", registryName);
+ MetricRegistry result = getMetricRegistryFromCamelRegistry(camelRegistry, registryName);
+ if (result == null) {
LOG.debug("MetricRegistry not found from Camel Registry for name \"{}\"", registryName);
LOG.info("Creating new default MetricRegistry");
- metricRegistry = createMetricRegistry();
+ result = createMetricRegistry();
}
- return metricRegistry;
+ return result;
}
MetricRegistry getMetricRegistryFromCamelRegistry(Registry camelRegistry, String registryName) {
http://git-wip-us.apache.org/repos/asf/camel/blob/225d11d9/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java b/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
new file mode 100644
index 0000000..0b24cf8
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
@@ -0,0 +1,81 @@
+package org.apache.camel.metrics;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AbstractMetricsEndpointTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+
+ @Mock
+ private MetricRegistry registry;
+
+ @Mock
+ private Processor processor;
+
+ private AbstractMetricsEndpoint endpoint;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ endpoint = new AbstractMetricsEndpoint(registry, METRICS_NAME) {
+ @Override
+ public Producer createProducer() throws Exception {
+ return null;
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return "not real endpoint";
+ }
+ };
+ inOrder = Mockito.inOrder(registry, processor);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testAbstractMetricsEndpoint() throws Exception {
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ assertThat(endpoint.getRegistry(), is(registry));
+ }
+
+ @Test(expected = RuntimeCamelException.class)
+ public void testCreateConsumer() throws Exception {
+ endpoint.createConsumer(processor);
+ }
+
+ @Test
+ public void testIsSingleton() throws Exception {
+ assertThat(endpoint.isSingleton(), is(false));
+ }
+
+ @Test
+ public void testGetRegistry() throws Exception {
+ assertThat(endpoint.getRegistry(), is(registry));
+ }
+
+ @Test
+ public void testGetMetricsName() throws Exception {
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/225d11d9/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java b/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
new file mode 100644
index 0000000..2dd9391
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
@@ -0,0 +1,77 @@
+package org.apache.camel.metrics;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
+import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(CamelSpringJUnit4ClassRunner.class)
+@ContextConfiguration(
+ classes = { MetricComponentSpringTest.TestConfig.class },
+ loader = CamelSpringDelegatingTestContextLoader.class)
+@MockEndpoints
+public class MetricComponentSpringTest {
+
+ @EndpointInject(uri = "mock:out")
+ private MockEndpoint endpoint;
+
+ @Produce(uri = "direct:in")
+ private ProducerTemplate producer;
+
+ @Configuration
+ public static class TestConfig extends SingleRouteCamelConfiguration {
+
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:in")
+ .to("metrics:counter:A?increment=512")
+ .to("mock:out");
+ }
+ };
+ }
+
+ @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
+ public MetricRegistry getMetricRegistry() {
+ return Mockito.mock(MetricRegistry.class);
+ }
+ }
+
+ @Test
+ public void testMetricsRegistryFromCamelRegistry() throws Exception {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
+ Counter mockCounter = Mockito.mock(Counter.class);
+ InOrder inOrder = Mockito.inOrder(mockRegistry, mockCounter);
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+
+ endpoint.expectedMessageCount(1);
+ producer.sendBody(new Object());
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).inc(512);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/225d11d9/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java b/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
new file mode 100644
index 0000000..b005b93
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
@@ -0,0 +1,42 @@
+package org.apache.camel.metrics;
+
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class MetricsComponentRouteTest extends CamelTestSupport {
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ @Test
+ public void testMetrics() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+ template.sendBody(new Object());
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start")
+ // .to("metrics")
+ // .to("metrics:")
+ .to("metrics:A")
+ .to("metrics:counter://B")
+ .to("metrics:counter:C?increment=19291")
+ .to("metrics:counter:C?decrement=19292")
+ .to("metrics:counter:C")
+ .to("metrics:meter:D")
+ .to("metrics:meter:D?mark=90001")
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/225d11d9/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java b/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
index 8eb6b42..f8dd013 100644
--- a/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
+++ b/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
@@ -1,42 +1,198 @@
package org.apache.camel.metrics;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.metrics.counter.CounterEndpoint;
+import org.apache.camel.metrics.meter.MeterEndpoint;
+import org.apache.camel.spi.Registry;
+import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MetricsComponentTest {
+
+ @Mock
+ private CamelContext camelContext;
+
+ @Mock
+ private Registry camelRegistry;
+
+ @Mock
+ private MetricRegistry metricRegistry;
+
+ private InOrder inOrder;
+
+ private MetricsComponent component;
+
+ @Before
+ public void setUp() throws Exception {
+ component = new MetricsComponent();
+ inOrder = Mockito.inOrder(camelContext, camelRegistry, metricRegistry);
+
+ }
+
+ @Test
+ public void testCreateEndpoint() throws Exception {
+ component.setCamelContext(camelContext);
+ when(camelContext.getRegistry()).thenReturn(camelRegistry);
+ when(camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class)).thenReturn(metricRegistry);
+ Map<String, Object> params = new HashMap<String, Object>();
+ Long value = System.currentTimeMillis();
+ params.put("mark", value);
+ Endpoint result = component.createEndpoint("metrics:meter:long.meter", "meter:long.meter", params);
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(instanceOf(MeterEndpoint.class)));
+ MeterEndpoint me = (MeterEndpoint) result;
+ assertThat(me.getMark(), is(value));
+ assertThat(me.getMetricsName(), is("long.meter"));
+ assertThat(me.getRegistry(), is(metricRegistry));
+ inOrder.verify(camelContext, times(1)).getRegistry();
+ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
+ inOrder.verify(camelContext, times(1)).getTypeConverter();
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testCreateEndpoints() throws Exception {
+ component.setCamelContext(camelContext);
+ when(camelContext.getRegistry()).thenReturn(camelRegistry);
+ when(camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class)).thenReturn(metricRegistry);
+ Map<String, Object> params = new HashMap<String, Object>();
+ Long value = System.currentTimeMillis();
+ params.put("mark", value);
+ Endpoint result = component.createEndpoint("metrics:meter:long.meter", "meter:long.meter", params);
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(instanceOf(MeterEndpoint.class)));
+ MeterEndpoint me = (MeterEndpoint) result;
+ assertThat(me.getMark(), is(value));
+ assertThat(me.getMetricsName(), is("long.meter"));
+ assertThat(me.getRegistry(), is(metricRegistry));
+
+ params = new HashMap<String, Object>();
+ params.put("increment", value + 1);
+ params.put("decrement", value - 1);
+
+ result = component.createEndpoint("metrics:counter:long.counter", "counter:long.counter", params);
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(instanceOf(CounterEndpoint.class)));
+ CounterEndpoint ce = (CounterEndpoint) result;
+ assertThat(ce.getIncrement(), is(value + 1));
+ assertThat(ce.getDecrement(), is(value - 1));
+ assertThat(ce.getMetricsName(), is("long.counter"));
+ assertThat(ce.getRegistry(), is(metricRegistry));
+
+ inOrder.verify(camelContext, times(1)).getRegistry();
+ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
+ inOrder.verify(camelContext, times(2)).getTypeConverter();
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetMetricsName() throws Exception {
+ assertThat(component.getMetricsName("meter:metric-a"), is("metric-a"));
+ assertThat(component.getMetricsName("meter:metric-a:sub-b"), is("metric-a:sub-b"));
+ assertThat(component.getMetricsName("metric-a"), is("metric-a"));
+ assertThat(component.getMetricsName("//metric-a"), is("//metric-a"));
+ assertThat(component.getMetricsName("meter://metric-a"), is("//metric-a"));
+ }
+
+ @Test
+ public void testCreateNewEndpointForCounter() throws Exception {
+ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.COUNTER, "a name");
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint, is(instanceOf(CounterEndpoint.class)));
+ }
-public class MetricsComponentTest extends CamelTestSupport {
-
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
-
- @Test
- public void testMetrics() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMinimumMessageCount(1);
- template.sendBody(new Object());
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() {
- from("direct:start")
- // .to("metrics")
- // .to("metrics:")
- .to("metrics:A")
- .to("metrics:counter://B")
- .to("metrics:counter:C?increment=19291")
- .to("metrics:counter:C?decrement=19292")
- .to("metrics:counter:C")
- .to("metrics:meter:D")
- .to("metrics:meter:D?mark=90001")
- .to("mock:result");
- }
- };
+ @Test
+ public void testCreateNewEndpointForMeter() throws Exception {
+ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.METER, "a name");
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint, is(instanceOf(MeterEndpoint.class)));
+ }
+
+ @Test(expected = RuntimeCamelException.class)
+ public void testCreateNewEndpointForGauge() throws Exception {
+ component.createNewEndpoint(metricRegistry, MetricsType.GAUGE, "a name");
+ }
+
+ @Test(expected = RuntimeCamelException.class)
+ public void testCreateNewEndpointForHistogram() throws Exception {
+ component.createNewEndpoint(metricRegistry, MetricsType.HISTOGRAM, "a name");
+ }
+
+ @Test(expected = RuntimeCamelException.class)
+ public void testCreateNewEndpointForTimer() throws Exception {
+ component.createNewEndpoint(metricRegistry, MetricsType.TIMER, "a name");
+ }
+
+ @Test
+ public void testGetMetricsType() throws Exception {
+ for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
+ assertThat(component.getMetricsType(type.toString() + ":metrics-name"), is(type));
+ }
+ }
+
+ @Test
+ public void testGetMetricsTypeNotSet() throws Exception {
+ assertThat(component.getMetricsType("no-metrics-type"), is(MetricsComponent.DEFAULT_METRICS_TYPE));
+ }
+
+ @Test(expected = RuntimeCamelException.class)
+ public void testGetMetricsTypeNotFound() throws Exception {
+ component.getMetricsType("unknown-metrics:metrics-name");
+ }
+
+ @Test
+ public void testGetOrCreateMetricRegistryFoundInCamelRegistry() throws Exception {
+ when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(metricRegistry);
+ MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
+ assertThat(result, is(metricRegistry));
+ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetOrCreateMetricRegistryNotFoundInCamelRegistry() throws Exception {
+ when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(null);
+ MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(not(metricRegistry)));
+ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetMetricRegistryFromCamelRegistry() throws Exception {
+ when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(metricRegistry);
+ MetricRegistry result = component.getMetricRegistryFromCamelRegistry(camelRegistry, "name");
+ assertThat(result, is(metricRegistry));
+ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testCreateMetricRegistry() throws Exception {
+ MetricRegistry registry = component.createMetricRegistry();
+ assertThat(registry, is(notNullValue()));
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/225d11d9/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java b/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
new file mode 100644
index 0000000..2d0d28d
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
@@ -0,0 +1,19 @@
+package org.apache.camel.metrics;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.EnumSet;
+
+import org.junit.Test;
+
+public class MetricsTypeTest {
+
+ @Test
+ public void testGetByName() throws Exception {
+ for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
+ MetricsType t = MetricsType.getByName(type.toString());
+ assertThat(t, is(type));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/225d11d9/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java b/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
new file mode 100644
index 0000000..8f713a2
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
@@ -0,0 +1,88 @@
+package org.apache.camel.metrics.counter;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+import org.apache.camel.Producer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CounterEndpointTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final Long VALUE = System.currentTimeMillis();
+
+ @Mock
+ private MetricRegistry registry;
+
+ private CounterEndpoint endpoint;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ endpoint = new CounterEndpoint(registry, METRICS_NAME);
+ inOrder = Mockito.inOrder(registry);
+ }
+
+ @After
+ public void tearDown() {
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testCounterEndpoint() throws Exception {
+ assertThat(endpoint.getRegistry(), is(registry));
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ assertThat(endpoint.getIncrement(), is(nullValue()));
+ assertThat(endpoint.getDecrement(), is(nullValue()));
+ }
+
+ @Test
+ public void testCreateProducer() throws Exception {
+ Producer producer = endpoint.createProducer();
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer, is(instanceOf(CounterProducer.class)));
+ }
+
+ @Test
+ public void testGetIncrement() throws Exception {
+ assertThat(endpoint.getIncrement(), is(nullValue()));
+ }
+
+ @Test
+ public void testSetIncrement() throws Exception {
+ assertThat(endpoint.getIncrement(), is(nullValue()));
+ endpoint.setIncrement(VALUE);
+ assertThat(endpoint.getIncrement(), is(VALUE));
+ }
+
+ @Test
+ public void testGetDecrement() throws Exception {
+ assertThat(endpoint.getDecrement(), is(nullValue()));
+ }
+
+ @Test
+ public void testSetDecrement() throws Exception {
+ assertThat(endpoint.getDecrement(), is(nullValue()));
+ endpoint.setDecrement(VALUE);
+ assertThat(endpoint.getDecrement(), is(VALUE));
+ }
+
+ @Test
+ public void testCreateEndpointUri() throws Exception {
+ assertThat(endpoint.createEndpointUri(), is(CounterEndpoint.ENDPOINT_URI));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/225d11d9/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java b/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
new file mode 100644
index 0000000..3b1b89b
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
@@ -0,0 +1,112 @@
+package org.apache.camel.metrics.counter;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.Exchange;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CounterProducerTest {
+
+ private static final String ENDPOINT_NAME = "endpoint.name";
+ private static final Long INCREMENT = 100000L;
+ private static final Long DECREMENT = 91929199L;
+
+ @Mock
+ private CounterEndpoint endpoint;
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private MetricRegistry registry;
+
+ @Mock
+ private Counter counter;
+
+ private CounterProducer producer;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ producer = new CounterProducer(endpoint);
+ inOrder = Mockito.inOrder(endpoint, exchange, registry, counter);
+ when(endpoint.getMetricsName()).thenReturn(ENDPOINT_NAME);
+ when(endpoint.getRegistry()).thenReturn(registry);
+ when(registry.counter(ENDPOINT_NAME)).thenReturn(counter);
+ }
+
+ @Test
+ public void testCounterProducer() throws Exception {
+ assertThat(producer.getEndpoint().equals(endpoint), is(true));
+ }
+
+ @Test
+ public void testProcessWithIncrementOnly() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(INCREMENT);
+ when(endpoint.getDecrement()).thenReturn(null);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(counter, times(1)).inc(INCREMENT);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessWithDecrementOnly() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(null);
+ when(endpoint.getDecrement()).thenReturn(DECREMENT);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(counter, times(1)).dec(DECREMENT);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessWithIncrementAndDecrement() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(INCREMENT);
+ when(endpoint.getDecrement()).thenReturn(DECREMENT);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(counter, times(1)).inc(INCREMENT);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessWithOutIncrementAndDecrement() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(null);
+ when(endpoint.getDecrement()).thenReturn(null);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(counter, times(1)).inc();
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/225d11d9/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java b/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
new file mode 100644
index 0000000..3779da9
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
@@ -0,0 +1,75 @@
+package org.apache.camel.metrics.meter;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+import org.apache.camel.Producer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MeterEndpointTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final Long VALUE = System.currentTimeMillis();
+
+ @Mock
+ private MetricRegistry registry;
+
+ private MeterEndpoint endpoint;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ endpoint = new MeterEndpoint(registry, METRICS_NAME);
+ inOrder = Mockito.inOrder(registry);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testMeterEndpoint() throws Exception {
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint.getRegistry(), is(registry));
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ }
+
+ @Test
+ public void testCreateProducer() throws Exception {
+ Producer producer = endpoint.createProducer();
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer, is(instanceOf(MeterProducer.class)));
+ }
+
+ @Test
+ public void testGetMark() throws Exception {
+ assertThat(endpoint.getMark(), is(nullValue()));
+ }
+
+ @Test
+ public void testSetMark() throws Exception {
+ assertThat(endpoint.getMark(), is(nullValue()));
+ endpoint.setMark(VALUE);
+ assertThat(endpoint.getMark(), is(VALUE));
+ }
+
+ @Test
+ public void testCreateEndpointUri() throws Exception {
+ assertThat(endpoint.createEndpointUri(), is(MeterEndpoint.ENDPOINT_URI));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/225d11d9/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java b/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
new file mode 100644
index 0000000..26c853a
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
@@ -0,0 +1,81 @@
+package org.apache.camel.metrics.meter;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.Exchange;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MeterProducerTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final Long MARK = 9919120L;
+
+ @Mock
+ private MeterEndpoint endpoint;
+
+ @Mock
+ private MetricRegistry registry;
+
+ @Mock
+ private Meter meter;
+
+ @Mock
+ private Exchange exchange;
+
+ private MeterProducer producer;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ producer = new MeterProducer(endpoint);
+ inOrder = Mockito.inOrder(endpoint, registry, meter, exchange);
+ when(endpoint.getRegistry()).thenReturn(registry);
+ when(endpoint.getMetricsName()).thenReturn(METRICS_NAME);
+ when(registry.meter(METRICS_NAME)).thenReturn(meter);
+ }
+
+ @Test
+ public void testMeterProducer() throws Exception {
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer.getEndpoint().equals(endpoint), is(true));
+ }
+
+ @Test
+ public void testProcessMarkSet() throws Exception {
+ when(endpoint.getMark()).thenReturn(MARK);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getMark();
+ inOrder.verify(meter, times(1)).mark(MARK);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessMarkNotSet() throws Exception {
+ when(endpoint.getMark()).thenReturn(null);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getMark();
+ inOrder.verify(meter, times(1)).mark();
+ inOrder.verifyNoMoreInteractions();
+ }
+}
[33/34] git commit: CAMEL-7554: Added camel-metrics to kit
Posted by da...@apache.org.
CAMEL-7554: Added camel-metrics to kit
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c41496cb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c41496cb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c41496cb
Branch: refs/heads/master
Commit: c41496cb7cd28d119fc0b214e5c4dc3e94beaa53
Parents: dd33bc7
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 30 14:53:32 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 30 14:53:32 2014 +0200
----------------------------------------------------------------------
apache-camel/pom.xml | 4 ++++
apache-camel/src/main/descriptors/common-bin.xml | 1 +
parent/pom.xml | 5 +++++
3 files changed, 10 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c41496cb/apache-camel/pom.xml
----------------------------------------------------------------------
diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml
index f9ca9ba..acfeb72 100644
--- a/apache-camel/pom.xml
+++ b/apache-camel/pom.xml
@@ -400,6 +400,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-metrics</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-mina</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/c41496cb/apache-camel/src/main/descriptors/common-bin.xml
----------------------------------------------------------------------
diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml
index 87e5607..cef837d 100644
--- a/apache-camel/src/main/descriptors/common-bin.xml
+++ b/apache-camel/src/main/descriptors/common-bin.xml
@@ -110,6 +110,7 @@
<include>org.apache.camel:camel-ldap</include>
<include>org.apache.camel:camel-leveldb</include>
<include>org.apache.camel:camel-lucene</include>
+ <include>org.apache.camel:camel-metrics</include>
<include>org.apache.camel:camel-mail</include>
<include>org.apache.camel:camel-mina</include>
<include>org.apache.camel:camel-mina2</include>
http://git-wip-us.apache.org/repos/asf/camel/blob/c41496cb/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 2da285a..3a65461 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -968,6 +968,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-metrics</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-mina</artifactId>
<version>${project.version}</version>
</dependency>
[07/34] git commit: Added header to enable overriding metrics name in
the URI.
Posted by da...@apache.org.
Added header to enable overriding metrics name in the URI.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/85ca4c1f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/85ca4c1f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/85ca4c1f
Branch: refs/heads/master
Commit: 85ca4c1f8b67480415077f0316e4ac66f11db079
Parents: 89abb88
Author: Lauri Kimmel <la...@gmx.com>
Authored: Tue May 20 23:03:48 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Tue May 20 23:03:48 2014 +1000
----------------------------------------------------------------------
README.md | 16 ++++
.../camel/metrics/AbstractMetricsEndpoint.java | 18 +++++
.../apache/camel/metrics/MetricsComponent.java | 1 +
.../camel/metrics/counter/CounterProducer.java | 2 +-
.../metrics/histogram/HistogramProducer.java | 2 +-
.../camel/metrics/meter/MeterProducer.java | 2 +-
.../camel/metrics/timer/TimerProducer.java | 2 +-
.../metrics/AbstractMetricsEndpointTest.java | 82 +++++++++++++++++++-
.../metrics/MetricComponentSpringTest.java | 2 +-
.../metrics/MetricsComponentRouteTest.java | 22 ++++++
.../metrics/counter/CounterProducerTest.java | 10 +--
.../camel/metrics/counter/CounterRouteTest.java | 78 +++++++++++++++++++
.../histogram/HistogramProducerTest.java | 6 +-
.../metrics/histogram/HistogramRouteTest.java | 78 +++++++++++++++++++
.../camel/metrics/meter/MeterProducerTest.java | 6 +-
.../camel/metrics/meter/MeterRouteTest.java | 78 +++++++++++++++++++
.../camel/metrics/timer/TimerProducerTest.java | 8 +-
.../camel/metrics/timer/TimerRouteTest.java | 78 +++++++++++++++++++
18 files changed, 470 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 6a46282..34bbb23 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,22 @@ MetricRegistry instance can be configured by adding bean with name ```metricRegi
Each metric has type and name. Supported types are ```counter```, ```meter```, ```histogram``` and ```timer```. Metric name is simple string. If metric type is not provided then type ```meter``` is used by default.
+### Headers
+
+Metric name defined in URI can be overridden by using Header with name ```org.apache.camel.metrics.metricName```.
+
+For example
+
+```java
+from("direct:in")
+ .setHeader(MetricsComponent.HEADER_METRIC_NAME, constant("new.name"))
+ .to("metrics:counter:name.not.used")
+ .to("direct:out")
+```
+
+will update counter with name ```new.name``` instead of ```name.not.used```.
+
+
## Metrics type counter
```
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java b/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
index d8c8af7..9560758 100644
--- a/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
+++ b/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
@@ -1,9 +1,12 @@
package org.apache.camel.metrics;
import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.util.ObjectHelper;
import com.codahale.metrics.MetricRegistry;
@@ -34,4 +37,19 @@ public abstract class AbstractMetricsEndpoint extends DefaultEndpoint {
public String getMetricsName() {
return metricsName;
}
+
+ public String getMetricsName(Exchange exchange) {
+ return getStringHeader(exchange, MetricsComponent.HEADER_METRIC_NAME, metricsName);
+ }
+
+ public String getStringHeader(Exchange exchange, String header, String defaultValue) {
+ Message in = exchange.getIn();
+ String headerValue = in.getHeader(header, String.class);
+ return ObjectHelper.isNotEmpty(headerValue) ? headerValue : defaultValue;
+ }
+
+ public Long getLongHeader(Exchange exchange, String header, Long defaultValue) {
+ Message in = exchange.getIn();
+ return in.getHeader(header, defaultValue, Long.class);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index 1f467c4..bc4a2af 100644
--- a/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -26,6 +26,7 @@ public class MetricsComponent extends DefaultComponent {
public static final String METRIC_REGISTRY_NAME = "metricRegistry";
public static final MetricsType DEFAULT_METRICS_TYPE = MetricsType.METER;
public static final long DEFAULT_REPORTING_INTERVAL_SECONDS = 60L;
+ public static final String HEADER_METRIC_NAME = "org.apache.camel.metrics.metricName";
private static final Logger LOG = LoggerFactory.getLogger(MetricsComponent.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java b/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
index 19c470f..ec9f426 100644
--- a/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
+++ b/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
@@ -15,7 +15,7 @@ public class CounterProducer extends DefaultProducer {
@Override
public void process(Exchange exchange) throws Exception {
CounterEndpoint endpoint = (CounterEndpoint) getEndpoint();
- String metricName = endpoint.getMetricsName();
+ String metricName = endpoint.getMetricsName(exchange);
Counter counter = endpoint.getRegistry().counter(metricName);
Long increment = endpoint.getIncrement();
Long decrement = endpoint.getDecrement();
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java b/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
index 9a15607..41b5cf7 100644
--- a/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
+++ b/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
@@ -21,7 +21,7 @@ public class HistogramProducer extends DefaultProducer {
public void process(Exchange exchange) throws Exception {
HistogramEndpoint endpoint = (HistogramEndpoint) getEndpoint();
MetricRegistry registry = endpoint.getRegistry();
- String metricsName = endpoint.getMetricsName();
+ String metricsName = endpoint.getMetricsName(exchange);
Histogram histogram = registry.histogram(metricsName);
Long value = endpoint.getValue();
if (value != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java b/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
index 6cb7896..0de6ba5 100644
--- a/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
+++ b/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
@@ -16,7 +16,7 @@ public class MeterProducer extends DefaultProducer {
@Override
public void process(Exchange exchange) throws Exception {
MeterEndpoint endpoint = (MeterEndpoint) getEndpoint();
- String metricsName = endpoint.getMetricsName();
+ String metricsName = endpoint.getMetricsName(exchange);
MetricRegistry registry = endpoint.getRegistry();
Meter meter = registry.meter(metricsName);
Long mark = endpoint.getMark();
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java b/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
index f655352..bd8e2b1 100644
--- a/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
+++ b/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
@@ -22,7 +22,7 @@ public class TimerProducer extends DefaultProducer {
public void process(Exchange exchange) throws Exception {
TimerEndpoint endpoint = (TimerEndpoint) getEndpoint();
MetricRegistry registry = endpoint.getRegistry();
- String metricsName = endpoint.getMetricsName();
+ String metricsName = endpoint.getMetricsName(exchange);
TimerAction action = endpoint.getAction();
if (action == TimerAction.start) {
handleStart(exchange, registry, metricsName);
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java b/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
index 0b24cf8..824581c 100644
--- a/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
+++ b/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
@@ -2,7 +2,11 @@ package org.apache.camel.metrics;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.RuntimeCamelException;
@@ -21,6 +25,11 @@ import com.codahale.metrics.MetricRegistry;
public class AbstractMetricsEndpointTest {
private static final String METRICS_NAME = "metrics.name";
+ private static final String HEADER = "header";
+ private static final String STRING_VALUE = "string-value";
+ private static final String DEFAULT_STRING_VALUE = "default-value";
+ private static final Long LONG_VALUE = System.currentTimeMillis();
+ private static final Long DEFAULT_LONG_VALUE = -10101L;
@Mock
private MetricRegistry registry;
@@ -28,6 +37,12 @@ public class AbstractMetricsEndpointTest {
@Mock
private Processor processor;
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private Message in;
+
private AbstractMetricsEndpoint endpoint;
private InOrder inOrder;
@@ -45,7 +60,8 @@ public class AbstractMetricsEndpointTest {
return "not real endpoint";
}
};
- inOrder = Mockito.inOrder(registry, processor);
+ inOrder = Mockito.inOrder(registry, processor, exchange, in);
+ when(exchange.getIn()).thenReturn(in);
}
@After
@@ -78,4 +94,68 @@ public class AbstractMetricsEndpointTest {
public void testGetMetricsName() throws Exception {
assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
}
+
+ @Test
+ public void testGetStringHeaderValue() {
+ when(in.getHeader(HEADER, String.class)).thenReturn(STRING_VALUE);
+ assertThat(endpoint.getStringHeader(exchange, HEADER, DEFAULT_STRING_VALUE), is(STRING_VALUE));
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(in, times(1)).getHeader(HEADER, String.class);
+ }
+
+ @Test
+ public void testGetStringHeaderValueNotFound() {
+ when(in.getHeader(HEADER, String.class)).thenReturn(null);
+ assertThat(endpoint.getStringHeader(exchange, HEADER, DEFAULT_STRING_VALUE), is(DEFAULT_STRING_VALUE));
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(in, times(1)).getHeader(HEADER, String.class);
+ }
+
+ @Test
+ public void testGetStringHeaderValueEmptyString() {
+ when(in.getHeader(HEADER, String.class)).thenReturn("");
+ assertThat(endpoint.getStringHeader(exchange, HEADER, DEFAULT_STRING_VALUE), is(DEFAULT_STRING_VALUE));
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(in, times(1)).getHeader(HEADER, String.class);
+ }
+
+ @Test
+ public void testGetStringHeaderValueWhiteSpaces() {
+ when(in.getHeader(HEADER, String.class)).thenReturn(" \n\t\r");
+ assertThat(endpoint.getStringHeader(exchange, HEADER, DEFAULT_STRING_VALUE), is(DEFAULT_STRING_VALUE));
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(in, times(1)).getHeader(HEADER, String.class);
+ }
+
+ @Test
+ public void testGetLongHeaderValue() {
+ when(in.getHeader(HEADER, DEFAULT_LONG_VALUE, Long.class)).thenReturn(LONG_VALUE);
+ assertThat(endpoint.getLongHeader(exchange, HEADER, DEFAULT_LONG_VALUE), is(LONG_VALUE));
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(in, times(1)).getHeader(HEADER, DEFAULT_LONG_VALUE, Long.class);
+ }
+
+ @Test
+ public void testGetLongHeaderValueNotFound() {
+ when(in.getHeader(HEADER, DEFAULT_LONG_VALUE, Long.class)).thenReturn(DEFAULT_LONG_VALUE);
+ assertThat(endpoint.getLongHeader(exchange, HEADER, DEFAULT_LONG_VALUE), is(DEFAULT_LONG_VALUE));
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(in, times(1)).getHeader(HEADER, DEFAULT_LONG_VALUE, Long.class);
+ }
+
+ @Test
+ public void testGetMetricsNameFromExchange() {
+ when(in.getHeader(MetricsComponent.HEADER_METRIC_NAME, String.class)).thenReturn(STRING_VALUE);
+ assertThat(endpoint.getMetricsName(exchange), is(STRING_VALUE));
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(in, times(1)).getHeader(MetricsComponent.HEADER_METRIC_NAME, String.class);
+ }
+
+ @Test
+ public void testGetMetricsNameFromExchangeNotFound() {
+ when(in.getHeader(MetricsComponent.HEADER_METRIC_NAME, String.class)).thenReturn(null);
+ assertThat(endpoint.getMetricsName(exchange), is(METRICS_NAME));
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(in, times(1)).getHeader(MetricsComponent.HEADER_METRIC_NAME, String.class);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java b/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
index 2dd9391..a6590c5 100644
--- a/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
+++ b/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
@@ -71,7 +71,7 @@ public class MetricComponentSpringTest {
producer.sendBody(new Object());
endpoint.assertIsSatisfied();
inOrder.verify(mockRegistry, times(1)).counter("A");
- inOrder.verify(mockCounter, times(1)).inc(512);
+ inOrder.verify(mockCounter, times(1)).inc(512L);
inOrder.verifyNoMoreInteractions();
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java b/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
index 5af70b9..97301c3 100644
--- a/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
+++ b/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
@@ -1,5 +1,9 @@
package org.apache.camel.metrics;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
@@ -20,6 +24,24 @@ public class MetricsComponentRouteTest extends CamelTestSupport {
assertMockEndpointsSatisfied();
}
+ @Test
+ public void testMessageContentDelivery() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ String body = "Message Body";
+ String header1 = "Header 1";
+ String header2 = "Header 2";
+ Object value1 = new Date();
+ Object value2 = System.currentTimeMillis();
+ mock.expectedBodiesReceived(body);
+ mock.expectedHeaderReceived(header1, value1);
+ mock.expectedHeaderReceived(header2, value2);
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(header1, value1);
+ headers.put(header2, value2);
+ template.sendBodyAndHeaders(body, headers);
+ assertMockEndpointsSatisfied();
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java b/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
index 3b1b89b..c6ecaa4 100644
--- a/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
@@ -44,7 +44,7 @@ public class CounterProducerTest {
public void setUp() throws Exception {
producer = new CounterProducer(endpoint);
inOrder = Mockito.inOrder(endpoint, exchange, registry, counter);
- when(endpoint.getMetricsName()).thenReturn(ENDPOINT_NAME);
+ when(endpoint.getMetricsName(exchange)).thenReturn(ENDPOINT_NAME);
when(endpoint.getRegistry()).thenReturn(registry);
when(registry.counter(ENDPOINT_NAME)).thenReturn(counter);
}
@@ -59,7 +59,7 @@ public class CounterProducerTest {
when(endpoint.getIncrement()).thenReturn(INCREMENT);
when(endpoint.getDecrement()).thenReturn(null);
producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
@@ -73,7 +73,7 @@ public class CounterProducerTest {
when(endpoint.getIncrement()).thenReturn(null);
when(endpoint.getDecrement()).thenReturn(DECREMENT);
producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
@@ -87,7 +87,7 @@ public class CounterProducerTest {
when(endpoint.getIncrement()).thenReturn(INCREMENT);
when(endpoint.getDecrement()).thenReturn(DECREMENT);
producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
@@ -101,7 +101,7 @@ public class CounterProducerTest {
when(endpoint.getIncrement()).thenReturn(null);
when(endpoint.getDecrement()).thenReturn(null);
producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java b/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
new file mode 100644
index 0000000..df9185b
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
@@ -0,0 +1,78 @@
+package org.apache.camel.metrics.counter;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.metrics.MetricsComponent;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
+import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(CamelSpringJUnit4ClassRunner.class)
+@ContextConfiguration(
+ classes = { CounterRouteTest.TestConfig.class },
+ loader = CamelSpringDelegatingTestContextLoader.class)
+@MockEndpoints
+public class CounterRouteTest {
+
+ @EndpointInject(uri = "mock:out")
+ private MockEndpoint endpoint;
+
+ @Produce(uri = "direct:in")
+ private ProducerTemplate producer;
+
+ @Configuration
+ public static class TestConfig extends SingleRouteCamelConfiguration {
+
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:in")
+ .to("metrics:counter:A?increment=5")
+ .to("mock:out");
+ }
+ };
+ }
+
+ @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
+ public MetricRegistry getMetricRegistry() {
+ return Mockito.mock(MetricRegistry.class);
+ }
+ }
+
+ @Test
+ public void testOverrideMetricsName() throws Exception {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
+ Counter mockCounter = Mockito.mock(Counter.class);
+ InOrder inOrder = Mockito.inOrder(mockRegistry, mockCounter);
+ when(mockRegistry.counter("B")).thenReturn(mockCounter);
+
+ endpoint.expectedMessageCount(1);
+ producer.sendBodyAndHeader(new Object(), MetricsComponent.HEADER_METRIC_NAME, "B");
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("B");
+ inOrder.verify(mockCounter, times(1)).inc(5L);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java b/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
index 296c52c..8662e9d 100644
--- a/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
@@ -44,7 +44,7 @@ public class HistogramProducerTest {
producer = new HistogramProducer(endpoint);
inOrder = Mockito.inOrder(endpoint, registry, histogram, exchange);
when(endpoint.getRegistry()).thenReturn(registry);
- when(endpoint.getMetricsName()).thenReturn(METRICS_NAME);
+ when(endpoint.getMetricsName(exchange)).thenReturn(METRICS_NAME);
when(registry.histogram(METRICS_NAME)).thenReturn(histogram);
}
@@ -58,7 +58,7 @@ public class HistogramProducerTest {
when(endpoint.getValue()).thenReturn(VALUE);
producer.process(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getValue();
inOrder.verify(histogram, times(1)).update(VALUE);
@@ -70,7 +70,7 @@ public class HistogramProducerTest {
when(endpoint.getValue()).thenReturn(null);
producer.process(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getValue();
inOrder.verifyNoMoreInteractions();
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java b/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
new file mode 100644
index 0000000..e8646cb
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
@@ -0,0 +1,78 @@
+package org.apache.camel.metrics.histogram;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.metrics.MetricsComponent;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
+import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(CamelSpringJUnit4ClassRunner.class)
+@ContextConfiguration(
+ classes = { HistogramRouteTest.TestConfig.class },
+ loader = CamelSpringDelegatingTestContextLoader.class)
+@MockEndpoints
+public class HistogramRouteTest {
+
+ @EndpointInject(uri = "mock:out")
+ private MockEndpoint endpoint;
+
+ @Produce(uri = "direct:in")
+ private ProducerTemplate producer;
+
+ @Configuration
+ public static class TestConfig extends SingleRouteCamelConfiguration {
+
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:in")
+ .to("metrics:histogram:A?value=332491")
+ .to("mock:out");
+ }
+ };
+ }
+
+ @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
+ public MetricRegistry getMetricRegistry() {
+ return Mockito.mock(MetricRegistry.class);
+ }
+ }
+
+ @Test
+ public void testOverrideMetricsName() throws Exception {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
+ Histogram mockHistogram = Mockito.mock(Histogram.class);
+ InOrder inOrder = Mockito.inOrder(mockRegistry, mockHistogram);
+ when(mockRegistry.histogram("B")).thenReturn(mockHistogram);
+
+ endpoint.expectedMessageCount(1);
+ producer.sendBodyAndHeader(new Object(), MetricsComponent.HEADER_METRIC_NAME, "B");
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).histogram("B");
+ inOrder.verify(mockHistogram, times(1)).update(332491L);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java b/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
index 26c853a..ba62a18 100644
--- a/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
@@ -45,7 +45,7 @@ public class MeterProducerTest {
producer = new MeterProducer(endpoint);
inOrder = Mockito.inOrder(endpoint, registry, meter, exchange);
when(endpoint.getRegistry()).thenReturn(registry);
- when(endpoint.getMetricsName()).thenReturn(METRICS_NAME);
+ when(endpoint.getMetricsName(exchange)).thenReturn(METRICS_NAME);
when(registry.meter(METRICS_NAME)).thenReturn(meter);
}
@@ -59,7 +59,7 @@ public class MeterProducerTest {
public void testProcessMarkSet() throws Exception {
when(endpoint.getMark()).thenReturn(MARK);
producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(registry, times(1)).meter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getMark();
@@ -71,7 +71,7 @@ public class MeterProducerTest {
public void testProcessMarkNotSet() throws Exception {
when(endpoint.getMark()).thenReturn(null);
producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(registry, times(1)).meter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getMark();
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java b/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
new file mode 100644
index 0000000..d6daf33
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
@@ -0,0 +1,78 @@
+package org.apache.camel.metrics.meter;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.metrics.MetricsComponent;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
+import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(CamelSpringJUnit4ClassRunner.class)
+@ContextConfiguration(
+ classes = { MeterRouteTest.TestConfig.class },
+ loader = CamelSpringDelegatingTestContextLoader.class)
+@MockEndpoints
+public class MeterRouteTest {
+
+ @EndpointInject(uri = "mock:out")
+ private MockEndpoint endpoint;
+
+ @Produce(uri = "direct:in")
+ private ProducerTemplate producer;
+
+ @Configuration
+ public static class TestConfig extends SingleRouteCamelConfiguration {
+
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:in")
+ .to("metrics:meter:A?mark=3179")
+ .to("mock:out");
+ }
+ };
+ }
+
+ @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
+ public MetricRegistry getMetricRegistry() {
+ return Mockito.mock(MetricRegistry.class);
+ }
+ }
+
+ @Test
+ public void testOverrideMetricsName() throws Exception {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
+ Meter mockMeter = Mockito.mock(Meter.class);
+ InOrder inOrder = Mockito.inOrder(mockRegistry, mockMeter);
+ when(mockRegistry.meter("B")).thenReturn(mockMeter);
+
+ endpoint.expectedMessageCount(1);
+ producer.sendBodyAndHeader(new Object(), MetricsComponent.HEADER_METRIC_NAME, "B");
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).meter("B");
+ inOrder.verify(mockMeter, times(1)).mark(3179L);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java b/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
index 86ec26d..09e572b 100644
--- a/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
@@ -51,7 +51,7 @@ public class TimerProducerTest {
producer = new TimerProducer(endpoint);
inOrder = Mockito.inOrder(endpoint, exchange, registry, timer, context);
when(endpoint.getRegistry()).thenReturn(registry);
- when(endpoint.getMetricsName()).thenReturn(METRICS_NAME);
+ when(endpoint.getMetricsName(exchange)).thenReturn(METRICS_NAME);
when(registry.timer(METRICS_NAME)).thenReturn(timer);
when(timer.time()).thenReturn(context);
}
@@ -68,7 +68,7 @@ public class TimerProducerTest {
when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
producer.process(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getAction();
inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
inOrder.verify(registry, times(1)).timer(METRICS_NAME);
@@ -83,7 +83,7 @@ public class TimerProducerTest {
when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
producer.process(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getAction();
inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
inOrder.verify(context, times(1)).stop();
@@ -96,7 +96,7 @@ public class TimerProducerTest {
when(endpoint.getAction()).thenReturn(null);
producer.process(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getAction();
inOrder.verifyNoMoreInteractions();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/85ca4c1f/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java b/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
new file mode 100644
index 0000000..279be95
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
@@ -0,0 +1,78 @@
+package org.apache.camel.metrics.timer;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.metrics.MetricsComponent;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
+import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+
+@RunWith(CamelSpringJUnit4ClassRunner.class)
+@ContextConfiguration(
+ classes = { TimerRouteTest.TestConfig.class },
+ loader = CamelSpringDelegatingTestContextLoader.class)
+@MockEndpoints
+public class TimerRouteTest {
+
+ @EndpointInject(uri = "mock:out")
+ private MockEndpoint endpoint;
+
+ @Produce(uri = "direct:in")
+ private ProducerTemplate producer;
+
+ @Configuration
+ public static class TestConfig extends SingleRouteCamelConfiguration {
+
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:in")
+ .to("metrics:timer:A?action=start")
+ .to("mock:out");
+ }
+ };
+ }
+
+ @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
+ public MetricRegistry getMetricRegistry() {
+ return Mockito.mock(MetricRegistry.class);
+ }
+ }
+
+ @Test
+ public void testOverrideMetricsName() throws Exception {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
+ Timer mockTimer = Mockito.mock(Timer.class);
+ InOrder inOrder = Mockito.inOrder(mockRegistry, mockTimer);
+ when(mockRegistry.timer("B")).thenReturn(mockTimer);
+
+ endpoint.expectedMessageCount(1);
+ producer.sendBodyAndHeader(new Object(), MetricsComponent.HEADER_METRIC_NAME, "B");
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).timer("B");
+ inOrder.verify(mockTimer, times(1)).time();
+ inOrder.verifyNoMoreInteractions();
+ }
+}
[16/34] Merge 'https://github.com/laurikimmel/camel-metrics.git' into
camel-metrics
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
index 0000000,0000000..844401e
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
@@@ -1,0 -1,0 +1,195 @@@
++package org.apache.camel.metrics.counter;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
++import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
++import static org.mockito.Mockito.mock;
++import static org.mockito.Mockito.reset;
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.when;
++
++import java.util.HashMap;
++import java.util.Map;
++
++import org.apache.camel.EndpointInject;
++import org.apache.camel.Produce;
++import org.apache.camel.ProducerTemplate;
++import org.apache.camel.builder.RouteBuilder;
++import org.apache.camel.component.mock.MockEndpoint;
++import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
++import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
++import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
++import org.apache.camel.test.spring.MockEndpoints;
++import org.junit.After;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mockito;
++import org.springframework.context.annotation.Bean;
++import org.springframework.context.annotation.Configuration;
++import org.springframework.test.context.ContextConfiguration;
++
++import com.codahale.metrics.Counter;
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(CamelSpringJUnit4ClassRunner.class)
++@ContextConfiguration(
++ classes = { CounterRouteTest.TestConfig.class },
++ loader = CamelSpringDelegatingTestContextLoader.class)
++@MockEndpoints
++public class CounterRouteTest {
++
++ @EndpointInject(uri = "mock:out")
++ private MockEndpoint endpoint;
++
++ @Produce(uri = "direct:in-1")
++ private ProducerTemplate producer1;
++
++ @Produce(uri = "direct:in-2")
++ private ProducerTemplate producer2;
++
++ @Produce(uri = "direct:in-3")
++ private ProducerTemplate producer3;
++
++ @Produce(uri = "direct:in-4")
++ private ProducerTemplate producer4;
++
++ private MetricRegistry mockRegistry;
++
++ private Counter mockCounter;
++
++ private InOrder inOrder;
++
++ @Configuration
++ public static class TestConfig extends SingleRouteCamelConfiguration {
++
++ @Bean
++ @Override
++ public RouteBuilder route() {
++ return new RouteBuilder() {
++
++ @Override
++ public void configure() throws Exception {
++ from("direct:in-1")
++ .to("metrics:counter:A?increment=5")
++ .to("mock:out");
++
++ from("direct:in-2")
++ .to("metrics:counter:A?decrement=9")
++ .to("mock:out");
++
++ from("direct:in-3")
++ .setHeader(HEADER_COUNTER_INCREMENT, constant(417L))
++ .to("metrics:counter:A")
++ .to("mock:out");
++
++ from("direct:in-4")
++ .setHeader(HEADER_COUNTER_INCREMENT, simple("${body.length}"))
++ .to("metrics:counter:A")
++ .to("mock:out");
++ }
++ };
++ }
++
++ @Bean(name = METRIC_REGISTRY_NAME)
++ public MetricRegistry getMetricRegistry() {
++ return Mockito.mock(MetricRegistry.class);
++ }
++ }
++
++ @Before
++ public void setup() {
++ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
++ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
++ mockCounter = mock(Counter.class);
++ inOrder = Mockito.inOrder(mockRegistry, mockCounter);
++ }
++
++ @After
++ public void tearDown() {
++ endpoint.reset();
++ reset(mockRegistry, mockCounter);
++ }
++
++ @Test
++ public void testOverrideMetricsName() throws Exception {
++ when(mockRegistry.counter("B")).thenReturn(mockCounter);
++ endpoint.expectedMessageCount(1);
++ producer1.sendBodyAndHeader(new Object(), HEADER_METRIC_NAME, "B");
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).counter("B");
++ inOrder.verify(mockCounter, times(1)).inc(5L);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testOverrideIncrement() throws Exception {
++ when(mockRegistry.counter("A")).thenReturn(mockCounter);
++ endpoint.expectedMessageCount(1);
++ producer1.sendBodyAndHeader(new Object(), HEADER_COUNTER_INCREMENT, 14L);
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).counter("A");
++ inOrder.verify(mockCounter, times(1)).inc(14L);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testOverrideIncrementAndDecrement() throws Exception {
++ when(mockRegistry.counter("A")).thenReturn(mockCounter);
++ endpoint.expectedMessageCount(1);
++ Map<String, Object> headers = new HashMap<String, Object>();
++ headers.put(HEADER_COUNTER_INCREMENT, 912L);
++ headers.put(HEADER_COUNTER_DECREMENT, 43219L);
++ producer1.sendBodyAndHeaders(new Object(), headers);
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).counter("A");
++ inOrder.verify(mockCounter, times(1)).inc(912L);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testOverrideDecrement() throws Exception {
++ when(mockRegistry.counter("A")).thenReturn(mockCounter);
++ endpoint.expectedMessageCount(1);
++ producer2.sendBodyAndHeader(new Object(), HEADER_COUNTER_DECREMENT, 7L);
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).counter("A");
++ inOrder.verify(mockCounter, times(1)).dec(7L);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testOverrideIncrementWithWrongType() throws Exception {
++ when(mockRegistry.counter("A")).thenReturn(mockCounter);
++ endpoint.expectedMessageCount(1);
++ producer1.sendBodyAndHeader(new Object(), HEADER_COUNTER_INCREMENT, "this is not a valid long value");
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).counter("A");
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testOverrideUsingConstantValue() throws Exception {
++ when(mockRegistry.counter("A")).thenReturn(mockCounter);
++ endpoint.expectedMessageCount(1);
++ producer3.sendBody(new Object());
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).counter("A");
++ inOrder.verify(mockCounter, times(1)).inc(417L);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testOverrideUsingScriptEvaluation() throws Exception {
++ when(mockRegistry.counter("A")).thenReturn(mockCounter);
++ endpoint.expectedMessageCount(1);
++ String message = "Hello from Camel Metrics!";
++ producer4.sendBody(message);
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).counter("A");
++ inOrder.verify(mockCounter, times(1)).inc(message.length());
++ inOrder.verifyNoMoreInteractions();
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
index 0000000,0000000..3ba9ea1
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
@@@ -1,0 -1,0 +1,74 @@@
++package org.apache.camel.metrics.histogram;
++
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.MatcherAssert.assertThat;
++import static org.hamcrest.Matchers.notNullValue;
++import static org.hamcrest.Matchers.nullValue;
++
++import org.apache.camel.Producer;
++import org.junit.After;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mock;
++import org.mockito.Mockito;
++import org.mockito.runners.MockitoJUnitRunner;
++
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(MockitoJUnitRunner.class)
++public class HistogramEndpointTest {
++
++ private static final String METRICS_NAME = "metrics.name";
++ private static final Long VALUE = System.currentTimeMillis();
++
++ @Mock
++ private MetricRegistry registry;
++
++ private HistogramEndpoint endpoint;
++
++ private InOrder inOrder;
++
++ @Before
++ public void setUp() throws Exception {
++ endpoint = new HistogramEndpoint(registry, METRICS_NAME);
++ inOrder = Mockito.inOrder(registry);
++ }
++
++ @After
++ public void tearDown() throws Exception {
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testHistogramEndpoint() throws Exception {
++ assertThat(endpoint, is(notNullValue()));
++ assertThat(endpoint.getRegistry(), is(registry));
++ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
++ }
++
++ @Test
++ public void testCreateProducer() throws Exception {
++ Producer producer = endpoint.createProducer();
++ assertThat(producer, is(notNullValue()));
++ assertThat(producer, is(HistogramProducer.class));
++ }
++
++ @Test
++ public void testGetValue() throws Exception {
++ assertThat(endpoint.getValue(), is(nullValue()));
++ }
++
++ @Test
++ public void testSetValue() throws Exception {
++ assertThat(endpoint.getValue(), is(nullValue()));
++ endpoint.setValue(VALUE);
++ assertThat(endpoint.getValue(), is(VALUE));
++ }
++
++ @Test
++ public void testCreateEndpointUri() throws Exception {
++ assertThat(endpoint.createEndpointUri(), is(HistogramEndpoint.ENDPOINT_URI));
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
index 0000000,0000000..8fe1e06
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
@@@ -1,0 -1,0 +1,111 @@@
++package org.apache.camel.metrics.histogram;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.MatcherAssert.assertThat;
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.when;
++
++import org.apache.camel.Exchange;
++import org.apache.camel.Message;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mock;
++import org.mockito.Mockito;
++import org.mockito.runners.MockitoJUnitRunner;
++
++import com.codahale.metrics.Histogram;
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(MockitoJUnitRunner.class)
++public class HistogramProducerTest {
++
++ private static final String METRICS_NAME = "metrics.name";
++ private static final Long VALUE = System.currentTimeMillis();
++
++ @Mock
++ private HistogramEndpoint endpoint;
++
++ @Mock
++ private MetricRegistry registry;
++
++ @Mock
++ private Histogram histogram;
++
++ @Mock
++ private Exchange exchange;
++
++ @Mock
++ private Message in;
++
++ private HistogramProducer producer;
++
++ private InOrder inOrder;
++
++ @Before
++ public void setUp() throws Exception {
++ producer = new HistogramProducer(endpoint);
++ inOrder = Mockito.inOrder(endpoint, registry, histogram, exchange, in);
++ when(endpoint.getRegistry()).thenReturn(registry);
++ when(registry.histogram(METRICS_NAME)).thenReturn(histogram);
++ when(exchange.getIn()).thenReturn(in);
++ }
++
++ @Test
++ public void testHistogramProducer() throws Exception {
++ assertThat(producer.getEndpoint().equals(endpoint), is(true));
++ }
++
++ @Test
++ public void testProcessValueSet() throws Exception {
++ when(endpoint.getValue()).thenReturn(VALUE);
++ when(in.getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class)).thenReturn(VALUE);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getValue();
++ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class);
++ inOrder.verify(histogram, times(1)).update(VALUE);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessValueNotSet() throws Exception {
++ when(endpoint.getValue()).thenReturn(null);
++ when(in.getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class)).thenReturn(null);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getValue();
++ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessOverrideValue() throws Exception {
++ when(endpoint.getValue()).thenReturn(VALUE);
++ when(in.getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class)).thenReturn(VALUE + 3);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getValue();
++ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class);
++ inOrder.verify(histogram, times(1)).update(VALUE + 3);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessOverrideUriValueNotSet() throws Exception {
++ when(endpoint.getValue()).thenReturn(null);
++ when(in.getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class)).thenReturn(VALUE + 2);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getValue();
++ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class);
++ inOrder.verify(histogram, times(1)).update(VALUE + 2);
++ inOrder.verifyNoMoreInteractions();
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
index 0000000,0000000..cc01a1d
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
@@@ -1,0 -1,0 +1,109 @@@
++package org.apache.camel.metrics.histogram;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
++import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
++import static org.mockito.Mockito.reset;
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.when;
++
++import org.apache.camel.EndpointInject;
++import org.apache.camel.Produce;
++import org.apache.camel.ProducerTemplate;
++import org.apache.camel.builder.RouteBuilder;
++import org.apache.camel.component.mock.MockEndpoint;
++import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
++import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
++import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
++import org.apache.camel.test.spring.MockEndpoints;
++import org.junit.After;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mockito;
++import org.springframework.context.annotation.Bean;
++import org.springframework.context.annotation.Configuration;
++import org.springframework.test.context.ContextConfiguration;
++
++import com.codahale.metrics.Histogram;
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(CamelSpringJUnit4ClassRunner.class)
++@ContextConfiguration(
++ classes = { HistogramRouteTest.TestConfig.class },
++ loader = CamelSpringDelegatingTestContextLoader.class)
++@MockEndpoints
++public class HistogramRouteTest {
++
++ @EndpointInject(uri = "mock:out")
++ private MockEndpoint endpoint;
++
++ @Produce(uri = "direct:in")
++ private ProducerTemplate producer;
++
++ private MetricRegistry mockRegistry;
++
++ private Histogram mockHistogram;
++
++ private InOrder inOrder;
++
++ @Configuration
++ public static class TestConfig extends SingleRouteCamelConfiguration {
++
++ @Bean
++ @Override
++ public RouteBuilder route() {
++ return new RouteBuilder() {
++
++ @Override
++ public void configure() throws Exception {
++ from("direct:in")
++ .to("metrics:histogram:A?value=332491")
++ .to("mock:out");
++ }
++ };
++ }
++
++ @Bean(name = METRIC_REGISTRY_NAME)
++ public MetricRegistry getMetricRegistry() {
++ return Mockito.mock(MetricRegistry.class);
++ }
++ }
++
++ @Before
++ public void setup() {
++ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
++ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
++ mockHistogram = Mockito.mock(Histogram.class);
++ inOrder = Mockito.inOrder(mockRegistry, mockHistogram);
++ }
++
++ @After
++ public void tearDown() {
++ endpoint.reset();
++ reset(mockRegistry);
++ }
++
++ @Test
++ public void testOverrideMetricsName() throws Exception {
++ when(mockRegistry.histogram("B")).thenReturn(mockHistogram);
++ endpoint.expectedMessageCount(1);
++ producer.sendBodyAndHeader(new Object(), HEADER_METRIC_NAME, "B");
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).histogram("B");
++ inOrder.verify(mockHistogram, times(1)).update(332491L);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testOverrideValue() throws Exception {
++ when(mockRegistry.histogram("A")).thenReturn(mockHistogram);
++ endpoint.expectedMessageCount(1);
++ producer.sendBodyAndHeader(new Object(), HEADER_HISTOGRAM_VALUE, 181L);
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).histogram("A");
++ inOrder.verify(mockHistogram, times(1)).update(181L);
++ inOrder.verifyNoMoreInteractions();
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
index 0000000,0000000..3779da9
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
@@@ -1,0 -1,0 +1,75 @@@
++package org.apache.camel.metrics.meter;
++
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.MatcherAssert.assertThat;
++import static org.hamcrest.Matchers.instanceOf;
++import static org.hamcrest.Matchers.notNullValue;
++import static org.hamcrest.Matchers.nullValue;
++
++import org.apache.camel.Producer;
++import org.junit.After;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mock;
++import org.mockito.Mockito;
++import org.mockito.runners.MockitoJUnitRunner;
++
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(MockitoJUnitRunner.class)
++public class MeterEndpointTest {
++
++ private static final String METRICS_NAME = "metrics.name";
++ private static final Long VALUE = System.currentTimeMillis();
++
++ @Mock
++ private MetricRegistry registry;
++
++ private MeterEndpoint endpoint;
++
++ private InOrder inOrder;
++
++ @Before
++ public void setUp() throws Exception {
++ endpoint = new MeterEndpoint(registry, METRICS_NAME);
++ inOrder = Mockito.inOrder(registry);
++ }
++
++ @After
++ public void tearDown() throws Exception {
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testMeterEndpoint() throws Exception {
++ assertThat(endpoint, is(notNullValue()));
++ assertThat(endpoint.getRegistry(), is(registry));
++ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
++ }
++
++ @Test
++ public void testCreateProducer() throws Exception {
++ Producer producer = endpoint.createProducer();
++ assertThat(producer, is(notNullValue()));
++ assertThat(producer, is(instanceOf(MeterProducer.class)));
++ }
++
++ @Test
++ public void testGetMark() throws Exception {
++ assertThat(endpoint.getMark(), is(nullValue()));
++ }
++
++ @Test
++ public void testSetMark() throws Exception {
++ assertThat(endpoint.getMark(), is(nullValue()));
++ endpoint.setMark(VALUE);
++ assertThat(endpoint.getMark(), is(VALUE));
++ }
++
++ @Test
++ public void testCreateEndpointUri() throws Exception {
++ assertThat(endpoint.createEndpointUri(), is(MeterEndpoint.ENDPOINT_URI));
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
index 0000000,0000000..66dcce2
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
@@@ -1,0 -1,0 +1,112 @@@
++package org.apache.camel.metrics.meter;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.MatcherAssert.assertThat;
++import static org.hamcrest.Matchers.notNullValue;
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.when;
++
++import org.apache.camel.Exchange;
++import org.apache.camel.Message;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mock;
++import org.mockito.Mockito;
++import org.mockito.runners.MockitoJUnitRunner;
++
++import com.codahale.metrics.Meter;
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(MockitoJUnitRunner.class)
++public class MeterProducerTest {
++
++ private static final String METRICS_NAME = "metrics.name";
++ private static final Long MARK = 9919120L;
++
++ @Mock
++ private MeterEndpoint endpoint;
++
++ @Mock
++ private MetricRegistry registry;
++
++ @Mock
++ private Meter meter;
++
++ @Mock
++ private Exchange exchange;
++
++ @Mock
++ private Message in;
++
++ private MeterProducer producer;
++
++ private InOrder inOrder;
++
++ @Before
++ public void setUp() throws Exception {
++ producer = new MeterProducer(endpoint);
++ inOrder = Mockito.inOrder(endpoint, registry, meter, exchange, in);
++ when(endpoint.getRegistry()).thenReturn(registry);
++ when(registry.meter(METRICS_NAME)).thenReturn(meter);
++ when(exchange.getIn()).thenReturn(in);
++ }
++
++ @Test
++ public void testMeterProducer() throws Exception {
++ assertThat(producer, is(notNullValue()));
++ assertThat(producer.getEndpoint().equals(endpoint), is(true));
++ }
++
++ @Test
++ public void testProcessMarkSet() throws Exception {
++ when(endpoint.getMark()).thenReturn(MARK);
++ when(in.getHeader(HEADER_METER_MARK, MARK, Long.class)).thenReturn(MARK);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getMark();
++ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, MARK, Long.class);
++ inOrder.verify(meter, times(1)).mark(MARK);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessMarkSetOverrideByHeaderValue() throws Exception {
++ when(endpoint.getMark()).thenReturn(MARK);
++ when(in.getHeader(HEADER_METER_MARK, MARK, Long.class)).thenReturn(MARK + 101);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getMark();
++ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, MARK, Long.class);
++ inOrder.verify(meter, times(1)).mark(MARK + 101);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessMarkNotSet() throws Exception {
++ when(endpoint.getMark()).thenReturn(null);
++ when(in.getHeader(HEADER_METER_MARK, null, Long.class)).thenReturn(null);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getMark();
++ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, null, Long.class);
++ inOrder.verify(meter, times(1)).mark();
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessMarkNotSetOverrideByHeaderValue() throws Exception {
++ when(endpoint.getMark()).thenReturn(null);
++ when(in.getHeader(HEADER_METER_MARK, null, Long.class)).thenReturn(MARK);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(registry, times(1)).meter(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getMark();
++ inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, null, Long.class);
++ inOrder.verify(meter, times(1)).mark(MARK);
++ inOrder.verifyNoMoreInteractions();
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
index 0000000,0000000..6bd5b59
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
@@@ -1,0 -1,0 +1,151 @@@
++package org.apache.camel.metrics.meter;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
++import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
++import static org.mockito.Mockito.reset;
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.when;
++
++import org.apache.camel.EndpointInject;
++import org.apache.camel.Produce;
++import org.apache.camel.ProducerTemplate;
++import org.apache.camel.builder.RouteBuilder;
++import org.apache.camel.component.mock.MockEndpoint;
++import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
++import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
++import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
++import org.apache.camel.test.spring.MockEndpoints;
++import org.junit.After;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mockito;
++import org.springframework.context.annotation.Bean;
++import org.springframework.context.annotation.Configuration;
++import org.springframework.test.context.ContextConfiguration;
++
++import com.codahale.metrics.Meter;
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(CamelSpringJUnit4ClassRunner.class)
++@ContextConfiguration(
++ classes = { MeterRouteTest.TestConfig.class },
++ loader = CamelSpringDelegatingTestContextLoader.class)
++@MockEndpoints
++public class MeterRouteTest {
++
++ @EndpointInject(uri = "mock:out")
++ private MockEndpoint endpoint;
++
++ @Produce(uri = "direct:in-1")
++ private ProducerTemplate producer1;
++
++ @Produce(uri = "direct:in-2")
++ private ProducerTemplate producer2;
++
++ private MetricRegistry mockRegistry;
++
++ private Meter mockMeter;
++
++ private InOrder inOrder;
++
++ @Configuration
++ public static class TestConfig extends SingleRouteCamelConfiguration {
++
++ @Bean
++ @Override
++ public RouteBuilder route() {
++ return new RouteBuilder() {
++
++ @Override
++ public void configure() throws Exception {
++ from("direct:in-1")
++ .to("metrics:meter:A?mark=3179")
++ .to("mock:out");
++
++ from("direct:in-2")
++ .to("metrics:meter:A")
++ .to("mock:out");
++ }
++ };
++ }
++
++ @Bean(name = METRIC_REGISTRY_NAME)
++ public MetricRegistry getMetricRegistry() {
++ return Mockito.mock(MetricRegistry.class);
++ }
++ }
++
++ @Before
++ public void setup() {
++ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
++ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
++ mockMeter = Mockito.mock(Meter.class);
++ inOrder = Mockito.inOrder(mockRegistry, mockMeter);
++ when(mockRegistry.meter("A")).thenReturn(mockMeter);
++ }
++
++ @After
++ public void tearDown() {
++ endpoint.reset();
++ reset(mockRegistry, mockMeter);
++ }
++
++ @Test
++ public void testValueSetInUri() throws Exception {
++ Object body = new Object();
++ endpoint.expectedBodiesReceived(body);
++ producer1.sendBody(body);
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).meter("A");
++ inOrder.verify(mockMeter, times(1)).mark(3179L);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testValueNoSetInUri() throws Exception {
++ Object body = new Object();
++ endpoint.expectedBodiesReceived(body);
++ producer2.sendBody(body);
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).meter("A");
++ inOrder.verify(mockMeter, times(1)).mark();
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testOverrideMetricsName() throws Exception {
++ when(mockRegistry.meter("B")).thenReturn(mockMeter);
++ Object body = new Object();
++ endpoint.expectedBodiesReceived(body);
++ producer1.sendBodyAndHeader(body, HEADER_METRIC_NAME, "B");
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).meter("B");
++ inOrder.verify(mockMeter, times(1)).mark(3179L);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testOverrideValueWithHeader() throws Exception {
++ Object body = new Object();
++ endpoint.expectedBodiesReceived(body);
++ producer1.sendBodyAndHeader(body, HEADER_METER_MARK, 9926L);
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).meter("A");
++ inOrder.verify(mockMeter, times(1)).mark(9926L);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testValueNoSetInUriOverrideWithHeader() throws Exception {
++ Object body = new Object();
++ endpoint.expectedBodiesReceived(body);
++ producer2.sendBodyAndHeader(body, HEADER_METER_MARK, 7707370L);
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).meter("A");
++ inOrder.verify(mockMeter, times(1)).mark(7707370L);
++ inOrder.verifyNoMoreInteractions();
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
index 0000000,0000000..cb3232f
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
@@@ -1,0 -1,0 +1,75 @@@
++package org.apache.camel.metrics.timer;
++
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.MatcherAssert.assertThat;
++import static org.hamcrest.Matchers.instanceOf;
++import static org.hamcrest.Matchers.notNullValue;
++import static org.hamcrest.Matchers.nullValue;
++
++import org.apache.camel.Producer;
++import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
++import org.junit.After;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mock;
++import org.mockito.Mockito;
++import org.mockito.runners.MockitoJUnitRunner;
++
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(MockitoJUnitRunner.class)
++public class TimerEndpointTest {
++
++ private static final String METRICS_NAME = "metrics.name";
++
++ @Mock
++ private MetricRegistry registry;
++
++ private TimerEndpoint endpoint;
++
++ private InOrder inOrder;
++
++ @Before
++ public void setUp() throws Exception {
++ endpoint = new TimerEndpoint(registry, METRICS_NAME);
++ inOrder = Mockito.inOrder(registry);
++ }
++
++ @After
++ public void tearDown() throws Exception {
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testTimerEndpoint() throws Exception {
++ assertThat(endpoint, is(notNullValue()));
++ assertThat(endpoint.getRegistry(), is(registry));
++ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
++ }
++
++ @Test
++ public void testCreateProducer() throws Exception {
++ Producer producer = endpoint.createProducer();
++ assertThat(producer, is(notNullValue()));
++ assertThat(producer, is(instanceOf(TimerProducer.class)));
++ }
++
++ @Test
++ public void testGetAction() throws Exception {
++ assertThat(endpoint.getAction(), is(nullValue()));
++ }
++
++ @Test
++ public void testSetAction() throws Exception {
++ assertThat(endpoint.getAction(), is(nullValue()));
++ endpoint.setAction(TimerAction.start);
++ assertThat(endpoint.getAction(), is(TimerAction.start));
++ }
++
++ @Test
++ public void testCreateEndpointUri() throws Exception {
++ assertThat(endpoint.createEndpointUri(), is(TimerEndpoint.ENDPOINT_URI));
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
index 0000000,0000000..ff7c1f6
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
@@@ -1,0 -1,0 +1,215 @@@
++package org.apache.camel.metrics.timer;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.MatcherAssert.assertThat;
++import static org.hamcrest.Matchers.notNullValue;
++import static org.hamcrest.Matchers.nullValue;
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.when;
++
++import org.apache.camel.Exchange;
++import org.apache.camel.Message;
++import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mock;
++import org.mockito.Mockito;
++import org.mockito.runners.MockitoJUnitRunner;
++
++import com.codahale.metrics.MetricRegistry;
++import com.codahale.metrics.Timer;
++
++@RunWith(MockitoJUnitRunner.class)
++public class TimerProducerTest {
++
++ private static final String METRICS_NAME = "metrics.name";
++ private static final String PROPERTY_NAME = TimerEndpoint.ENDPOINT_URI + ":" + METRICS_NAME;
++
++ @Mock
++ private TimerEndpoint endpoint;
++
++ @Mock
++ private Exchange exchange;
++
++ @Mock
++ private MetricRegistry registry;
++
++ @Mock
++ private Timer timer;
++
++ @Mock
++ private Timer.Context context;
++
++ @Mock
++ private Message in;
++
++ private TimerProducer producer;
++
++ @Mock
++ private InOrder inOrder;
++
++ @Before
++ public void setUp() throws Exception {
++ producer = new TimerProducer(endpoint);
++ inOrder = Mockito.inOrder(endpoint, exchange, registry, timer, context, in);
++ when(endpoint.getRegistry()).thenReturn(registry);
++ when(registry.timer(METRICS_NAME)).thenReturn(timer);
++ when(timer.time()).thenReturn(context);
++ when(exchange.getIn()).thenReturn(in);
++ }
++
++ @Test
++ public void testTimerProducer() throws Exception {
++ assertThat(producer, is(notNullValue()));
++ assertThat(producer.getEndpoint().equals(endpoint), is(true));
++ }
++
++ @Test
++ public void testProcessStart() throws Exception {
++ when(endpoint.getAction()).thenReturn(TimerAction.start);
++ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class)).thenReturn(TimerAction.start);
++ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(endpoint, times(1)).getAction();
++ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class);
++ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
++ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
++ inOrder.verify(timer, times(1)).time();
++ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessStartWithOverride() throws Exception {
++ when(endpoint.getAction()).thenReturn(TimerAction.start);
++ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class)).thenReturn(TimerAction.stop);
++ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(endpoint, times(1)).getAction();
++ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class);
++ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
++ inOrder.verify(context, times(1)).stop();
++ inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessStop() throws Exception {
++ when(endpoint.getAction()).thenReturn(TimerAction.stop);
++ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class)).thenReturn(TimerAction.stop);
++ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(endpoint, times(1)).getAction();
++ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class);
++ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
++ inOrder.verify(context, times(1)).stop();
++ inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessStopWithOverride() throws Exception {
++ when(endpoint.getAction()).thenReturn(TimerAction.stop);
++ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class)).thenReturn(TimerAction.start);
++ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(endpoint, times(1)).getAction();
++ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class);
++ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
++ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
++ inOrder.verify(timer, times(1)).time();
++ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessNoAction() throws Exception {
++ when(endpoint.getAction()).thenReturn(null);
++ when(in.getHeader(HEADER_TIMER_ACTION, null, TimerAction.class)).thenReturn(null);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(endpoint, times(1)).getAction();
++ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, null, TimerAction.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessNoActionOverride() throws Exception {
++ when(endpoint.getAction()).thenReturn(null);
++ when(in.getHeader(HEADER_TIMER_ACTION, null, TimerAction.class)).thenReturn(TimerAction.start);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(endpoint, times(1)).getAction();
++ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, null, TimerAction.class);
++ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
++ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
++ inOrder.verify(timer, times(1)).time();
++ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testHandleStart() throws Exception {
++ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
++ producer.handleStart(exchange, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
++ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
++ inOrder.verify(timer, times(1)).time();
++ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testHandleStartAlreadyRunning() throws Exception {
++ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
++ producer.handleStart(exchange, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testHandleStop() throws Exception {
++ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
++ producer.handleStop(exchange, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
++ inOrder.verify(context, times(1)).stop();
++ inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testHandleStopContextNotFound() throws Exception {
++ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
++ producer.handleStop(exchange, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetPropertyName() throws Exception {
++ assertThat(producer.getPropertyName(METRICS_NAME), is(TimerEndpoint.ENDPOINT_URI + ":" + METRICS_NAME));
++ }
++
++ @Test
++ public void testGetTimerContextFromExchange() throws Exception {
++ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
++ assertThat(producer.getTimerContextFromExchange(exchange, PROPERTY_NAME), is(context));
++ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetTimerContextFromExchangeNotFound() throws Exception {
++ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
++ assertThat(producer.getTimerContextFromExchange(exchange, PROPERTY_NAME), is(nullValue()));
++ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
index 0000000,0000000..1a6581c
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
@@@ -1,0 -1,0 +1,130 @@@
++package org.apache.camel.metrics.timer;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
++import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
++import static org.mockito.Mockito.reset;
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.when;
++
++import org.apache.camel.EndpointInject;
++import org.apache.camel.Produce;
++import org.apache.camel.ProducerTemplate;
++import org.apache.camel.builder.RouteBuilder;
++import org.apache.camel.component.mock.MockEndpoint;
++import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
++import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
++import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
++import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
++import org.apache.camel.test.spring.MockEndpoints;
++import org.junit.After;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mockito;
++import org.springframework.context.annotation.Bean;
++import org.springframework.context.annotation.Configuration;
++import org.springframework.test.context.ContextConfiguration;
++
++import com.codahale.metrics.MetricRegistry;
++import com.codahale.metrics.Timer;
++
++@RunWith(CamelSpringJUnit4ClassRunner.class)
++@ContextConfiguration(
++ classes = { TimerRouteTest.TestConfig.class },
++ loader = CamelSpringDelegatingTestContextLoader.class)
++@MockEndpoints
++public class TimerRouteTest {
++
++ @EndpointInject(uri = "mock:out")
++ private MockEndpoint endpoint;
++
++ @Produce(uri = "direct:in-1")
++ private ProducerTemplate producer1;
++
++ @Produce(uri = "direct:in-2")
++ private ProducerTemplate producer2;
++
++ private MetricRegistry mockRegistry;
++
++ private Timer mockTimer;
++
++ private InOrder inOrder;
++
++ @Configuration
++ public static class TestConfig extends SingleRouteCamelConfiguration {
++
++ @Bean
++ @Override
++ public RouteBuilder route() {
++ return new RouteBuilder() {
++
++ @Override
++ public void configure() throws Exception {
++ from("direct:in-1")
++ .to("metrics:timer:A?action=start")
++ .to("mock:out");
++
++ from("direct:in-2")
++ .to("metrics:timer:A")
++ .to("mock:out");
++ }
++ };
++ }
++
++ @Bean(name = METRIC_REGISTRY_NAME)
++ public MetricRegistry getMetricRegistry() {
++ return Mockito.mock(MetricRegistry.class);
++ }
++ }
++
++ @Before
++ public void setup() {
++ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
++ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
++ mockTimer = Mockito.mock(Timer.class);
++ inOrder = Mockito.inOrder(mockRegistry, mockTimer);
++ }
++
++ @After
++ public void tearDown() {
++ endpoint.reset();
++ reset(mockRegistry, mockTimer);
++ }
++
++ @Test
++ public void testOverrideMetricsName() throws Exception {
++ when(mockRegistry.timer("B")).thenReturn(mockTimer);
++
++ Object body = new Object();
++ endpoint.expectedBodiesReceived(body);
++ producer1.sendBodyAndHeader(body, HEADER_METRIC_NAME, "B");
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).timer("B");
++ inOrder.verify(mockTimer, times(1)).time();
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testOverrideExistingAction() throws Exception {
++ when(mockRegistry.timer("A")).thenReturn(mockTimer);
++ Object body = new Object();
++ endpoint.expectedBodiesReceived(body);
++ producer1.sendBodyAndHeader(body, HEADER_TIMER_ACTION, TimerAction.stop);
++ endpoint.assertIsSatisfied();
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testOverrideNoAction() throws Exception {
++ when(mockRegistry.timer("A")).thenReturn(mockTimer);
++ Object body = new Object();
++ endpoint.expectedBodiesReceived(body);
++ producer2.sendBodyAndHeader(body, HEADER_TIMER_ACTION, TimerAction.start);
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).timer("A");
++ inOrder.verify(mockTimer, times(1)).time();
++ inOrder.verifyNoMoreInteractions();
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/resources/log4j.properties
index 0000000,0000000..3b1bd38
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/resources/log4j.properties
@@@ -1,0 -1,0 +1,14 @@@
++#
++# The logging properties used
++#
++log4j.rootLogger=INFO, out
++
++# uncomment the following line to turn on Camel debugging
++#log4j.logger.org.apache.camel=DEBUG
++
++# CONSOLE appender not used by default
++log4j.appender.out=org.apache.log4j.ConsoleAppender
++log4j.appender.out.layout=org.apache.log4j.PatternLayout
++log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
++#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
++
[20/34] git commit: CAMEL-7554 - camel-metrics
Posted by da...@apache.org.
CAMEL-7554 - camel-metrics
* Compliance with Checkstyle rules.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4ea79b19
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4ea79b19
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4ea79b19
Branch: refs/heads/master
Commit: 4ea79b197bf3413f72195814ac704aaf7e628702
Parents: 5068b9c
Author: Lauri Kimmel <la...@gmx.com>
Authored: Thu Jul 3 22:31:11 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Thu Jul 3 22:31:11 2014 +1000
----------------------------------------------------------------------
.../camel/metrics/AbstractMetricsEndpoint.java | 18 ++++++-
.../camel/metrics/AbstractMetricsProducer.java | 29 ++++++++---
.../apache/camel/metrics/MetricsComponent.java | 53 ++++++++++++--------
.../org/apache/camel/metrics/MetricsType.java | 24 +++++++--
.../camel/metrics/counter/CounterEndpoint.java | 18 ++++++-
.../camel/metrics/counter/CounterProducer.java | 30 ++++++++---
.../metrics/histogram/HistogramEndpoint.java | 20 +++++++-
.../metrics/histogram/HistogramProducer.java | 26 +++++++---
.../camel/metrics/meter/MeterEndpoint.java | 18 ++++++-
.../camel/metrics/meter/MeterProducer.java | 27 +++++++---
.../camel/metrics/timer/TimerEndpoint.java | 19 ++++++-
.../camel/metrics/timer/TimerProducer.java | 38 ++++++++------
.../metrics/AbstractMetricsEndpointTest.java | 31 ++++++++----
.../metrics/AbstractMetricsProducerTest.java | 34 +++++++++----
.../metrics/MetricComponentSpringTest.java | 26 +++++++---
.../metrics/MetricsComponentRouteTest.java | 24 +++++++--
.../camel/metrics/MetricsComponentTest.java | 35 +++++++++----
.../apache/camel/metrics/MetricsTypeTest.java | 22 ++++++--
.../metrics/counter/CounterEndpointTest.java | 30 ++++++++---
.../metrics/counter/CounterProducerTest.java | 34 +++++++++----
.../camel/metrics/counter/CounterRouteTest.java | 38 +++++++++-----
.../histogram/HistogramEndpointTest.java | 28 ++++++++---
.../histogram/HistogramProducerTest.java | 32 ++++++++----
.../metrics/histogram/HistogramRouteTest.java | 34 +++++++++----
.../camel/metrics/meter/MeterEndpointTest.java | 30 ++++++++---
.../camel/metrics/meter/MeterProducerTest.java | 34 +++++++++----
.../camel/metrics/meter/MeterRouteTest.java | 34 +++++++++----
.../camel/metrics/timer/TimerEndpointTest.java | 30 ++++++++---
.../camel/metrics/timer/TimerProducerTest.java | 36 +++++++++----
.../camel/metrics/timer/TimerRouteTest.java | 34 +++++++++----
30 files changed, 653 insertions(+), 233 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
index d8c8af7..f437846 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
@@ -1,11 +1,27 @@
+/**
+ * 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.metrics;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.impl.DefaultEndpoint;
-import com.codahale.metrics.MetricRegistry;
public abstract class AbstractMetricsEndpoint extends DefaultEndpoint {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
index 8bf99d0..cd11447 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
@@ -1,16 +1,31 @@
+/**
+ * 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.metrics;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_PERFIX;
-
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_PERFIX;
-import com.codahale.metrics.MetricRegistry;
public abstract class AbstractMetricsProducer<T extends AbstractMetricsEndpoint> extends DefaultProducer {
@@ -31,9 +46,9 @@ public abstract class AbstractMetricsProducer<T extends AbstractMetricsEndpoint>
MetricRegistry registry = endpoint.getRegistry();
try {
doProcess(exchange, endpoint, registry, finalMetricsName);
- }
- catch (Exception e) {
- LOG.warn("Failed to produce metrics for {} in {} - {}", new Object[] { finalMetricsName, getClass().getSimpleName(), e.getMessage() });
+ } catch (Exception e) {
+ LOG.warn("Failed to produce metrics for {} in {} - {}", new Object[] {
+ finalMetricsName, getClass().getSimpleName(), e.getMessage() });
}
clearMetricsHeaders(in);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index 596b08b..b73626a 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -1,8 +1,25 @@
+/**
+ * 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.metrics;
import java.util.Map;
import java.util.concurrent.TimeUnit;
-
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Slf4jReporter;
import org.apache.camel.Endpoint;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.impl.DefaultComponent;
@@ -15,9 +32,6 @@ import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Slf4jReporter;
-
/**
* Represents the component that manages {@link MetricsEndpoint}.
*/
@@ -60,20 +74,20 @@ public class MetricsComponent extends DefaultComponent {
Endpoint createNewEndpoint(MetricRegistry registry, MetricsType type, String metricsName) {
Endpoint endpoint;
switch (type) {
- case COUNTER:
- endpoint = new CounterEndpoint(registry, metricsName);
- break;
- case METER:
- endpoint = new MeterEndpoint(registry, metricsName);
- break;
- case HISTOGRAM:
- endpoint = new HistogramEndpoint(registry, metricsName);
- break;
- case TIMER:
- endpoint = new TimerEndpoint(registry, metricsName);
- break;
- default:
- throw new RuntimeCamelException("Metrics type \"" + type.toString() + "\" not supported");
+ case COUNTER:
+ endpoint = new CounterEndpoint(registry, metricsName);
+ break;
+ case METER:
+ endpoint = new MeterEndpoint(registry, metricsName);
+ break;
+ case HISTOGRAM:
+ endpoint = new HistogramEndpoint(registry, metricsName);
+ break;
+ case TIMER:
+ endpoint = new TimerEndpoint(registry, metricsName);
+ break;
+ default:
+ throw new RuntimeCamelException("Metrics type \"" + type.toString() + "\" not supported");
}
return endpoint;
}
@@ -83,8 +97,7 @@ public class MetricsComponent extends DefaultComponent {
MetricsType type;
if (name == null) {
type = DEFAULT_METRICS_TYPE;
- }
- else {
+ } else {
type = MetricsType.getByName(name);
}
if (type == null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java
index f602647..760c794 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java
@@ -1,3 +1,19 @@
+/**
+ * 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.metrics;
import java.util.EnumSet;
@@ -10,15 +26,15 @@ public enum MetricsType {
COUNTER("counter"),
HISTOGRAM("histogram"),
METER("meter"),
- TIMER("timer"), ;
+ TIMER("timer");
- private static final Map<String, MetricsType> map = new HashMap<String, MetricsType>();
+ private static final Map<String, MetricsType> MAP = new HashMap<String, MetricsType>();
private final String name;
static {
for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
- map.put(type.name, type);
+ MAP.put(type.name, type);
}
}
@@ -32,6 +48,6 @@ public enum MetricsType {
}
public static MetricsType getByName(String name) {
- return map.get(name);
+ return MAP.get(name);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
index 508e485..406c21d 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
@@ -1,11 +1,27 @@
+/**
+ * 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.metrics.counter;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Producer;
import org.apache.camel.metrics.AbstractMetricsEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
-import com.codahale.metrics.MetricRegistry;
@UriEndpoint(scheme = "metrics")
public class CounterEndpoint extends AbstractMetricsEndpoint {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
index 2d9431c..bdabba3 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
@@ -1,14 +1,30 @@
+/**
+ * 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.metrics.counter;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.metrics.AbstractMetricsProducer;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.MetricRegistry;
public class CounterProducer extends AbstractMetricsProducer<CounterEndpoint> {
@@ -26,11 +42,9 @@ public class CounterProducer extends AbstractMetricsProducer<CounterEndpoint> {
Long finalDecrement = getLongHeader(in, HEADER_COUNTER_DECREMENT, decrement);
if (finalIncrement != null) {
counter.inc(finalIncrement);
- }
- else if (finalDecrement != null) {
+ } else if (finalDecrement != null) {
counter.dec(finalDecrement);
- }
- else {
+ } else {
counter.inc();
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
index c6e7157..fad53c0 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
@@ -1,16 +1,32 @@
+/**
+ * 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.metrics.histogram;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Producer;
import org.apache.camel.metrics.AbstractMetricsEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
-import com.codahale.metrics.MetricRegistry;
@UriEndpoint(scheme = "metrics")
public class HistogramEndpoint extends AbstractMetricsEndpoint {
- public static String ENDPOINT_URI = "metrics:histogram";
+ public static final String ENDPOINT_URI = "metrics:histogram";
@UriParam
private Long value;
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
index 46c586d..b29505a 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
@@ -1,15 +1,30 @@
+/**
+ * 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.metrics.histogram;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.metrics.AbstractMetricsProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.MetricRegistry;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
public class HistogramProducer extends AbstractMetricsProducer<HistogramEndpoint> {
@@ -27,8 +42,7 @@ public class HistogramProducer extends AbstractMetricsProducer<HistogramEndpoint
Long finalValue = getLongHeader(in, HEADER_HISTOGRAM_VALUE, value);
if (finalValue != null) {
histogram.update(finalValue);
- }
- else {
+ } else {
LOG.warn("Cannot update histogram \"{}\" with null value", metricsName);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
index 82c7187..84c6316 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
@@ -1,11 +1,27 @@
+/**
+ * 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.metrics.meter;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Producer;
import org.apache.camel.metrics.AbstractMetricsEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
-import com.codahale.metrics.MetricRegistry;
@UriEndpoint(scheme = "metrics")
public class MeterEndpoint extends AbstractMetricsEndpoint {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
index 7622112..686b198 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
@@ -1,13 +1,27 @@
+/**
+ * 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.metrics.meter;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
-
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.metrics.AbstractMetricsProducer;
-
-import com.codahale.metrics.Meter;
-import com.codahale.metrics.MetricRegistry;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
public class MeterProducer extends AbstractMetricsProducer<MeterEndpoint> {
@@ -23,8 +37,7 @@ public class MeterProducer extends AbstractMetricsProducer<MeterEndpoint> {
Long finalMark = getLongHeader(in, HEADER_METER_MARK, mark);
if (finalMark == null) {
meter.mark();
- }
- else {
+ } else {
meter.mark(finalMark);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
index 7b534c4..10bc25f 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
@@ -1,12 +1,27 @@
+/**
+ * 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.metrics.timer;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Producer;
import org.apache.camel.metrics.AbstractMetricsEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
-import com.codahale.metrics.MetricRegistry;
-
@UriEndpoint(scheme = "metrics")
public class TimerEndpoint extends AbstractMetricsEndpoint {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
index 9586bbd..d12726e 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
@@ -1,17 +1,31 @@
+/**
+ * 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.metrics.timer;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
-import static org.apache.camel.metrics.timer.TimerEndpoint.ENDPOINT_URI;
-
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.metrics.AbstractMetricsProducer;
import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Timer;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
+import static org.apache.camel.metrics.timer.TimerEndpoint.ENDPOINT_URI;
public class TimerProducer extends AbstractMetricsProducer<TimerEndpoint> {
@@ -28,11 +42,9 @@ public class TimerProducer extends AbstractMetricsProducer<TimerEndpoint> {
TimerAction finalAction = in.getHeader(HEADER_TIMER_ACTION, action, TimerAction.class);
if (finalAction == TimerAction.start) {
handleStart(exchange, registry, metricsName);
- }
- else if (finalAction == TimerAction.stop) {
+ } else if (finalAction == TimerAction.stop) {
handleStop(exchange, registry, metricsName);
- }
- else {
+ } else {
LOG.warn("No action provided for timer \"{}\"", metricsName);
}
}
@@ -44,8 +56,7 @@ public class TimerProducer extends AbstractMetricsProducer<TimerEndpoint> {
Timer timer = registry.timer(metricsName);
context = timer.time();
exchange.setProperty(propertyName, context);
- }
- else {
+ } else {
LOG.warn("Timer \"{}\" already running", metricsName);
}
}
@@ -56,8 +67,7 @@ public class TimerProducer extends AbstractMetricsProducer<TimerEndpoint> {
if (context != null) {
context.stop();
exchange.removeProperty(propertyName);
- }
- else {
+ } else {
LOG.warn("Timer \"{}\" not found", metricsName);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
index 1a7543e..a4e1218 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
@@ -1,9 +1,22 @@
+/**
+ * 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.metrics;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.when;
-
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
@@ -17,18 +30,14 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import com.codahale.metrics.MetricRegistry;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class AbstractMetricsEndpointTest {
private static final String METRICS_NAME = "metrics.name";
- private static final String HEADER = "header";
- private static final String STRING_VALUE = "string-value";
- private static final String DEFAULT_STRING_VALUE = "default-value";
- private static final Long LONG_VALUE = System.currentTimeMillis();
- private static final Long DEFAULT_LONG_VALUE = -10101L;
@Mock
private MetricRegistry registry;
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
index 3435247..b740634 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
@@ -1,13 +1,22 @@
+/**
+ * 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.metrics;
-import static org.apache.camel.metrics.AbstractMetricsProducer.HEADER_PATTERN;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.impl.DefaultMessage;
@@ -18,8 +27,13 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import com.codahale.metrics.MetricRegistry;
+import static org.apache.camel.metrics.AbstractMetricsProducer.HEADER_PATTERN;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class AbstractMetricsProducerTest {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
index a6590c5..417cab6 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
@@ -1,8 +1,23 @@
+/**
+ * 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.metrics;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
@@ -19,9 +34,8 @@ import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.MetricRegistry;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
index 4ef44f3..09270c1 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
@@ -1,19 +1,33 @@
+/**
+ * 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.metrics;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_PERFIX;
-
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_PERFIX;
public class MetricsComponentRouteTest extends CamelTestSupport {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
index 74d91c2..8fd02ce 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
@@ -1,17 +1,25 @@
+/**
+ * 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.metrics;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
-
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.RuntimeCamelException;
@@ -27,8 +35,13 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import com.codahale.metrics.MetricRegistry;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class MetricsComponentTest {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
index 2d0d28d..9a3129a 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
@@ -1,11 +1,25 @@
+/**
+ * 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.metrics;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
import java.util.EnumSet;
-
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
public class MetricsTypeTest {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
index 8f713a2..0d5c015 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
@@ -1,11 +1,22 @@
+/**
+ * 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.metrics.counter;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Producer;
import org.junit.After;
import org.junit.Before;
@@ -15,8 +26,11 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import com.codahale.metrics.MetricRegistry;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
@RunWith(MockitoJUnitRunner.class)
public class CounterEndpointTest {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
index 6351814..e33429d 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
@@ -1,12 +1,23 @@
+/**
+ * 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.metrics.counter;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.junit.Before;
@@ -16,9 +27,12 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.MetricRegistry;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class CounterProducerTest {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
index 844401e..246f11e 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
@@ -1,17 +1,26 @@
+/**
+ * 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.metrics.counter;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
import java.util.HashMap;
import java.util.Map;
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
@@ -30,9 +39,14 @@ import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.MetricRegistry;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
index 3ba9ea1..688337b 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
@@ -1,10 +1,22 @@
+/**
+ * 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.metrics.histogram;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Producer;
import org.junit.After;
import org.junit.Before;
@@ -14,8 +26,10 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import com.codahale.metrics.MetricRegistry;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
@RunWith(MockitoJUnitRunner.class)
public class HistogramEndpointTest {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
index 8fe1e06..4513027 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
@@ -1,11 +1,23 @@
+/**
+ * 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.metrics.histogram;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.junit.Before;
@@ -15,9 +27,11 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.MetricRegistry;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class HistogramProducerTest {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
index cc01a1d..a06cd22 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
@@ -1,12 +1,23 @@
+/**
+ * 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.metrics.histogram;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
@@ -25,9 +36,12 @@ import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
-
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.MetricRegistry;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
index 3779da9..73935fa 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
@@ -1,11 +1,22 @@
+/**
+ * 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.metrics.meter;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Producer;
import org.junit.After;
import org.junit.Before;
@@ -15,8 +26,11 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import com.codahale.metrics.MetricRegistry;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
@RunWith(MockitoJUnitRunner.class)
public class MeterEndpointTest {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
index 66dcce2..7c9c47b 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
@@ -1,12 +1,23 @@
+/**
+ * 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.metrics.meter;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.junit.Before;
@@ -16,9 +27,12 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import com.codahale.metrics.Meter;
-import com.codahale.metrics.MetricRegistry;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class MeterProducerTest {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
index 6bd5b59..a8de5ea 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
@@ -1,12 +1,23 @@
+/**
+ * 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.metrics.meter;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
@@ -25,9 +36,12 @@ import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
-
-import com.codahale.metrics.Meter;
-import com.codahale.metrics.MetricRegistry;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
index cb3232f..82c9213 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
@@ -1,11 +1,22 @@
+/**
+ * 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.metrics.timer;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-
+import com.codahale.metrics.MetricRegistry;
import org.apache.camel.Producer;
import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
import org.junit.After;
@@ -16,8 +27,11 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import com.codahale.metrics.MetricRegistry;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
@RunWith(MockitoJUnitRunner.class)
public class TimerEndpointTest {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
index ff7c1f6..3a2c364 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
@@ -1,13 +1,23 @@
+/**
+ * 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.metrics.timer;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
@@ -18,9 +28,13 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Timer;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class TimerProducerTest {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ea79b19/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
index 1a6581c..4dab66a 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
@@ -1,12 +1,23 @@
+/**
+ * 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.metrics.timer;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
-import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
@@ -26,9 +37,12 @@ import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
-
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Timer;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
+import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(
[11/34] git commit: Configuration for Travis CI.
Posted by da...@apache.org.
Configuration for Travis CI.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f4d87714
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f4d87714
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f4d87714
Branch: refs/heads/master
Commit: f4d877141a9fdaa4194039c55dd7de69dd8aa254
Parents: 6a006eb
Author: Lauri Kimmel <la...@gmx.com>
Authored: Thu May 29 23:16:53 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Mon Jun 16 21:04:20 2014 +1000
----------------------------------------------------------------------
.travis.yml | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f4d87714/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..d99f43b
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+language: java
+jdk:
+ - oraclejdk7
+ - openjdk7
+ - openjdk6
[10/34] git commit: Improved exception and header handling.
Posted by da...@apache.org.
Improved exception and header handling.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6a006eba
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6a006eba
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6a006eba
Branch: refs/heads/master
Commit: 6a006eba25fbb9357b8eece030ef0956938aa641
Parents: 3fe1d6c
Author: Lauri Kimmel <la...@gmx.com>
Authored: Wed May 28 23:55:40 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Mon Jun 16 21:02:52 2014 +1000
----------------------------------------------------------------------
README.md | 61 ++++---
.../camel/metrics/AbstractMetricsEndpoint.java | 18 --
.../camel/metrics/AbstractMetricsProducer.java | 59 +++++++
.../apache/camel/metrics/MetricsComponent.java | 9 +-
.../camel/metrics/counter/CounterProducer.java | 20 +--
.../metrics/histogram/HistogramProducer.java | 16 +-
.../camel/metrics/meter/MeterProducer.java | 12 +-
.../camel/metrics/timer/TimerProducer.java | 12 +-
.../metrics/AbstractMetricsEndpointTest.java | 65 -------
.../metrics/AbstractMetricsProducerTest.java | 172 +++++++++++++++++++
.../metrics/MetricsComponentRouteTest.java | 42 ++++-
.../metrics/counter/CounterProducerTest.java | 119 +++++++------
.../camel/metrics/counter/CounterRouteTest.java | 14 +-
.../histogram/HistogramProducerTest.java | 44 ++---
.../camel/metrics/meter/MeterProducerTest.java | 9 +-
.../camel/metrics/timer/TimerProducerTest.java | 13 +-
16 files changed, 418 insertions(+), 267 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 296b2f3..2a99a44 100644
--- a/README.md
+++ b/README.md
@@ -72,6 +72,9 @@ from("direct:in")
will update counter with name ```new.name``` instead of ```name.not.used```.
+All Metrics specific headers are removed from the message once Metrics endpoint finishes processing of exchange.
+While processing exchange Metrics endpoint will catch all exceptions and write log entry using level warn.
+
## Metrics type counter
@@ -133,34 +136,6 @@ from("direct:in")
```
-## Metric type meter
-
-```
-metrics:meter:metricname[?options]
-```
-
-Where options are
-
-| Name | Default | Description |
-|------|---------|---------------------------|
-| mark | | long value to use as mark |
-
-If ```mark``` is not set ```meter.mark()``` is called without argument.
-
-```java
-// marks simple.meter without value
-from("direct:in")
- .to("metric:simple.meter")
- .to("direct:out")
-```
-
-```java
-// marks simple.meter with value 81
-from("direct:in")
- .to("metric:meter:simple.meter?mark=81")
- .to("direct:out")
-```
-
## Metric type histogram
```
@@ -203,6 +178,36 @@ from("direct:in")
.to("direct:out")
```
+
+## Metric type meter
+
+```
+metrics:meter:metricname[?options]
+```
+
+Where options are
+
+| Name | Default | Description |
+|------|---------|---------------------------|
+| mark | | long value to use as mark |
+
+If ```mark``` is not set ```meter.mark()``` is called without argument.
+
+```java
+// marks simple.meter without value
+from("direct:in")
+ .to("metric:simple.meter")
+ .to("direct:out")
+```
+
+```java
+// marks simple.meter with value 81
+from("direct:in")
+ .to("metric:meter:simple.meter?mark=81")
+ .to("direct:out")
+```
+
+
## Metrics type timer
```
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java b/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
index 9560758..d8c8af7 100644
--- a/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
+++ b/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
@@ -1,12 +1,9 @@
package org.apache.camel.metrics;
import org.apache.camel.Consumer;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.camel.util.ObjectHelper;
import com.codahale.metrics.MetricRegistry;
@@ -37,19 +34,4 @@ public abstract class AbstractMetricsEndpoint extends DefaultEndpoint {
public String getMetricsName() {
return metricsName;
}
-
- public String getMetricsName(Exchange exchange) {
- return getStringHeader(exchange, MetricsComponent.HEADER_METRIC_NAME, metricsName);
- }
-
- public String getStringHeader(Exchange exchange, String header, String defaultValue) {
- Message in = exchange.getIn();
- String headerValue = in.getHeader(header, String.class);
- return ObjectHelper.isNotEmpty(headerValue) ? headerValue : defaultValue;
- }
-
- public Long getLongHeader(Exchange exchange, String header, Long defaultValue) {
- Message in = exchange.getIn();
- return in.getHeader(header, defaultValue, Long.class);
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java b/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
new file mode 100644
index 0000000..24149af
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
@@ -0,0 +1,59 @@
+package org.apache.camel.metrics;
+
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_PERFIX;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.codahale.metrics.MetricRegistry;
+
+public abstract class AbstractMetricsProducer<T extends AbstractMetricsEndpoint> extends DefaultProducer {
+
+ public static final String HEADER_PATTERN = HEADER_PERFIX + "*";
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractMetricsProducer.class);
+
+ public AbstractMetricsProducer(T endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ @SuppressWarnings("unchecked")
+ T endpoint = (T) getEndpoint();
+ Message in = exchange.getIn();
+ String defaultMetricsName = endpoint.getMetricsName();
+ String finalMetricsName = getMetricsName(in, defaultMetricsName);
+ MetricRegistry registry = endpoint.getRegistry();
+ try {
+ doProcess(exchange, endpoint, registry, finalMetricsName);
+ }
+ catch (Exception e) {
+ LOG.warn("Failed to produce metrics for {} in {} - {}", finalMetricsName, getClass().getSimpleName(), e.getMessage());
+ }
+ clearMetricsHeaders(in);
+ }
+
+ protected abstract void doProcess(Exchange exchange, T endpoint, MetricRegistry registry, String metricsName) throws Exception;
+
+ public String getMetricsName(Message in, String defaultValue) {
+ return getStringHeader(in, HEADER_METRIC_NAME, defaultValue);
+ }
+
+ public String getStringHeader(Message in, String header, String defaultValue) {
+ String headerValue = in.getHeader(header, String.class);
+ return ObjectHelper.isNotEmpty(headerValue) ? headerValue : defaultValue;
+ }
+
+ public Long getLongHeader(Message in, String header, Long defaultValue) {
+ return in.getHeader(header, defaultValue, Long.class);
+ }
+
+ protected boolean clearMetricsHeaders(Message in) {
+ return in.removeHeaders(HEADER_PATTERN);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index c129c07..1ff175d 100644
--- a/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -26,10 +26,11 @@ public class MetricsComponent extends DefaultComponent {
public static final String METRIC_REGISTRY_NAME = "metricRegistry";
public static final MetricsType DEFAULT_METRICS_TYPE = MetricsType.METER;
public static final long DEFAULT_REPORTING_INTERVAL_SECONDS = 60L;
- public static final String HEADER_METRIC_NAME = "CamelMetricsName";
- public static final String HEADER_COUNTER_INCREMENT = "CamelMetricsCounterIncrement";
- public static final String HEADER_COUNTER_DECREMENT = "CamelMetricsCounterDecrement";
- public static final String HEADER_HISTOGRAM_VALUE = "CamelMetricsHistogramValue";
+ public static final String HEADER_PERFIX = "CamelMetrics";
+ public static final String HEADER_METRIC_NAME = HEADER_PERFIX + "Name";
+ public static final String HEADER_COUNTER_INCREMENT = HEADER_PERFIX + "CounterIncrement";
+ public static final String HEADER_COUNTER_DECREMENT = HEADER_PERFIX + "CounterDecrement";
+ public static final String HEADER_HISTOGRAM_VALUE = HEADER_PERFIX + "HistogramValue";
private static final Logger LOG = LoggerFactory.getLogger(MetricsComponent.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java b/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
index e7db514..2d9431c 100644
--- a/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
+++ b/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
@@ -3,27 +3,27 @@ package org.apache.camel.metrics.counter;
import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
-import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.Message;
+import org.apache.camel.metrics.AbstractMetricsProducer;
import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
-public class CounterProducer extends DefaultProducer {
+public class CounterProducer extends AbstractMetricsProducer<CounterEndpoint> {
- public CounterProducer(Endpoint endpoint) {
+ public CounterProducer(CounterEndpoint endpoint) {
super(endpoint);
}
@Override
- public void process(Exchange exchange) throws Exception {
- CounterEndpoint endpoint = (CounterEndpoint) getEndpoint();
- String metricName = endpoint.getMetricsName(exchange);
- Counter counter = endpoint.getRegistry().counter(metricName);
+ protected void doProcess(Exchange exchange, CounterEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ Message in = exchange.getIn();
+ Counter counter = registry.counter(metricsName);
Long increment = endpoint.getIncrement();
Long decrement = endpoint.getDecrement();
- Long finalIncrement = endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, increment);
- Long finalDecrement = endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, decrement);
+ Long finalIncrement = getLongHeader(in, HEADER_COUNTER_INCREMENT, increment);
+ Long finalDecrement = getLongHeader(in, HEADER_COUNTER_DECREMENT, decrement);
if (finalIncrement != null) {
counter.inc(finalIncrement);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java b/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
index bd701c0..46c586d 100644
--- a/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
+++ b/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
@@ -2,31 +2,29 @@ package org.apache.camel.metrics.histogram;
import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.Message;
+import org.apache.camel.metrics.AbstractMetricsProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.MetricRegistry;
-public class HistogramProducer extends DefaultProducer {
+public class HistogramProducer extends AbstractMetricsProducer<HistogramEndpoint> {
private static final Logger LOG = LoggerFactory.getLogger(HistogramProducer.class);
- public HistogramProducer(Endpoint endpoint) {
+ public HistogramProducer(HistogramEndpoint endpoint) {
super(endpoint);
}
@Override
- public void process(Exchange exchange) throws Exception {
- HistogramEndpoint endpoint = (HistogramEndpoint) getEndpoint();
- MetricRegistry registry = endpoint.getRegistry();
- String metricsName = endpoint.getMetricsName(exchange);
+ protected void doProcess(Exchange exchange, HistogramEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ Message in = exchange.getIn();
Histogram histogram = registry.histogram(metricsName);
Long value = endpoint.getValue();
- Long finalValue = endpoint.getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, value);
+ Long finalValue = getLongHeader(in, HEADER_HISTOGRAM_VALUE, value);
if (finalValue != null) {
histogram.update(finalValue);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java b/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
index 0de6ba5..5777134 100644
--- a/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
+++ b/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
@@ -1,23 +1,19 @@
package org.apache.camel.metrics.meter;
-import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.metrics.AbstractMetricsProducer;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
-public class MeterProducer extends DefaultProducer {
+public class MeterProducer extends AbstractMetricsProducer<MeterEndpoint> {
- public MeterProducer(Endpoint endpoint) {
+ public MeterProducer(MeterEndpoint endpoint) {
super(endpoint);
}
@Override
- public void process(Exchange exchange) throws Exception {
- MeterEndpoint endpoint = (MeterEndpoint) getEndpoint();
- String metricsName = endpoint.getMetricsName(exchange);
- MetricRegistry registry = endpoint.getRegistry();
+ protected void doProcess(Exchange exchange, MeterEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
Meter meter = registry.meter(metricsName);
Long mark = endpoint.getMark();
if (mark == null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java b/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
index bd8e2b1..4f5b809 100644
--- a/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
+++ b/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
@@ -1,8 +1,7 @@
package org.apache.camel.metrics.timer;
-import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.metrics.AbstractMetricsProducer;
import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -10,19 +9,16 @@ import org.slf4j.LoggerFactory;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
-public class TimerProducer extends DefaultProducer {
+public class TimerProducer extends AbstractMetricsProducer<TimerEndpoint> {
private static final Logger LOG = LoggerFactory.getLogger(TimerProducer.class);
- public TimerProducer(Endpoint endpoint) {
+ public TimerProducer(TimerEndpoint endpoint) {
super(endpoint);
}
@Override
- public void process(Exchange exchange) throws Exception {
- TimerEndpoint endpoint = (TimerEndpoint) getEndpoint();
- MetricRegistry registry = endpoint.getRegistry();
- String metricsName = endpoint.getMetricsName(exchange);
+ protected void doProcess(Exchange exchange, TimerEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
TimerAction action = endpoint.getAction();
if (action == TimerAction.start) {
handleStart(exchange, registry, metricsName);
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java b/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
index 824581c..1a7543e 100644
--- a/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
+++ b/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
@@ -2,7 +2,6 @@ package org.apache.camel.metrics;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
import org.apache.camel.Exchange;
@@ -94,68 +93,4 @@ public class AbstractMetricsEndpointTest {
public void testGetMetricsName() throws Exception {
assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
}
-
- @Test
- public void testGetStringHeaderValue() {
- when(in.getHeader(HEADER, String.class)).thenReturn(STRING_VALUE);
- assertThat(endpoint.getStringHeader(exchange, HEADER, DEFAULT_STRING_VALUE), is(STRING_VALUE));
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(in, times(1)).getHeader(HEADER, String.class);
- }
-
- @Test
- public void testGetStringHeaderValueNotFound() {
- when(in.getHeader(HEADER, String.class)).thenReturn(null);
- assertThat(endpoint.getStringHeader(exchange, HEADER, DEFAULT_STRING_VALUE), is(DEFAULT_STRING_VALUE));
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(in, times(1)).getHeader(HEADER, String.class);
- }
-
- @Test
- public void testGetStringHeaderValueEmptyString() {
- when(in.getHeader(HEADER, String.class)).thenReturn("");
- assertThat(endpoint.getStringHeader(exchange, HEADER, DEFAULT_STRING_VALUE), is(DEFAULT_STRING_VALUE));
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(in, times(1)).getHeader(HEADER, String.class);
- }
-
- @Test
- public void testGetStringHeaderValueWhiteSpaces() {
- when(in.getHeader(HEADER, String.class)).thenReturn(" \n\t\r");
- assertThat(endpoint.getStringHeader(exchange, HEADER, DEFAULT_STRING_VALUE), is(DEFAULT_STRING_VALUE));
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(in, times(1)).getHeader(HEADER, String.class);
- }
-
- @Test
- public void testGetLongHeaderValue() {
- when(in.getHeader(HEADER, DEFAULT_LONG_VALUE, Long.class)).thenReturn(LONG_VALUE);
- assertThat(endpoint.getLongHeader(exchange, HEADER, DEFAULT_LONG_VALUE), is(LONG_VALUE));
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(in, times(1)).getHeader(HEADER, DEFAULT_LONG_VALUE, Long.class);
- }
-
- @Test
- public void testGetLongHeaderValueNotFound() {
- when(in.getHeader(HEADER, DEFAULT_LONG_VALUE, Long.class)).thenReturn(DEFAULT_LONG_VALUE);
- assertThat(endpoint.getLongHeader(exchange, HEADER, DEFAULT_LONG_VALUE), is(DEFAULT_LONG_VALUE));
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(in, times(1)).getHeader(HEADER, DEFAULT_LONG_VALUE, Long.class);
- }
-
- @Test
- public void testGetMetricsNameFromExchange() {
- when(in.getHeader(MetricsComponent.HEADER_METRIC_NAME, String.class)).thenReturn(STRING_VALUE);
- assertThat(endpoint.getMetricsName(exchange), is(STRING_VALUE));
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(in, times(1)).getHeader(MetricsComponent.HEADER_METRIC_NAME, String.class);
- }
-
- @Test
- public void testGetMetricsNameFromExchangeNotFound() {
- when(in.getHeader(MetricsComponent.HEADER_METRIC_NAME, String.class)).thenReturn(null);
- assertThat(endpoint.getMetricsName(exchange), is(METRICS_NAME));
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(in, times(1)).getHeader(MetricsComponent.HEADER_METRIC_NAME, String.class);
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java b/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
new file mode 100644
index 0000000..3435247
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
@@ -0,0 +1,172 @@
+package org.apache.camel.metrics;
+
+import static org.apache.camel.metrics.AbstractMetricsProducer.HEADER_PATTERN;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.impl.DefaultMessage;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AbstractMetricsProducerTest {
+
+ public static final String METRIC_NAME = "a metric";
+
+ @Mock
+ private AbstractMetricsEndpoint endpoint;
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private Message in;
+
+ @Mock
+ private MetricRegistry registry;
+
+ private AbstractMetricsProducer<AbstractMetricsEndpoint> okProducer;
+
+ private AbstractMetricsProducer<AbstractMetricsEndpoint> failProducer;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ okProducer = new AbstractMetricsProducer<AbstractMetricsEndpoint>(endpoint) {
+ @Override
+ protected void doProcess(Exchange exchange, AbstractMetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ }
+ };
+ failProducer = new AbstractMetricsProducer<AbstractMetricsEndpoint>(endpoint) {
+
+ @Override
+ protected void doProcess(Exchange exchange, AbstractMetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ throw new Exception("Muchos problemos");
+ }
+ };
+ inOrder = Mockito.inOrder(endpoint, exchange, in, registry);
+ when(exchange.getIn()).thenReturn(in);
+ when(endpoint.getMetricsName()).thenReturn(METRIC_NAME);
+ when(endpoint.getRegistry()).thenReturn(registry);
+ }
+
+ @Test
+ public void testDoProcess() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
+ when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
+ okProducer.process(exchange);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testDoProcessWithException() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
+ when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
+ failProducer.process(exchange);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetMetricsName() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("A");
+ assertThat(okProducer.getMetricsName(in, "value"), is("A"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetMetricsNameNotSet() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
+ assertThat(okProducer.getMetricsName(in, "name"), is("name"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetStringHeader() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("A");
+ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("A"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetStringHeaderWithNullValue() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
+ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetStringHeaderWithWhiteSpaces() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(" ");
+ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetStringHeaderWithEmptySrting() throws Exception {
+ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("");
+ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
+ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetLongHeader() throws Exception {
+ when(in.getHeader(HEADER_HISTOGRAM_VALUE, 19L, Long.class)).thenReturn(201L);
+ assertThat(okProducer.getLongHeader(in, HEADER_HISTOGRAM_VALUE, 19L), is(201L));
+ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, 19L, Long.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testClearMetricsHeaders() throws Exception {
+ when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
+ assertThat(okProducer.clearMetricsHeaders(in), is(true));
+ inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testClearRealHeaders() throws Exception {
+ Message msg = new DefaultMessage();
+ Object val = new Object();
+ msg.setHeader(HEADER_HISTOGRAM_VALUE, 109L);
+ msg.setHeader(HEADER_METRIC_NAME, "the metric");
+ msg.setHeader("notRemoved", val);
+ assertThat(msg.getHeaders().size(), is(3));
+ assertThat(msg.getHeader(HEADER_HISTOGRAM_VALUE, Long.class), is(109L));
+ assertThat(msg.getHeader(HEADER_METRIC_NAME, String.class), is("the metric"));
+ assertThat(msg.getHeader("notRemoved"), is(val));
+ okProducer.clearMetricsHeaders(msg);
+ assertThat(msg.getHeaders().size(), is(1));
+ assertThat(msg.getHeader("notRemoved"), is(val));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java b/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
index 97301c3..4ef44f3 100644
--- a/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
+++ b/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
@@ -1,5 +1,9 @@
package org.apache.camel.metrics;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_PERFIX;
+
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -13,14 +17,17 @@ import org.junit.Test;
public class MetricsComponentRouteTest extends CamelTestSupport {
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
+ @Produce(uri = "direct:start-1")
+ protected ProducerTemplate template1;
+
+ @Produce(uri = "direct:start-2")
+ protected ProducerTemplate template2;
@Test
public void testMetrics() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
- template.sendBody(new Object());
+ template1.sendBody(new Object());
assertMockEndpointsSatisfied();
}
@@ -38,7 +45,28 @@ public class MetricsComponentRouteTest extends CamelTestSupport {
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(header1, value1);
headers.put(header2, value2);
- template.sendBodyAndHeaders(body, headers);
+ template1.sendBodyAndHeaders(body, headers);
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testHeaderRemoval() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ Object body = new Object();
+ Date now = new Date();
+
+ mock.expectedBodiesReceived(body);
+ mock.expectedHeaderReceived("." + HEADER_PERFIX, "value");
+ mock.expectedHeaderReceived("date", now);
+
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(HEADER_METRIC_NAME, "a name");
+ headers.put(HEADER_HISTOGRAM_VALUE, 34L);
+ headers.put(HEADER_PERFIX + "notExistingHeader", "?");
+ headers.put("." + HEADER_PERFIX, "value");
+ headers.put("date", now);
+
+ template2.sendBodyAndHeaders(body, headers);
assertMockEndpointsSatisfied();
}
@@ -47,7 +75,7 @@ public class MetricsComponentRouteTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
public void configure() {
- from("direct:start")
+ from("direct:start-1")
.to("metrics:timer:T?action=start")
.to("metrics:A")
.to("metrics:counter://B")
@@ -61,6 +89,10 @@ public class MetricsComponentRouteTest extends CamelTestSupport {
.to("metrics:histogram:E?value=12000000031")
.to("metrics:timer:T?action=stop")
.to("mock:result");
+
+ from("direct:start-2")
+ .to("metrics:meter:F?mark=88")
+ .to("mock:result");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java b/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
index c136cf8..6351814 100644
--- a/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
@@ -8,6 +8,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
import org.apache.camel.Exchange;
+import org.apache.camel.Message;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -22,7 +23,7 @@ import com.codahale.metrics.MetricRegistry;
@RunWith(MockitoJUnitRunner.class)
public class CounterProducerTest {
- private static final String ENDPOINT_NAME = "endpoint.name";
+ private static final String METRICS_NAME = "metrics.name";
private static final Long INCREMENT = 100000L;
private static final Long DECREMENT = 91929199L;
@@ -38,6 +39,9 @@ public class CounterProducerTest {
@Mock
private Counter counter;
+ @Mock
+ private Message in;
+
private CounterProducer producer;
private InOrder inOrder;
@@ -45,10 +49,10 @@ public class CounterProducerTest {
@Before
public void setUp() throws Exception {
producer = new CounterProducer(endpoint);
- inOrder = Mockito.inOrder(endpoint, exchange, registry, counter);
- when(endpoint.getMetricsName(exchange)).thenReturn(ENDPOINT_NAME);
+ inOrder = Mockito.inOrder(endpoint, exchange, registry, counter, in);
when(endpoint.getRegistry()).thenReturn(registry);
- when(registry.counter(ENDPOINT_NAME)).thenReturn(counter);
+ when(registry.counter(METRICS_NAME)).thenReturn(counter);
+ when(exchange.getIn()).thenReturn(in);
}
@Test
@@ -60,16 +64,15 @@ public class CounterProducerTest {
public void testProcessWithIncrementOnly() throws Exception {
when(endpoint.getIncrement()).thenReturn(INCREMENT);
when(endpoint.getDecrement()).thenReturn(null);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT)).thenReturn(INCREMENT);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null)).thenReturn(null);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT);
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
inOrder.verify(counter, times(1)).inc(INCREMENT);
inOrder.verifyNoMoreInteractions();
}
@@ -78,34 +81,32 @@ public class CounterProducerTest {
public void testProcessWithDecrementOnly() throws Exception {
when(endpoint.getIncrement()).thenReturn(null);
when(endpoint.getDecrement()).thenReturn(DECREMENT);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null)).thenReturn(null);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT)).thenReturn(DECREMENT);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null);
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
inOrder.verify(counter, times(1)).dec(DECREMENT);
inOrder.verifyNoMoreInteractions();
}
@Test
- public void testProcessWithIncrementAndDecrement() throws Exception {
+ public void testDoProcessWithIncrementAndDecrement() throws Exception {
when(endpoint.getIncrement()).thenReturn(INCREMENT);
when(endpoint.getDecrement()).thenReturn(DECREMENT);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT)).thenReturn(INCREMENT);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT)).thenReturn(DECREMENT);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT);
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
inOrder.verify(counter, times(1)).inc(INCREMENT);
inOrder.verifyNoMoreInteractions();
}
@@ -114,16 +115,15 @@ public class CounterProducerTest {
public void testProcessWithOutIncrementAndDecrement() throws Exception {
when(endpoint.getIncrement()).thenReturn(null);
when(endpoint.getDecrement()).thenReturn(null);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null)).thenReturn(null);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null)).thenReturn(null);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null);
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
inOrder.verify(counter, times(1)).inc();
inOrder.verifyNoMoreInteractions();
}
@@ -132,16 +132,15 @@ public class CounterProducerTest {
public void testProcessWithHeaderValuesOnly() throws Exception {
when(endpoint.getIncrement()).thenReturn(null);
when(endpoint.getDecrement()).thenReturn(null);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null)).thenReturn(INCREMENT + 1);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null)).thenReturn(DECREMENT - 1);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(INCREMENT + 1);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(DECREMENT - 1);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null);
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
inOrder.verify(counter, times(1)).inc(INCREMENT + 1);
inOrder.verifyNoMoreInteractions();
}
@@ -150,16 +149,15 @@ public class CounterProducerTest {
public void testProcessOverridingIncrement() throws Exception {
when(endpoint.getIncrement()).thenReturn(INCREMENT);
when(endpoint.getDecrement()).thenReturn(DECREMENT);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT)).thenReturn(INCREMENT + 1);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT)).thenReturn(DECREMENT);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT + 1);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT);
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
inOrder.verify(counter, times(1)).inc(INCREMENT + 1);
inOrder.verifyNoMoreInteractions();
}
@@ -168,16 +166,15 @@ public class CounterProducerTest {
public void testProcessOverridingDecrement() throws Exception {
when(endpoint.getIncrement()).thenReturn(null);
when(endpoint.getDecrement()).thenReturn(DECREMENT);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null)).thenReturn(null);
- when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT)).thenReturn(DECREMENT - 1);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
+ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT - 1);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
inOrder.verify(endpoint, times(1)).getDecrement();
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null);
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
+ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
inOrder.verify(counter, times(1)).dec(DECREMENT - 1);
inOrder.verifyNoMoreInteractions();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java b/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
index d28e07a..844401e 100644
--- a/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
+++ b/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
@@ -4,9 +4,6 @@ import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT
import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
@@ -15,7 +12,6 @@ import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.Map;
-import org.apache.camel.CamelExecutionException;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
@@ -167,14 +163,8 @@ public class CounterRouteTest {
@Test
public void testOverrideIncrementWithWrongType() throws Exception {
when(mockRegistry.counter("A")).thenReturn(mockCounter);
- endpoint.expectedMessageCount(0);
- try {
- producer1.sendBodyAndHeader(new Object(), HEADER_COUNTER_INCREMENT, "this is not a valid long value");
- fail("Exception expected");
- }
- catch (Exception e) {
- assertThat(e, instanceOf(CamelExecutionException.class));
- }
+ endpoint.expectedMessageCount(1);
+ producer1.sendBodyAndHeader(new Object(), HEADER_COUNTER_INCREMENT, "this is not a valid long value");
endpoint.assertIsSatisfied();
inOrder.verify(mockRegistry, times(1)).counter("A");
inOrder.verifyNoMoreInteractions();
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java b/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
index 5cb5529..8fe1e06 100644
--- a/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
@@ -7,6 +7,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
import org.apache.camel.Exchange;
+import org.apache.camel.Message;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,6 +37,9 @@ public class HistogramProducerTest {
@Mock
private Exchange exchange;
+ @Mock
+ private Message in;
+
private HistogramProducer producer;
private InOrder inOrder;
@@ -43,10 +47,10 @@ public class HistogramProducerTest {
@Before
public void setUp() throws Exception {
producer = new HistogramProducer(endpoint);
- inOrder = Mockito.inOrder(endpoint, registry, histogram, exchange);
+ inOrder = Mockito.inOrder(endpoint, registry, histogram, exchange, in);
when(endpoint.getRegistry()).thenReturn(registry);
- when(endpoint.getMetricsName(exchange)).thenReturn(METRICS_NAME);
when(registry.histogram(METRICS_NAME)).thenReturn(histogram);
+ when(exchange.getIn()).thenReturn(in);
}
@Test
@@ -57,13 +61,12 @@ public class HistogramProducerTest {
@Test
public void testProcessValueSet() throws Exception {
when(endpoint.getValue()).thenReturn(VALUE);
- when(endpoint.getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, VALUE)).thenReturn(VALUE);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ when(in.getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class)).thenReturn(VALUE);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getValue();
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, VALUE);
+ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class);
inOrder.verify(histogram, times(1)).update(VALUE);
inOrder.verifyNoMoreInteractions();
}
@@ -71,26 +74,24 @@ public class HistogramProducerTest {
@Test
public void testProcessValueNotSet() throws Exception {
when(endpoint.getValue()).thenReturn(null);
- when(endpoint.getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, null)).thenReturn(null);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ when(in.getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getValue();
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, null);
+ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class);
inOrder.verifyNoMoreInteractions();
}
@Test
public void testProcessOverrideValue() throws Exception {
when(endpoint.getValue()).thenReturn(VALUE);
- when(endpoint.getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, VALUE)).thenReturn(VALUE + 3);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ when(in.getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class)).thenReturn(VALUE + 3);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getValue();
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, VALUE);
+ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class);
inOrder.verify(histogram, times(1)).update(VALUE + 3);
inOrder.verifyNoMoreInteractions();
}
@@ -98,13 +99,12 @@ public class HistogramProducerTest {
@Test
public void testProcessOverrideUriValueNotSet() throws Exception {
when(endpoint.getValue()).thenReturn(null);
- when(endpoint.getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, null)).thenReturn(VALUE + 2);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ when(in.getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class)).thenReturn(VALUE + 2);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getValue();
- inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, null);
+ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class);
inOrder.verify(histogram, times(1)).update(VALUE + 2);
inOrder.verifyNoMoreInteractions();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java b/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
index ba62a18..ffa8224 100644
--- a/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
@@ -45,7 +45,6 @@ public class MeterProducerTest {
producer = new MeterProducer(endpoint);
inOrder = Mockito.inOrder(endpoint, registry, meter, exchange);
when(endpoint.getRegistry()).thenReturn(registry);
- when(endpoint.getMetricsName(exchange)).thenReturn(METRICS_NAME);
when(registry.meter(METRICS_NAME)).thenReturn(meter);
}
@@ -58,9 +57,7 @@ public class MeterProducerTest {
@Test
public void testProcessMarkSet() throws Exception {
when(endpoint.getMark()).thenReturn(MARK);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
inOrder.verify(registry, times(1)).meter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getMark();
inOrder.verify(meter, times(1)).mark(MARK);
@@ -70,9 +67,7 @@ public class MeterProducerTest {
@Test
public void testProcessMarkNotSet() throws Exception {
when(endpoint.getMark()).thenReturn(null);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
inOrder.verify(registry, times(1)).meter(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getMark();
inOrder.verify(meter, times(1)).mark();
http://git-wip-us.apache.org/repos/asf/camel/blob/6a006eba/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java b/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
index 09e572b..e61da97 100644
--- a/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
@@ -51,7 +51,6 @@ public class TimerProducerTest {
producer = new TimerProducer(endpoint);
inOrder = Mockito.inOrder(endpoint, exchange, registry, timer, context);
when(endpoint.getRegistry()).thenReturn(registry);
- when(endpoint.getMetricsName(exchange)).thenReturn(METRICS_NAME);
when(registry.timer(METRICS_NAME)).thenReturn(timer);
when(timer.time()).thenReturn(context);
}
@@ -66,9 +65,7 @@ public class TimerProducerTest {
public void testProcessStart() throws Exception {
when(endpoint.getAction()).thenReturn(TimerAction.start);
when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
inOrder.verify(endpoint, times(1)).getAction();
inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
inOrder.verify(registry, times(1)).timer(METRICS_NAME);
@@ -81,9 +78,7 @@ public class TimerProducerTest {
public void testProcessStop() throws Exception {
when(endpoint.getAction()).thenReturn(TimerAction.stop);
when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
inOrder.verify(endpoint, times(1)).getAction();
inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
inOrder.verify(context, times(1)).stop();
@@ -94,9 +89,7 @@ public class TimerProducerTest {
@Test
public void testProcessNoAction() throws Exception {
when(endpoint.getAction()).thenReturn(null);
- producer.process(exchange);
- inOrder.verify(endpoint, times(1)).getRegistry();
- inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
inOrder.verify(endpoint, times(1)).getAction();
inOrder.verifyNoMoreInteractions();
}
[12/34] git commit: Documentation update.
Posted by da...@apache.org.
Documentation update.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ddec990d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ddec990d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ddec990d
Branch: refs/heads/master
Commit: ddec990d766671d9cc24ee8be5fd81635000e7bf
Parents: f4d8771
Author: Lauri Kimmel <la...@gmx.com>
Authored: Thu May 29 23:29:16 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Mon Jun 16 21:04:21 2014 +1000
----------------------------------------------------------------------
README.md | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ddec990d/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 2a99a44..35f9f89 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
# Metrics Component
+[](https://travis-ci.org/laurikimmel/camel-metrics)
+
**Available as of Camel 2.13**
The **metrics:** component allows you to collect various metrics directly from Camel routes. Supported metric types are _counter_, _meter_, _histogram_ and _timer_. [Metrics](http://metrics.codahale.com) provides simple way to measure behaviour of your application. Configurable reporting _backend_ is enabling different integration options for collecting and visualizing statistics.
@@ -86,8 +88,8 @@ Where options are
| Name | Default | Description |
|-----------|---------|-----------------------------------------|
-| increment | | long value to add to the counter |
-| decrement | | long value to subtract from the counter |
+| increment | - | Long value to add to the counter |
+| decrement | - | Long value to subtract from the counter |
If neither ```increment``` or ```decrement``` is defined counter value will be incremented by one. If ```increment``` and ```decrement``` are both defined only increment operation is called.
@@ -114,10 +116,10 @@ from("direct:in")
### Headers
-| Name | Description
-|------------------------------|---------------------------------|
-| CamelMetricsCounterIncrement | Override increment value in URI |
-| CamelMetricsCounterDecrement | Override decrement value in URI |
+| Name | Description | Expected type |
+|------------------------------|---------------------------------|---------------|
+| CamelMetricsCounterIncrement | Override increment value in URI | Long |
+| CamelMetricsCounterDecrement | Override decrement value in URI | Long |
```java
// update counter simple.counter by 417
@@ -146,7 +148,7 @@ Where options are
| Name | Default | Description |
|-------|---------|---------------------------|
-| value | | value to use in histogram |
+| value | - | Value to use in histogram |
If no ```value``` is not set nothing is added to histogram and warning is logged.
@@ -166,9 +168,9 @@ from("direct:in")
### Headers
-| Name | Description
-|----------------------------|---------------------------------|
-| CamelMetricsHistogramValue | Override increment value in URI |
+| Name | Description | Expected type |
+|----------------------------|---------------------------------|---------------|
+| CamelMetricsHistogramValue | Override increment value in URI | Long |
```java
// adds value 992 to simple.histogram
@@ -189,7 +191,7 @@ Where options are
| Name | Default | Description |
|------|---------|---------------------------|
-| mark | | long value to use as mark |
+| mark | - | Long value to use as mark |
If ```mark``` is not set ```meter.mark()``` is called without argument.
@@ -218,7 +220,7 @@ Where options are
| Name | Default | Description |
|--------|---------|---------------------------|
-| action | | ```start``` or ```stop``` |
+| action | - | ```start``` or ```stop``` |
If no ```action``` or invalid value is provided warning is logged and no timer is updated. If ```action``` ```start``` is called on already running timer or ```stop``` is called on not running timer nothing is updated and warning is logged.
@@ -230,4 +232,4 @@ from("direct:in")
.to("metrics:timer:simple.timer?action=stop");
```
-Timer Context objects are stored as Exchange properties.
+`Timer Context` objects are stored as `Exchange` properties.
[30/34] git commit: CAMEL-7554: Renamed package to include component
which is the way we do in Camel.
Posted by da...@apache.org.
CAMEL-7554: Renamed package to include component which is the way we do in Camel.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/acf0fa39
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/acf0fa39
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/acf0fa39
Branch: refs/heads/master
Commit: acf0fa39634346a86c7d1f5d0a99f9ef79e94a36
Parents: f52b7a5
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 30 14:17:47 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 30 14:17:47 2014 +0200
----------------------------------------------------------------------
components/camel-metrics/README.md | 2 +-
components/camel-metrics/pom.xml | 147 ++++++------
.../metrics/AbstractMetricsEndpoint.java | 53 +++++
.../metrics/AbstractMetricsProducer.java | 72 ++++++
.../component/metrics/MetricsComponent.java | 134 +++++++++++
.../camel/component/metrics/MetricsType.java | 53 +++++
.../metrics/counter/CounterEndpoint.java | 66 ++++++
.../metrics/counter/CounterProducer.java | 51 +++++
.../metrics/histogram/HistogramEndpoint.java | 55 +++++
.../metrics/histogram/HistogramProducer.java | 49 ++++
.../component/metrics/meter/MeterEndpoint.java | 55 +++++
.../component/metrics/meter/MeterProducer.java | 44 ++++
.../component/metrics/timer/TimerEndpoint.java | 59 +++++
.../component/metrics/timer/TimerProducer.java | 85 +++++++
.../camel/metrics/AbstractMetricsEndpoint.java | 53 -----
.../camel/metrics/AbstractMetricsProducer.java | 74 ------
.../apache/camel/metrics/MetricsComponent.java | 134 -----------
.../org/apache/camel/metrics/MetricsType.java | 53 -----
.../camel/metrics/counter/CounterEndpoint.java | 66 ------
.../camel/metrics/counter/CounterProducer.java | 51 -----
.../metrics/histogram/HistogramEndpoint.java | 55 -----
.../metrics/histogram/HistogramProducer.java | 49 ----
.../camel/metrics/meter/MeterEndpoint.java | 55 -----
.../camel/metrics/meter/MeterProducer.java | 44 ----
.../camel/metrics/timer/TimerEndpoint.java | 59 -----
.../camel/metrics/timer/TimerProducer.java | 85 -------
.../services/org/apache/camel/component/metrics | 19 +-
.../metrics/AbstractMetricsEndpointTest.java | 105 +++++++++
.../metrics/AbstractMetricsProducerTest.java | 186 +++++++++++++++
.../metrics/MetricComponentSpringTest.java | 91 ++++++++
.../metrics/MetricsComponentRouteTest.java | 113 +++++++++
.../component/metrics/MetricsComponentTest.java | 217 ++++++++++++++++++
.../component/metrics/MetricsTypeTest.java | 34 +++
.../metrics/counter/CounterEndpointTest.java | 102 +++++++++
.../metrics/counter/CounterProducerTest.java | 195 ++++++++++++++++
.../metrics/counter/CounterRouteTest.java | 209 +++++++++++++++++
.../histogram/HistogramEndpointTest.java | 88 +++++++
.../histogram/HistogramProducerTest.java | 125 ++++++++++
.../metrics/histogram/HistogramRouteTest.java | 123 ++++++++++
.../metrics/meter/MeterEndpointTest.java | 89 +++++++
.../metrics/meter/MeterProducerTest.java | 126 ++++++++++
.../component/metrics/meter/MeterRouteTest.java | 165 +++++++++++++
.../metrics/timer/TimerEndpointTest.java | 89 +++++++
.../metrics/timer/TimerProducerTest.java | 229 +++++++++++++++++++
.../component/metrics/timer/TimerRouteTest.java | 144 ++++++++++++
.../metrics/AbstractMetricsEndpointTest.java | 105 ---------
.../metrics/AbstractMetricsProducerTest.java | 186 ---------------
.../metrics/MetricComponentSpringTest.java | 91 --------
.../metrics/MetricsComponentRouteTest.java | 113 ---------
.../camel/metrics/MetricsComponentTest.java | 217 ------------------
.../apache/camel/metrics/MetricsTypeTest.java | 33 ---
.../metrics/counter/CounterEndpointTest.java | 102 ---------
.../metrics/counter/CounterProducerTest.java | 195 ----------------
.../camel/metrics/counter/CounterRouteTest.java | 209 -----------------
.../histogram/HistogramEndpointTest.java | 88 -------
.../histogram/HistogramProducerTest.java | 125 ----------
.../metrics/histogram/HistogramRouteTest.java | 123 ----------
.../camel/metrics/meter/MeterEndpointTest.java | 89 -------
.../camel/metrics/meter/MeterProducerTest.java | 126 ----------
.../camel/metrics/meter/MeterRouteTest.java | 165 -------------
.../camel/metrics/timer/TimerEndpointTest.java | 89 -------
.../camel/metrics/timer/TimerProducerTest.java | 229 -------------------
.../camel/metrics/timer/TimerRouteTest.java | 144 ------------
.../src/test/resources/log4j.properties | 38 ++-
.../features/src/main/resources/features.xml | 5 +
.../camel/itest/karaf/CamelMetricsTest.java | 40 ++++
66 files changed, 3378 insertions(+), 3286 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/README.md
----------------------------------------------------------------------
diff --git a/components/camel-metrics/README.md b/components/camel-metrics/README.md
index b0b7bab..1e2b7c6 100644
--- a/components/camel-metrics/README.md
+++ b/components/camel-metrics/README.md
@@ -260,7 +260,7 @@ Message header can be used to override `action` value specified in Metrics compo
| Name | Description | Expected type |
|-------------------------|------------------------------|----------------------------------------------------------|
-| CamelMetricsTimerAction | Override timer action in URI | org.apache.camel.metrics.timer.TimerEndpoint.TimerAction |
+| CamelMetricsTimerAction | Override timer action in URI | org.apache.camel.component.timer.TimerEndpoint.TimerAction |
```java
// sets timer action using header
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-metrics/pom.xml b/components/camel-metrics/pom.xml
index 940a9b6..58aaf69 100644
--- a/components/camel-metrics/pom.xml
+++ b/components/camel-metrics/pom.xml
@@ -14,81 +14,86 @@
the specific language governing permissions and limitations under the
License.
-->
-<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/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>components</artifactId>
- <version>2.14-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.14-SNAPSHOT</version>
+ </parent>
- <artifactId>camel-metrics</artifactId>
- <packaging>bundle</packaging>
- <name>Camel :: Metrics</name>
- <description>Camel Metrics based monitoring component</description>
+ <artifactId>camel-metrics</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Metrics</name>
+ <description>Camel Metrics based monitoring component</description>
- <properties>
- <camel.osgi.export.pkg>
- org.apache.camel.component.metrics.*
- </camel.osgi.export.pkg>
- <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=metrics</camel.osgi.export.service>
- </properties>
+ <properties>
+ <camel.osgi.export.pkg>
+ org.apache.camel.component.metrics.*
+ </camel.osgi.export.pkg>
+ <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=metrics</camel.osgi.export.service>
+ </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- </dependency>
- <dependency>
- <groupId>com.codahale.metrics</groupId>
- <artifactId>metrics-core</artifactId>
- <version>${metrics-version}</version>
- </dependency>
+ <dependencies>
- <!-- testing -->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-spring</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-spring-javaconfig</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test-spring3</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <version>${hamcrest-version}</version>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.codahale.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ <version>${metrics-version}</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring-javaconfig</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-spring3</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>${hamcrest-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
- <!-- logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsEndpoint.java
new file mode 100644
index 0000000..594e0c3
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsEndpoint.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;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.DefaultEndpoint;
+
+
+public abstract class AbstractMetricsEndpoint extends DefaultEndpoint {
+
+ protected final MetricRegistry registry;
+ protected final String metricsName;
+
+ public AbstractMetricsEndpoint(MetricRegistry registry, String metricsName) {
+ this.registry = registry;
+ this.metricsName = metricsName;
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new RuntimeCamelException("Cannot consume from " + getClass().getSimpleName() + ": " + getEndpointUri());
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return false;
+ }
+
+ public MetricRegistry getRegistry() {
+ return registry;
+ }
+
+ public String getMetricsName() {
+ return metricsName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsProducer.java
new file mode 100644
index 0000000..539847a
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/AbstractMetricsProducer.java
@@ -0,0 +1,72 @@
+/**
+ * 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;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public abstract class AbstractMetricsProducer<T extends AbstractMetricsEndpoint> extends DefaultProducer {
+
+ public static final String HEADER_PATTERN = MetricsComponent.HEADER_PERFIX + "*";
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractMetricsProducer.class);
+
+ public AbstractMetricsProducer(T endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ @SuppressWarnings("unchecked")
+ T endpoint = (T) getEndpoint();
+ Message in = exchange.getIn();
+ String defaultMetricsName = endpoint.getMetricsName();
+ String finalMetricsName = getMetricsName(in, defaultMetricsName);
+ MetricRegistry registry = endpoint.getRegistry();
+ try {
+ doProcess(exchange, endpoint, registry, finalMetricsName);
+ } catch (Exception e) {
+ LOG.warn("Failed to produce metrics for {} in {} - {}", new Object[] {
+ finalMetricsName, getClass().getSimpleName(), e.getMessage() });
+ }
+ clearMetricsHeaders(in);
+ }
+
+ protected abstract void doProcess(Exchange exchange, T endpoint, MetricRegistry registry, String metricsName) throws Exception;
+
+ public String getMetricsName(Message in, String defaultValue) {
+ return getStringHeader(in, MetricsComponent.HEADER_METRIC_NAME, defaultValue);
+ }
+
+ public String getStringHeader(Message in, String header, String defaultValue) {
+ String headerValue = in.getHeader(header, String.class);
+ return ObjectHelper.isNotEmpty(headerValue) ? headerValue : defaultValue;
+ }
+
+ public Long getLongHeader(Message in, String header, Long defaultValue) {
+ return in.getHeader(header, defaultValue, Long.class);
+ }
+
+ protected boolean clearMetricsHeaders(Message in) {
+ return in.removeHeaders(HEADER_PATTERN);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java
new file mode 100644
index 0000000..bb2813a
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java
@@ -0,0 +1,134 @@
+/**
+ * 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;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Slf4jReporter;
+import org.apache.camel.Endpoint;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.component.metrics.counter.CounterEndpoint;
+import org.apache.camel.component.metrics.histogram.HistogramEndpoint;
+import org.apache.camel.component.metrics.meter.MeterEndpoint;
+import org.apache.camel.component.metrics.timer.TimerEndpoint;
+import org.apache.camel.spi.Registry;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents the component that manages {@link MetricsEndpoint}.
+ */
+public class MetricsComponent extends DefaultComponent {
+
+ public static final String METRIC_REGISTRY_NAME = "metricRegistry";
+ public static final MetricsType DEFAULT_METRICS_TYPE = MetricsType.METER;
+ public static final long DEFAULT_REPORTING_INTERVAL_SECONDS = 60L;
+ public static final String HEADER_PERFIX = "CamelMetrics";
+ public static final String HEADER_METRIC_NAME = HEADER_PERFIX + "Name";
+ public static final String HEADER_COUNTER_INCREMENT = HEADER_PERFIX + "CounterIncrement";
+ public static final String HEADER_COUNTER_DECREMENT = HEADER_PERFIX + "CounterDecrement";
+ public static final String HEADER_HISTOGRAM_VALUE = HEADER_PERFIX + "HistogramValue";
+ public static final String HEADER_METER_MARK = HEADER_PERFIX + "MeterMark";
+ public static final String HEADER_TIMER_ACTION = HEADER_PERFIX + "TimerAction";
+
+ private static final Logger LOG = LoggerFactory.getLogger(MetricsComponent.class);
+
+ private MetricRegistry metricRegistry;
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ if (metricRegistry == null) {
+ Registry camelRegistry = getCamelContext().getRegistry();
+ metricRegistry = getOrCreateMetricRegistry(camelRegistry, METRIC_REGISTRY_NAME);
+ }
+ String metricsName = getMetricsName(remaining);
+ MetricsType metricsType = getMetricsType(remaining);
+ LOG.info("Metrics type: {}; name: {}", metricsType, metricsName);
+ Endpoint endpoint = createNewEndpoint(metricRegistry, metricsType, metricsName);
+ setProperties(endpoint, parameters);
+ return endpoint;
+ }
+
+ String getMetricsName(String remaining) {
+ String name = ObjectHelper.after(remaining, ":");
+ return name == null ? remaining : name;
+ }
+
+ Endpoint createNewEndpoint(MetricRegistry registry, MetricsType type, String metricsName) {
+ Endpoint endpoint;
+ switch (type) {
+ case COUNTER:
+ endpoint = new CounterEndpoint(registry, metricsName);
+ break;
+ case METER:
+ endpoint = new MeterEndpoint(registry, metricsName);
+ break;
+ case HISTOGRAM:
+ endpoint = new HistogramEndpoint(registry, metricsName);
+ break;
+ case TIMER:
+ endpoint = new TimerEndpoint(registry, metricsName);
+ break;
+ default:
+ throw new RuntimeCamelException("Metrics type \"" + type.toString() + "\" not supported");
+ }
+ return endpoint;
+ }
+
+ MetricsType getMetricsType(String remaining) {
+ String name = ObjectHelper.before(remaining, ":");
+ MetricsType type;
+ if (name == null) {
+ type = DEFAULT_METRICS_TYPE;
+ } else {
+ type = MetricsType.getByName(name);
+ }
+ if (type == null) {
+ throw new RuntimeCamelException("Unknown metrics type \"" + name + "\"");
+ }
+ return type;
+ }
+
+ MetricRegistry getOrCreateMetricRegistry(Registry camelRegistry, String registryName) {
+ LOG.debug("Looking up MetricRegistry from Camel Registry for name \"{}\"", registryName);
+ MetricRegistry result = getMetricRegistryFromCamelRegistry(camelRegistry, registryName);
+ if (result == null) {
+ LOG.debug("MetricRegistry not found from Camel Registry for name \"{}\"", registryName);
+ LOG.info("Creating new default MetricRegistry");
+ result = createMetricRegistry();
+ }
+ return result;
+ }
+
+ MetricRegistry getMetricRegistryFromCamelRegistry(Registry camelRegistry, String registryName) {
+ return camelRegistry.lookupByNameAndType(registryName, MetricRegistry.class);
+ }
+
+ MetricRegistry createMetricRegistry() {
+ MetricRegistry registry = new MetricRegistry();
+ final Slf4jReporter reporter = Slf4jReporter.forRegistry(registry)
+ .outputTo(LOG)
+ .convertRatesTo(TimeUnit.SECONDS)
+ .convertDurationsTo(TimeUnit.MILLISECONDS)
+ .build();
+ reporter.start(DEFAULT_REPORTING_INTERVAL_SECONDS, TimeUnit.SECONDS);
+ return registry;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsType.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsType.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsType.java
new file mode 100644
index 0000000..3348578
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsType.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;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+public enum MetricsType {
+
+ GAUGE("gauge"),
+ COUNTER("counter"),
+ HISTOGRAM("histogram"),
+ METER("meter"),
+ TIMER("timer");
+
+ private static final Map<String, MetricsType> MAP = new HashMap<String, MetricsType>();
+
+ private final String name;
+
+ static {
+ for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
+ MAP.put(type.name, type);
+ }
+ }
+
+ private MetricsType(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ public static MetricsType getByName(String name) {
+ return MAP.get(name);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterEndpoint.java
new file mode 100644
index 0000000..2eae8f2
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterEndpoint.java
@@ -0,0 +1,66 @@
+/**
+ * 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.counter;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Producer;
+import org.apache.camel.component.metrics.AbstractMetricsEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+
+
+@UriEndpoint(scheme = "metrics")
+public class CounterEndpoint extends AbstractMetricsEndpoint {
+
+ public static final String ENDPOINT_URI = "metrics:counter";
+
+ @UriParam
+ private Long increment;
+
+ @UriParam
+ private Long decrement;
+
+ public CounterEndpoint(MetricRegistry registry, String metricsName) {
+ super(registry, metricsName);
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new CounterProducer(this);
+ }
+
+ public Long getIncrement() {
+ return increment;
+ }
+
+ public void setIncrement(Long increment) {
+ this.increment = increment;
+ }
+
+ public Long getDecrement() {
+ return decrement;
+ }
+
+ public void setDecrement(Long decrement) {
+ this.decrement = decrement;
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return ENDPOINT_URI;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterProducer.java
new file mode 100644
index 0000000..5a9dd42
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/counter/CounterProducer.java
@@ -0,0 +1,51 @@
+/**
+ * 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.counter;
+
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.metrics.AbstractMetricsProducer;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
+
+
+public class CounterProducer extends AbstractMetricsProducer<CounterEndpoint> {
+
+ public CounterProducer(CounterEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ protected void doProcess(Exchange exchange, CounterEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ Message in = exchange.getIn();
+ Counter counter = registry.counter(metricsName);
+ Long increment = endpoint.getIncrement();
+ Long decrement = endpoint.getDecrement();
+ Long finalIncrement = getLongHeader(in, HEADER_COUNTER_INCREMENT, increment);
+ Long finalDecrement = getLongHeader(in, HEADER_COUNTER_DECREMENT, decrement);
+ if (finalIncrement != null) {
+ counter.inc(finalIncrement);
+ } else if (finalDecrement != null) {
+ counter.dec(finalDecrement);
+ } else {
+ counter.inc();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramEndpoint.java
new file mode 100644
index 0000000..bf7ce6c
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramEndpoint.java
@@ -0,0 +1,55 @@
+/**
+ * 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.histogram;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Producer;
+import org.apache.camel.component.metrics.AbstractMetricsEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+
+
+@UriEndpoint(scheme = "metrics")
+public class HistogramEndpoint extends AbstractMetricsEndpoint {
+
+ public static final String ENDPOINT_URI = "metrics:histogram";
+
+ @UriParam
+ private Long value;
+
+ public HistogramEndpoint(MetricRegistry registry, String metricsName) {
+ super(registry, metricsName);
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new HistogramProducer(this);
+ }
+
+ public Long getValue() {
+ return value;
+ }
+
+ public void setValue(Long value) {
+ this.value = value;
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return ENDPOINT_URI;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramProducer.java
new file mode 100644
index 0000000..161da92
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/histogram/HistogramProducer.java
@@ -0,0 +1,49 @@
+/**
+ * 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.histogram;
+
+
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.metrics.AbstractMetricsProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+
+public class HistogramProducer extends AbstractMetricsProducer<HistogramEndpoint> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(HistogramProducer.class);
+
+ public HistogramProducer(HistogramEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ protected void doProcess(Exchange exchange, HistogramEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ Message in = exchange.getIn();
+ Histogram histogram = registry.histogram(metricsName);
+ Long value = endpoint.getValue();
+ Long finalValue = getLongHeader(in, HEADER_HISTOGRAM_VALUE, value);
+ if (finalValue != null) {
+ histogram.update(finalValue);
+ } else {
+ LOG.warn("Cannot update histogram \"{}\" with null value", metricsName);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterEndpoint.java
new file mode 100644
index 0000000..f376261
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterEndpoint.java
@@ -0,0 +1,55 @@
+/**
+ * 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.meter;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Producer;
+import org.apache.camel.component.metrics.AbstractMetricsEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+
+
+@UriEndpoint(scheme = "metrics")
+public class MeterEndpoint extends AbstractMetricsEndpoint {
+
+ public static final String ENDPOINT_URI = "metrics:meter";
+
+ @UriParam
+ private Long mark;
+
+ public MeterEndpoint(MetricRegistry registry, String metricsName) {
+ super(registry, metricsName);
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new MeterProducer(this);
+ }
+
+ public Long getMark() {
+ return mark;
+ }
+
+ public void setMark(Long mark) {
+ this.mark = mark;
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return ENDPOINT_URI;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterProducer.java
new file mode 100644
index 0000000..b3474bb
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/meter/MeterProducer.java
@@ -0,0 +1,44 @@
+/**
+ * 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.meter;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.metrics.AbstractMetricsProducer;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_METER_MARK;
+
+public class MeterProducer extends AbstractMetricsProducer<MeterEndpoint> {
+
+ public MeterProducer(MeterEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ protected void doProcess(Exchange exchange, MeterEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ Message in = exchange.getIn();
+ Meter meter = registry.meter(metricsName);
+ Long mark = endpoint.getMark();
+ Long finalMark = getLongHeader(in, HEADER_METER_MARK, mark);
+ if (finalMark == null) {
+ meter.mark();
+ } else {
+ meter.mark(finalMark);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerEndpoint.java
new file mode 100644
index 0000000..f1591a0
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerEndpoint.java
@@ -0,0 +1,59 @@
+/**
+ * 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.timer;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.camel.Producer;
+import org.apache.camel.component.metrics.AbstractMetricsEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+
+@UriEndpoint(scheme = "metrics")
+public class TimerEndpoint extends AbstractMetricsEndpoint {
+
+ public static final String ENDPOINT_URI = "metrics:timer";
+
+ public enum TimerAction {
+ start,
+ stop;
+ }
+
+ @UriParam
+ private TimerAction action;
+
+ public TimerEndpoint(MetricRegistry registry, String metricsName) {
+ super(registry, metricsName);
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new TimerProducer(this);
+ }
+
+ public TimerAction getAction() {
+ return action;
+ }
+
+ public void setAction(TimerAction action) {
+ this.action = action;
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return ENDPOINT_URI;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerProducer.java
new file mode 100644
index 0000000..57cf471
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/timer/TimerProducer.java
@@ -0,0 +1,85 @@
+/**
+ * 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.timer;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.metrics.AbstractMetricsProducer;
+import org.apache.camel.component.metrics.timer.TimerEndpoint.TimerAction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static org.apache.camel.component.metrics.MetricsComponent.HEADER_TIMER_ACTION;
+import static org.apache.camel.component.metrics.timer.TimerEndpoint.ENDPOINT_URI;
+
+public class TimerProducer extends AbstractMetricsProducer<TimerEndpoint> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TimerProducer.class);
+
+ public TimerProducer(TimerEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ protected void doProcess(Exchange exchange, TimerEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ Message in = exchange.getIn();
+ TimerAction action = endpoint.getAction();
+ TimerAction finalAction = in.getHeader(HEADER_TIMER_ACTION, action, TimerAction.class);
+ if (finalAction == TimerAction.start) {
+ handleStart(exchange, registry, metricsName);
+ } else if (finalAction == TimerAction.stop) {
+ handleStop(exchange, registry, metricsName);
+ } else {
+ LOG.warn("No action provided for timer \"{}\"", metricsName);
+ }
+ }
+
+ void handleStart(Exchange exchange, MetricRegistry registry, String metricsName) {
+ String propertyName = getPropertyName(metricsName);
+ Timer.Context context = getTimerContextFromExchange(exchange, propertyName);
+ if (context == null) {
+ Timer timer = registry.timer(metricsName);
+ context = timer.time();
+ exchange.setProperty(propertyName, context);
+ } else {
+ LOG.warn("Timer \"{}\" already running", metricsName);
+ }
+ }
+
+ void handleStop(Exchange exchange, MetricRegistry registry, String metricsName) {
+ String propertyName = getPropertyName(metricsName);
+ Timer.Context context = getTimerContextFromExchange(exchange, propertyName);
+ if (context != null) {
+ context.stop();
+ exchange.removeProperty(propertyName);
+ } else {
+ LOG.warn("Timer \"{}\" not found", metricsName);
+ }
+ }
+
+ String getPropertyName(String metricsName) {
+ return new StringBuilder(ENDPOINT_URI)
+ .append(":")
+ .append(metricsName)
+ .toString();
+ }
+
+ Timer.Context getTimerContextFromExchange(Exchange exchange, String propertyName) {
+ return exchange.getProperty(propertyName, Timer.Context.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
deleted file mode 100644
index f437846..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.metrics;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Consumer;
-import org.apache.camel.Processor;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.impl.DefaultEndpoint;
-
-
-public abstract class AbstractMetricsEndpoint extends DefaultEndpoint {
-
- protected final MetricRegistry registry;
- protected final String metricsName;
-
- public AbstractMetricsEndpoint(MetricRegistry registry, String metricsName) {
- this.registry = registry;
- this.metricsName = metricsName;
- }
-
- @Override
- public Consumer createConsumer(Processor processor) throws Exception {
- throw new RuntimeCamelException("Cannot consume from " + getClass().getSimpleName() + ": " + getEndpointUri());
- }
-
- @Override
- public boolean isSingleton() {
- return false;
- }
-
- public MetricRegistry getRegistry() {
- return registry;
- }
-
- public String getMetricsName() {
- return metricsName;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
deleted file mode 100644
index cd11447..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * 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.metrics;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.impl.DefaultProducer;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_PERFIX;
-
-
-public abstract class AbstractMetricsProducer<T extends AbstractMetricsEndpoint> extends DefaultProducer {
-
- public static final String HEADER_PATTERN = HEADER_PERFIX + "*";
- private static final Logger LOG = LoggerFactory.getLogger(AbstractMetricsProducer.class);
-
- public AbstractMetricsProducer(T endpoint) {
- super(endpoint);
- }
-
- @Override
- public void process(Exchange exchange) throws Exception {
- @SuppressWarnings("unchecked")
- T endpoint = (T) getEndpoint();
- Message in = exchange.getIn();
- String defaultMetricsName = endpoint.getMetricsName();
- String finalMetricsName = getMetricsName(in, defaultMetricsName);
- MetricRegistry registry = endpoint.getRegistry();
- try {
- doProcess(exchange, endpoint, registry, finalMetricsName);
- } catch (Exception e) {
- LOG.warn("Failed to produce metrics for {} in {} - {}", new Object[] {
- finalMetricsName, getClass().getSimpleName(), e.getMessage() });
- }
- clearMetricsHeaders(in);
- }
-
- protected abstract void doProcess(Exchange exchange, T endpoint, MetricRegistry registry, String metricsName) throws Exception;
-
- public String getMetricsName(Message in, String defaultValue) {
- return getStringHeader(in, HEADER_METRIC_NAME, defaultValue);
- }
-
- public String getStringHeader(Message in, String header, String defaultValue) {
- String headerValue = in.getHeader(header, String.class);
- return ObjectHelper.isNotEmpty(headerValue) ? headerValue : defaultValue;
- }
-
- public Long getLongHeader(Message in, String header, Long defaultValue) {
- return in.getHeader(header, defaultValue, Long.class);
- }
-
- protected boolean clearMetricsHeaders(Message in) {
- return in.removeHeaders(HEADER_PATTERN);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
deleted file mode 100644
index b73626a..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * 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.metrics;
-
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Slf4jReporter;
-import org.apache.camel.Endpoint;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.metrics.counter.CounterEndpoint;
-import org.apache.camel.metrics.histogram.HistogramEndpoint;
-import org.apache.camel.metrics.meter.MeterEndpoint;
-import org.apache.camel.metrics.timer.TimerEndpoint;
-import org.apache.camel.spi.Registry;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Represents the component that manages {@link MetricsEndpoint}.
- */
-public class MetricsComponent extends DefaultComponent {
-
- public static final String METRIC_REGISTRY_NAME = "metricRegistry";
- public static final MetricsType DEFAULT_METRICS_TYPE = MetricsType.METER;
- public static final long DEFAULT_REPORTING_INTERVAL_SECONDS = 60L;
- public static final String HEADER_PERFIX = "CamelMetrics";
- public static final String HEADER_METRIC_NAME = HEADER_PERFIX + "Name";
- public static final String HEADER_COUNTER_INCREMENT = HEADER_PERFIX + "CounterIncrement";
- public static final String HEADER_COUNTER_DECREMENT = HEADER_PERFIX + "CounterDecrement";
- public static final String HEADER_HISTOGRAM_VALUE = HEADER_PERFIX + "HistogramValue";
- public static final String HEADER_METER_MARK = HEADER_PERFIX + "MeterMark";
- public static final String HEADER_TIMER_ACTION = HEADER_PERFIX + "TimerAction";
-
- private static final Logger LOG = LoggerFactory.getLogger(MetricsComponent.class);
-
- private MetricRegistry metricRegistry;
-
- @Override
- protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- if (metricRegistry == null) {
- Registry camelRegistry = getCamelContext().getRegistry();
- metricRegistry = getOrCreateMetricRegistry(camelRegistry, METRIC_REGISTRY_NAME);
- }
- String metricsName = getMetricsName(remaining);
- MetricsType metricsType = getMetricsType(remaining);
- LOG.info("Metrics type: {}; name: {}", metricsType, metricsName);
- Endpoint endpoint = createNewEndpoint(metricRegistry, metricsType, metricsName);
- setProperties(endpoint, parameters);
- return endpoint;
- }
-
- String getMetricsName(String remaining) {
- String name = ObjectHelper.after(remaining, ":");
- return name == null ? remaining : name;
- }
-
- Endpoint createNewEndpoint(MetricRegistry registry, MetricsType type, String metricsName) {
- Endpoint endpoint;
- switch (type) {
- case COUNTER:
- endpoint = new CounterEndpoint(registry, metricsName);
- break;
- case METER:
- endpoint = new MeterEndpoint(registry, metricsName);
- break;
- case HISTOGRAM:
- endpoint = new HistogramEndpoint(registry, metricsName);
- break;
- case TIMER:
- endpoint = new TimerEndpoint(registry, metricsName);
- break;
- default:
- throw new RuntimeCamelException("Metrics type \"" + type.toString() + "\" not supported");
- }
- return endpoint;
- }
-
- MetricsType getMetricsType(String remaining) {
- String name = ObjectHelper.before(remaining, ":");
- MetricsType type;
- if (name == null) {
- type = DEFAULT_METRICS_TYPE;
- } else {
- type = MetricsType.getByName(name);
- }
- if (type == null) {
- throw new RuntimeCamelException("Unknown metrics type \"" + name + "\"");
- }
- return type;
- }
-
- MetricRegistry getOrCreateMetricRegistry(Registry camelRegistry, String registryName) {
- LOG.debug("Looking up MetricRegistry from Camel Registry for name \"{}\"", registryName);
- MetricRegistry result = getMetricRegistryFromCamelRegistry(camelRegistry, registryName);
- if (result == null) {
- LOG.debug("MetricRegistry not found from Camel Registry for name \"{}\"", registryName);
- LOG.info("Creating new default MetricRegistry");
- result = createMetricRegistry();
- }
- return result;
- }
-
- MetricRegistry getMetricRegistryFromCamelRegistry(Registry camelRegistry, String registryName) {
- return camelRegistry.lookupByNameAndType(registryName, MetricRegistry.class);
- }
-
- MetricRegistry createMetricRegistry() {
- MetricRegistry registry = new MetricRegistry();
- final Slf4jReporter reporter = Slf4jReporter.forRegistry(registry)
- .outputTo(LOG)
- .convertRatesTo(TimeUnit.SECONDS)
- .convertDurationsTo(TimeUnit.MILLISECONDS)
- .build();
- reporter.start(DEFAULT_REPORTING_INTERVAL_SECONDS, TimeUnit.SECONDS);
- return registry;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java
deleted file mode 100644
index 760c794..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.metrics;
-
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.Map;
-
-public enum MetricsType {
-
- GAUGE("gauge"),
- COUNTER("counter"),
- HISTOGRAM("histogram"),
- METER("meter"),
- TIMER("timer");
-
- private static final Map<String, MetricsType> MAP = new HashMap<String, MetricsType>();
-
- private final String name;
-
- static {
- for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
- MAP.put(type.name, type);
- }
- }
-
- private MetricsType(String name) {
- this.name = name;
- }
-
- @Override
- public String toString() {
- return name;
- }
-
- public static MetricsType getByName(String name) {
- return MAP.get(name);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
deleted file mode 100644
index 406c21d..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * 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.metrics.counter;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Producer;
-import org.apache.camel.metrics.AbstractMetricsEndpoint;
-import org.apache.camel.spi.UriEndpoint;
-import org.apache.camel.spi.UriParam;
-
-
-@UriEndpoint(scheme = "metrics")
-public class CounterEndpoint extends AbstractMetricsEndpoint {
-
- public static final String ENDPOINT_URI = "metrics:counter";
-
- @UriParam
- private Long increment;
-
- @UriParam
- private Long decrement;
-
- public CounterEndpoint(MetricRegistry registry, String metricsName) {
- super(registry, metricsName);
- }
-
- @Override
- public Producer createProducer() throws Exception {
- return new CounterProducer(this);
- }
-
- public Long getIncrement() {
- return increment;
- }
-
- public void setIncrement(Long increment) {
- this.increment = increment;
- }
-
- public Long getDecrement() {
- return decrement;
- }
-
- public void setDecrement(Long decrement) {
- this.decrement = decrement;
- }
-
- @Override
- protected String createEndpointUri() {
- return ENDPOINT_URI;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
deleted file mode 100644
index bdabba3..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.metrics.counter;
-
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.metrics.AbstractMetricsProducer;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
-
-
-public class CounterProducer extends AbstractMetricsProducer<CounterEndpoint> {
-
- public CounterProducer(CounterEndpoint endpoint) {
- super(endpoint);
- }
-
- @Override
- protected void doProcess(Exchange exchange, CounterEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
- Message in = exchange.getIn();
- Counter counter = registry.counter(metricsName);
- Long increment = endpoint.getIncrement();
- Long decrement = endpoint.getDecrement();
- Long finalIncrement = getLongHeader(in, HEADER_COUNTER_INCREMENT, increment);
- Long finalDecrement = getLongHeader(in, HEADER_COUNTER_DECREMENT, decrement);
- if (finalIncrement != null) {
- counter.inc(finalIncrement);
- } else if (finalDecrement != null) {
- counter.dec(finalDecrement);
- } else {
- counter.inc();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
deleted file mode 100644
index fad53c0..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * 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.metrics.histogram;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Producer;
-import org.apache.camel.metrics.AbstractMetricsEndpoint;
-import org.apache.camel.spi.UriEndpoint;
-import org.apache.camel.spi.UriParam;
-
-
-@UriEndpoint(scheme = "metrics")
-public class HistogramEndpoint extends AbstractMetricsEndpoint {
-
- public static final String ENDPOINT_URI = "metrics:histogram";
-
- @UriParam
- private Long value;
-
- public HistogramEndpoint(MetricRegistry registry, String metricsName) {
- super(registry, metricsName);
- }
-
- @Override
- public Producer createProducer() throws Exception {
- return new HistogramProducer(this);
- }
-
- public Long getValue() {
- return value;
- }
-
- public void setValue(Long value) {
- this.value = value;
- }
-
- @Override
- protected String createEndpointUri() {
- return ENDPOINT_URI;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
deleted file mode 100644
index b29505a..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.metrics.histogram;
-
-
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.metrics.AbstractMetricsProducer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-
-public class HistogramProducer extends AbstractMetricsProducer<HistogramEndpoint> {
-
- private static final Logger LOG = LoggerFactory.getLogger(HistogramProducer.class);
-
- public HistogramProducer(HistogramEndpoint endpoint) {
- super(endpoint);
- }
-
- @Override
- protected void doProcess(Exchange exchange, HistogramEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
- Message in = exchange.getIn();
- Histogram histogram = registry.histogram(metricsName);
- Long value = endpoint.getValue();
- Long finalValue = getLongHeader(in, HEADER_HISTOGRAM_VALUE, value);
- if (finalValue != null) {
- histogram.update(finalValue);
- } else {
- LOG.warn("Cannot update histogram \"{}\" with null value", metricsName);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
deleted file mode 100644
index 84c6316..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * 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.metrics.meter;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Producer;
-import org.apache.camel.metrics.AbstractMetricsEndpoint;
-import org.apache.camel.spi.UriEndpoint;
-import org.apache.camel.spi.UriParam;
-
-
-@UriEndpoint(scheme = "metrics")
-public class MeterEndpoint extends AbstractMetricsEndpoint {
-
- public static final String ENDPOINT_URI = "metrics:meter";
-
- @UriParam
- private Long mark;
-
- public MeterEndpoint(MetricRegistry registry, String metricsName) {
- super(registry, metricsName);
- }
-
- @Override
- public Producer createProducer() throws Exception {
- return new MeterProducer(this);
- }
-
- public Long getMark() {
- return mark;
- }
-
- public void setMark(Long mark) {
- this.mark = mark;
- }
-
- @Override
- protected String createEndpointUri() {
- return ENDPOINT_URI;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
deleted file mode 100644
index 686b198..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * 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.metrics.meter;
-
-import com.codahale.metrics.Meter;
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.metrics.AbstractMetricsProducer;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
-
-public class MeterProducer extends AbstractMetricsProducer<MeterEndpoint> {
-
- public MeterProducer(MeterEndpoint endpoint) {
- super(endpoint);
- }
-
- @Override
- protected void doProcess(Exchange exchange, MeterEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
- Message in = exchange.getIn();
- Meter meter = registry.meter(metricsName);
- Long mark = endpoint.getMark();
- Long finalMark = getLongHeader(in, HEADER_METER_MARK, mark);
- if (finalMark == null) {
- meter.mark();
- } else {
- meter.mark(finalMark);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
deleted file mode 100644
index 10bc25f..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * 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.metrics.timer;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Producer;
-import org.apache.camel.metrics.AbstractMetricsEndpoint;
-import org.apache.camel.spi.UriEndpoint;
-import org.apache.camel.spi.UriParam;
-
-@UriEndpoint(scheme = "metrics")
-public class TimerEndpoint extends AbstractMetricsEndpoint {
-
- public static final String ENDPOINT_URI = "metrics:timer";
-
- public enum TimerAction {
- start,
- stop;
- }
-
- @UriParam
- private TimerAction action;
-
- public TimerEndpoint(MetricRegistry registry, String metricsName) {
- super(registry, metricsName);
- }
-
- @Override
- public Producer createProducer() throws Exception {
- return new TimerProducer(this);
- }
-
- public TimerAction getAction() {
- return action;
- }
-
- public void setAction(TimerAction action) {
- this.action = action;
- }
-
- @Override
- protected String createEndpointUri() {
- return ENDPOINT_URI;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
deleted file mode 100644
index d12726e..0000000
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * 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.metrics.timer;
-
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Timer;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.metrics.AbstractMetricsProducer;
-import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
-import static org.apache.camel.metrics.timer.TimerEndpoint.ENDPOINT_URI;
-
-public class TimerProducer extends AbstractMetricsProducer<TimerEndpoint> {
-
- private static final Logger LOG = LoggerFactory.getLogger(TimerProducer.class);
-
- public TimerProducer(TimerEndpoint endpoint) {
- super(endpoint);
- }
-
- @Override
- protected void doProcess(Exchange exchange, TimerEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
- Message in = exchange.getIn();
- TimerAction action = endpoint.getAction();
- TimerAction finalAction = in.getHeader(HEADER_TIMER_ACTION, action, TimerAction.class);
- if (finalAction == TimerAction.start) {
- handleStart(exchange, registry, metricsName);
- } else if (finalAction == TimerAction.stop) {
- handleStop(exchange, registry, metricsName);
- } else {
- LOG.warn("No action provided for timer \"{}\"", metricsName);
- }
- }
-
- void handleStart(Exchange exchange, MetricRegistry registry, String metricsName) {
- String propertyName = getPropertyName(metricsName);
- Timer.Context context = getTimerContextFromExchange(exchange, propertyName);
- if (context == null) {
- Timer timer = registry.timer(metricsName);
- context = timer.time();
- exchange.setProperty(propertyName, context);
- } else {
- LOG.warn("Timer \"{}\" already running", metricsName);
- }
- }
-
- void handleStop(Exchange exchange, MetricRegistry registry, String metricsName) {
- String propertyName = getPropertyName(metricsName);
- Timer.Context context = getTimerContextFromExchange(exchange, propertyName);
- if (context != null) {
- context.stop();
- exchange.removeProperty(propertyName);
- } else {
- LOG.warn("Timer \"{}\" not found", metricsName);
- }
- }
-
- String getPropertyName(String metricsName) {
- return new StringBuilder(ENDPOINT_URI)
- .append(":")
- .append(metricsName)
- .toString();
- }
-
- Timer.Context getTimerContextFromExchange(Exchange exchange, String propertyName) {
- return exchange.getProperty(propertyName, Timer.Context.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/main/resources/META-INF/services/org/apache/camel/component/metrics
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/resources/META-INF/services/org/apache/camel/component/metrics b/components/camel-metrics/src/main/resources/META-INF/services/org/apache/camel/component/metrics
index debbe31..6701de5 100644
--- a/components/camel-metrics/src/main/resources/META-INF/services/org/apache/camel/component/metrics
+++ b/components/camel-metrics/src/main/resources/META-INF/services/org/apache/camel/component/metrics
@@ -1 +1,18 @@
-class=org.apache.camel.metrics.MetricsComponent
+#
+# 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.
+#
+
+class=org.apache.camel.component.metrics.MetricsComponent
[34/34] git commit: sort the camel-core osgi export services so its
easier to find mistakes.
Posted by da...@apache.org.
sort the camel-core osgi export services so its easier to find mistakes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ca67967e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ca67967e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ca67967e
Branch: refs/heads/master
Commit: ca67967e02c0ad51f791d01d6fd4887dc4ef5290
Parents: c41496c
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 30 14:58:51 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 30 14:58:51 2014 +0200
----------------------------------------------------------------------
camel-core/pom.xml | 44 +++++++++++++++++++++++---------------------
1 file changed, 23 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ca67967e/camel-core/pom.xml
----------------------------------------------------------------------
diff --git a/camel-core/pom.xml b/camel-core/pom.xml
index 6051d23..98f6ad8 100644
--- a/camel-core/pom.xml
+++ b/camel-core/pom.xml
@@ -52,40 +52,42 @@
*
</camel.osgi.import>
<camel.osgi.export.service>
- org.apache.camel.spi.ComponentResolver;component=direct,
- org.apache.camel.spi.ComponentResolver;component=vm,
org.apache.camel.spi.ComponentResolver;component=bean,
- org.apache.camel.spi.ComponentResolver;component=mock,
- org.apache.camel.spi.ComponentResolver;component=test,
- org.apache.camel.spi.ComponentResolver;component=stub,
- org.apache.camel.spi.ComponentResolver;component=validator,
- org.apache.camel.spi.ComponentResolver;component=class,
- org.apache.camel.spi.ComponentResolver;component=properties,
- org.apache.camel.spi.ComponentResolver;component=direct-vm,
- org.apache.camel.spi.ComponentResolver;component=log,
- org.apache.camel.spi.ComponentResolver;component=ref,
- org.apache.camel.spi.ComponentResolver;component=xslt,
+ org.apache.camel.spi.ComponentResolver;component=binding,
org.apache.camel.spi.ComponentResolver;component=browse,
+ org.apache.camel.spi.ComponentResolver;component=class,
+ org.apache.camel.spi.ComponentResolver;component=controlbus,
org.apache.camel.spi.ComponentResolver;component=dataformat,
org.apache.camel.spi.ComponentResolver;component=dataset,
- org.apache.camel.spi.ComponentResolver;component=timer,
+ org.apache.camel.spi.ComponentResolver;component=direct,
+ org.apache.camel.spi.ComponentResolver;component=direct-vm,
org.apache.camel.spi.ComponentResolver;component=file,
- org.apache.camel.spi.ComponentResolver;component=controlbus,
- org.apache.camel.spi.ComponentResolver;component=binding,
- org.apache.camel.spi.ComponentResolver;component=seda,
org.apache.camel.spi.ComponentResolver;component=language,
+ org.apache.camel.spi.ComponentResolver;component=log,
+ org.apache.camel.spi.ComponentResolver;component=mock,
+ org.apache.camel.spi.ComponentResolver;component=properties,
+ org.apache.camel.spi.ComponentResolver;component=ref,
+ org.apache.camel.spi.ComponentResolver;component=rest,
+ org.apache.camel.spi.ComponentResolver;component=seda,
+ org.apache.camel.spi.ComponentResolver;component=stub,
+ org.apache.camel.spi.ComponentResolver;component=test,
+ org.apache.camel.spi.ComponentResolver;component=timer,
+ org.apache.camel.spi.ComponentResolver;component=validator,
+ org.apache.camel.spi.ComponentResolver;component=vm,
+ org.apache.camel.spi.ComponentResolver;component=xslt,
org.apache.camel.spi.DataFormatResolver;dataformat=serialization,
org.apache.camel.spi.DataFormatResolver;dataformat=string,
org.apache.camel.spi.DataFormatResolver;dataformat=zip,
- org.apache.camel.spi.LanguageResolver;language=ref,
- org.apache.camel.spi.LanguageResolver;language=constant,
org.apache.camel.spi.LanguageResolver;language=bean,
- org.apache.camel.spi.LanguageResolver;language=simple,
+ org.apache.camel.spi.LanguageResolver;language=constant,
org.apache.camel.spi.LanguageResolver;language=file,
- org.apache.camel.spi.LanguageResolver;language=property,
org.apache.camel.spi.LanguageResolver;language=header,
+ org.apache.camel.spi.LanguageResolver;language=property,
+ org.apache.camel.spi.LanguageResolver;language=ref,
+ org.apache.camel.spi.LanguageResolver;language=simple,
+ org.apache.camel.spi.LanguageResolver;language=tokenize,
org.apache.camel.spi.LanguageResolver;language=xpath,
- org.apache.camel.spi.LanguageResolver;language=tokenize
+ org.apache.camel.spi.LanguageResolver;language=xtokenize
</camel.osgi.export.service>
<camel.osgi.dynamic>
org.apache.camel.spring.util;${camel.osgi.import.strict.version},
[13/34] git commit: Added header to enable overriding timer action in
the URI.
Posted by da...@apache.org.
Added header to enable overriding timer action in the URI.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5845dbe7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5845dbe7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5845dbe7
Branch: refs/heads/master
Commit: 5845dbe77f6c7908e0cf81f679496cecd6776f58
Parents: 10f5c7c
Author: Lauri Kimmel <la...@gmx.com>
Authored: Mon Jun 2 23:46:18 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Mon Jun 16 21:04:22 2014 +1000
----------------------------------------------------------------------
README.md | 16 +++++
.../apache/camel/metrics/MetricsComponent.java | 1 +
.../camel/metrics/timer/TimerProducer.java | 12 +++-
.../camel/metrics/timer/TimerProducerTest.java | 63 ++++++++++++++++-
.../camel/metrics/timer/TimerRouteTest.java | 74 +++++++++++++++++---
5 files changed, 151 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5845dbe7/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 10a1e4c..b0b7bab 100644
--- a/README.md
+++ b/README.md
@@ -253,3 +253,19 @@ from("direct:in")
```
`Timer Context` objects are stored as `Exchange` properties between different Metrics component calls.
+
+### Headers
+
+Message header can be used to override `action` value specified in Metrics component URI.
+
+| Name | Description | Expected type |
+|-------------------------|------------------------------|----------------------------------------------------------|
+| CamelMetricsTimerAction | Override timer action in URI | org.apache.camel.metrics.timer.TimerEndpoint.TimerAction |
+
+```java
+// sets timer action using header
+from("direct:in")
+ .setHeader(MetricsComponent.HEADER_TIMER_ACTION, TimerAction.start)
+ .to("metric:timer:simple.timer")
+ .to("direct:out")
+```
http://git-wip-us.apache.org/repos/asf/camel/blob/5845dbe7/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index ba04c23..c803e4f 100644
--- a/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -32,6 +32,7 @@ public class MetricsComponent extends DefaultComponent {
public static final String HEADER_COUNTER_DECREMENT = HEADER_PERFIX + "CounterDecrement";
public static final String HEADER_HISTOGRAM_VALUE = HEADER_PERFIX + "HistogramValue";
public static final String HEADER_METER_MARK = HEADER_PERFIX + "MeterMark";
+ public static final String HEADER_TIMER_ACTION = HEADER_PERFIX + "TimerAction";
private static final Logger LOG = LoggerFactory.getLogger(MetricsComponent.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/5845dbe7/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java b/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
index 4f5b809..9586bbd 100644
--- a/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
+++ b/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
@@ -1,6 +1,10 @@
package org.apache.camel.metrics.timer;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
+import static org.apache.camel.metrics.timer.TimerEndpoint.ENDPOINT_URI;
+
import org.apache.camel.Exchange;
+import org.apache.camel.Message;
import org.apache.camel.metrics.AbstractMetricsProducer;
import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
import org.slf4j.Logger;
@@ -19,11 +23,13 @@ public class TimerProducer extends AbstractMetricsProducer<TimerEndpoint> {
@Override
protected void doProcess(Exchange exchange, TimerEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
+ Message in = exchange.getIn();
TimerAction action = endpoint.getAction();
- if (action == TimerAction.start) {
+ TimerAction finalAction = in.getHeader(HEADER_TIMER_ACTION, action, TimerAction.class);
+ if (finalAction == TimerAction.start) {
handleStart(exchange, registry, metricsName);
}
- else if (action == TimerAction.stop) {
+ else if (finalAction == TimerAction.stop) {
handleStop(exchange, registry, metricsName);
}
else {
@@ -57,7 +63,7 @@ public class TimerProducer extends AbstractMetricsProducer<TimerEndpoint> {
}
String getPropertyName(String metricsName) {
- return new StringBuilder(TimerEndpoint.ENDPOINT_URI)
+ return new StringBuilder(ENDPOINT_URI)
.append(":")
.append(metricsName)
.toString();
http://git-wip-us.apache.org/repos/asf/camel/blob/5845dbe7/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java b/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
index e61da97..ff7c1f6 100644
--- a/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
@@ -1,5 +1,6 @@
package org.apache.camel.metrics.timer;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
@@ -8,6 +9,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
import org.apache.camel.Exchange;
+import org.apache.camel.Message;
import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
import org.junit.Before;
import org.junit.Test;
@@ -41,6 +43,9 @@ public class TimerProducerTest {
@Mock
private Timer.Context context;
+ @Mock
+ private Message in;
+
private TimerProducer producer;
@Mock
@@ -49,10 +54,11 @@ public class TimerProducerTest {
@Before
public void setUp() throws Exception {
producer = new TimerProducer(endpoint);
- inOrder = Mockito.inOrder(endpoint, exchange, registry, timer, context);
+ inOrder = Mockito.inOrder(endpoint, exchange, registry, timer, context, in);
when(endpoint.getRegistry()).thenReturn(registry);
when(registry.timer(METRICS_NAME)).thenReturn(timer);
when(timer.time()).thenReturn(context);
+ when(exchange.getIn()).thenReturn(in);
}
@Test
@@ -64,9 +70,12 @@ public class TimerProducerTest {
@Test
public void testProcessStart() throws Exception {
when(endpoint.getAction()).thenReturn(TimerAction.start);
+ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class)).thenReturn(TimerAction.start);
when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class);
inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
inOrder.verify(registry, times(1)).timer(METRICS_NAME);
inOrder.verify(timer, times(1)).time();
@@ -75,11 +84,29 @@ public class TimerProducerTest {
}
@Test
+ public void testProcessStartWithOverride() throws Exception {
+ when(endpoint.getAction()).thenReturn(TimerAction.start);
+ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class)).thenReturn(TimerAction.stop);
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(context, times(1)).stop();
+ inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
public void testProcessStop() throws Exception {
when(endpoint.getAction()).thenReturn(TimerAction.stop);
+ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class)).thenReturn(TimerAction.stop);
when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class);
inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
inOrder.verify(context, times(1)).stop();
inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
@@ -87,10 +114,44 @@ public class TimerProducerTest {
}
@Test
+ public void testProcessStopWithOverride() throws Exception {
+ when(endpoint.getAction()).thenReturn(TimerAction.stop);
+ when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class)).thenReturn(TimerAction.start);
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
+ inOrder.verify(timer, times(1)).time();
+ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
public void testProcessNoAction() throws Exception {
when(endpoint.getAction()).thenReturn(null);
+ when(in.getHeader(HEADER_TIMER_ACTION, null, TimerAction.class)).thenReturn(null);
+ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, null, TimerAction.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessNoActionOverride() throws Exception {
+ when(endpoint.getAction()).thenReturn(null);
+ when(in.getHeader(HEADER_TIMER_ACTION, null, TimerAction.class)).thenReturn(TimerAction.start);
producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getIn();
inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, null, TimerAction.class);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
+ inOrder.verify(timer, times(1)).time();
+ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
inOrder.verifyNoMoreInteractions();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/5845dbe7/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java b/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
index 279be95..1a6581c 100644
--- a/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
+++ b/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
@@ -1,5 +1,9 @@
package org.apache.camel.metrics.timer;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
+import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
@@ -8,11 +12,13 @@ import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.metrics.MetricsComponent;
+import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
@@ -34,8 +40,17 @@ public class TimerRouteTest {
@EndpointInject(uri = "mock:out")
private MockEndpoint endpoint;
- @Produce(uri = "direct:in")
- private ProducerTemplate producer;
+ @Produce(uri = "direct:in-1")
+ private ProducerTemplate producer1;
+
+ @Produce(uri = "direct:in-2")
+ private ProducerTemplate producer2;
+
+ private MetricRegistry mockRegistry;
+
+ private Timer mockTimer;
+
+ private InOrder inOrder;
@Configuration
public static class TestConfig extends SingleRouteCamelConfiguration {
@@ -47,32 +62,69 @@ public class TimerRouteTest {
@Override
public void configure() throws Exception {
- from("direct:in")
+ from("direct:in-1")
.to("metrics:timer:A?action=start")
.to("mock:out");
+
+ from("direct:in-2")
+ .to("metrics:timer:A")
+ .to("mock:out");
}
};
}
- @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
+ @Bean(name = METRIC_REGISTRY_NAME)
public MetricRegistry getMetricRegistry() {
return Mockito.mock(MetricRegistry.class);
}
}
+ @Before
+ public void setup() {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
+ mockTimer = Mockito.mock(Timer.class);
+ inOrder = Mockito.inOrder(mockRegistry, mockTimer);
+ }
+
+ @After
+ public void tearDown() {
+ endpoint.reset();
+ reset(mockRegistry, mockTimer);
+ }
+
@Test
public void testOverrideMetricsName() throws Exception {
- // TODO - 12.05.2014, Lauri - is there any better way to set this up?
- MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
- Timer mockTimer = Mockito.mock(Timer.class);
- InOrder inOrder = Mockito.inOrder(mockRegistry, mockTimer);
when(mockRegistry.timer("B")).thenReturn(mockTimer);
- endpoint.expectedMessageCount(1);
- producer.sendBodyAndHeader(new Object(), MetricsComponent.HEADER_METRIC_NAME, "B");
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer1.sendBodyAndHeader(body, HEADER_METRIC_NAME, "B");
endpoint.assertIsSatisfied();
inOrder.verify(mockRegistry, times(1)).timer("B");
inOrder.verify(mockTimer, times(1)).time();
inOrder.verifyNoMoreInteractions();
}
+
+ @Test
+ public void testOverrideExistingAction() throws Exception {
+ when(mockRegistry.timer("A")).thenReturn(mockTimer);
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer1.sendBodyAndHeader(body, HEADER_TIMER_ACTION, TimerAction.stop);
+ endpoint.assertIsSatisfied();
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideNoAction() throws Exception {
+ when(mockRegistry.timer("A")).thenReturn(mockTimer);
+ Object body = new Object();
+ endpoint.expectedBodiesReceived(body);
+ producer2.sendBodyAndHeader(body, HEADER_TIMER_ACTION, TimerAction.start);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).timer("A");
+ inOrder.verify(mockTimer, times(1)).time();
+ inOrder.verifyNoMoreInteractions();
+ }
}
[18/34] git commit: CAMEL-7554 - camel-metrics
Posted by da...@apache.org.
CAMEL-7554 - camel-metrics
* Preparing for the pull request
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b11d68a8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b11d68a8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b11d68a8
Branch: refs/heads/master
Commit: b11d68a86f8bdb814a15a3f20a3f8c26a36ea00a
Parents: 641de09
Author: Lauri Kimmel <la...@gmx.com>
Authored: Thu Jul 3 08:29:51 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Thu Jul 3 08:29:51 2014 +1000
----------------------------------------------------------------------
components/camel-metrics/.gitignore | 8 --
components/camel-metrics/.travis.yml | 9 --
components/camel-metrics/pom.xml | 205 ++++++++++++------------------
components/pom.xml | 1 +
4 files changed, 80 insertions(+), 143 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b11d68a8/components/camel-metrics/.gitignore
----------------------------------------------------------------------
diff --git a/components/camel-metrics/.gitignore b/components/camel-metrics/.gitignore
deleted file mode 100644
index 9365f3c..0000000
--- a/components/camel-metrics/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Maven
-target
-
-# Eclipse
-
-.classpath
-.project
-.settings/
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/b11d68a8/components/camel-metrics/.travis.yml
----------------------------------------------------------------------
diff --git a/components/camel-metrics/.travis.yml b/components/camel-metrics/.travis.yml
deleted file mode 100644
index 5cf3ef3..0000000
--- a/components/camel-metrics/.travis.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-language: java
-jdk:
- - oraclejdk7
- - openjdk7
- - openjdk6
-
-branches:
- only:
- - master
http://git-wip-us.apache.org/repos/asf/camel/blob/b11d68a8/components/camel-metrics/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-metrics/pom.xml b/components/camel-metrics/pom.xml
index 0f65ab5..db89694 100644
--- a/components/camel-metrics/pom.xml
+++ b/components/camel-metrics/pom.xml
@@ -1,137 +1,90 @@
<?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/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-metrics</artifactId>
- <packaging>bundle</packaging>
- <version>2.13.0</version>
-
- <name>Camel Metrics Component</name>
- <url>http://camel.apache.org</url>
+<!--
+ 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
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- <version>2.13.0</version>
- </dependency>
- <dependency>
- <groupId>com.codahale.metrics</groupId>
- <artifactId>metrics-core</artifactId>
- <version>3.0.1</version>
- </dependency>
-
- <!-- logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.6</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.6</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.17</version>
- <scope>test</scope>
- </dependency>
-
- <!-- testing -->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
- <version>2.13.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-spring</artifactId>
- <version>2.13.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-spring-javaconfig</artifactId>
- <version>2.13.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test-spring</artifactId>
- <version>2.13.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>1.9.5</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <version>1.3</version>
- <scope>test</scope>
- </dependency>
+ 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.
+-->
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- </dependencies>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.14-SNAPSHOT</version>
+ </parent>
- <build>
- <defaultGoal>install</defaultGoal>
+ <artifactId>camel-metrics</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Metrics</name>
+ <description>Camel Metrics based monitoring component</description>
- <plugins>
+ <properties>
+ <camel.osgi.export.pkg>
+ org.apache.camel.component.metrics.*
+ </camel.osgi.export.pkg>
+ <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=metrics</camel.osgi.export.service>
+ </properties>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.5.1</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.codahale.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ <version>3.0.1</version>
+ </dependency>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>2.6</version>
- <configuration>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring-javaconfig</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
- <!-- to generate the MANIFEST-FILE of the bundle -->
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>2.3.7</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>org.apache.camel.camel-metrics</Bundle-SymbolicName>
- <Export-Service>org.apache.camel.spi.ComponentResolver;component=metrics</Export-Service>
- </instructions>
- </configuration>
- </plugin>
+ <!-- logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
- </plugins>
- </build>
+ </dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/b11d68a8/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index 108ecc6..002dc91 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -130,6 +130,7 @@
<module>camel-leveldb</module>
<module>camel-lucene</module>
<module>camel-mail</module>
+ <module>camel-metrics</module>
<module>camel-mina</module>
<module>camel-mina2</module>
<module>camel-mongodb</module>
[05/34] git commit: Implemented metrics:timer endpoint.
Posted by da...@apache.org.
Implemented metrics:timer endpoint.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5deafafa
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5deafafa
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5deafafa
Branch: refs/heads/master
Commit: 5deafafa4d673fbce2c89ca54cfc340597cfc384
Parents: 0ad223e
Author: Lauri Kimmel <la...@gmx.com>
Authored: Wed May 14 00:20:13 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Wed May 14 00:20:13 2014 +1000
----------------------------------------------------------------------
.../apache/camel/metrics/MetricsComponent.java | 4 +
.../camel/metrics/timer/TimerEndpoint.java | 44 +++++
.../camel/metrics/timer/TimerProducer.java | 73 +++++++++
.../metrics/MetricsComponentRouteTest.java | 5 +-
.../camel/metrics/MetricsComponentTest.java | 7 +-
.../camel/metrics/timer/TimerEndpointTest.java | 75 +++++++++
.../camel/metrics/timer/TimerProducerTest.java | 161 +++++++++++++++++++
7 files changed, 365 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5deafafa/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index 7d7d5ef..1f467c4 100644
--- a/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -9,6 +9,7 @@ import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.metrics.counter.CounterEndpoint;
import org.apache.camel.metrics.histogram.HistogramEndpoint;
import org.apache.camel.metrics.meter.MeterEndpoint;
+import org.apache.camel.metrics.timer.TimerEndpoint;
import org.apache.camel.spi.Registry;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
@@ -61,6 +62,9 @@ public class MetricsComponent extends DefaultComponent {
case HISTOGRAM:
endpoint = new HistogramEndpoint(registry, metricsName);
break;
+ case TIMER:
+ endpoint = new TimerEndpoint(registry, metricsName);
+ break;
default:
throw new RuntimeCamelException("Metrics type \"" + type.toString() + "\" not supported");
}
http://git-wip-us.apache.org/repos/asf/camel/blob/5deafafa/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java b/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
new file mode 100644
index 0000000..6de4e32
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
@@ -0,0 +1,44 @@
+package org.apache.camel.metrics.timer;
+
+import org.apache.camel.Producer;
+import org.apache.camel.metrics.AbstractMetricsEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+
+import com.codahale.metrics.MetricRegistry;
+
+@UriEndpoint(scheme = "metrics:timer")
+public class TimerEndpoint extends AbstractMetricsEndpoint {
+
+ public static final String ENDPOINT_URI = "metrics:timer";
+
+ public enum TimerAction {
+ start,
+ stop;
+ }
+
+ @UriParam
+ private TimerAction action;
+
+ public TimerEndpoint(MetricRegistry registry, String metricsName) {
+ super(registry, metricsName);
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new TimerProducer(this);
+ }
+
+ public TimerAction getAction() {
+ return action;
+ }
+
+ public void setAction(TimerAction action) {
+ this.action = action;
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return ENDPOINT_URI;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/5deafafa/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java b/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
new file mode 100644
index 0000000..f655352
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
@@ -0,0 +1,73 @@
+package org.apache.camel.metrics.timer;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+
+public class TimerProducer extends DefaultProducer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TimerProducer.class);
+
+ public TimerProducer(Endpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ TimerEndpoint endpoint = (TimerEndpoint) getEndpoint();
+ MetricRegistry registry = endpoint.getRegistry();
+ String metricsName = endpoint.getMetricsName();
+ TimerAction action = endpoint.getAction();
+ if (action == TimerAction.start) {
+ handleStart(exchange, registry, metricsName);
+ }
+ else if (action == TimerAction.stop) {
+ handleStop(exchange, registry, metricsName);
+ }
+ else {
+ LOG.warn("No action provided for timer \"{}\"", metricsName);
+ }
+ }
+
+ void handleStart(Exchange exchange, MetricRegistry registry, String metricsName) {
+ String propertyName = getPropertyName(metricsName);
+ Timer.Context context = getTimerContextFromExchange(exchange, propertyName);
+ if (context == null) {
+ Timer timer = registry.timer(metricsName);
+ context = timer.time();
+ exchange.setProperty(propertyName, context);
+ }
+ else {
+ LOG.warn("Timer \"{}\" already running", metricsName);
+ }
+ }
+
+ void handleStop(Exchange exchange, MetricRegistry registry, String metricsName) {
+ String propertyName = getPropertyName(metricsName);
+ Timer.Context context = getTimerContextFromExchange(exchange, propertyName);
+ if (context != null) {
+ context.stop();
+ exchange.removeProperty(propertyName);
+ }
+ else {
+ LOG.warn("Timer \"{}\" not found", metricsName);
+ }
+ }
+
+ String getPropertyName(String metricsName) {
+ return new StringBuilder(TimerEndpoint.ENDPOINT_URI)
+ .append(":")
+ .append(metricsName)
+ .toString();
+ }
+
+ Timer.Context getTimerContextFromExchange(Exchange exchange, String propertyName) {
+ return exchange.getProperty(propertyName, Timer.Context.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/5deafafa/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java b/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
index 5ff0ed4..5af70b9 100644
--- a/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
+++ b/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
@@ -26,8 +26,7 @@ public class MetricsComponentRouteTest extends CamelTestSupport {
@Override
public void configure() {
from("direct:start")
- // .to("metrics")
- // .to("metrics:")
+ .to("metrics:timer:T?action=start")
.to("metrics:A")
.to("metrics:counter://B")
.to("metrics:counter:C?increment=19291")
@@ -36,7 +35,9 @@ public class MetricsComponentRouteTest extends CamelTestSupport {
.to("metrics:meter:D")
.to("metrics:meter:D?mark=90001")
.to("metrics:histogram:E")
+ .to("metrics:timer:T")
.to("metrics:histogram:E?value=12000000031")
+ .to("metrics:timer:T?action=stop")
.to("mock:result");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/5deafafa/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java b/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
index 7c1c189..74d91c2 100644
--- a/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
+++ b/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
@@ -18,6 +18,7 @@ import org.apache.camel.RuntimeCamelException;
import org.apache.camel.metrics.counter.CounterEndpoint;
import org.apache.camel.metrics.histogram.HistogramEndpoint;
import org.apache.camel.metrics.meter.MeterEndpoint;
+import org.apache.camel.metrics.timer.TimerEndpoint;
import org.apache.camel.spi.Registry;
import org.junit.Before;
import org.junit.Test;
@@ -143,9 +144,11 @@ public class MetricsComponentTest {
assertThat(endpoint, is(instanceOf(HistogramEndpoint.class)));
}
- @Test(expected = RuntimeCamelException.class)
+ @Test
public void testCreateNewEndpointForTimer() throws Exception {
- component.createNewEndpoint(metricRegistry, MetricsType.TIMER, "a name");
+ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.TIMER, "a name");
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint, is(instanceOf(TimerEndpoint.class)));
}
@Test
http://git-wip-us.apache.org/repos/asf/camel/blob/5deafafa/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java b/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
new file mode 100644
index 0000000..cb3232f
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
@@ -0,0 +1,75 @@
+package org.apache.camel.metrics.timer;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+import org.apache.camel.Producer;
+import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.codahale.metrics.MetricRegistry;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TimerEndpointTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+
+ @Mock
+ private MetricRegistry registry;
+
+ private TimerEndpoint endpoint;
+
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ endpoint = new TimerEndpoint(registry, METRICS_NAME);
+ inOrder = Mockito.inOrder(registry);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testTimerEndpoint() throws Exception {
+ assertThat(endpoint, is(notNullValue()));
+ assertThat(endpoint.getRegistry(), is(registry));
+ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
+ }
+
+ @Test
+ public void testCreateProducer() throws Exception {
+ Producer producer = endpoint.createProducer();
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer, is(instanceOf(TimerProducer.class)));
+ }
+
+ @Test
+ public void testGetAction() throws Exception {
+ assertThat(endpoint.getAction(), is(nullValue()));
+ }
+
+ @Test
+ public void testSetAction() throws Exception {
+ assertThat(endpoint.getAction(), is(nullValue()));
+ endpoint.setAction(TimerAction.start);
+ assertThat(endpoint.getAction(), is(TimerAction.start));
+ }
+
+ @Test
+ public void testCreateEndpointUri() throws Exception {
+ assertThat(endpoint.createEndpointUri(), is(TimerEndpoint.ENDPOINT_URI));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/5deafafa/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java b/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
new file mode 100644
index 0000000..86ec26d
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
@@ -0,0 +1,161 @@
+package org.apache.camel.metrics.timer;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TimerProducerTest {
+
+ private static final String METRICS_NAME = "metrics.name";
+ private static final String PROPERTY_NAME = TimerEndpoint.ENDPOINT_URI + ":" + METRICS_NAME;
+
+ @Mock
+ private TimerEndpoint endpoint;
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private MetricRegistry registry;
+
+ @Mock
+ private Timer timer;
+
+ @Mock
+ private Timer.Context context;
+
+ private TimerProducer producer;
+
+ @Mock
+ private InOrder inOrder;
+
+ @Before
+ public void setUp() throws Exception {
+ producer = new TimerProducer(endpoint);
+ inOrder = Mockito.inOrder(endpoint, exchange, registry, timer, context);
+ when(endpoint.getRegistry()).thenReturn(registry);
+ when(endpoint.getMetricsName()).thenReturn(METRICS_NAME);
+ when(registry.timer(METRICS_NAME)).thenReturn(timer);
+ when(timer.time()).thenReturn(context);
+ }
+
+ @Test
+ public void testTimerProducer() throws Exception {
+ assertThat(producer, is(notNullValue()));
+ assertThat(producer.getEndpoint().equals(endpoint), is(true));
+ }
+
+ @Test
+ public void testProcessStart() throws Exception {
+ when(endpoint.getAction()).thenReturn(TimerAction.start);
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
+ inOrder.verify(timer, times(1)).time();
+ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessStop() throws Exception {
+ when(endpoint.getAction()).thenReturn(TimerAction.stop);
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(context, times(1)).stop();
+ inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessNoAction() throws Exception {
+ when(endpoint.getAction()).thenReturn(null);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(endpoint, times(1)).getMetricsName();
+ inOrder.verify(endpoint, times(1)).getAction();
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testHandleStart() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
+ producer.handleStart(exchange, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(registry, times(1)).timer(METRICS_NAME);
+ inOrder.verify(timer, times(1)).time();
+ inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testHandleStartAlreadyRunning() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
+ producer.handleStart(exchange, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testHandleStop() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
+ producer.handleStop(exchange, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verify(context, times(1)).stop();
+ inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testHandleStopContextNotFound() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
+ producer.handleStop(exchange, registry, METRICS_NAME);
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetPropertyName() throws Exception {
+ assertThat(producer.getPropertyName(METRICS_NAME), is(TimerEndpoint.ENDPOINT_URI + ":" + METRICS_NAME));
+ }
+
+ @Test
+ public void testGetTimerContextFromExchange() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
+ assertThat(producer.getTimerContextFromExchange(exchange, PROPERTY_NAME), is(context));
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testGetTimerContextFromExchangeNotFound() throws Exception {
+ when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
+ assertThat(producer.getTimerContextFromExchange(exchange, PROPERTY_NAME), is(nullValue()));
+ inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
+ inOrder.verifyNoMoreInteractions();
+ }
+}
[32/34] git commit: CAMEL-7554: Upgraded codemetrics
Posted by da...@apache.org.
CAMEL-7554: Upgraded codemetrics
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/dd33bc7c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/dd33bc7c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/dd33bc7c
Branch: refs/heads/master
Commit: dd33bc7c703f2efcb0483b6d46542636614407c4
Parents: 3373b6f
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 30 14:25:46 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 30 14:25:46 2014 +0200
----------------------------------------------------------------------
parent/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/dd33bc7c/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index bd6bc40..2da285a 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -299,7 +299,7 @@
<maven-surefire-report-plugin-version>2.13</maven-surefire-report-plugin-version>
<maven-war-plugin-version>2.4</maven-war-plugin-version>
<maven-version>2.0</maven-version>
- <metrics-version>3.0.1</metrics-version>
+ <metrics-version>3.0.2</metrics-version>
<mina-bundle-version>1.1.7_6</mina-bundle-version>
<mina-version>1.1.7</mina-version>
<mina2-version>2.0.7</mina2-version>
[22/34] git commit: Merge branch 'master' into camel-metrics
Posted by da...@apache.org.
Merge branch 'master' into camel-metrics
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/838eb591
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/838eb591
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/838eb591
Branch: refs/heads/master
Commit: 838eb591af147cb537f9746f704c0912d7f6e482
Parents: 1ff159a 89bf253
Author: Lauri Kimmel <la...@gmx.com>
Authored: Thu Jul 24 22:59:29 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Thu Jul 24 22:59:29 2014 +1000
----------------------------------------------------------------------
apache-camel/pom.xml | 8 +-
.../src/main/descriptors/common-bin.xml | 5 +-
.../java/org/apache/camel/CamelContext.java | 51 +
.../java/org/apache/camel/RecipientList.java | 1 +
.../mbean/ManagedBacklogDebuggerMBean.java | 9 +
.../mbean/ManagedBacklogTracerMBean.java | 6 +
.../mbean/ManagedCamelContextMBean.java | 8 +-
.../ManagedStreamCachingStrategyMBean.java | 2 +-
.../mbean/ManagedThreadPoolMBean.java | 6 +
.../management/mbean/ManagedTracerMBean.java | 6 +
.../apache/camel/builder/AdviceWithTasks.java | 62 +-
.../apache/camel/builder/DataFormatClause.java | 18 +-
.../apache/camel/builder/ExpressionClause.java | 12 +-
.../org/apache/camel/builder/RouteBuilder.java | 96 +-
.../apache/camel/component/bean/MethodInfo.java | 1 +
.../component/file/GenericFileEndpoint.java | 11 +
.../GenericFileExclusiveReadLockStrategy.java | 7 +-
.../FileChangedExclusiveReadLockStrategy.java | 2 +
.../strategy/FileProcessStrategyFactory.java | 4 +
.../FileRenameExclusiveReadLockStrategy.java | 15 +-
.../GenericFileProcessStrategyFactory.java | 4 +
...ericFileRenameExclusiveReadLockStrategy.java | 5 +
.../MarkerFileExclusiveReadLockStrategy.java | 18 +
.../camel/component/log/LogComponent.java | 48 +-
.../apache/camel/component/log/LogEndpoint.java | 59 +
.../properties/PropertiesComponent.java | 12 +-
.../camel/component/rest/RestComponent.java | 55 +
.../camel/component/rest/RestEndpoint.java | 157 ++
.../apache/camel/component/rest/package.html | 26 +
.../org/apache/camel/converter/IOConverter.java | 2 +-
.../apache/camel/impl/DefaultCamelContext.java | 110 +-
.../apache/camel/impl/EmptyProducerCache.java | 13 +-
.../org/apache/camel/impl/JndiRegistry.java | 8 +-
.../org/apache/camel/impl/ProducerCache.java | 14 +-
.../converter/BaseTypeConverterRegistry.java | 17 +-
.../DefaultManagementLifecycleStrategy.java | 4 +-
.../mbean/ManagedBacklogDebugger.java | 24 +
.../management/mbean/ManagedBacklogTracer.java | 8 +
.../management/mbean/ManagedCamelContext.java | 20 +-
.../management/mbean/ManagedThreadPool.java | 8 +
.../camel/management/mbean/ManagedTracer.java | 8 +
.../apache/camel/model/AggregateDefinition.java | 2 +-
.../apache/camel/model/ChoiceDefinition.java | 2 +-
.../java/org/apache/camel/model/Constants.java | 3 +-
.../org/apache/camel/model/ExpressionNode.java | 2 +-
.../apache/camel/model/ModelCamelContext.java | 16 +
.../apache/camel/model/MulticastDefinition.java | 37 +-
.../apache/camel/model/ProcessorDefinition.java | 19 +-
.../camel/model/ProcessorDefinitionHelper.java | 20 +-
.../camel/model/RecipientListDefinition.java | 38 +-
.../org/apache/camel/model/RouteDefinition.java | 25 +
.../camel/model/RouteDefinitionHelper.java | 12 +-
.../org/apache/camel/model/SplitDefinition.java | 35 +-
.../apache/camel/model/ThrottleDefinition.java | 2 +-
.../camel/model/dataformat/JsonDataFormat.java | 62 +-
.../model/dataformat/XStreamDataFormat.java | 17 +
.../camel/model/rest/DeleteVerbDefinition.java | 27 +
.../camel/model/rest/GetVerbDefinition.java | 27 +
.../camel/model/rest/HeadVerbDefinition.java | 27 +
.../camel/model/rest/PostVerbDefinition.java | 27 +
.../camel/model/rest/PutVerbDefinition.java | 27 +
.../camel/model/rest/RestBindingDefinition.java | 218 ++
.../camel/model/rest/RestBindingMode.java | 28 +
.../model/rest/RestConfigurationDefinition.java | 269 +++
.../apache/camel/model/rest/RestContainer.java | 41 +
.../apache/camel/model/rest/RestDefinition.java | 331 +++
.../model/rest/RestPropertyDefinition.java | 52 +
.../camel/model/rest/RestsDefinition.java | 114 +
.../apache/camel/model/rest/VerbDefinition.java | 269 +++
.../apache/camel/model/rest/package-info.java | 23 +
.../org/apache/camel/processor/Enricher.java | 18 +-
.../camel/processor/MulticastProcessor.java | 45 +-
.../apache/camel/processor/RecipientList.java | 11 +-
.../camel/processor/RecipientListProcessor.java | 12 +-
.../org/apache/camel/processor/Splitter.java | 11 +-
.../org/apache/camel/processor/Throttler.java | 3 +-
.../ThrottlerRejectedExecutionException.java | 28 +
.../processor/binding/BindingException.java | 30 +
.../processor/binding/RestBindingProcessor.java | 208 ++
.../loadbalancer/QueueLoadBalancer.java | 3 +-
.../org/apache/camel/spi/RestConfiguration.java | 192 ++
.../apache/camel/spi/RestConsumerFactory.java | 43 +
.../apache/camel/support/RecordableReader.java | 94 +
.../support/XMLTokenExpressionIterator.java | 55 +-
.../org/apache/camel/util/KeyValueHolder.java | 2 +
.../org/apache/camel/util/MessageHelper.java | 57 +-
.../util/component/AbstractApiConsumer.java | 129 +-
.../util/component/AbstractApiEndpoint.java | 118 +-
.../util/component/AbstractApiProducer.java | 92 +-
.../camel/util/component/ApiConsumerHelper.java | 128 +
.../camel/util/component/ApiMethodHelper.java | 90 +-
.../camel/util/component/ApiMethodParser.java | 4 +-
.../component/ApiMethodPropertiesHelper.java | 3 +-
.../util/component/PropertiesInterceptor.java | 32 +
.../component/PropertyNamesInterceptor.java | 32 +
.../camel/util/component/ResultInterceptor.java | 39 +
.../services/org/apache/camel/component/rest | 18 +
.../org/apache/camel/model/rest/jaxb.index | 28 +
.../bean/BeanMethodWithExchangeTest.java | 68 +
...ConsumerBridgeRouteExceptionHandlerTest.java | 5 +
.../FileConsumerCustomExceptionHandlerTest.java | 5 +
.../FileChangedReadLockMarkerFileFalseTest.java | 32 +
.../camel/component/log/LogEndpointTest.java | 23 +-
.../properties/PropertiesComponentTest.java | 25 +-
.../rest/DummyRestConsumerFactory.java | 43 +
.../rest/FromRestConfigurationTest.java | 62 +
.../rest/FromRestExplicitComponentTest.java | 46 +
.../rest/FromRestGetEmbeddedRouteTest.java | 90 +
.../component/rest/FromRestGetEndPathTest.java | 75 +
.../camel/component/rest/FromRestGetTest.java | 89 +
.../component/rest/FromRestUriPrefixTest.java | 71 +
.../org/apache/camel/impl/JndiRegistryTest.java | 59 +
.../apache/camel/issues/AdviceWithCBRTest.java | 67 +
.../camel/issues/AdviceWithOnExceptionTest.java | 62 +
.../camel/issues/AdviceWithPolicyTest.java | 78 +
.../camel/management/BacklogDebuggerTest.java | 13 +
.../JmxInstrumentationUsingDefaultsTest.java | 2 +-
.../ManagedCamelContextNewProxyTest.java | 40 +
.../management/ManagedCamelContextTest.java | 2 +-
.../ManagedFromRestGetEmbeddedRouteTest.java | 93 +
.../management/ManagedFromRestGetTest.java | 91 +
...ProducerRecipientListRegisterAlwaysTest.java | 83 +
.../ManagedProducerRecipientListTest.java | 59 +
...roducerRouteAddRemoveRegisterAlwaysTest.java | 112 +
.../camel/management/ManagedProducerTest.java | 74 +
.../management/ManagedRouteAddRemoveTest.java | 45 +-
.../model/ProcessorDefinitionHelperTest.java | 53 +
.../SplitterParallelAggregateTest.java | 135 ++
.../apache/camel/processor/SplitterTest.java | 21 +
.../apache/camel/processor/ThrottlerTest.java | 5 +-
.../enricher/EnricherSendEventTest.java | 118 +
.../support/RecordableInputStreamTest.java | 9 +-
.../camel/support/RecordableReaderTest.java | 104 +
.../XMLTokenExpressionIteratorCharsetTest.java | 102 +
.../support/XMLTokenExpressionIteratorTest.java | 90 +-
.../apache/camel/util/KeyValueHolderTest.java | 36 +-
.../util/component/ApiMethodHelperTest.java | 18 +-
.../properties/myproperties.properties | 3 +
components/camel-atmosphere-websocket/pom.xml | 1 +
.../websocket/WebsocketComponent.java | 1 +
.../atmosphere/websocket/WebsocketEndpoint.java | 5 +
...ponentConfigurationAndDocumentationTest.java | 56 +
.../component/aws/sqs/SqsConfiguration.java | 10 +
.../camel/component/aws/sqs/SqsConstants.java | 1 +
.../camel/component/aws/sqs/SqsConsumer.java | 1 +
.../camel/component/aws/sqs/SqsEndpoint.java | 2 +-
.../aws/sqs/SqsComponentConfigurationTest.java | 11 +-
.../aws/sqs/SqsComponentSpringTest.java | 2 +
.../component/aws/sqs/SqsComponentTest.java | 2 +
.../SqsComponentIntegrationTest.java | 2 +
.../camel/dataformat/bindy/FormatFactory.java | 8 +-
.../bindy/csv/BindyPatternLocaleTest.java | 103 +
.../dataformat/bindy/model/padding/Unity.java | 51 +
.../blueprint/BlueprintPropertiesParser.java | 29 +-
.../blueprint/CamelContextFactoryBean.java | 22 +
.../handler/CamelNamespaceHandler.java | 2 +
.../camel/blueprint/BlueprintJaxbRestTest.java | 86 +
.../camel/blueprint/BlueprintJaxbTest.java | 3 +-
.../src/test/resources/test-rest.xml | 42 +
components/camel-box/pom.xml | 111 +-
.../apache/camel/component/box/BoxConsumer.java | 104 +-
.../camel/component/box/BoxConverter.java | 54 +
.../apache/camel/component/box/BoxEndpoint.java | 22 +-
.../apache/camel/component/box/BoxProducer.java | 4 -
.../component/box/internal/BoxClientHelper.java | 14 +-
.../component/box/internal/BoxConstants.java | 2 +
.../component/box/internal/EventCallback.java | 29 +
.../box/internal/LongPollingEventsManager.java | 302 +++
.../box/internal/OAuthHelperListener.java | 4 +
.../services/org/apache/camel/TypeConverter | 17 +
.../signatures/long-polling-events-manager.txt | 1 +
.../component/box/AbstractBoxTestSupport.java | 40 +-
...BoxCollaborationsManagerIntegrationTest.java | 22 +-
.../box/IBoxCommentsManagerIntegrationTest.java | 20 +-
.../box/IBoxEventsManagerIntegrationTest.java | 8 +-
.../box/IBoxFilesManagerIntegrationTest.java | 66 +-
.../box/IBoxFoldersManagerIntegrationTest.java | 26 +-
.../box/IBoxGroupsManagerIntegrationTest.java | 48 +-
.../box/IBoxSearchManagerIntegrationTest.java | 4 +-
.../IBoxSharedItemsManagerIntegrationTest.java | 4 +-
.../box/IBoxUsersManagerIntegrationTest.java | 38 +-
...LongPollingEventsManagerIntegrationTest.java | 125 +
.../xml/AbstractCamelContextFactoryBean.java | 16 +-
.../apache/camel/component/cxf/CxfProducer.java | 4 +-
.../component/cxf/jaxrs/CxfRsProducer.java | 62 +-
.../cxf/jaxrs/DefaultCxfRsBinding.java | 12 +-
.../src/main/resources/META-INF/spring.schemas | 3 +
.../component/cxf/jaxrs/CxfRsProducerTest.java | 2 +
.../mtom/CxfMtomProducerPayloadModeTest.java | 13 +-
.../component/cxf/jaxrs/CxfRsSpringProducer.xml | 3 +-
.../elasticsearch/ElasticsearchComponent.java | 7 +-
.../ElasticsearchConfiguration.java | 14 +
.../elasticsearch/ElasticsearchEndpoint.java | 30 +-
...ponentConfigurationAndDocumentationTest.java | 58 +
components/camel-facebook/pom.xml | 3 +
.../FtpChangedExclusiveReadLockStrategy.java | 5 +
.../strategy/FtpProcessStrategyFactory.java | 8 +
.../SftpChangedExclusiveReadLockStrategy.java | 5 +
.../component/gae/auth/GAuthComponent.java | 8 +-
.../camel/component/gae/auth/GAuthEndpoint.java | 8 +
.../component/gae/http/GHttpComponent.java | 3 +
.../camel/component/gae/http/GHttpEndpoint.java | 9 +-
.../component/gae/login/GLoginComponent.java | 8 +-
.../component/gae/login/GLoginEndpoint.java | 10 +
.../component/gae/mail/GMailComponent.java | 8 +-
.../camel/component/gae/mail/GMailEndpoint.java | 8 +
.../component/gae/task/GTaskComponent.java | 3 +
.../camel/component/gae/task/GTaskEndpoint.java | 4 +
...ponentConfigurationAndDocumentationTest.java | 56 +
...ponentConfigurationAndDocumentationTest.java | 57 +
...ponentConfigurationAndDocumentationTest.java | 56 +
...ponentConfigurationAndDocumentationTest.java | 56 +
...ponentConfigurationAndDocumentationTest.java | 55 +
components/camel-hazelcast/pom.xml | 2 +-
.../component/hazelcast/HazelcastComponent.java | 37 +-
.../component/hazelcast/HazelcastConstants.java | 8 -
.../instance/HazelcastInstanceConsumer.java | 23 +-
...astComponentInstanceReferenceSpringTest.java | 49 +
.../HazelcastInstanceConsumerTest.java | 4 +-
.../hazelcast/HazelcastListProducerTest.java | 8 +-
...mel-context-hazelcast-instance-reference.xml | 49 +
.../camel/component/http/HttpComponent.java | 4 +
components/camel-jackson/pom.xml | 3 +
.../component/jackson/JacksonConstants.java | 25 +
.../component/jackson/JacksonDataFormat.java | 102 +-
.../jackson/ListJacksonDataFormat.java | 50 +
.../jackson/JacksonIncludeDefaultTest.java | 53 +
.../jackson/JacksonIncludeNotNulllTest.java | 54 +
.../jackson/JacksonMarshalAllowJMSTypeTest.java | 56 +
.../JacksonMarshalUnmarshalListTest.java | 83 +
.../JacksonMarshalUnmarshalTypeHeaderTest.java | 56 +
.../jackson/JacksonMarshalViewTest.java | 2 +-
.../jackson/ListJacksonUnmarshalDTest.java | 34 +
.../SpringJacksonJsonDataFormatTest.java | 2 +-
.../SpringJacksonMarshalUnmarshalListTest.java | 79 +
.../camel/component/jackson/TestOtherPojo.java | 40 +
.../SpringJacksonMarshalUnmarshalListTest.xml | 43 +
.../camel/component/jdbc/JdbcProducer.java | 8 +-
.../component/jetty/JettyHttpComponent.java | 4 +
.../component/jetty/JettyHttpEndpoint.java | 12 +
...ponentConfigurationAndDocumentationTest.java | 57 +
.../camel-linkedin/camel-linkedin-api/pom.xml | 238 ++
.../component/linkedin/api/DoubleAdapter.java | 35 +
.../linkedin/api/LinkedInException.java | 47 +
.../api/LinkedInExceptionResponseFilter.java | 77 +
.../api/LinkedInOAuthRequestFilter.java | 269 +++
.../component/linkedin/api/LongAdapter.java | 35 +
.../component/linkedin/api/OAuthParams.java | 107 +
.../component/linkedin/api/OAuthScope.java | 64 +
.../linkedin/api/OAuthSecureStorage.java | 36 +
.../component/linkedin/api/OAuthToken.java | 50 +
.../src/main/resources/linkedin-api-schema.xjb | 447 ++++
.../src/main/resources/linkedin-api-schema.xsd | 2255 ++++++++++++++++++
.../src/main/resources/linkedin-api-wadl.xml | 1045 ++++++++
.../src/main/resources/wadl.xsd | 263 ++
.../api/AbstractResourceIntegrationTest.java | 125 +
.../api/PeopleResourceIntegrationTest.java | 99 +
.../api/SearchResourceIntegrationTest.java | 47 +
.../camel-linkedin-component/pom.xml | 280 +++
.../component/linkedin/LinkedInComponent.java | 106 +
.../linkedin/LinkedInConfiguration.java | 155 ++
.../component/linkedin/LinkedInConsumer.java | 58 +
.../component/linkedin/LinkedInEndpoint.java | 174 ++
.../component/linkedin/LinkedInProducer.java | 59 +
.../internal/CachingOAuthSecureStorage.java | 50 +
.../linkedin/internal/LinkedInConstants.java | 29 +
.../internal/LinkedInPropertiesHelper.java | 40 +
.../org/apache/camel/component/linkedin | 1 +
.../linkedin/AbstractLinkedInTestSupport.java | 73 +
.../CommentsResourceIntegrationTest.java | 66 +
.../CompaniesResourceIntegrationTest.java | 353 +++
.../linkedin/GroupsResourceIntegrationTest.java | 65 +
.../linkedin/JobsResourceIntegrationTest.java | 93 +
.../linkedin/PeopleResourceIntegrationTest.java | 636 +++++
.../linkedin/PostsResourceIntegrationTest.java | 162 ++
.../linkedin/SearchResourceIntegrationTest.java | 161 ++
.../src/test/resources/log4j.properties | 36 +
.../src/test/resources/test-options.properties | 28 +
components/camel-linkedin/pom.xml | 66 +
.../netty/http/HttpServerPipelineFactory.java | 4 +-
.../netty/http/NettyHttpComponent.java | 1 +
.../netty/http/NettyHttpConfiguration.java | 19 +
.../component/netty/http/NettyHttpEndpoint.java | 5 +
...ponentConfigurationAndDocumentationTest.java | 58 +
.../netty/NettyClientBossPoolBuilder.java | 2 +-
.../camel/component/netty/NettyComponent.java | 4 +
.../netty/NettyServerBossPoolBuilder.java | 2 +-
.../component/netty/NettyWorkerPoolBuilder.java | 2 +-
.../netty/UnsharableCodecsConflicts2Test.java | 4 +-
.../netty/UnsharableCodecsConflictsTest.java | 2 +-
components/camel-netty4/pom.xml | 94 +
.../netty4/ChannelHandlerFactories.java | 128 +
.../component/netty4/ChannelHandlerFactory.java | 35 +
.../component/netty4/ClientPipelineFactory.java | 42 +
.../netty4/DefaultChannelHandlerFactory.java | 37 +
.../netty4/DefaultClientPipelineFactory.java | 170 ++
.../netty4/DefaultServerPipelineFactory.java | 191 ++
.../camel/component/netty4/NettyCamelState.java | 46 +
.../camel/component/netty4/NettyComponent.java | 148 ++
.../component/netty4/NettyConfiguration.java | 465 ++++
.../camel/component/netty4/NettyConstants.java | 42 +
.../camel/component/netty4/NettyConsumer.java | 119 +
.../netty4/NettyConsumerExceptionHandler.java | 66 +
.../camel/component/netty4/NettyConverter.java | 130 +
.../camel/component/netty4/NettyEndpoint.java | 171 ++
.../camel/component/netty4/NettyHelper.java | 125 +
.../component/netty4/NettyPayloadHelper.java | 105 +
.../camel/component/netty4/NettyProducer.java | 526 ++++
.../NettyServerBootstrapConfiguration.java | 450 ++++
.../netty4/NettyServerBootstrapFactory.java | 73 +
.../netty4/NettyServerBossPoolBuilder.java | 67 +
.../netty4/NettyWorkerPoolBuilder.java | 79 +
.../component/netty4/ServerPipelineFactory.java | 43 +
.../netty4/ShareableChannelHandlerFactory.java | 36 +
.../netty4/SharedSingletonObjectPool.java | 86 +
.../SingleTCPNettyServerBootstrapFactory.java | 206 ++
.../SingleUDPNettyServerBootstrapFactory.java | 200 ++
.../component/netty4/TextLineDelimiter.java | 26 +
.../netty4/codec/DatagramPacketDecoder.java | 40 +
.../codec/DatagramPacketDelimiterDecoder.java | 47 +
.../netty4/codec/DatagramPacketEncoder.java | 42 +
.../codec/DatagramPacketObjectDecoder.java | 51 +
.../codec/DatagramPacketObjectEncoder.java | 51 +
.../codec/DatagramPacketStringDecoder.java | 62 +
.../codec/DatagramPacketStringEncoder.java | 69 +
.../codec/DelimiterBasedFrameDecoder.java | 34 +
.../component/netty4/codec/ObjectDecoder.java | 38 +
.../component/netty4/codec/ObjectEncoder.java | 34 +
.../netty4/handlers/ClientChannelHandler.java | 237 ++
.../netty4/handlers/ServerChannelHandler.java | 212 ++
.../handlers/ServerResponseFutureListener.java | 78 +
.../component/netty4/ssl/SSLEngineFactory.java | 85 +
.../component/netty4/util/SubnetUtils.java | 360 +++
.../src/main/resources/META-INF/LICENSE.txt | 203 ++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../services/org/apache/camel/TypeConverter | 18 +
.../services/org/apache/camel/component/netty4 | 17 +
.../camel-netty4/src/test/data/message1.txt | 1 +
.../camel/component/netty4/BaseNettyTest.java | 95 +
.../netty4/MultipleCodecsSpringTest.java | 43 +
.../component/netty4/MultipleCodecsTest.java | 87 +
.../camel/component/netty4/MyCustomCodec.java | 79 +
.../component/netty4/Netty2978IssueTest.java | 123 +
.../component/netty4/NettyBacklogTest.java | 46 +
...ponentConfigurationAndDocumentationTest.java | 57 +
.../NettyComponentWithConfigurationTest.java | 57 +
.../component/netty4/NettyConcurrentTest.java | 105 +
.../component/netty4/NettyConverterTest.java | 61 +
.../component/netty4/NettyCustomCodecTest.java | 64 +
.../NettyCustomPipelineFactoryAsynchTest.java | 120 +
.../NettyCustomPipelineFactorySynchTest.java | 125 +
.../component/netty4/NettyDisconnectTest.java | 49 +
.../component/netty4/NettyFileTcpTest.java | 50 +
.../NettyInOutCloseChannelWhenCompleteTest.java | 50 +
.../netty4/NettyInOutFromSedaTest.java | 56 +
.../NettyInOutWithForcedNoResponseTest.java | 55 +
.../netty4/NettyManualEndpointTest.java | 80 +
.../NettyMultipleSimultaneousClientsTest.java | 95 +
.../camel/component/netty4/NettyOptionTest.java | 46 +
.../netty4/NettyProducerAsyncEndpointTest.java | 76 +
.../netty4/NettyProducerPoolDisabledTest.java | 50 +
.../camel/component/netty4/NettyProxyTest.java | 61 +
.../netty4/NettyRequestTimeoutIssueTest.java | 50 +
.../netty4/NettyRequestTimeoutTest.java | 84 +
.../netty4/NettyReuseConnectionTest.java | 46 +
.../component/netty4/NettySSLClasspathTest.java | 57 +
.../netty4/NettySSLClientCertHeadersTest.java | 74 +
.../netty4/NettySSLContextParametersTest.java | 92 +
.../netty4/NettySSLPassphaseBeanTest.java | 65 +
.../camel/component/netty4/NettySSLTest.java | 79 +
.../component/netty4/NettySingleCodecTest.java | 63 +
.../netty4/NettySuspendResumeTest.java | 61 +
.../component/netty4/NettyTCPAsyncTest.java | 75 +
.../netty4/NettyTCPSyncNotLazyChannelTest.java | 62 +
.../component/netty4/NettyTCPSyncTest.java | 75 +
.../NettyTcpWithInOutUsingPlainSocketTest.java | 143 ++
.../NettyTextlineInOnlyNullDelimiterTest.java | 48 +
.../netty4/NettyTextlineInOnlyTest.java | 66 +
.../NettyTextlineInOutNonBlockingTest.java | 87 +
.../NettyTextlineInOutSynchronousFalseTest.java | 72 +
.../NettyTextlineInOutSynchronousTest.java | 72 +
.../netty4/NettyTextlineInOutTest.java | 50 +
.../netty4/NettyTransferExchangeOptionTest.java | 128 +
.../component/netty4/NettyUDPAsyncTest.java | 63 +
.../netty4/NettyUDPLargeMessageInOnlyTest.java | 68 +
.../netty4/NettyUDPMulticastAsyncTest.java | 91 +
.../netty4/NettyUDPObjectSyncTest.java | 50 +
.../component/netty4/NettyUDPSyncTest.java | 54 +
.../NettyUdpWithInOutUsingPlainSocketTest.java | 80 +
...UseSharedWorkerThreadPoolManyRoutesTest.java | 83 +
.../NettyUseSharedWorkerThreadPoolTest.java | 103 +
.../apache/camel/component/netty4/Poetry.java | 57 +
...pringNettyUseSharedWorkerThreadPoolTest.java | 51 +
.../netty4/UnsharableCodecsConflicts2Test.java | 120 +
.../netty4/UnsharableCodecsConflictsTest.java | 128 +
.../src/test/resources/keystore.jks | Bin 0 -> 1473 bytes
.../src/test/resources/log4j.properties | 38 +
...SpringNettyUseSharedWorkerThreadPoolTest.xml | 52 +
.../camel/component/netty4/multiple-codecs.xml | 72 +
.../camel-netty4/src/test/resources/test.txt | 19 +
.../component/rabbitmq/RabbitMQComponent.java | 3 +
.../component/rabbitmq/RabbitMQConsumer.java | 85 +-
.../component/rabbitmq/RabbitMQEndpoint.java | 12 +
.../component/rabbitmq/RabbitMQProducer.java | 8 +-
.../component/rabbitmq/RabbitMQLoadIntTest.java | 103 +
components/camel-restlet/pom.xml | 14 +-
.../restlet/DefaultRestletBinding.java | 13 +-
.../component/restlet/RestletComponent.java | 83 +-
.../component/restlet/RestletConsumer.java | 2 +-
.../component/restlet/RestletEndpoint.java | 21 +-
.../camel/component/restlet/RestletHelper.java | 54 +
.../component/restlet/RestletProducer.java | 26 +-
.../camel/component/restlet/CountryPojo.java | 39 +
.../restlet/RestRestletBindingModeJsonTest.java | 78 +
.../restlet/RestRestletBindingModeXmlTest.java | 78 +
.../component/restlet/RestRestletGetTest.java | 57 +
.../restlet/RestRestletPojoInOutTest.java | 53 +
.../RestRestletPostJsonJaxbPojoTest.java | 60 +
.../RestRestletPostJsonPojoListTest.java | 67 +
.../restlet/RestRestletPostJsonPojoTest.java | 60 +
.../restlet/RestRestletPostXmlJaxbPojoTest.java | 78 +
.../restlet/RestletContentTypeTest.java | 79 +
.../component/restlet/RestletPostFormTest.java | 2 +
.../component/restlet/RestletResponseTest.java | 4 +-
.../component/restlet/RestletSetBodyTest.java | 4 +
.../camel/component/restlet/UserJaxbPojo.java | 48 +
.../camel/component/restlet/UserPojo.java | 39 +
.../camel/component/restlet/UserService.java | 33 +
components/camel-scala/pom.xml | 4 +-
.../org/apache/camel/scala/RichMessage.scala | 74 +-
.../camel/scala/dsl/SAbstractDefinition.scala | 10 +-
.../camel/scala/dsl/SMulticastDefinition.scala | 5 +
.../camel/scala/dsl/SSplitDefinition.scala | 4 +-
.../camel/scala/dsl/builder/RouteBuilder.scala | 4 +-
.../camel/scala/dsl/InterceptFromTest.scala | 4 +-
.../apache/camel/scala/dsl/MulticastTest.scala | 2 +-
.../camel/scala/dsl/OnExceptionTest.scala | 8 +-
.../scala/dsl/SetExchangePatternTest.scala | 4 +-
.../org/apache/camel/scala/routeSpec.scala | 12 +-
.../camel/builder/script/ScriptBuilder.java | 4 +
.../script/LanguagePythonStatementsTest.java | 46 +
.../camel-script/src/test/resources/mypython.py | 3 +
.../component/servlet/ServletComponent.java | 10 +
.../component/servlet/ServletEndpoint.java | 4 +
...ponentConfigurationAndDocumentationTest.java | 58 +
components/camel-solr/pom.xml | 22 +-
.../camel/component/solr/SolrComponent.java | 34 +-
.../camel/component/solr/SolrConstants.java | 1 +
.../camel/component/solr/SolrEndpoint.java | 101 +-
.../camel/component/solr/SolrProducer.java | 70 +-
.../org/apache/camel/component/solrCloud | 18 +
.../services/org/apache/camel/component/solrs | 18 +
.../camel/component/solr/JettySolrFactory.java | 133 ++
.../camel/component/solr/SolrAddBeanTest.java | 4 +
.../camel/component/solr/SolrCloudFixture.java | 173 ++
.../solr/SolrComponentTestSupport.java | 74 +-
.../camel/component/solr/SolrDeleteTest.java | 7 +-
.../camel/component/solr/SolrFixtures.java | 115 +
.../camel/component/solr/SolrTestSupport.java | 6 +
.../component/solr/SolrTransactionsTest.java | 4 +
.../camel/component/solr/SolrUpdateTest.java | 12 +-
.../src/test/resources/log4j.properties | 1 +
.../resources/solr/collection1/conf/elevate.xml | 36 +
.../solr/collection1/conf/protwords.txt | 21 +
.../resources/solr/collection1/conf/schema.xml | 652 +++++
.../solr/collection1/conf/scripts.conf | 24 +
.../solr/collection1/conf/solrconfig.xml | 1871 +++++++++++++++
.../solr/collection1/conf/spellings.txt | 2 +
.../solr/collection1/conf/stopwords.txt | 14 +
.../solr/collection1/conf/stopwords_en.txt | 54 +
.../solr/collection1/conf/synonyms.txt | 29 +
.../resources/solr/collection1/core.properties | 1 +
.../resources/solr/conf/collection1/elevate.xml | 36 +
.../solr/conf/collection1/protwords.txt | 21 +
.../resources/solr/conf/collection1/schema.xml | 648 +++++
.../solr/conf/collection1/scripts.conf | 24 +
.../solr/conf/collection1/solrconfig.xml | 1871 +++++++++++++++
.../solr/conf/collection1/spellings.txt | 2 +
.../solr/conf/collection1/stopwords.txt | 14 +
.../solr/conf/collection1/stopwords_en.txt | 54 +
.../solr/conf/collection1/synonyms.txt | 29 +
.../src/test/resources/solr/conf/elevate.xml | 36 -
.../src/test/resources/solr/conf/protwords.txt | 21 -
.../src/test/resources/solr/conf/schema.xml | 648 -----
.../src/test/resources/solr/conf/scripts.conf | 24 -
.../src/test/resources/solr/conf/solrconfig.xml | 1528 ------------
.../src/test/resources/solr/conf/spellings.txt | 2 -
.../src/test/resources/solr/conf/stopwords.txt | 14 -
.../test/resources/solr/conf/stopwords_en.txt | 54 -
.../src/test/resources/solr/conf/synonyms.txt | 29 -
.../src/test/resources/solr/solr-no-core.xml | 31 +
.../camel-solr/src/test/resources/solr/solr.xml | 19 +-
.../src/test/resources/solrtest.keystore | Bin 0 -> 2208 bytes
components/camel-spark-rest/pom.xml | 136 ++
.../camel/component/sparkrest/CamelSpark.java | 84 +
.../component/sparkrest/CamelSparkRoute.java | 65 +
.../sparkrest/DefaultSparkBinding.java | 218 ++
.../sparkrest/ServletSparkApplication.java | 37 +
.../camel/component/sparkrest/SparkBinding.java | 60 +
.../component/sparkrest/SparkComponent.java | 170 ++
.../component/sparkrest/SparkConfiguration.java | 65 +
.../component/sparkrest/SparkConstants.java | 26 +
.../component/sparkrest/SparkConsumer.java | 53 +
.../component/sparkrest/SparkConverter.java | 82 +
.../component/sparkrest/SparkEndpoint.java | 115 +
.../sparkrest/SparkHeaderFilterStrategy.java | 57 +
.../camel/component/sparkrest/SparkHelper.java | 56 +
.../camel/component/sparkrest/SparkMessage.java | 51 +
.../sparkrest/SparkServletContextListener.java | 46 +
.../src/main/resources/META-INF/LICENSE.txt | 203 ++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../services/org/apache/camel/TypeConverter | 18 +
.../org/apache/camel/component/spark-rest | 17 +
.../component/sparkrest/BaseSparkTest.java | 46 +
.../sparkrest/CamelSparkAcceptTest.java | 55 +
.../sparkrest/CamelSparkParamTest.java | 46 +
.../sparkrest/CamelSparkRequestBeanTest.java | 50 +
.../sparkrest/CamelSparkSplatTest.java | 45 +
.../component/sparkrest/CamelSparkTest.java | 45 +
.../sparkrest/RestCamelSparkAcceptTest.java | 38 +
.../sparkrest/RestCamelSparkComponentTest.java | 46 +
.../RestCamelSparkMapHeadersFalseTest.java | 51 +
.../sparkrest/RestCamelSparkParamTest.java | 36 +
.../RestCamelSparkRequestBeanTest.java | 36 +
.../sparkrest/RestCamelSparkSplatTest.java | 35 +
.../component/sparkrest/RestCamelSparkTest.java | 66 +
.../RestConfigurationCamelSparkTest.java | 75 +
.../src/test/resources/log4j.properties | 36 +
components/camel-spark/pom.xml | 136 --
.../camel/component/spark/CamelSpark.java | 84 -
.../camel/component/spark/CamelSparkRoute.java | 65 -
.../component/spark/DefaultSparkBinding.java | 218 --
.../camel/component/spark/SparkBinding.java | 60 -
.../camel/component/spark/SparkComponent.java | 92 -
.../component/spark/SparkConfiguration.java | 65 -
.../camel/component/spark/SparkConstants.java | 26 -
.../camel/component/spark/SparkConsumer.java | 53 -
.../camel/component/spark/SparkConverter.java | 79 -
.../camel/component/spark/SparkEndpoint.java | 115 -
.../spark/SparkHeaderFilterStrategy.java | 57 -
.../camel/component/spark/SparkHelper.java | 56 -
.../camel/component/spark/SparkMessage.java | 51 -
.../component/spark/SparkRouteBuilder.java | 91 -
.../src/main/resources/META-INF/LICENSE.txt | 203 --
.../src/main/resources/META-INF/NOTICE.txt | 11 -
.../services/org/apache/camel/TypeConverter | 18 -
.../services/org/apache/camel/component/spark | 17 -
.../camel/component/spark/BaseSparkTest.java | 46 -
.../component/spark/CamelSparkAcceptTest.java | 55 -
.../component/spark/CamelSparkParamTest.java | 46 -
.../spark/CamelSparkRequestBeanTest.java | 50 -
.../spark/CamelSparkRouteBuilderPostTest.java | 45 -
.../spark/CamelSparkRouteBuilderTest.java | 45 -
.../component/spark/CamelSparkSplatTest.java | 45 -
.../camel/component/spark/CamelSparkTest.java | 45 -
.../src/test/resources/log4j.properties | 36 -
.../src/main/resources/META-INF/spring.schemas | 3 +
components/camel-spring-javaconfig/pom.xml | 2 +-
.../src/main/resources/META-INF/spring.schemas | 3 +
.../camel/spring/CamelContextFactoryBean.java | 22 +
.../spring/handler/CamelNamespaceHandler.java | 4 +
.../src/main/resources/META-INF/spring.schemas | 6 +
.../rest/SpringFromRestConfigurationTest.java | 29 +
.../SpringFromRestGetEmbeddedRouteTest.java | 29 +
.../component/rest/SpringFromRestGetTest.java | 29 +
.../rest/SpringFromRestUriPrefixTest.java | 29 +
.../issues/AdviceWithTransactionIssueTest.java | 76 +
.../SpringJmxDumpCBRRoutesAsXmlTest.java | 55 +
.../rest/SpringFromRestConfigurationTest.xml | 66 +
.../rest/SpringFromRestGetEmbeddedRouteTest.xml | 56 +
.../component/rest/SpringFromRestGetTest.xml | 59 +
.../rest/SpringFromRestUriPrefixTest.xml | 57 +
.../issues/AdviceWithTransactionIssueTest.xml | 35 +
.../SpringJmxDumpCBRRouteAsXmlTest.xml | 43 +
.../apache/camel/spring/processor/throttler.xml | 2 +-
.../rest/DummyRestConsumerFactory.java | 43 +
.../rest/FromRestConfigurationTest.java | 41 +
.../rest/FromRestGetEmbeddedRouteTest.java | 66 +
.../component/rest/FromRestGetTest.java | 67 +
.../component/rest/FromRestUriPrefixTest.java | 63 +
.../rest/FromRestConfigurationTest.xml | 64 +
.../rest/FromRestGetEmbeddedRouteTest.xml | 54 +
.../component/rest/FromRestGetTest.xml | 57 +
.../component/rest/FromRestUriPrefixTest.xml | 55 +
components/camel-test-spring/pom.xml | 39 +-
components/camel-test-spring3/pom.xml | 92 +
.../CamelSpringDelegatingTestContextLoader.java | 321 +++
.../spring/CamelSpringJUnit4ClassRunner.java | 88 +
.../spring/CamelSpringTestContextLoader.java | 473 ++++
...gTestContextLoaderTestExecutionListener.java | 36 +
.../test/spring/CamelSpringTestHelper.java | 99 +
.../test/spring/CamelSpringTestSupport.java | 220 ++
.../apache/camel/test/spring/DisableJmx.java | 43 +
.../spring/DisableJmxTestExecutionListener.java | 39 +
.../apache/camel/test/spring/ExcludeRoutes.java | 44 +
.../test/spring/LazyLoadTypeConverters.java | 44 +
.../apache/camel/test/spring/MockEndpoints.java | 43 +
.../camel/test/spring/MockEndpointsAndSkip.java | 43 +
.../camel/test/spring/ProvidesBreakpoint.java | 36 +
.../camel/test/spring/ShutdownTimeout.java | 49 +
.../spring/StopWatchTestExecutionListener.java | 60 +
.../apache/camel/test/spring/UseAdviceWith.java | 49 +
.../src/main/resources/META-INF/LICENSE.txt | 203 ++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../AdviceWithOnExceptionMultipleIssueTest.java | 116 +
.../test/issues/MockEndpointsAndSkipTest.java | 46 +
.../patterns/DebugSpringCamelContextTest.java | 40 +
.../camel/test/patterns/DebugSpringTest.java | 81 +
.../camel/test/patterns/MyProduceBean.java | 41 +
.../apache/camel/test/patterns/MySender.java | 25 +
.../camel/test/patterns/ProduceBeanTest.java | 42 +
.../test/patterns/ProducerBeanInjectTest.java | 38 +
.../spring/CamelSpringActiveProfileTest.java | 56 +
...ssRunnerDisableJmxInheritedOverrideTest.java | 32 +
...Unit4ClassRunnerDisableJmxInheritedTest.java | 21 +
...elSpringJUnit4ClassRunnerDisableJmxTest.java | 33 +
...pringJUnit4ClassRunnerExcludeRoutesTest.java | 29 +
...LoadTypeConvertersInheritedOverrideTest.java | 33 +
...nnerLazyLoadTypeConvertersInheritedTest.java | 21 +
...t4ClassRunnerLazyLoadTypeConvertersTest.java | 33 +
...nit4ClassRunnerMockEndpointsAndSkipTest.java | 56 +
...pringJUnit4ClassRunnerMockEndpointsTest.java | 57 +
.../CamelSpringJUnit4ClassRunnerPlainTest.java | 126 +
...sRunnerProvidesBreakpointInherritedTest.java | 22 +
...JUnit4ClassRunnerProvidesBreakpointTest.java | 67 +
...nerShutdownTimeoutInheritedOverrideTest.java | 34 +
...ClassRunnerShutdownTimeoutInheritedTest.java | 22 +
...ingJUnit4ClassRunnerShutdownTimeoutTest.java | 34 +
...pringJUnit4ClassRunnerUseAdviceWithTest.java | 52 +
...CamelSpringTestSupportActiveProfileTest.java | 51 +
.../camel/test/spring/TestRouteBuilder.java | 30 +
.../src/test/resources/jndi.properties | 22 +
.../src/test/resources/log4j.properties | 37 +
.../AdviceWithOnExceptionMultipleIssueTest.xml | 47 +
.../test/issues/MockEndpointsAndSkipTest.xml | 35 +
.../test/patterns/ProduceBeanInjectTest.xml | 39 +
.../camel/test/patterns/ProduceBeanTest.xml | 33 +
.../camel/test/patterns/applicationContext.xml | 38 +
.../CamelSpringActiveProfileTest-context.xml | 41 +
...SpringJUnit4ClassRunnerPlainTest-context.xml | 50 +
.../apache/camel/test/spring/test.properties | 18 +
components/camel-testng/pom.xml | 2 +-
.../component/twitter/TwitterConfiguration.java | 12 -
.../twitter/TwitterEndpointDirect.java | 8 -
.../component/twitter/TwitterEndpointEvent.java | 6 -
.../twitter/TwitterEndpointPolling.java | 6 -
.../component/twitter/UriConfigurationTest.java | 10 -
.../xmlsecurity/XmlSignatureEndpoint.java | 8 +
.../xmlsecurity/XmlSignerEndpoint.java | 25 +
.../api/DefaultXmlSignature2Message.java | 64 +-
.../component/xmlsecurity/api/KeyAccessor.java | 5 +-
.../xmlsecurity/api/SignatureType.java | 23 +
.../xmlsecurity/api/XmlSignature2Message.java | 7 +-
.../xmlsecurity/api/XmlSignatureChecker.java | 29 +
.../xmlsecurity/api/XmlSignatureConstants.java | 4 +
.../xmlsecurity/api/XmlSignatureHelper.java | 17 +-
.../xmlsecurity/api/XmlSignatureProperties.java | 27 +-
.../processor/XmlSignatureConfiguration.java | 17 +
.../processor/XmlSignatureProcessor.java | 55 +-
.../processor/XmlSignerConfiguration.java | 104 +-
.../processor/XmlSignerProcessor.java | 416 +++-
.../processor/XmlVerifierProcessor.java | 291 ++-
.../xmlsecurity/SpringXmlSignatureTest.java | 8 +
.../component/xmlsecurity/XmlSignatureTest.java | 771 ++++--
.../src/test/resources/log4j.properties | 1 +
.../xmlsecurity/SpringXmlSignatureTests.xml | 830 +++----
.../apache/camel/component/xmlsecurity/Test.xsd | 25 +
.../camel/component/xmlsecurity/TestB.xsd | 21 +
.../camel/component/xmlsecurity/TestComplex.xsd | 24 +
.../xmlsecurity/xmldsig-core-schema.xsd | 308 +++
.../xstream/AbstractXStreamWrapper.java | 36 +-
.../xstream/SpringXStreamConfigurationTest.xml | 4 +-
.../camel/dataformat/zipfile/ZipIterator.java | 12 +-
.../component/zookeeper/ZooKeeperComponent.java | 8 +-
.../zookeeper/ZooKeeperConfiguration.java | 12 +
.../component/zookeeper/ZooKeeperEndpoint.java | 4 +
...ponentConfigurationAndDocumentationTest.java | 56 +
components/pom.xml | 12 +-
examples/camel-example-box-osgi/README.txt | 38 +
examples/camel-example-box-osgi/pom.xml | 85 +
.../src/main/resources/META-INF/LICENSE.txt | 203 ++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../resources/META-INF/spring/camel-context.xml | 55 +
.../src/test/resources/log4j.properties | 31 +
.../camel-example-spark-rest-tomcat/README.txt | 25 +
.../camel-example-spark-rest-tomcat/pom.xml | 85 +
.../example/spark/MySparkRouteBuilder.java | 48 +
.../src/main/resources/META-INF/LICENSE.txt | 203 ++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../src/main/resources/camel-config.xml | 34 +
.../src/main/resources/log4j.properties | 28 +
.../src/main/webapp/WEB-INF/web.xml | 59 +
.../src/main/webapp/index.html | 70 +
examples/pom.xml | 1 +
parent/pom.xml | 98 +-
.../features/src/main/resources/features.xml | 31 +
pom.xml | 25 +-
tests/camel-blueprint-cxf-test/pom.xml | 18 +
.../test/cxf/blueprint/CxfEndpointBeans.xml | 16 +-
...lueprintPropertiesCustomPrefixRouteTest.java | 82 +
.../camel/itest/osgi/blueprint/blueprint-27.xml | 51 +
tests/camel-itest-spring32/pom.xml | 52 +-
.../camel/itest/async/MyAsyncComponent.java | 37 +
.../camel/itest/async/MyAsyncEndpoint.java | 73 +
.../camel/itest/async/MyAsyncProducer.java | 77 +
.../ibatis/AsyncEndpointTransacted2Test.java | 96 +
.../ibatis/AsyncEndpointTransactedTest.java | 88 +
.../apache/camel/itest/ibatis/DummyTable.java | 35 +
.../camel/itest/ibatis/DummyTableImpl.java | 54 +
.../camel/itest/ibatis/ExceptionRethrower.java | 30 +
.../camel/itest/ibatis/LoggingPipelineTest.java | 95 +
.../ibatis/PartiallyTransactedPipelineTest.java | 99 +
...edExceptionClauseAfterTransactedTagTest.java | 99 +
.../itest/ibatis/TransactedFullExampleTest.java | 127 +
.../ibatis/TransactedOnCompletionTest.java | 99 +
.../itest/ibatis/TransactedOnExceptionTest.java | 99 +
.../itest/ibatis/TransactedPipelineTest.java | 94 +
.../itest/ibatis/TransactedTryCatchTest.java | 107 +
.../src/test/resources/ibatis-config.xml | 8 +
.../ibatis/AsyncEndpointTransacted2Test.xml | 52 +
.../ibatis/AsyncEndpointTransactedTest.xml | 41 +
.../camel/itest/ibatis/LoggingPipelineTest.xml | 43 +
.../ibatis/PartiallyTransactedPipelineTest.xml | 37 +
...nsactedExceptionClauseAfterTransactedTag.xml | 46 +
.../itest/ibatis/TransactedFullExampleTest.xml | 58 +
.../itest/ibatis/TransactedOnCompletionTest.xml | 39 +
.../itest/ibatis/TransactedOnExceptionTest.xml | 44 +
.../itest/ibatis/TransactedPipelineTest.xml | 36 +
.../itest/ibatis/TransactedTryCatchTest.xml | 48 +
.../camel/itest/ibatis/database-context.xml | 44 +
.../src/test/resources/table.xml | 13 +
.../src/test/resources/transactions.properties | 43 +
tests/camel-itest/pom.xml | 34 +-
.../apache/camel/itest/http/Http4RouteTest.java | 37 +-
.../ibatis/AsyncEndpointTransacted2Test.java | 96 -
.../ibatis/AsyncEndpointTransactedTest.java | 88 -
.../apache/camel/itest/ibatis/DummyTable.java | 35 -
.../camel/itest/ibatis/DummyTableImpl.java | 54 -
.../camel/itest/ibatis/ExceptionRethrower.java | 30 -
.../camel/itest/ibatis/LoggingPipelineTest.java | 95 -
.../ibatis/PartiallyTransactedPipelineTest.java | 99 -
...edExceptionClauseAfterTransactedTagTest.java | 99 -
.../itest/ibatis/TransactedFullExampleTest.java | 127 -
.../ibatis/TransactedOnCompletionTest.java | 99 -
.../itest/ibatis/TransactedOnExceptionTest.java | 99 -
.../itest/ibatis/TransactedPipelineTest.java | 94 -
.../itest/ibatis/TransactedTryCatchTest.java | 107 -
.../jms/AdviceWithTransactionIssueTest.java | 76 +
.../restlet/example/RestletGroovyIssueTest.java | 6 +-
.../src/test/resources/ibatis-config.xml | 8 -
.../ibatis/AsyncEndpointTransacted2Test.xml | 52 -
.../ibatis/AsyncEndpointTransactedTest.xml | 41 -
.../camel/itest/ibatis/LoggingPipelineTest.xml | 43 -
.../ibatis/PartiallyTransactedPipelineTest.xml | 37 -
...nsactedExceptionClauseAfterTransactedTag.xml | 46 -
.../itest/ibatis/TransactedFullExampleTest.xml | 58 -
.../itest/ibatis/TransactedOnCompletionTest.xml | 39 -
.../itest/ibatis/TransactedOnExceptionTest.xml | 44 -
.../itest/ibatis/TransactedPipelineTest.xml | 36 -
.../itest/ibatis/TransactedTryCatchTest.xml | 48 -
.../camel/itest/ibatis/database-context.xml | 44 -
.../jms/AdviceWithTransactionIssueTest.xml | 58 +
tests/camel-itest/src/test/resources/table.xml | 13 -
.../src/test/resources/transactions.properties | 43 -
.../__artifactId__-api/pom.xml | 22 +-
.../__artifactId__-component/pom.xml | 1 -
.../src/main/java/__name__Endpoint.java | 7 +-
.../src/main/java/__name__Producer.java | 5 -
.../src/test/resources/test-options.properties | 2 +-
tooling/camel-manual/pom.xml | 14 +-
.../src/it/all-it/pom.xml | 3 +
.../maven/AbstractApiMethodGeneratorMojo.java | 10 +-
.../camel/maven/ApiComponentGeneratorMojo.java | 29 +
.../java/org/apache/camel/maven/ApiProxy.java | 10 +
.../camel/maven/DocumentGeneratorMojo.java | 9 +-
.../maven/JavadocApiMethodGeneratorMojo.java | 150 +-
.../org/apache/camel/maven/JavadocParser.java | 197 ++
.../src/main/resources/api-collection.vm | 6 +-
.../src/main/resources/api-document.vm | 22 +-
.../src/main/resources/api-route-test.vm | 2 +-
.../maven/ApiComponentGeneratorMojoTest.java | 1 +
.../apache/camel/maven/JavadocParserTest.java | 55 +
782 files changed, 47413 insertions(+), 8036 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/838eb591/components/pom.xml
----------------------------------------------------------------------
diff --cc components/pom.xml
index 002dc91,159bd55..e2287f9
--- a/components/pom.xml
+++ b/components/pom.xml
@@@ -128,9 -129,9 +129,10 @@@
<module>camel-krati</module>
<module>camel-ldap</module>
<module>camel-leveldb</module>
+ <module>camel-linkedin</module>
<module>camel-lucene</module>
<module>camel-mail</module>
+ <module>camel-metrics</module>
<module>camel-mina</module>
<module>camel-mina2</module>
<module>camel-mongodb</module>
http://git-wip-us.apache.org/repos/asf/camel/blob/838eb591/parent/pom.xml
----------------------------------------------------------------------
[06/34] git commit: Added README.md
Posted by da...@apache.org.
Added README.md
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/89abb88c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/89abb88c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/89abb88c
Branch: refs/heads/master
Commit: 89abb88ccddc9a9747ff0b8c40d934fb557c387e
Parents: 5deafaf
Author: Lauri Kimmel <la...@gmx.com>
Authored: Mon May 19 21:57:05 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Mon May 19 21:57:05 2014 +1000
----------------------------------------------------------------------
README.md | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 160 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/89abb88c/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..6a46282
--- /dev/null
+++ b/README.md
@@ -0,0 +1,160 @@
+# Metrics Component
+
+**Available as of Camel 2.13**
+
+The **metrics:** component allows you to collect various metrics directly from Camel routes. Supported metric types are _counter_, _meter_, _histogram_ and _timer_. [Metrics](http://metrics.codahale.com) provides simple way to measure behaviour of your application. Configurable reporting _backend_ is enabling different integration options for collecting and visualizing statistics.
+
+Maven users will need to add the following dependency to their pom.xml for this component:
+
+```xml
+
+<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-metrics</artifactId>
+ <version>x.x.x</version>
+ <!-- use the same version as your Camel core version -->
+</dependency>
+```
+
+# URI format
+
+```
+metrics:[ meter | counter | histogram | timer ]:metricname[?options]
+```
+
+# Metric Registry
+
+If MetricRegistry instance for name ```metricRegistry``` is not found from Camel registry default one is used. Default MetricRegistry uses Slf4jReporter and 60 second reporting interval.
+MetricRegistry instance can be configured by adding bean with name ```metricRegistry``` to Camel registry. For example using Spring Java Configuration.
+
+```java
+
+ @Configuration
+ public static class MyConfig extends SingleRouteCamelConfiguration {
+
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ // define Camel routes here
+ }
+ };
+ }
+
+ @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
+ public MetricRegistry getMetricRegistry() {
+ MetricRegistry registry = ...;
+ return registry;
+ }
+ }
+
+```
+
+# Usage
+
+Each metric has type and name. Supported types are ```counter```, ```meter```, ```histogram``` and ```timer```. Metric name is simple string. If metric type is not provided then type ```meter``` is used by default.
+
+## Metrics type counter
+
+```
+metrics:counter:metricname[?options]
+```
+
+Where options are
+
+| Name | Default | Description |
+|-----------|---------|-----------------------------------------|
+| increment | | long value to add to the counter |
+| decrement | | long value to subtract from the counter |
+
+If neither ```increment``` or ```decrement``` is defined counter value will be incremented by one. If ```increment``` and ```decrement``` are both defined only increment operation is called.
+
+```java
+// update counter simple.counter by 7
+from("direct:in").to("metric:counter:simple.counter?increment=7").to("direct:out")
+```
+
+```java
+// increment counter simple.counter by 1
+from("direct:in").to("metric:counter:simple.counter").to("direct:out")
+```
+
+```java
+// decrement counter simple.counter by 3
+from("direct:in").to("metric:counter:simple.counter?decrement=3").to("direct:out")
+```
+
+## Metric type meter
+
+```
+metrics:meter:metricname[?options]
+```
+
+Where options are
+
+| Name | Default | Description |
+|------|---------|---------------------------|
+| mark | | long value to use as mark |
+
+If ```mark``` is not set ```meter.mark()``` is called without argument.
+
+```java
+// marks simple.meter without value
+from("direct:in").to("metric:simple.meter").to("direct:out")
+```
+
+```java
+// marks simple.meter with value 81
+from("direct:in").to("metric:meter:simple.meter?mark=81").to("direct:out")
+```
+
+## Metric type histogram
+
+```
+metrics:histogram:metricname[?options]
+```
+
+Where options are
+
+| Name | Default | Description |
+|-------|---------|---------------------------|
+| value | | value to use in histogram |
+
+If no ```value``` is not set nothing is added to histogram and warning is logged.
+
+```java
+// adds value 9923 to simple.histogram
+from("direct:in").to("metric:histogram:simple.histogram?value=9923").to("direct:out")
+```
+
+```java
+// nothing is added to simple.histogram; warning is logged
+from("direct:in").to("metric:histogram:simple.histogram").to("direct:out")
+```
+
+## Metrics type timer
+
+```
+metrics:timer:metricname[?options]
+```
+
+Where options are
+
+| Name | Default | Description |
+|--------|---------|---------------------------|
+| action | | ```start``` or ```stop``` |
+
+If no ```action``` or invalid value is provided warning is logged and no timer is updated. If ```action``` ```start``` is called on already running timer or ```stop``` is called on not running timer nothing is updated and warning is logged.
+
+```java
+// measure time taken by route calculate
+from("direct:in")
+ .to("metrics:timer:simple.timer?action=start")
+ .to("direct:calculate")
+ .to("metrics:timer:simple.timer?action=stop");
+```
+
+Timer Context objects are stored as Exchange properties.
[15/34] git commit: Update Travis config to build only master branch.
Posted by da...@apache.org.
Update Travis config to build only master branch.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/03afdee6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/03afdee6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/03afdee6
Branch: refs/heads/master
Commit: 03afdee69aed6fbd9e9aff4bb0898dadd9d235d6
Parents: 5845dbe
Author: Lauri Kimmel <la...@gmx.com>
Authored: Mon Jun 30 22:11:38 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Mon Jun 30 22:11:38 2014 +1000
----------------------------------------------------------------------
.travis.yml | 4 ++++
1 file changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/03afdee6/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index d99f43b..5cf3ef3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,3 +3,7 @@ jdk:
- oraclejdk7
- openjdk7
- openjdk6
+
+branches:
+ only:
+ - master
[19/34] git commit: CAMEL-7554 - camel-metrics
Posted by da...@apache.org.
CAMEL-7554 - camel-metrics
* Fixed build issues.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5068b9c0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5068b9c0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5068b9c0
Branch: refs/heads/master
Commit: 5068b9c0d6164c1617e54a1dcb3748bbf06d1b2e
Parents: b11d68a
Author: Lauri Kimmel <la...@gmx.com>
Authored: Thu Jul 3 21:04:34 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Thu Jul 3 21:04:34 2014 +1000
----------------------------------------------------------------------
components/camel-metrics/pom.xml | 7 ++++++-
.../org/apache/camel/metrics/AbstractMetricsProducer.java | 2 +-
.../main/java/org/apache/camel/metrics/MetricsComponent.java | 2 +-
.../org/apache/camel/metrics/counter/CounterEndpoint.java | 2 +-
.../org/apache/camel/metrics/histogram/HistogramEndpoint.java | 2 +-
.../java/org/apache/camel/metrics/meter/MeterEndpoint.java | 2 +-
.../java/org/apache/camel/metrics/timer/TimerEndpoint.java | 2 +-
7 files changed, 12 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5068b9c0/components/camel-metrics/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-metrics/pom.xml b/components/camel-metrics/pom.xml
index db89694..bf3fdc8 100644
--- a/components/camel-metrics/pom.xml
+++ b/components/camel-metrics/pom.xml
@@ -77,7 +77,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
http://git-wip-us.apache.org/repos/asf/camel/blob/5068b9c0/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
index 24149af..8bf99d0 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
@@ -33,7 +33,7 @@ public abstract class AbstractMetricsProducer<T extends AbstractMetricsEndpoint>
doProcess(exchange, endpoint, registry, finalMetricsName);
}
catch (Exception e) {
- LOG.warn("Failed to produce metrics for {} in {} - {}", finalMetricsName, getClass().getSimpleName(), e.getMessage());
+ LOG.warn("Failed to produce metrics for {} in {} - {}", new Object[] { finalMetricsName, getClass().getSimpleName(), e.getMessage() });
}
clearMetricsHeaders(in);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/5068b9c0/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index c803e4f..596b08b 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -88,7 +88,7 @@ public class MetricsComponent extends DefaultComponent {
type = MetricsType.getByName(name);
}
if (type == null) {
- throw new RuntimeCamelException("Unknow metrics type \"" + name + "\"");
+ throw new RuntimeCamelException("Unknown metrics type \"" + name + "\"");
}
return type;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/5068b9c0/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
index 8d0b34e..508e485 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
@@ -7,7 +7,7 @@ import org.apache.camel.spi.UriParam;
import com.codahale.metrics.MetricRegistry;
-@UriEndpoint(scheme = "metrics:counter")
+@UriEndpoint(scheme = "metrics")
public class CounterEndpoint extends AbstractMetricsEndpoint {
public static final String ENDPOINT_URI = "metrics:counter";
http://git-wip-us.apache.org/repos/asf/camel/blob/5068b9c0/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
index 8024289..c6e7157 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
@@ -7,7 +7,7 @@ import org.apache.camel.spi.UriParam;
import com.codahale.metrics.MetricRegistry;
-@UriEndpoint(scheme = "metrics:histogram")
+@UriEndpoint(scheme = "metrics")
public class HistogramEndpoint extends AbstractMetricsEndpoint {
public static String ENDPOINT_URI = "metrics:histogram";
http://git-wip-us.apache.org/repos/asf/camel/blob/5068b9c0/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
index d0b609e..82c7187 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
@@ -7,7 +7,7 @@ import org.apache.camel.spi.UriParam;
import com.codahale.metrics.MetricRegistry;
-@UriEndpoint(scheme = "metrics:meter")
+@UriEndpoint(scheme = "metrics")
public class MeterEndpoint extends AbstractMetricsEndpoint {
public static final String ENDPOINT_URI = "metrics:meter";
http://git-wip-us.apache.org/repos/asf/camel/blob/5068b9c0/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java b/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
index 6de4e32..7b534c4 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
@@ -7,7 +7,7 @@ import org.apache.camel.spi.UriParam;
import com.codahale.metrics.MetricRegistry;
-@UriEndpoint(scheme = "metrics:timer")
+@UriEndpoint(scheme = "metrics")
public class TimerEndpoint extends AbstractMetricsEndpoint {
public static final String ENDPOINT_URI = "metrics:timer";
[09/34] git commit: Added header to enable overriding histogram value
in the URI.
Posted by da...@apache.org.
Added header to enable overriding histogram value in the URI.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3fe1d6c6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3fe1d6c6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3fe1d6c6
Branch: refs/heads/master
Commit: 3fe1d6c6f3acc5a62c6894d33f2efa11694743c3
Parents: e6cd8d5
Author: Lauri Kimmel <la...@gmx.com>
Authored: Mon May 26 22:14:58 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Mon May 26 22:14:58 2014 +1000
----------------------------------------------------------------------
README.md | 14 ++++++
.../apache/camel/metrics/MetricsComponent.java | 1 +
.../metrics/histogram/HistogramProducer.java | 7 ++-
.../histogram/HistogramProducerTest.java | 33 ++++++++++++++
.../metrics/histogram/HistogramRouteTest.java | 47 ++++++++++++++++----
5 files changed, 92 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3fe1d6c6/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index f961937..296b2f3 100644
--- a/README.md
+++ b/README.md
@@ -189,6 +189,20 @@ from("direct:in")
.to("direct:out")
```
+### Headers
+
+| Name | Description
+|----------------------------|---------------------------------|
+| CamelMetricsHistogramValue | Override increment value in URI |
+
+```java
+// adds value 992 to simple.histogram
+from("direct:in")
+ .setHeader(MetricsComponent.HEADER_HISTOGRAM_VALUE, constant(992L))
+ .to("metric:histogram:simple.histogram?value=700")
+ .to("direct:out")
+```
+
## Metrics type timer
```
http://git-wip-us.apache.org/repos/asf/camel/blob/3fe1d6c6/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index cc6a64b..c129c07 100644
--- a/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -29,6 +29,7 @@ public class MetricsComponent extends DefaultComponent {
public static final String HEADER_METRIC_NAME = "CamelMetricsName";
public static final String HEADER_COUNTER_INCREMENT = "CamelMetricsCounterIncrement";
public static final String HEADER_COUNTER_DECREMENT = "CamelMetricsCounterDecrement";
+ public static final String HEADER_HISTOGRAM_VALUE = "CamelMetricsHistogramValue";
private static final Logger LOG = LoggerFactory.getLogger(MetricsComponent.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/3fe1d6c6/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java b/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
index 41b5cf7..bd701c0 100644
--- a/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
+++ b/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
@@ -1,5 +1,7 @@
package org.apache.camel.metrics.histogram;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.impl.DefaultProducer;
@@ -24,8 +26,9 @@ public class HistogramProducer extends DefaultProducer {
String metricsName = endpoint.getMetricsName(exchange);
Histogram histogram = registry.histogram(metricsName);
Long value = endpoint.getValue();
- if (value != null) {
- histogram.update(value);
+ Long finalValue = endpoint.getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, value);
+ if (finalValue != null) {
+ histogram.update(finalValue);
}
else {
LOG.warn("Cannot update histogram \"{}\" with null value", metricsName);
http://git-wip-us.apache.org/repos/asf/camel/blob/3fe1d6c6/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java b/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
index 8662e9d..5cb5529 100644
--- a/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
@@ -1,5 +1,6 @@
package org.apache.camel.metrics.histogram;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.times;
@@ -56,11 +57,13 @@ public class HistogramProducerTest {
@Test
public void testProcessValueSet() throws Exception {
when(endpoint.getValue()).thenReturn(VALUE);
+ when(endpoint.getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, VALUE)).thenReturn(VALUE);
producer.process(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getValue();
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, VALUE);
inOrder.verify(histogram, times(1)).update(VALUE);
inOrder.verifyNoMoreInteractions();
}
@@ -68,11 +71,41 @@ public class HistogramProducerTest {
@Test
public void testProcessValueNotSet() throws Exception {
when(endpoint.getValue()).thenReturn(null);
+ when(endpoint.getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, null)).thenReturn(null);
producer.process(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
inOrder.verify(endpoint, times(1)).getValue();
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, null);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessOverrideValue() throws Exception {
+ when(endpoint.getValue()).thenReturn(VALUE);
+ when(endpoint.getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, VALUE)).thenReturn(VALUE + 3);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getValue();
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, VALUE);
+ inOrder.verify(histogram, times(1)).update(VALUE + 3);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessOverrideUriValueNotSet() throws Exception {
+ when(endpoint.getValue()).thenReturn(null);
+ when(endpoint.getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, null)).thenReturn(VALUE + 2);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
+ inOrder.verify(endpoint, times(1)).getValue();
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_HISTOGRAM_VALUE, null);
+ inOrder.verify(histogram, times(1)).update(VALUE + 2);
inOrder.verifyNoMoreInteractions();
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3fe1d6c6/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java b/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
index e8646cb..cc01a1d 100644
--- a/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
+++ b/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
@@ -1,5 +1,9 @@
package org.apache.camel.metrics.histogram;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
@@ -8,11 +12,12 @@ import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.metrics.MetricsComponent;
import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
@@ -37,6 +42,12 @@ public class HistogramRouteTest {
@Produce(uri = "direct:in")
private ProducerTemplate producer;
+ private MetricRegistry mockRegistry;
+
+ private Histogram mockHistogram;
+
+ private InOrder inOrder;
+
@Configuration
public static class TestConfig extends SingleRouteCamelConfiguration {
@@ -54,25 +65,45 @@ public class HistogramRouteTest {
};
}
- @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
+ @Bean(name = METRIC_REGISTRY_NAME)
public MetricRegistry getMetricRegistry() {
return Mockito.mock(MetricRegistry.class);
}
}
+ @Before
+ public void setup() {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
+ mockHistogram = Mockito.mock(Histogram.class);
+ inOrder = Mockito.inOrder(mockRegistry, mockHistogram);
+ }
+
+ @After
+ public void tearDown() {
+ endpoint.reset();
+ reset(mockRegistry);
+ }
+
@Test
public void testOverrideMetricsName() throws Exception {
- // TODO - 12.05.2014, Lauri - is there any better way to set this up?
- MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
- Histogram mockHistogram = Mockito.mock(Histogram.class);
- InOrder inOrder = Mockito.inOrder(mockRegistry, mockHistogram);
when(mockRegistry.histogram("B")).thenReturn(mockHistogram);
-
endpoint.expectedMessageCount(1);
- producer.sendBodyAndHeader(new Object(), MetricsComponent.HEADER_METRIC_NAME, "B");
+ producer.sendBodyAndHeader(new Object(), HEADER_METRIC_NAME, "B");
endpoint.assertIsSatisfied();
inOrder.verify(mockRegistry, times(1)).histogram("B");
inOrder.verify(mockHistogram, times(1)).update(332491L);
inOrder.verifyNoMoreInteractions();
}
+
+ @Test
+ public void testOverrideValue() throws Exception {
+ when(mockRegistry.histogram("A")).thenReturn(mockHistogram);
+ endpoint.expectedMessageCount(1);
+ producer.sendBodyAndHeader(new Object(), HEADER_HISTOGRAM_VALUE, 181L);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).histogram("A");
+ inOrder.verify(mockHistogram, times(1)).update(181L);
+ inOrder.verifyNoMoreInteractions();
+ }
}
[27/34] CAMEL-7554: Renamed package to include component which is the
way we do in Camel.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
deleted file mode 100644
index 688337b..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramEndpointTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * 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.metrics.histogram;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Producer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-
-@RunWith(MockitoJUnitRunner.class)
-public class HistogramEndpointTest {
-
- private static final String METRICS_NAME = "metrics.name";
- private static final Long VALUE = System.currentTimeMillis();
-
- @Mock
- private MetricRegistry registry;
-
- private HistogramEndpoint endpoint;
-
- private InOrder inOrder;
-
- @Before
- public void setUp() throws Exception {
- endpoint = new HistogramEndpoint(registry, METRICS_NAME);
- inOrder = Mockito.inOrder(registry);
- }
-
- @After
- public void tearDown() throws Exception {
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testHistogramEndpoint() throws Exception {
- assertThat(endpoint, is(notNullValue()));
- assertThat(endpoint.getRegistry(), is(registry));
- assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
- }
-
- @Test
- public void testCreateProducer() throws Exception {
- Producer producer = endpoint.createProducer();
- assertThat(producer, is(notNullValue()));
- assertThat(producer, is(HistogramProducer.class));
- }
-
- @Test
- public void testGetValue() throws Exception {
- assertThat(endpoint.getValue(), is(nullValue()));
- }
-
- @Test
- public void testSetValue() throws Exception {
- assertThat(endpoint.getValue(), is(nullValue()));
- endpoint.setValue(VALUE);
- assertThat(endpoint.getValue(), is(VALUE));
- }
-
- @Test
- public void testCreateEndpointUri() throws Exception {
- assertThat(endpoint.createEndpointUri(), is(HistogramEndpoint.ENDPOINT_URI));
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
deleted file mode 100644
index 4513027..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramProducerTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/**
- * 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.metrics.histogram;
-
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class HistogramProducerTest {
-
- private static final String METRICS_NAME = "metrics.name";
- private static final Long VALUE = System.currentTimeMillis();
-
- @Mock
- private HistogramEndpoint endpoint;
-
- @Mock
- private MetricRegistry registry;
-
- @Mock
- private Histogram histogram;
-
- @Mock
- private Exchange exchange;
-
- @Mock
- private Message in;
-
- private HistogramProducer producer;
-
- private InOrder inOrder;
-
- @Before
- public void setUp() throws Exception {
- producer = new HistogramProducer(endpoint);
- inOrder = Mockito.inOrder(endpoint, registry, histogram, exchange, in);
- when(endpoint.getRegistry()).thenReturn(registry);
- when(registry.histogram(METRICS_NAME)).thenReturn(histogram);
- when(exchange.getIn()).thenReturn(in);
- }
-
- @Test
- public void testHistogramProducer() throws Exception {
- assertThat(producer.getEndpoint().equals(endpoint), is(true));
- }
-
- @Test
- public void testProcessValueSet() throws Exception {
- when(endpoint.getValue()).thenReturn(VALUE);
- when(in.getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class)).thenReturn(VALUE);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getValue();
- inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class);
- inOrder.verify(histogram, times(1)).update(VALUE);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessValueNotSet() throws Exception {
- when(endpoint.getValue()).thenReturn(null);
- when(in.getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class)).thenReturn(null);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getValue();
- inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessOverrideValue() throws Exception {
- when(endpoint.getValue()).thenReturn(VALUE);
- when(in.getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class)).thenReturn(VALUE + 3);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getValue();
- inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Long.class);
- inOrder.verify(histogram, times(1)).update(VALUE + 3);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessOverrideUriValueNotSet() throws Exception {
- when(endpoint.getValue()).thenReturn(null);
- when(in.getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class)).thenReturn(VALUE + 2);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).histogram(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getValue();
- inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, null, Long.class);
- inOrder.verify(histogram, times(1)).update(VALUE + 2);
- inOrder.verifyNoMoreInteractions();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
deleted file mode 100644
index a06cd22..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/histogram/HistogramRouteTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * 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.metrics.histogram;
-
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.EndpointInject;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
-import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
-import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
-import org.apache.camel.test.spring.MockEndpoints;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mockito;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.context.ContextConfiguration;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-@RunWith(CamelSpringJUnit4ClassRunner.class)
-@ContextConfiguration(
- classes = { HistogramRouteTest.TestConfig.class },
- loader = CamelSpringDelegatingTestContextLoader.class)
-@MockEndpoints
-public class HistogramRouteTest {
-
- @EndpointInject(uri = "mock:out")
- private MockEndpoint endpoint;
-
- @Produce(uri = "direct:in")
- private ProducerTemplate producer;
-
- private MetricRegistry mockRegistry;
-
- private Histogram mockHistogram;
-
- private InOrder inOrder;
-
- @Configuration
- public static class TestConfig extends SingleRouteCamelConfiguration {
-
- @Bean
- @Override
- public RouteBuilder route() {
- return new RouteBuilder() {
-
- @Override
- public void configure() throws Exception {
- from("direct:in")
- .to("metrics:histogram:A?value=332491")
- .to("mock:out");
- }
- };
- }
-
- @Bean(name = METRIC_REGISTRY_NAME)
- public MetricRegistry getMetricRegistry() {
- return Mockito.mock(MetricRegistry.class);
- }
- }
-
- @Before
- public void setup() {
- // TODO - 12.05.2014, Lauri - is there any better way to set this up?
- mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
- mockHistogram = Mockito.mock(Histogram.class);
- inOrder = Mockito.inOrder(mockRegistry, mockHistogram);
- }
-
- @After
- public void tearDown() {
- endpoint.reset();
- reset(mockRegistry);
- }
-
- @Test
- public void testOverrideMetricsName() throws Exception {
- when(mockRegistry.histogram("B")).thenReturn(mockHistogram);
- endpoint.expectedMessageCount(1);
- producer.sendBodyAndHeader(new Object(), HEADER_METRIC_NAME, "B");
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).histogram("B");
- inOrder.verify(mockHistogram, times(1)).update(332491L);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testOverrideValue() throws Exception {
- when(mockRegistry.histogram("A")).thenReturn(mockHistogram);
- endpoint.expectedMessageCount(1);
- producer.sendBodyAndHeader(new Object(), HEADER_HISTOGRAM_VALUE, 181L);
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).histogram("A");
- inOrder.verify(mockHistogram, times(1)).update(181L);
- inOrder.verifyNoMoreInteractions();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
deleted file mode 100644
index 73935fa..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterEndpointTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * 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.metrics.meter;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Producer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-
-@RunWith(MockitoJUnitRunner.class)
-public class MeterEndpointTest {
-
- private static final String METRICS_NAME = "metrics.name";
- private static final Long VALUE = System.currentTimeMillis();
-
- @Mock
- private MetricRegistry registry;
-
- private MeterEndpoint endpoint;
-
- private InOrder inOrder;
-
- @Before
- public void setUp() throws Exception {
- endpoint = new MeterEndpoint(registry, METRICS_NAME);
- inOrder = Mockito.inOrder(registry);
- }
-
- @After
- public void tearDown() throws Exception {
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testMeterEndpoint() throws Exception {
- assertThat(endpoint, is(notNullValue()));
- assertThat(endpoint.getRegistry(), is(registry));
- assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
- }
-
- @Test
- public void testCreateProducer() throws Exception {
- Producer producer = endpoint.createProducer();
- assertThat(producer, is(notNullValue()));
- assertThat(producer, is(instanceOf(MeterProducer.class)));
- }
-
- @Test
- public void testGetMark() throws Exception {
- assertThat(endpoint.getMark(), is(nullValue()));
- }
-
- @Test
- public void testSetMark() throws Exception {
- assertThat(endpoint.getMark(), is(nullValue()));
- endpoint.setMark(VALUE);
- assertThat(endpoint.getMark(), is(VALUE));
- }
-
- @Test
- public void testCreateEndpointUri() throws Exception {
- assertThat(endpoint.createEndpointUri(), is(MeterEndpoint.ENDPOINT_URI));
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
deleted file mode 100644
index 7c9c47b..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterProducerTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/**
- * 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.metrics.meter;
-
-import com.codahale.metrics.Meter;
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class MeterProducerTest {
-
- private static final String METRICS_NAME = "metrics.name";
- private static final Long MARK = 9919120L;
-
- @Mock
- private MeterEndpoint endpoint;
-
- @Mock
- private MetricRegistry registry;
-
- @Mock
- private Meter meter;
-
- @Mock
- private Exchange exchange;
-
- @Mock
- private Message in;
-
- private MeterProducer producer;
-
- private InOrder inOrder;
-
- @Before
- public void setUp() throws Exception {
- producer = new MeterProducer(endpoint);
- inOrder = Mockito.inOrder(endpoint, registry, meter, exchange, in);
- when(endpoint.getRegistry()).thenReturn(registry);
- when(registry.meter(METRICS_NAME)).thenReturn(meter);
- when(exchange.getIn()).thenReturn(in);
- }
-
- @Test
- public void testMeterProducer() throws Exception {
- assertThat(producer, is(notNullValue()));
- assertThat(producer.getEndpoint().equals(endpoint), is(true));
- }
-
- @Test
- public void testProcessMarkSet() throws Exception {
- when(endpoint.getMark()).thenReturn(MARK);
- when(in.getHeader(HEADER_METER_MARK, MARK, Long.class)).thenReturn(MARK);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).meter(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getMark();
- inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, MARK, Long.class);
- inOrder.verify(meter, times(1)).mark(MARK);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessMarkSetOverrideByHeaderValue() throws Exception {
- when(endpoint.getMark()).thenReturn(MARK);
- when(in.getHeader(HEADER_METER_MARK, MARK, Long.class)).thenReturn(MARK + 101);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(registry, times(1)).meter(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getMark();
- inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, MARK, Long.class);
- inOrder.verify(meter, times(1)).mark(MARK + 101);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessMarkNotSet() throws Exception {
- when(endpoint.getMark()).thenReturn(null);
- when(in.getHeader(HEADER_METER_MARK, null, Long.class)).thenReturn(null);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(registry, times(1)).meter(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getMark();
- inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, null, Long.class);
- inOrder.verify(meter, times(1)).mark();
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessMarkNotSetOverrideByHeaderValue() throws Exception {
- when(endpoint.getMark()).thenReturn(null);
- when(in.getHeader(HEADER_METER_MARK, null, Long.class)).thenReturn(MARK);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(registry, times(1)).meter(METRICS_NAME);
- inOrder.verify(endpoint, times(1)).getMark();
- inOrder.verify(in, times(1)).getHeader(HEADER_METER_MARK, null, Long.class);
- inOrder.verify(meter, times(1)).mark(MARK);
- inOrder.verifyNoMoreInteractions();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
deleted file mode 100644
index a8de5ea..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/meter/MeterRouteTest.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/**
- * 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.metrics.meter;
-
-import com.codahale.metrics.Meter;
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.EndpointInject;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
-import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
-import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
-import org.apache.camel.test.spring.MockEndpoints;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mockito;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.context.ContextConfiguration;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-@RunWith(CamelSpringJUnit4ClassRunner.class)
-@ContextConfiguration(
- classes = { MeterRouteTest.TestConfig.class },
- loader = CamelSpringDelegatingTestContextLoader.class)
-@MockEndpoints
-public class MeterRouteTest {
-
- @EndpointInject(uri = "mock:out")
- private MockEndpoint endpoint;
-
- @Produce(uri = "direct:in-1")
- private ProducerTemplate producer1;
-
- @Produce(uri = "direct:in-2")
- private ProducerTemplate producer2;
-
- private MetricRegistry mockRegistry;
-
- private Meter mockMeter;
-
- private InOrder inOrder;
-
- @Configuration
- public static class TestConfig extends SingleRouteCamelConfiguration {
-
- @Bean
- @Override
- public RouteBuilder route() {
- return new RouteBuilder() {
-
- @Override
- public void configure() throws Exception {
- from("direct:in-1")
- .to("metrics:meter:A?mark=3179")
- .to("mock:out");
-
- from("direct:in-2")
- .to("metrics:meter:A")
- .to("mock:out");
- }
- };
- }
-
- @Bean(name = METRIC_REGISTRY_NAME)
- public MetricRegistry getMetricRegistry() {
- return Mockito.mock(MetricRegistry.class);
- }
- }
-
- @Before
- public void setup() {
- // TODO - 12.05.2014, Lauri - is there any better way to set this up?
- mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
- mockMeter = Mockito.mock(Meter.class);
- inOrder = Mockito.inOrder(mockRegistry, mockMeter);
- when(mockRegistry.meter("A")).thenReturn(mockMeter);
- }
-
- @After
- public void tearDown() {
- endpoint.reset();
- reset(mockRegistry, mockMeter);
- }
-
- @Test
- public void testValueSetInUri() throws Exception {
- Object body = new Object();
- endpoint.expectedBodiesReceived(body);
- producer1.sendBody(body);
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).meter("A");
- inOrder.verify(mockMeter, times(1)).mark(3179L);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testValueNoSetInUri() throws Exception {
- Object body = new Object();
- endpoint.expectedBodiesReceived(body);
- producer2.sendBody(body);
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).meter("A");
- inOrder.verify(mockMeter, times(1)).mark();
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testOverrideMetricsName() throws Exception {
- when(mockRegistry.meter("B")).thenReturn(mockMeter);
- Object body = new Object();
- endpoint.expectedBodiesReceived(body);
- producer1.sendBodyAndHeader(body, HEADER_METRIC_NAME, "B");
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).meter("B");
- inOrder.verify(mockMeter, times(1)).mark(3179L);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testOverrideValueWithHeader() throws Exception {
- Object body = new Object();
- endpoint.expectedBodiesReceived(body);
- producer1.sendBodyAndHeader(body, HEADER_METER_MARK, 9926L);
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).meter("A");
- inOrder.verify(mockMeter, times(1)).mark(9926L);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testValueNoSetInUriOverrideWithHeader() throws Exception {
- Object body = new Object();
- endpoint.expectedBodiesReceived(body);
- producer2.sendBodyAndHeader(body, HEADER_METER_MARK, 7707370L);
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).meter("A");
- inOrder.verify(mockMeter, times(1)).mark(7707370L);
- inOrder.verifyNoMoreInteractions();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
deleted file mode 100644
index 82c9213..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerEndpointTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * 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.metrics.timer;
-
-import com.codahale.metrics.MetricRegistry;
-import org.apache.camel.Producer;
-import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TimerEndpointTest {
-
- private static final String METRICS_NAME = "metrics.name";
-
- @Mock
- private MetricRegistry registry;
-
- private TimerEndpoint endpoint;
-
- private InOrder inOrder;
-
- @Before
- public void setUp() throws Exception {
- endpoint = new TimerEndpoint(registry, METRICS_NAME);
- inOrder = Mockito.inOrder(registry);
- }
-
- @After
- public void tearDown() throws Exception {
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testTimerEndpoint() throws Exception {
- assertThat(endpoint, is(notNullValue()));
- assertThat(endpoint.getRegistry(), is(registry));
- assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
- }
-
- @Test
- public void testCreateProducer() throws Exception {
- Producer producer = endpoint.createProducer();
- assertThat(producer, is(notNullValue()));
- assertThat(producer, is(instanceOf(TimerProducer.class)));
- }
-
- @Test
- public void testGetAction() throws Exception {
- assertThat(endpoint.getAction(), is(nullValue()));
- }
-
- @Test
- public void testSetAction() throws Exception {
- assertThat(endpoint.getAction(), is(nullValue()));
- endpoint.setAction(TimerAction.start);
- assertThat(endpoint.getAction(), is(TimerAction.start));
- }
-
- @Test
- public void testCreateEndpointUri() throws Exception {
- assertThat(endpoint.createEndpointUri(), is(TimerEndpoint.ENDPOINT_URI));
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
deleted file mode 100644
index 3a2c364..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerProducerTest.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/**
- * 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.metrics.timer;
-
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Timer;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TimerProducerTest {
-
- private static final String METRICS_NAME = "metrics.name";
- private static final String PROPERTY_NAME = TimerEndpoint.ENDPOINT_URI + ":" + METRICS_NAME;
-
- @Mock
- private TimerEndpoint endpoint;
-
- @Mock
- private Exchange exchange;
-
- @Mock
- private MetricRegistry registry;
-
- @Mock
- private Timer timer;
-
- @Mock
- private Timer.Context context;
-
- @Mock
- private Message in;
-
- private TimerProducer producer;
-
- @Mock
- private InOrder inOrder;
-
- @Before
- public void setUp() throws Exception {
- producer = new TimerProducer(endpoint);
- inOrder = Mockito.inOrder(endpoint, exchange, registry, timer, context, in);
- when(endpoint.getRegistry()).thenReturn(registry);
- when(registry.timer(METRICS_NAME)).thenReturn(timer);
- when(timer.time()).thenReturn(context);
- when(exchange.getIn()).thenReturn(in);
- }
-
- @Test
- public void testTimerProducer() throws Exception {
- assertThat(producer, is(notNullValue()));
- assertThat(producer.getEndpoint().equals(endpoint), is(true));
- }
-
- @Test
- public void testProcessStart() throws Exception {
- when(endpoint.getAction()).thenReturn(TimerAction.start);
- when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class)).thenReturn(TimerAction.start);
- when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(endpoint, times(1)).getAction();
- inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class);
- inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
- inOrder.verify(registry, times(1)).timer(METRICS_NAME);
- inOrder.verify(timer, times(1)).time();
- inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessStartWithOverride() throws Exception {
- when(endpoint.getAction()).thenReturn(TimerAction.start);
- when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class)).thenReturn(TimerAction.stop);
- when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(endpoint, times(1)).getAction();
- inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.start, TimerAction.class);
- inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
- inOrder.verify(context, times(1)).stop();
- inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessStop() throws Exception {
- when(endpoint.getAction()).thenReturn(TimerAction.stop);
- when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class)).thenReturn(TimerAction.stop);
- when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(endpoint, times(1)).getAction();
- inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class);
- inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
- inOrder.verify(context, times(1)).stop();
- inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessStopWithOverride() throws Exception {
- when(endpoint.getAction()).thenReturn(TimerAction.stop);
- when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class)).thenReturn(TimerAction.start);
- when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(endpoint, times(1)).getAction();
- inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class);
- inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
- inOrder.verify(registry, times(1)).timer(METRICS_NAME);
- inOrder.verify(timer, times(1)).time();
- inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessNoAction() throws Exception {
- when(endpoint.getAction()).thenReturn(null);
- when(in.getHeader(HEADER_TIMER_ACTION, null, TimerAction.class)).thenReturn(null);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(endpoint, times(1)).getAction();
- inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, null, TimerAction.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testProcessNoActionOverride() throws Exception {
- when(endpoint.getAction()).thenReturn(null);
- when(in.getHeader(HEADER_TIMER_ACTION, null, TimerAction.class)).thenReturn(TimerAction.start);
- producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getIn();
- inOrder.verify(endpoint, times(1)).getAction();
- inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, null, TimerAction.class);
- inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
- inOrder.verify(registry, times(1)).timer(METRICS_NAME);
- inOrder.verify(timer, times(1)).time();
- inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testHandleStart() throws Exception {
- when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
- producer.handleStart(exchange, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
- inOrder.verify(registry, times(1)).timer(METRICS_NAME);
- inOrder.verify(timer, times(1)).time();
- inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testHandleStartAlreadyRunning() throws Exception {
- when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
- producer.handleStart(exchange, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testHandleStop() throws Exception {
- when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
- producer.handleStop(exchange, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
- inOrder.verify(context, times(1)).stop();
- inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testHandleStopContextNotFound() throws Exception {
- when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
- producer.handleStop(exchange, registry, METRICS_NAME);
- inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetPropertyName() throws Exception {
- assertThat(producer.getPropertyName(METRICS_NAME), is(TimerEndpoint.ENDPOINT_URI + ":" + METRICS_NAME));
- }
-
- @Test
- public void testGetTimerContextFromExchange() throws Exception {
- when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context);
- assertThat(producer.getTimerContextFromExchange(exchange, PROPERTY_NAME), is(context));
- inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testGetTimerContextFromExchangeNotFound() throws Exception {
- when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(null);
- assertThat(producer.getTimerContextFromExchange(exchange, PROPERTY_NAME), is(nullValue()));
- inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class);
- inOrder.verifyNoMoreInteractions();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java b/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
deleted file mode 100644
index 4dab66a..0000000
--- a/components/camel-metrics/src/test/java/org/apache/camel/metrics/timer/TimerRouteTest.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- * 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.metrics.timer;
-
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Timer;
-import org.apache.camel.EndpointInject;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
-import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
-import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
-import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
-import org.apache.camel.test.spring.MockEndpoints;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InOrder;
-import org.mockito.Mockito;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.context.ContextConfiguration;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
-import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
-import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-@RunWith(CamelSpringJUnit4ClassRunner.class)
-@ContextConfiguration(
- classes = { TimerRouteTest.TestConfig.class },
- loader = CamelSpringDelegatingTestContextLoader.class)
-@MockEndpoints
-public class TimerRouteTest {
-
- @EndpointInject(uri = "mock:out")
- private MockEndpoint endpoint;
-
- @Produce(uri = "direct:in-1")
- private ProducerTemplate producer1;
-
- @Produce(uri = "direct:in-2")
- private ProducerTemplate producer2;
-
- private MetricRegistry mockRegistry;
-
- private Timer mockTimer;
-
- private InOrder inOrder;
-
- @Configuration
- public static class TestConfig extends SingleRouteCamelConfiguration {
-
- @Bean
- @Override
- public RouteBuilder route() {
- return new RouteBuilder() {
-
- @Override
- public void configure() throws Exception {
- from("direct:in-1")
- .to("metrics:timer:A?action=start")
- .to("mock:out");
-
- from("direct:in-2")
- .to("metrics:timer:A")
- .to("mock:out");
- }
- };
- }
-
- @Bean(name = METRIC_REGISTRY_NAME)
- public MetricRegistry getMetricRegistry() {
- return Mockito.mock(MetricRegistry.class);
- }
- }
-
- @Before
- public void setup() {
- // TODO - 12.05.2014, Lauri - is there any better way to set this up?
- mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
- mockTimer = Mockito.mock(Timer.class);
- inOrder = Mockito.inOrder(mockRegistry, mockTimer);
- }
-
- @After
- public void tearDown() {
- endpoint.reset();
- reset(mockRegistry, mockTimer);
- }
-
- @Test
- public void testOverrideMetricsName() throws Exception {
- when(mockRegistry.timer("B")).thenReturn(mockTimer);
-
- Object body = new Object();
- endpoint.expectedBodiesReceived(body);
- producer1.sendBodyAndHeader(body, HEADER_METRIC_NAME, "B");
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).timer("B");
- inOrder.verify(mockTimer, times(1)).time();
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testOverrideExistingAction() throws Exception {
- when(mockRegistry.timer("A")).thenReturn(mockTimer);
- Object body = new Object();
- endpoint.expectedBodiesReceived(body);
- producer1.sendBodyAndHeader(body, HEADER_TIMER_ACTION, TimerAction.stop);
- endpoint.assertIsSatisfied();
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void testOverrideNoAction() throws Exception {
- when(mockRegistry.timer("A")).thenReturn(mockTimer);
- Object body = new Object();
- endpoint.expectedBodiesReceived(body);
- producer2.sendBodyAndHeader(body, HEADER_TIMER_ACTION, TimerAction.start);
- endpoint.assertIsSatisfied();
- inOrder.verify(mockRegistry, times(1)).timer("A");
- inOrder.verify(mockTimer, times(1)).time();
- inOrder.verifyNoMoreInteractions();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/components/camel-metrics/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/resources/log4j.properties b/components/camel-metrics/src/test/resources/log4j.properties
index 3b1bd38..18be17d 100644
--- a/components/camel-metrics/src/test/resources/log4j.properties
+++ b/components/camel-metrics/src/test/resources/log4j.properties
@@ -1,14 +1,40 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
#
-# The logging properties used
+# The logging properties used for testing
#
-log4j.rootLogger=INFO, out
+log4j.rootLogger=INFO, file
-# uncomment the following line to turn on Camel debugging
-#log4j.logger.org.apache.camel=DEBUG
+#log4j.logger.com.codehale.metrics=DEBUG
+#log4j.logger.org.apache.camel.component.metrics=DEBUG
# CONSOLE appender not used by default
log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
-#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+# MDC
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camel.exchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.file=target/camel-test-metrics.log
+log4j.appender.file.append=true
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+# MDC
+#log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camel.exchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index 9b64032..ea04e1f 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -790,6 +790,11 @@
<feature version='${project.version}'>camel-core</feature>
<bundle>mvn:org.apache.camel/camel-mail/${project.version}</bundle>
</feature>
+ <feature name='camel-metrics' version='${project.version}' resolver='(obr)' start-level='50'>
+ <bundle dependency='true'>mvn:com.codahale.metrics/metrics-core</${metrics-version}</bundle>
+ <feature version='${project.version}'>camel-core</feature>
+ <bundle>mvn:org.apache.camel/camel-metrics/${project.version}</bundle>
+ </feature>
<feature name='camel-mina' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
<bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.mina/${mina-bundle-version}</bundle>
http://git-wip-us.apache.org/repos/asf/camel/blob/acf0fa39/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelMetricsTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelMetricsTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelMetricsTest.java
new file mode 100644
index 0000000..919d58f
--- /dev/null
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelMetricsTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.itest.karaf;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+
+@RunWith(JUnit4TestRunner.class)
+public class CamelMetricsTest extends AbstractFeatureTest {
+
+ public static final String COMPONENT = extractName(CamelMetricsTest.class);
+
+ @Test
+ public void test() throws Exception {
+ testComponent(COMPONENT);
+ }
+
+ @Configuration
+ public static Option[] configure() {
+ return configure(COMPONENT);
+ }
+
+}
\ No newline at end of file
[08/34] git commit: Added headers to enable overriding counter
increment/decrement in the URI.
Posted by da...@apache.org.
Added headers to enable overriding counter increment/decrement in the URI.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e6cd8d5d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e6cd8d5d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e6cd8d5d
Branch: refs/heads/master
Commit: e6cd8d5da16c8526619107ad74b34d0e21ac2f54
Parents: 85ca4c1
Author: Lauri Kimmel <la...@gmx.com>
Authored: Mon May 26 22:13:58 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Mon May 26 22:13:58 2014 +1000
----------------------------------------------------------------------
README.md | 54 ++++++-
.../apache/camel/metrics/MetricsComponent.java | 4 +-
.../camel/metrics/counter/CounterProducer.java | 13 +-
.../metrics/counter/CounterProducerTest.java | 72 +++++++++
.../camel/metrics/counter/CounterRouteTest.java | 149 +++++++++++++++++--
5 files changed, 268 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e6cd8d5d/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 34bbb23..f961937 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ Each metric has type and name. Supported types are ```counter```, ```meter```, `
### Headers
-Metric name defined in URI can be overridden by using Header with name ```org.apache.camel.metrics.metricName```.
+Metric name defined in URI can be overridden by using Header with name ```CamelMetricsName```.
For example
@@ -90,19 +90,49 @@ If neither ```increment``` or ```decrement``` is defined counter value will be i
```java
// update counter simple.counter by 7
-from("direct:in").to("metric:counter:simple.counter?increment=7").to("direct:out")
+from("direct:in")
+ .to("metric:counter:simple.counter?increment=7")
+ .to("direct:out")
```
```java
// increment counter simple.counter by 1
-from("direct:in").to("metric:counter:simple.counter").to("direct:out")
+from("direct:in")
+ .to("metric:counter:simple.counter")
+ .to("direct:out")
```
```java
// decrement counter simple.counter by 3
-from("direct:in").to("metric:counter:simple.counter?decrement=3").to("direct:out")
+from("direct:in")
+ .to("metric:counter:simple.counter?decrement=3")
+ .to("direct:out")
+```
+
+### Headers
+
+| Name | Description
+|------------------------------|---------------------------------|
+| CamelMetricsCounterIncrement | Override increment value in URI |
+| CamelMetricsCounterDecrement | Override decrement value in URI |
+
+```java
+// update counter simple.counter by 417
+from("direct:in")
+ .setHeader(MetricsComponent.HEADER_COUNTER_INCREMENT, constant(417L))
+ .to("metric:counter:simple.counter?increment=7")
+ .to("direct:out")
```
+```java
+// updates counter using simple language to evaluate body.length
+from("direct:in")
+ .setHeader(MetricsComponent.HEADER_COUNTER_INCREMENT, simple("${body.length}"))
+ .to("metrics:counter:body.length")
+ .to("mock:out");
+```
+
+
## Metric type meter
```
@@ -119,12 +149,16 @@ If ```mark``` is not set ```meter.mark()``` is called without argument.
```java
// marks simple.meter without value
-from("direct:in").to("metric:simple.meter").to("direct:out")
+from("direct:in")
+ .to("metric:simple.meter")
+ .to("direct:out")
```
```java
// marks simple.meter with value 81
-from("direct:in").to("metric:meter:simple.meter?mark=81").to("direct:out")
+from("direct:in")
+ .to("metric:meter:simple.meter?mark=81")
+ .to("direct:out")
```
## Metric type histogram
@@ -143,12 +177,16 @@ If no ```value``` is not set nothing is added to histogram and warning is logged
```java
// adds value 9923 to simple.histogram
-from("direct:in").to("metric:histogram:simple.histogram?value=9923").to("direct:out")
+from("direct:in")
+ .to("metric:histogram:simple.histogram?value=9923")
+ .to("direct:out")
```
```java
// nothing is added to simple.histogram; warning is logged
-from("direct:in").to("metric:histogram:simple.histogram").to("direct:out")
+from("direct:in")
+ .to("metric:histogram:simple.histogram")
+ .to("direct:out")
```
## Metrics type timer
http://git-wip-us.apache.org/repos/asf/camel/blob/e6cd8d5d/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index bc4a2af..cc6a64b 100644
--- a/src/main/java/org/apache/camel/metrics/MetricsComponent.java
+++ b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -26,7 +26,9 @@ public class MetricsComponent extends DefaultComponent {
public static final String METRIC_REGISTRY_NAME = "metricRegistry";
public static final MetricsType DEFAULT_METRICS_TYPE = MetricsType.METER;
public static final long DEFAULT_REPORTING_INTERVAL_SECONDS = 60L;
- public static final String HEADER_METRIC_NAME = "org.apache.camel.metrics.metricName";
+ public static final String HEADER_METRIC_NAME = "CamelMetricsName";
+ public static final String HEADER_COUNTER_INCREMENT = "CamelMetricsCounterIncrement";
+ public static final String HEADER_COUNTER_DECREMENT = "CamelMetricsCounterDecrement";
private static final Logger LOG = LoggerFactory.getLogger(MetricsComponent.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/e6cd8d5d/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java b/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
index ec9f426..e7db514 100644
--- a/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
+++ b/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
@@ -1,5 +1,8 @@
package org.apache.camel.metrics.counter;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
+
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.impl.DefaultProducer;
@@ -19,11 +22,13 @@ public class CounterProducer extends DefaultProducer {
Counter counter = endpoint.getRegistry().counter(metricName);
Long increment = endpoint.getIncrement();
Long decrement = endpoint.getDecrement();
- if (increment != null) {
- counter.inc(increment);
+ Long finalIncrement = endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, increment);
+ Long finalDecrement = endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, decrement);
+ if (finalIncrement != null) {
+ counter.inc(finalIncrement);
}
- else if (decrement != null) {
- counter.dec(decrement);
+ else if (finalDecrement != null) {
+ counter.dec(finalDecrement);
}
else {
counter.inc();
http://git-wip-us.apache.org/repos/asf/camel/blob/e6cd8d5d/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java b/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
index c6ecaa4..c136cf8 100644
--- a/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
+++ b/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
@@ -1,5 +1,7 @@
package org.apache.camel.metrics.counter;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.times;
@@ -58,12 +60,16 @@ public class CounterProducerTest {
public void testProcessWithIncrementOnly() throws Exception {
when(endpoint.getIncrement()).thenReturn(INCREMENT);
when(endpoint.getDecrement()).thenReturn(null);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT)).thenReturn(INCREMENT);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null)).thenReturn(null);
producer.process(exchange);
inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT);
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null);
inOrder.verify(counter, times(1)).inc(INCREMENT);
inOrder.verifyNoMoreInteractions();
}
@@ -72,12 +78,16 @@ public class CounterProducerTest {
public void testProcessWithDecrementOnly() throws Exception {
when(endpoint.getIncrement()).thenReturn(null);
when(endpoint.getDecrement()).thenReturn(DECREMENT);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null)).thenReturn(null);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT)).thenReturn(DECREMENT);
producer.process(exchange);
inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null);
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT);
inOrder.verify(counter, times(1)).dec(DECREMENT);
inOrder.verifyNoMoreInteractions();
}
@@ -86,12 +96,16 @@ public class CounterProducerTest {
public void testProcessWithIncrementAndDecrement() throws Exception {
when(endpoint.getIncrement()).thenReturn(INCREMENT);
when(endpoint.getDecrement()).thenReturn(DECREMENT);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT)).thenReturn(INCREMENT);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT)).thenReturn(DECREMENT);
producer.process(exchange);
inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT);
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT);
inOrder.verify(counter, times(1)).inc(INCREMENT);
inOrder.verifyNoMoreInteractions();
}
@@ -100,13 +114,71 @@ public class CounterProducerTest {
public void testProcessWithOutIncrementAndDecrement() throws Exception {
when(endpoint.getIncrement()).thenReturn(null);
when(endpoint.getDecrement()).thenReturn(null);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null)).thenReturn(null);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null)).thenReturn(null);
producer.process(exchange);
inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
inOrder.verify(endpoint, times(1)).getRegistry();
inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
inOrder.verify(endpoint, times(1)).getIncrement();
inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null);
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null);
inOrder.verify(counter, times(1)).inc();
inOrder.verifyNoMoreInteractions();
}
+
+ @Test
+ public void testProcessWithHeaderValuesOnly() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(null);
+ when(endpoint.getDecrement()).thenReturn(null);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null)).thenReturn(INCREMENT + 1);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null)).thenReturn(DECREMENT - 1);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null);
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, null);
+ inOrder.verify(counter, times(1)).inc(INCREMENT + 1);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessOverridingIncrement() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(INCREMENT);
+ when(endpoint.getDecrement()).thenReturn(DECREMENT);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT)).thenReturn(INCREMENT + 1);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT)).thenReturn(DECREMENT);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, INCREMENT);
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT);
+ inOrder.verify(counter, times(1)).inc(INCREMENT + 1);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testProcessOverridingDecrement() throws Exception {
+ when(endpoint.getIncrement()).thenReturn(null);
+ when(endpoint.getDecrement()).thenReturn(DECREMENT);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null)).thenReturn(null);
+ when(endpoint.getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT)).thenReturn(DECREMENT - 1);
+ producer.process(exchange);
+ inOrder.verify(endpoint, times(1)).getMetricsName(exchange);
+ inOrder.verify(endpoint, times(1)).getRegistry();
+ inOrder.verify(registry, times(1)).counter(ENDPOINT_NAME);
+ inOrder.verify(endpoint, times(1)).getIncrement();
+ inOrder.verify(endpoint, times(1)).getDecrement();
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_INCREMENT, null);
+ inOrder.verify(endpoint, times(1)).getLongHeader(exchange, HEADER_COUNTER_DECREMENT, DECREMENT);
+ inOrder.verify(counter, times(1)).dec(DECREMENT - 1);
+ inOrder.verifyNoMoreInteractions();
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/e6cd8d5d/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java b/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
index df9185b..d28e07a 100644
--- a/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
+++ b/src/test/java/org/apache/camel/metrics/counter/CounterRouteTest.java
@@ -1,18 +1,32 @@
package org.apache.camel.metrics.counter;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
+import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
+import static org.apache.camel.metrics.MetricsComponent.METRIC_REGISTRY_NAME;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelExecutionException;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.metrics.MetricsComponent;
import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
@@ -34,8 +48,23 @@ public class CounterRouteTest {
@EndpointInject(uri = "mock:out")
private MockEndpoint endpoint;
- @Produce(uri = "direct:in")
- private ProducerTemplate producer;
+ @Produce(uri = "direct:in-1")
+ private ProducerTemplate producer1;
+
+ @Produce(uri = "direct:in-2")
+ private ProducerTemplate producer2;
+
+ @Produce(uri = "direct:in-3")
+ private ProducerTemplate producer3;
+
+ @Produce(uri = "direct:in-4")
+ private ProducerTemplate producer4;
+
+ private MetricRegistry mockRegistry;
+
+ private Counter mockCounter;
+
+ private InOrder inOrder;
@Configuration
public static class TestConfig extends SingleRouteCamelConfiguration {
@@ -47,32 +76,130 @@ public class CounterRouteTest {
@Override
public void configure() throws Exception {
- from("direct:in")
+ from("direct:in-1")
.to("metrics:counter:A?increment=5")
.to("mock:out");
+
+ from("direct:in-2")
+ .to("metrics:counter:A?decrement=9")
+ .to("mock:out");
+
+ from("direct:in-3")
+ .setHeader(HEADER_COUNTER_INCREMENT, constant(417L))
+ .to("metrics:counter:A")
+ .to("mock:out");
+
+ from("direct:in-4")
+ .setHeader(HEADER_COUNTER_INCREMENT, simple("${body.length}"))
+ .to("metrics:counter:A")
+ .to("mock:out");
}
};
}
- @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
+ @Bean(name = METRIC_REGISTRY_NAME)
public MetricRegistry getMetricRegistry() {
return Mockito.mock(MetricRegistry.class);
}
}
+ @Before
+ public void setup() {
+ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
+ mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRIC_REGISTRY_NAME, MetricRegistry.class);
+ mockCounter = mock(Counter.class);
+ inOrder = Mockito.inOrder(mockRegistry, mockCounter);
+ }
+
+ @After
+ public void tearDown() {
+ endpoint.reset();
+ reset(mockRegistry, mockCounter);
+ }
+
@Test
public void testOverrideMetricsName() throws Exception {
- // TODO - 12.05.2014, Lauri - is there any better way to set this up?
- MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
- Counter mockCounter = Mockito.mock(Counter.class);
- InOrder inOrder = Mockito.inOrder(mockRegistry, mockCounter);
when(mockRegistry.counter("B")).thenReturn(mockCounter);
-
endpoint.expectedMessageCount(1);
- producer.sendBodyAndHeader(new Object(), MetricsComponent.HEADER_METRIC_NAME, "B");
+ producer1.sendBodyAndHeader(new Object(), HEADER_METRIC_NAME, "B");
endpoint.assertIsSatisfied();
inOrder.verify(mockRegistry, times(1)).counter("B");
inOrder.verify(mockCounter, times(1)).inc(5L);
inOrder.verifyNoMoreInteractions();
}
+
+ @Test
+ public void testOverrideIncrement() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ producer1.sendBodyAndHeader(new Object(), HEADER_COUNTER_INCREMENT, 14L);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).inc(14L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideIncrementAndDecrement() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(HEADER_COUNTER_INCREMENT, 912L);
+ headers.put(HEADER_COUNTER_DECREMENT, 43219L);
+ producer1.sendBodyAndHeaders(new Object(), headers);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).inc(912L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideDecrement() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ producer2.sendBodyAndHeader(new Object(), HEADER_COUNTER_DECREMENT, 7L);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).dec(7L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideIncrementWithWrongType() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(0);
+ try {
+ producer1.sendBodyAndHeader(new Object(), HEADER_COUNTER_INCREMENT, "this is not a valid long value");
+ fail("Exception expected");
+ }
+ catch (Exception e) {
+ assertThat(e, instanceOf(CamelExecutionException.class));
+ }
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideUsingConstantValue() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ producer3.sendBody(new Object());
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).inc(417L);
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testOverrideUsingScriptEvaluation() throws Exception {
+ when(mockRegistry.counter("A")).thenReturn(mockCounter);
+ endpoint.expectedMessageCount(1);
+ String message = "Hello from Camel Metrics!";
+ producer4.sendBody(message);
+ endpoint.assertIsSatisfied();
+ inOrder.verify(mockRegistry, times(1)).counter("A");
+ inOrder.verify(mockCounter, times(1)).inc(message.length());
+ inOrder.verifyNoMoreInteractions();
+ }
}
[26/34] git commit: Merge branch 'camel-metrics'
Posted by da...@apache.org.
Merge branch 'camel-metrics'
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f52b7a59
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f52b7a59
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f52b7a59
Branch: refs/heads/master
Commit: f52b7a597257692102da68d807e91923e393a97b
Parents: d98a45e 20f67f5
Author: Lauri Kimmel <la...@gmx.com>
Authored: Wed Jul 30 21:04:31 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Wed Jul 30 21:04:31 2014 +1000
----------------------------------------------------------------------
components/camel-metrics/README.md | 271 +++++++++++++++++++
components/camel-metrics/pom.xml | 94 +++++++
.../camel/metrics/AbstractMetricsEndpoint.java | 53 ++++
.../camel/metrics/AbstractMetricsProducer.java | 74 +++++
.../apache/camel/metrics/MetricsComponent.java | 134 +++++++++
.../org/apache/camel/metrics/MetricsType.java | 53 ++++
.../camel/metrics/counter/CounterEndpoint.java | 66 +++++
.../camel/metrics/counter/CounterProducer.java | 51 ++++
.../metrics/histogram/HistogramEndpoint.java | 55 ++++
.../metrics/histogram/HistogramProducer.java | 49 ++++
.../camel/metrics/meter/MeterEndpoint.java | 55 ++++
.../camel/metrics/meter/MeterProducer.java | 44 +++
.../camel/metrics/timer/TimerEndpoint.java | 59 ++++
.../camel/metrics/timer/TimerProducer.java | 85 ++++++
.../services/org/apache/camel/component/metrics | 1 +
.../metrics/AbstractMetricsEndpointTest.java | 105 +++++++
.../metrics/AbstractMetricsProducerTest.java | 186 +++++++++++++
.../metrics/MetricComponentSpringTest.java | 91 +++++++
.../metrics/MetricsComponentRouteTest.java | 113 ++++++++
.../camel/metrics/MetricsComponentTest.java | 217 +++++++++++++++
.../apache/camel/metrics/MetricsTypeTest.java | 33 +++
.../metrics/counter/CounterEndpointTest.java | 102 +++++++
.../metrics/counter/CounterProducerTest.java | 195 +++++++++++++
.../camel/metrics/counter/CounterRouteTest.java | 209 ++++++++++++++
.../histogram/HistogramEndpointTest.java | 88 ++++++
.../histogram/HistogramProducerTest.java | 125 +++++++++
.../metrics/histogram/HistogramRouteTest.java | 123 +++++++++
.../camel/metrics/meter/MeterEndpointTest.java | 89 ++++++
.../camel/metrics/meter/MeterProducerTest.java | 126 +++++++++
.../camel/metrics/meter/MeterRouteTest.java | 165 +++++++++++
.../camel/metrics/timer/TimerEndpointTest.java | 89 ++++++
.../camel/metrics/timer/TimerProducerTest.java | 229 ++++++++++++++++
.../camel/metrics/timer/TimerRouteTest.java | 144 ++++++++++
.../src/test/resources/log4j.properties | 14 +
components/pom.xml | 1 +
parent/pom.xml | 1 +
36 files changed, 3589 insertions(+)
----------------------------------------------------------------------
[24/34] git commit: CAMEL-7554 - camel-metrics
Posted by da...@apache.org.
CAMEL-7554 - camel-metrics
* using camel-test-spring3 instead of camel-test-spring
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4c41ca96
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4c41ca96
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4c41ca96
Branch: refs/heads/master
Commit: 4c41ca962219e62b010aabebc7a1093c1ea2c995
Parents: 85cc550
Author: Lauri Kimmel <la...@gmx.com>
Authored: Wed Jul 30 20:56:44 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Wed Jul 30 20:56:44 2014 +1000
----------------------------------------------------------------------
components/camel-metrics/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4c41ca96/components/camel-metrics/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-metrics/pom.xml b/components/camel-metrics/pom.xml
index e449e7e..940a9b6 100644
--- a/components/camel-metrics/pom.xml
+++ b/components/camel-metrics/pom.xml
@@ -64,7 +64,7 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-test-spring</artifactId>
+ <artifactId>camel-test-spring3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
[02/34] git commit: Implemented metrics:counter and metrics:meter
endpoints.
Posted by da...@apache.org.
Implemented metrics:counter and metrics:meter endpoints.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/98560c8e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/98560c8e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/98560c8e
Branch: refs/heads/master
Commit: 98560c8e44fc15aee75a2ccc1c35aa555d74677c
Parents: 375f13e
Author: Lauri Kimmel <la...@gmx.com>
Authored: Sun May 11 04:10:54 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Sun May 11 04:10:54 2014 +1000
----------------------------------------------------------------------
pom.xml | 7 +-
.../java/org/apache/camel/MetricsComponent.java | 18 ----
.../java/org/apache/camel/MetricsConsumer.java | 39 -------
.../java/org/apache/camel/MetricsEndpoint.java | 35 ------
.../java/org/apache/camel/MetricsProducer.java | 24 -----
.../camel/metrics/AbstractMetricsEndpoint.java | 37 +++++++
.../apache/camel/metrics/MetricsComponent.java | 107 +++++++++++++++++++
.../org/apache/camel/metrics/MetricsType.java | 37 +++++++
.../camel/metrics/counter/CounterEndpoint.java | 50 +++++++++
.../camel/metrics/counter/CounterProducer.java | 32 ++++++
.../camel/metrics/meter/MeterEndpoint.java | 39 +++++++
.../camel/metrics/meter/MeterProducer.java | 30 ++++++
.../services/org/apache/camel/component/metrics | 2 +-
.../org/apache/camel/MetricsComponentTest.java | 28 -----
.../camel/metrics/MetricsComponentTest.java | 42 ++++++++
15 files changed, 381 insertions(+), 146 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index ae5ac4a..2407292 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
<version>2.13.0</version>
<name>Camel Metrics Component</name>
- <url>http://www.myorganization.org</url>
+ <url>http://camel.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -22,6 +22,11 @@
<artifactId>camel-core</artifactId>
<version>2.13.0</version>
</dependency>
+ <dependency>
+ <groupId>com.codahale.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ <version>3.0.1</version>
+ </dependency>
<!-- logging -->
<dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/java/org/apache/camel/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsComponent.java b/src/main/java/org/apache/camel/MetricsComponent.java
deleted file mode 100644
index 2690fdb..0000000
--- a/src/main/java/org/apache/camel/MetricsComponent.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.apache.camel;
-
-import java.util.Map;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.impl.DefaultComponent;
-
-/**
- * Represents the component that manages {@link MetricsEndpoint}.
- */
-public class MetricsComponent extends DefaultComponent {
-
- protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- Endpoint endpoint = new MetricsEndpoint(uri, this);
- setProperties(endpoint, parameters);
- return endpoint;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/java/org/apache/camel/MetricsConsumer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsConsumer.java b/src/main/java/org/apache/camel/MetricsConsumer.java
deleted file mode 100644
index 26199ea..0000000
--- a/src/main/java/org/apache/camel/MetricsConsumer.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.apache.camel;
-
-import java.util.Date;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.impl.ScheduledPollConsumer;
-
-/**
- * The Metrics consumer.
- */
-public class MetricsConsumer extends ScheduledPollConsumer {
- private final MetricsEndpoint endpoint;
-
- public MetricsConsumer(MetricsEndpoint endpoint, Processor processor) {
- super(endpoint, processor);
- this.endpoint = endpoint;
- }
-
- @Override
- protected int poll() throws Exception {
- Exchange exchange = endpoint.createExchange();
-
- // create a message body
- Date now = new Date();
- exchange.getIn().setBody("Hello World! The time is " + now);
-
- try {
- // send message to next processor in the route
- getProcessor().process(exchange);
- return 1; // number of messages polled
- } finally {
- // log exception if an exception occurred and was not handled
- if (exchange.getException() != null) {
- getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/java/org/apache/camel/MetricsEndpoint.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsEndpoint.java b/src/main/java/org/apache/camel/MetricsEndpoint.java
deleted file mode 100644
index 4327a03..0000000
--- a/src/main/java/org/apache/camel/MetricsEndpoint.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.apache.camel;
-
-import org.apache.camel.Consumer;
-import org.apache.camel.Processor;
-import org.apache.camel.Producer;
-import org.apache.camel.impl.DefaultEndpoint;
-
-/**
- * Represents a Metrics endpoint.
- */
-public class MetricsEndpoint extends DefaultEndpoint {
-
- public MetricsEndpoint() {
- }
-
- public MetricsEndpoint(String uri, MetricsComponent component) {
- super(uri, component);
- }
-
- public MetricsEndpoint(String endpointUri) {
- super(endpointUri);
- }
-
- public Producer createProducer() throws Exception {
- return new MetricsProducer(this);
- }
-
- public Consumer createConsumer(Processor processor) throws Exception {
- return new MetricsConsumer(this, processor);
- }
-
- public boolean isSingleton() {
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/java/org/apache/camel/MetricsProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsProducer.java b/src/main/java/org/apache/camel/MetricsProducer.java
deleted file mode 100644
index 4d6a1cd..0000000
--- a/src/main/java/org/apache/camel/MetricsProducer.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.apache.camel;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The Metrics producer.
- */
-public class MetricsProducer extends DefaultProducer {
- private static final Logger LOG = LoggerFactory.getLogger(MetricsProducer.class);
- private MetricsEndpoint endpoint;
-
- public MetricsProducer(MetricsEndpoint endpoint) {
- super(endpoint);
- this.endpoint = endpoint;
- }
-
- public void process(Exchange exchange) throws Exception {
- System.out.println(exchange.getIn().getBody());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java b/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
new file mode 100644
index 0000000..d8c8af7
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
@@ -0,0 +1,37 @@
+package org.apache.camel.metrics;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.DefaultEndpoint;
+
+import com.codahale.metrics.MetricRegistry;
+
+public abstract class AbstractMetricsEndpoint extends DefaultEndpoint {
+
+ protected final MetricRegistry registry;
+ protected final String metricsName;
+
+ public AbstractMetricsEndpoint(MetricRegistry registry, String metricsName) {
+ this.registry = registry;
+ this.metricsName = metricsName;
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new RuntimeCamelException("Cannot consume from " + getClass().getSimpleName() + ": " + getEndpointUri());
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return false;
+ }
+
+ public MetricRegistry getRegistry() {
+ return registry;
+ }
+
+ public String getMetricsName() {
+ return metricsName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/MetricsComponent.java b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
new file mode 100644
index 0000000..14e93cb
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@ -0,0 +1,107 @@
+package org.apache.camel.metrics;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.metrics.counter.CounterEndpoint;
+import org.apache.camel.metrics.meter.MeterEndpoint;
+import org.apache.camel.spi.Registry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Slf4jReporter;
+
+/**
+ * Represents the component that manages {@link MetricsEndpoint}.
+ */
+public class MetricsComponent extends DefaultComponent {
+
+ public static final String NAME_METRIC_REGISTRY = "metricRegistry";
+ public static final MetricsType DEFAULT_METRICS_TYPE = MetricsType.METER;
+ public static final long DEFAULT_REPORTING_INTERVAL_SECONDS = 60L;
+
+ private static final Logger LOG = LoggerFactory.getLogger(MetricsComponent.class);
+
+ private MetricRegistry metricRegistry;
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ Registry camelRegistry = getCamelContext().getRegistry();
+ getOrCreateMetricRegistry(camelRegistry, NAME_METRIC_REGISTRY);
+ String metricsName = getMetricsName(remaining);
+ MetricsType metricsType = getMetricsType(remaining);
+ LOG.info("Metrics type: {}; name: {}", metricsType, metricsName);
+ Endpoint endpoint = createNewEndpoint(metricRegistry, metricsType, metricsName);
+ setProperties(endpoint, parameters);
+ return endpoint;
+ }
+
+ String getMetricsName(String remaining) {
+ int index = remaining.indexOf(":");
+ return index < 0 ? remaining : remaining.substring(index + 1);
+ }
+
+ Endpoint createNewEndpoint(MetricRegistry registry, MetricsType type, String metricsName) {
+ Endpoint endpoint;
+ switch (type) {
+ case COUNTER:
+ endpoint = new CounterEndpoint(registry, metricsName);
+ break;
+ case METER:
+ endpoint = new MeterEndpoint(registry, metricsName);
+ break;
+ default:
+ throw new RuntimeCamelException("Metrics type \"" + type.toString() + "\" not supported");
+ }
+ return endpoint;
+ }
+
+ MetricsType getMetricsType(String remaining) {
+ int index = remaining.indexOf(":");
+ String name = null;
+ MetricsType type;
+ if (index < 0) {
+ type = DEFAULT_METRICS_TYPE;
+ }
+ else {
+ name = remaining.substring(0, index);
+ type = MetricsType.getByName(name);
+ }
+ if (type == null) {
+ throw new RuntimeCamelException("Unknow metrics type \"" + name + "\"");
+ }
+ return type;
+ }
+
+ MetricRegistry getOrCreateMetricRegistry(Registry camelRegistry, String registryName) {
+ if (metricRegistry == null) {
+ LOG.debug("Looking up MetricRegistry from Camel Registry for name \"{}\"", registryName);
+ metricRegistry = getMetricRegistryFromCamelRegistry(camelRegistry, registryName);
+ }
+ if (metricRegistry == null) {
+ LOG.debug("MetricRegistry not found from Camel Registry for name \"{}\"", registryName);
+ LOG.info("Creating new default MetricRegistry");
+ metricRegistry = createMetricRegistry();
+ }
+ return metricRegistry;
+ }
+
+ MetricRegistry getMetricRegistryFromCamelRegistry(Registry camelRegistry, String registryName) {
+ return camelRegistry.lookupByNameAndType(registryName, MetricRegistry.class);
+ }
+
+ MetricRegistry createMetricRegistry() {
+ MetricRegistry registry = new MetricRegistry();
+ final Slf4jReporter reporter = Slf4jReporter.forRegistry(registry)
+ .outputTo(LOG)
+ .convertRatesTo(TimeUnit.SECONDS)
+ .convertDurationsTo(TimeUnit.MILLISECONDS)
+ .build();
+ reporter.start(DEFAULT_REPORTING_INTERVAL_SECONDS, TimeUnit.SECONDS);
+ return registry;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/java/org/apache/camel/metrics/MetricsType.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/MetricsType.java b/src/main/java/org/apache/camel/metrics/MetricsType.java
new file mode 100644
index 0000000..f602647
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/MetricsType.java
@@ -0,0 +1,37 @@
+package org.apache.camel.metrics;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+public enum MetricsType {
+
+ GAUGE("gauge"),
+ COUNTER("counter"),
+ HISTOGRAM("histogram"),
+ METER("meter"),
+ TIMER("timer"), ;
+
+ private static final Map<String, MetricsType> map = new HashMap<String, MetricsType>();
+
+ private final String name;
+
+ static {
+ for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
+ map.put(type.name, type);
+ }
+ }
+
+ private MetricsType(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ public static MetricsType getByName(String name) {
+ return map.get(name);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java b/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
new file mode 100644
index 0000000..8d0b34e
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
@@ -0,0 +1,50 @@
+package org.apache.camel.metrics.counter;
+
+import org.apache.camel.Producer;
+import org.apache.camel.metrics.AbstractMetricsEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+
+import com.codahale.metrics.MetricRegistry;
+
+@UriEndpoint(scheme = "metrics:counter")
+public class CounterEndpoint extends AbstractMetricsEndpoint {
+
+ public static final String ENDPOINT_URI = "metrics:counter";
+
+ @UriParam
+ private Long increment;
+
+ @UriParam
+ private Long decrement;
+
+ public CounterEndpoint(MetricRegistry registry, String metricsName) {
+ super(registry, metricsName);
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new CounterProducer(this);
+ }
+
+ public Long getIncrement() {
+ return increment;
+ }
+
+ public void setIncrement(Long increment) {
+ this.increment = increment;
+ }
+
+ public Long getDecrement() {
+ return decrement;
+ }
+
+ public void setDecrement(Long decrement) {
+ this.decrement = decrement;
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return ENDPOINT_URI;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java b/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
new file mode 100644
index 0000000..19c470f
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
@@ -0,0 +1,32 @@
+package org.apache.camel.metrics.counter;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+
+import com.codahale.metrics.Counter;
+
+public class CounterProducer extends DefaultProducer {
+
+ public CounterProducer(Endpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ CounterEndpoint endpoint = (CounterEndpoint) getEndpoint();
+ String metricName = endpoint.getMetricsName();
+ Counter counter = endpoint.getRegistry().counter(metricName);
+ Long increment = endpoint.getIncrement();
+ Long decrement = endpoint.getDecrement();
+ if (increment != null) {
+ counter.inc(increment);
+ }
+ else if (decrement != null) {
+ counter.dec(decrement);
+ }
+ else {
+ counter.inc();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java b/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
new file mode 100644
index 0000000..d0b609e
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
@@ -0,0 +1,39 @@
+package org.apache.camel.metrics.meter;
+
+import org.apache.camel.Producer;
+import org.apache.camel.metrics.AbstractMetricsEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+
+import com.codahale.metrics.MetricRegistry;
+
+@UriEndpoint(scheme = "metrics:meter")
+public class MeterEndpoint extends AbstractMetricsEndpoint {
+
+ public static final String ENDPOINT_URI = "metrics:meter";
+
+ @UriParam
+ private Long mark;
+
+ public MeterEndpoint(MetricRegistry registry, String metricsName) {
+ super(registry, metricsName);
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new MeterProducer(this);
+ }
+
+ public Long getMark() {
+ return mark;
+ }
+
+ public void setMark(Long mark) {
+ this.mark = mark;
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return ENDPOINT_URI;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java b/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
new file mode 100644
index 0000000..6cb7896
--- /dev/null
+++ b/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
@@ -0,0 +1,30 @@
+package org.apache.camel.metrics.meter;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+
+public class MeterProducer extends DefaultProducer {
+
+ public MeterProducer(Endpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ MeterEndpoint endpoint = (MeterEndpoint) getEndpoint();
+ String metricsName = endpoint.getMetricsName();
+ MetricRegistry registry = endpoint.getRegistry();
+ Meter meter = registry.meter(metricsName);
+ Long mark = endpoint.getMark();
+ if (mark == null) {
+ meter.mark();
+ }
+ else {
+ meter.mark(mark);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/main/resources/META-INF/services/org/apache/camel/component/metrics
----------------------------------------------------------------------
diff --git a/src/main/resources/META-INF/services/org/apache/camel/component/metrics b/src/main/resources/META-INF/services/org/apache/camel/component/metrics
index e7239ec..debbe31 100644
--- a/src/main/resources/META-INF/services/org/apache/camel/component/metrics
+++ b/src/main/resources/META-INF/services/org/apache/camel/component/metrics
@@ -1 +1 @@
-class=org.apache.camel.MetricsComponent
+class=org.apache.camel.metrics.MetricsComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/test/java/org/apache/camel/MetricsComponentTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/MetricsComponentTest.java b/src/test/java/org/apache/camel/MetricsComponentTest.java
deleted file mode 100644
index 2fb5926..0000000
--- a/src/test/java/org/apache/camel/MetricsComponentTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.apache.camel;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class MetricsComponentTest extends CamelTestSupport {
-
- @Test
- public void testMetrics() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMinimumMessageCount(1);
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() {
- from("metrics://foo")
- .to("metrics://bar")
- .to("mock:result");
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/98560c8e/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java b/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
new file mode 100644
index 0000000..8eb6b42
--- /dev/null
+++ b/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
@@ -0,0 +1,42 @@
+package org.apache.camel.metrics;
+
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class MetricsComponentTest extends CamelTestSupport {
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ @Test
+ public void testMetrics() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+ template.sendBody(new Object());
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start")
+ // .to("metrics")
+ // .to("metrics:")
+ .to("metrics:A")
+ .to("metrics:counter://B")
+ .to("metrics:counter:C?increment=19291")
+ .to("metrics:counter:C?decrement=19292")
+ .to("metrics:counter:C")
+ .to("metrics:meter:D")
+ .to("metrics:meter:D?mark=90001")
+ .to("mock:result");
+ }
+ };
+ }
+}
[25/34] git commit: Merge branch 'master' into camel-metrics
Posted by da...@apache.org.
Merge branch 'master' into camel-metrics
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/20f67f58
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/20f67f58
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/20f67f58
Branch: refs/heads/master
Commit: 20f67f58846153beb4047946e542a3e4af3de765
Parents: 4c41ca9 d98a45e
Author: Lauri Kimmel <la...@gmx.com>
Authored: Wed Jul 30 20:59:18 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Wed Jul 30 20:59:18 2014 +1000
----------------------------------------------------------------------
.../camel/model/RestContextRefDefinition.java | 59 ++++++++
.../model/RestContextRefDefinitionHelper.java | 151 +++++++++++++++++++
.../model/RouteContextRefDefinitionHelper.java | 2 +-
.../resources/org/apache/camel/model/jaxb.index | 1 +
.../apache/camel/model/XmlRestParseTest.java | 44 ++++++
.../org/apache/camel/model/XmlTestSupport.java | 8 +
.../org/apache/camel/model/simpleRest.xml | 27 ++++
.../blueprint/CamelContextFactoryBean.java | 11 ++
.../blueprint/CamelRestContextFactoryBean.java | 40 +++++
.../handler/CamelNamespaceHandler.java | 46 ++++++
.../org/apache/camel/blueprint/jaxb.index | 1 +
.../xml/AbstractCamelContextFactoryBean.java | 22 ++-
.../camel/osgi/CamelNamespaceHandler.java | 1 +
.../camel/spring/CamelContextFactoryBean.java | 11 ++
.../spring/CamelRestContextFactoryBean.java | 59 ++++++++
.../spring/handler/CamelNamespaceHandler.java | 38 ++++-
.../org/apache/camel/spring/jaxb.index | 1 +
.../camel/component/rest/RestRefTest.java | 64 ++++++++
.../apache/camel/component/rest/RestRefTest.xml | 64 ++++++++
.../blueprint/component/rest/RestRefTest.java | 66 ++++++++
.../blueprint/component/rest/RestRefTest.xml | 62 ++++++++
21 files changed, 774 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
[17/34] git commit: Merge
'https://github.com/laurikimmel/camel-metrics.git' into camel-metrics
Posted by da...@apache.org.
Merge 'https://github.com/laurikimmel/camel-metrics.git' into camel-metrics
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/641de098
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/641de098
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/641de098
Branch: refs/heads/master
Commit: 641de09867a8ecab71133cf7bf7fc66159323cdc
Parents: ed13d4e 03afdee
Author: Lauri Kimmel <la...@gmx.com>
Authored: Tue Jul 1 23:41:27 2014 +1000
Committer: Lauri Kimmel <la...@gmx.com>
Committed: Tue Jul 1 23:41:27 2014 +1000
----------------------------------------------------------------------
components/camel-metrics/.gitignore | 8 +
components/camel-metrics/.travis.yml | 9 +
components/camel-metrics/README.md | 271 +++++++++++++++++++
components/camel-metrics/pom.xml | 137 ++++++++++
.../camel/metrics/AbstractMetricsEndpoint.java | 37 +++
.../camel/metrics/AbstractMetricsProducer.java | 59 ++++
.../apache/camel/metrics/MetricsComponent.java | 121 +++++++++
.../org/apache/camel/metrics/MetricsType.java | 37 +++
.../camel/metrics/counter/CounterEndpoint.java | 50 ++++
.../camel/metrics/counter/CounterProducer.java | 37 +++
.../metrics/histogram/HistogramEndpoint.java | 39 +++
.../metrics/histogram/HistogramProducer.java | 35 +++
.../camel/metrics/meter/MeterEndpoint.java | 39 +++
.../camel/metrics/meter/MeterProducer.java | 31 +++
.../camel/metrics/timer/TimerEndpoint.java | 44 +++
.../camel/metrics/timer/TimerProducer.java | 75 +++++
.../services/org/apache/camel/component/metrics | 1 +
.../metrics/AbstractMetricsEndpointTest.java | 96 +++++++
.../metrics/AbstractMetricsProducerTest.java | 172 ++++++++++++
.../metrics/MetricComponentSpringTest.java | 77 ++++++
.../metrics/MetricsComponentRouteTest.java | 99 +++++++
.../camel/metrics/MetricsComponentTest.java | 204 ++++++++++++++
.../apache/camel/metrics/MetricsTypeTest.java | 19 ++
.../metrics/counter/CounterEndpointTest.java | 88 ++++++
.../metrics/counter/CounterProducerTest.java | 181 +++++++++++++
.../camel/metrics/counter/CounterRouteTest.java | 195 +++++++++++++
.../histogram/HistogramEndpointTest.java | 74 +++++
.../histogram/HistogramProducerTest.java | 111 ++++++++
.../metrics/histogram/HistogramRouteTest.java | 109 ++++++++
.../camel/metrics/meter/MeterEndpointTest.java | 75 +++++
.../camel/metrics/meter/MeterProducerTest.java | 112 ++++++++
.../camel/metrics/meter/MeterRouteTest.java | 151 +++++++++++
.../camel/metrics/timer/TimerEndpointTest.java | 75 +++++
.../camel/metrics/timer/TimerProducerTest.java | 215 +++++++++++++++
.../camel/metrics/timer/TimerRouteTest.java | 130 +++++++++
.../src/test/resources/log4j.properties | 14 +
36 files changed, 3227 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/.gitignore
----------------------------------------------------------------------
diff --cc components/camel-metrics/.gitignore
index 0000000,0000000..9365f3c
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/.gitignore
@@@ -1,0 -1,0 +1,8 @@@
++# Maven
++target
++
++# Eclipse
++
++.classpath
++.project
++.settings/
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/.travis.yml
----------------------------------------------------------------------
diff --cc components/camel-metrics/.travis.yml
index 0000000,0000000..5cf3ef3
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/.travis.yml
@@@ -1,0 -1,0 +1,9 @@@
++language: java
++jdk:
++ - oraclejdk7
++ - openjdk7
++ - openjdk6
++
++branches:
++ only:
++ - master
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/README.md
----------------------------------------------------------------------
diff --cc components/camel-metrics/README.md
index 0000000,0000000..b0b7bab
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/README.md
@@@ -1,0 -1,0 +1,271 @@@
++# Metrics Component
++
++[](https://travis-ci.org/laurikimmel/camel-metrics)
++
++**Available as of Camel 2.13**
++
++The **metrics:** component allows you to collect various metrics directly from Camel routes. Supported metric types are _counter_, _meter_, _histogram_ and _timer_. [Metrics](http://metrics.codahale.com) provides simple way to measure behaviour of your application. Configurable reporting _backend_ is enabling different integration options for collecting and visualizing statistics.
++
++Maven users will need to add the following dependency to their pom.xml for this component:
++
++```xml
++
++<dependency>
++ <groupId>org.apache.camel</groupId>
++ <artifactId>camel-metrics</artifactId>
++ <version>x.x.x</version>
++ <!-- use the same version as your Camel core version -->
++</dependency>
++```
++
++# URI format
++
++```
++metrics:[ meter | counter | histogram | timer ]:metricname[?options]
++```
++
++# Metric Registry
++
++If MetricRegistry instance for name `metricRegistry` is not found from Camel registry default one is used. Default MetricRegistry uses Slf4jReporter and 60 second reporting interval.
++MetricRegistry instance can be configured by adding bean with name `metricRegistry` to Camel registry. For example using Spring Java Configuration.
++
++```java
++
++ @Configuration
++ public static class MyConfig extends SingleRouteCamelConfiguration {
++
++ @Bean
++ @Override
++ public RouteBuilder route() {
++ return new RouteBuilder() {
++
++ @Override
++ public void configure() throws Exception {
++ // define Camel routes here
++ }
++ };
++ }
++
++ @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
++ public MetricRegistry getMetricRegistry() {
++ MetricRegistry registry = ...;
++ return registry;
++ }
++ }
++
++```
++
++# Usage
++
++Each metric has type and name. Supported types are `counter`, `meter`, `histogram` and `timer`. Metric name is simple string. If metric type is not provided then type `meter` is used by default.
++
++### Headers
++
++Metric name defined in URI can be overridden by using header with name `CamelMetricsName`.
++
++For example
++
++```java
++from("direct:in")
++ .setHeader(MetricsComponent.HEADER_METRIC_NAME, constant("new.name"))
++ .to("metrics:counter:name.not.used")
++ .to("direct:out")
++```
++
++will update counter with name `new.name` instead of `name.not.used`.
++
++All Metrics specific headers are removed from the message once Metrics endpoint finishes processing of exchange.
++While processing exchange Metrics endpoint will catch all exceptions and write log entry using level `warn`.
++
++
++## Metrics type counter
++
++```
++metrics:counter:metricname[?options]
++```
++
++Where options are
++
++| Name | Default | Description |
++|-----------|---------|-----------------------------------------|
++| increment | - | Long value to add to the counter |
++| decrement | - | Long value to subtract from the counter |
++
++If neither `increment` or `decrement` is defined counter value will be incremented by one. If `increment` and `decrement` are both defined only increment operation is called.
++
++```java
++// update counter simple.counter by 7
++from("direct:in")
++ .to("metric:counter:simple.counter?increment=7")
++ .to("direct:out")
++```
++
++```java
++// increment counter simple.counter by 1
++from("direct:in")
++ .to("metric:counter:simple.counter")
++ .to("direct:out")
++```
++
++```java
++// decrement counter simple.counter by 3
++from("direct:in")
++ .to("metric:counter:simple.counter?decrement=3")
++ .to("direct:out")
++```
++
++### Headers
++
++Message headers can be used to override `increment` and `decrement` values specified in Metrics component URI.
++
++| Name | Description | Expected type |
++|------------------------------|---------------------------------|---------------|
++| CamelMetricsCounterIncrement | Override increment value in URI | Long |
++| CamelMetricsCounterDecrement | Override decrement value in URI | Long |
++
++```java
++// update counter simple.counter by 417
++from("direct:in")
++ .setHeader(MetricsComponent.HEADER_COUNTER_INCREMENT, constant(417L))
++ .to("metric:counter:simple.counter?increment=7")
++ .to("direct:out")
++```
++
++```java
++// updates counter using simple language to evaluate body.length
++from("direct:in")
++ .setHeader(MetricsComponent.HEADER_COUNTER_INCREMENT, simple("${body.length}"))
++ .to("metrics:counter:body.length")
++ .to("mock:out");
++```
++
++
++## Metric type histogram
++
++```
++metrics:histogram:metricname[?options]
++```
++
++Where options are
++
++| Name | Default | Description |
++|-------|---------|---------------------------|
++| value | - | Value to use in histogram |
++
++If no `value` is not set nothing is added to histogram and warning is logged.
++
++```java
++// adds value 9923 to simple.histogram
++from("direct:in")
++ .to("metric:histogram:simple.histogram?value=9923")
++ .to("direct:out")
++```
++
++```java
++// nothing is added to simple.histogram; warning is logged
++from("direct:in")
++ .to("metric:histogram:simple.histogram")
++ .to("direct:out")
++```
++
++### Headers
++
++Message header can be used to override `value` specified in Metrics component URI.
++
++| Name | Description | Expected type |
++|----------------------------|---------------------------------|---------------|
++| CamelMetricsHistogramValue | Override histogram value in URI | Long |
++
++```java
++// adds value 992 to simple.histogram
++from("direct:in")
++ .setHeader(MetricsComponent.HEADER_HISTOGRAM_VALUE, constant(992L))
++ .to("metric:histogram:simple.histogram?value=700")
++ .to("direct:out")
++```
++
++
++## Metric type meter
++
++```
++metrics:meter:metricname[?options]
++```
++
++Where options are
++
++| Name | Default | Description |
++|------|---------|---------------------------|
++| mark | - | Long value to use as mark |
++
++If `mark` is not set `meter.mark()` is called without argument.
++
++```java
++// marks simple.meter without value
++from("direct:in")
++ .to("metric:simple.meter")
++ .to("direct:out")
++```
++
++```java
++// marks simple.meter with value 81
++from("direct:in")
++ .to("metric:meter:simple.meter?mark=81")
++ .to("direct:out")
++```
++
++### Headers
++
++Message header can be used to override `mark` value specified in Metrics component URI.
++
++| Name | Description | Expected type |
++|-----------------------|----------------------------|---------------|
++| CamelMetricsMeterMark | Override mark value in URI | Long |
++
++```java
++// updates meter simple.meter with value 345
++from("direct:in")
++ .setHeader(MetricsComponent.HEADER_METER_MARK, constant(345L))
++ .to("metric:meter:simple.meter?mark=123")
++ .to("direct:out")
++```
++
++
++## Metrics type timer
++
++```
++metrics:timer:metricname[?options]
++```
++
++Where options are
++
++| Name | Default | Description |
++|--------|---------|-------------------|
++| action | - | `start` or `stop` |
++
++If no `action` or invalid value is provided warning is logged and no timer is updated. If `action` `start` is called on already running timer or `stop` is called on not running timer nothing is updated and warning is logged.
++
++```java
++// measure time taken by route calculate
++from("direct:in")
++ .to("metrics:timer:simple.timer?action=start")
++ .to("direct:calculate")
++ .to("metrics:timer:simple.timer?action=stop");
++```
++
++`Timer Context` objects are stored as `Exchange` properties between different Metrics component calls.
++
++### Headers
++
++Message header can be used to override `action` value specified in Metrics component URI.
++
++| Name | Description | Expected type |
++|-------------------------|------------------------------|----------------------------------------------------------|
++| CamelMetricsTimerAction | Override timer action in URI | org.apache.camel.metrics.timer.TimerEndpoint.TimerAction |
++
++```java
++// sets timer action using header
++from("direct:in")
++ .setHeader(MetricsComponent.HEADER_TIMER_ACTION, TimerAction.start)
++ .to("metric:timer:simple.timer")
++ .to("direct:out")
++```
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/pom.xml
----------------------------------------------------------------------
diff --cc components/camel-metrics/pom.xml
index 0000000,0000000..0f65ab5
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/pom.xml
@@@ -1,0 -1,0 +1,137 @@@
++<?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/maven-v4_0_0.xsd">
++
++ <modelVersion>4.0.0</modelVersion>
++
++ <groupId>org.apache.camel</groupId>
++ <artifactId>camel-metrics</artifactId>
++ <packaging>bundle</packaging>
++ <version>2.13.0</version>
++
++ <name>Camel Metrics Component</name>
++ <url>http://camel.apache.org</url>
++
++ <properties>
++ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
++ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
++ </properties>
++
++ <dependencies>
++ <dependency>
++ <groupId>org.apache.camel</groupId>
++ <artifactId>camel-core</artifactId>
++ <version>2.13.0</version>
++ </dependency>
++ <dependency>
++ <groupId>com.codahale.metrics</groupId>
++ <artifactId>metrics-core</artifactId>
++ <version>3.0.1</version>
++ </dependency>
++
++ <!-- logging -->
++ <dependency>
++ <groupId>org.slf4j</groupId>
++ <artifactId>slf4j-api</artifactId>
++ <version>1.7.6</version>
++ </dependency>
++ <dependency>
++ <groupId>org.slf4j</groupId>
++ <artifactId>slf4j-log4j12</artifactId>
++ <version>1.7.6</version>
++ <scope>test</scope>
++ </dependency>
++ <dependency>
++ <groupId>log4j</groupId>
++ <artifactId>log4j</artifactId>
++ <version>1.2.17</version>
++ <scope>test</scope>
++ </dependency>
++
++ <!-- testing -->
++ <dependency>
++ <groupId>org.apache.camel</groupId>
++ <artifactId>camel-test</artifactId>
++ <version>2.13.0</version>
++ <scope>test</scope>
++ </dependency>
++ <dependency>
++ <groupId>org.apache.camel</groupId>
++ <artifactId>camel-spring</artifactId>
++ <version>2.13.0</version>
++ <scope>test</scope>
++ </dependency>
++ <dependency>
++ <groupId>org.apache.camel</groupId>
++ <artifactId>camel-spring-javaconfig</artifactId>
++ <version>2.13.0</version>
++ <scope>test</scope>
++ </dependency>
++ <dependency>
++ <groupId>org.apache.camel</groupId>
++ <artifactId>camel-test-spring</artifactId>
++ <version>2.13.0</version>
++ <scope>test</scope>
++ </dependency>
++ <dependency>
++ <groupId>org.mockito</groupId>
++ <artifactId>mockito-core</artifactId>
++ <version>1.9.5</version>
++ <scope>test</scope>
++ </dependency>
++ <dependency>
++ <groupId>junit</groupId>
++ <artifactId>junit</artifactId>
++ <version>4.11</version>
++ <scope>test</scope>
++ </dependency>
++ <dependency>
++ <groupId>org.hamcrest</groupId>
++ <artifactId>hamcrest-all</artifactId>
++ <version>1.3</version>
++ <scope>test</scope>
++ </dependency>
++
++ </dependencies>
++
++ <build>
++ <defaultGoal>install</defaultGoal>
++
++ <plugins>
++
++ <plugin>
++ <groupId>org.apache.maven.plugins</groupId>
++ <artifactId>maven-compiler-plugin</artifactId>
++ <version>2.5.1</version>
++ <configuration>
++ <source>1.6</source>
++ <target>1.6</target>
++ </configuration>
++ </plugin>
++
++ <plugin>
++ <groupId>org.apache.maven.plugins</groupId>
++ <artifactId>maven-resources-plugin</artifactId>
++ <version>2.6</version>
++ <configuration>
++ <encoding>UTF-8</encoding>
++ </configuration>
++ </plugin>
++
++ <!-- to generate the MANIFEST-FILE of the bundle -->
++ <plugin>
++ <groupId>org.apache.felix</groupId>
++ <artifactId>maven-bundle-plugin</artifactId>
++ <version>2.3.7</version>
++ <extensions>true</extensions>
++ <configuration>
++ <instructions>
++ <Bundle-SymbolicName>org.apache.camel.camel-metrics</Bundle-SymbolicName>
++ <Export-Service>org.apache.camel.spi.ComponentResolver;component=metrics</Export-Service>
++ </instructions>
++ </configuration>
++ </plugin>
++
++ </plugins>
++ </build>
++
++</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
index 0000000,0000000..d8c8af7
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsEndpoint.java
@@@ -1,0 -1,0 +1,37 @@@
++package org.apache.camel.metrics;
++
++import org.apache.camel.Consumer;
++import org.apache.camel.Processor;
++import org.apache.camel.RuntimeCamelException;
++import org.apache.camel.impl.DefaultEndpoint;
++
++import com.codahale.metrics.MetricRegistry;
++
++public abstract class AbstractMetricsEndpoint extends DefaultEndpoint {
++
++ protected final MetricRegistry registry;
++ protected final String metricsName;
++
++ public AbstractMetricsEndpoint(MetricRegistry registry, String metricsName) {
++ this.registry = registry;
++ this.metricsName = metricsName;
++ }
++
++ @Override
++ public Consumer createConsumer(Processor processor) throws Exception {
++ throw new RuntimeCamelException("Cannot consume from " + getClass().getSimpleName() + ": " + getEndpointUri());
++ }
++
++ @Override
++ public boolean isSingleton() {
++ return false;
++ }
++
++ public MetricRegistry getRegistry() {
++ return registry;
++ }
++
++ public String getMetricsName() {
++ return metricsName;
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
index 0000000,0000000..24149af
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/AbstractMetricsProducer.java
@@@ -1,0 -1,0 +1,59 @@@
++package org.apache.camel.metrics;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_PERFIX;
++
++import org.apache.camel.Exchange;
++import org.apache.camel.Message;
++import org.apache.camel.impl.DefaultProducer;
++import org.apache.camel.util.ObjectHelper;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
++
++import com.codahale.metrics.MetricRegistry;
++
++public abstract class AbstractMetricsProducer<T extends AbstractMetricsEndpoint> extends DefaultProducer {
++
++ public static final String HEADER_PATTERN = HEADER_PERFIX + "*";
++ private static final Logger LOG = LoggerFactory.getLogger(AbstractMetricsProducer.class);
++
++ public AbstractMetricsProducer(T endpoint) {
++ super(endpoint);
++ }
++
++ @Override
++ public void process(Exchange exchange) throws Exception {
++ @SuppressWarnings("unchecked")
++ T endpoint = (T) getEndpoint();
++ Message in = exchange.getIn();
++ String defaultMetricsName = endpoint.getMetricsName();
++ String finalMetricsName = getMetricsName(in, defaultMetricsName);
++ MetricRegistry registry = endpoint.getRegistry();
++ try {
++ doProcess(exchange, endpoint, registry, finalMetricsName);
++ }
++ catch (Exception e) {
++ LOG.warn("Failed to produce metrics for {} in {} - {}", finalMetricsName, getClass().getSimpleName(), e.getMessage());
++ }
++ clearMetricsHeaders(in);
++ }
++
++ protected abstract void doProcess(Exchange exchange, T endpoint, MetricRegistry registry, String metricsName) throws Exception;
++
++ public String getMetricsName(Message in, String defaultValue) {
++ return getStringHeader(in, HEADER_METRIC_NAME, defaultValue);
++ }
++
++ public String getStringHeader(Message in, String header, String defaultValue) {
++ String headerValue = in.getHeader(header, String.class);
++ return ObjectHelper.isNotEmpty(headerValue) ? headerValue : defaultValue;
++ }
++
++ public Long getLongHeader(Message in, String header, Long defaultValue) {
++ return in.getHeader(header, defaultValue, Long.class);
++ }
++
++ protected boolean clearMetricsHeaders(Message in) {
++ return in.removeHeaders(HEADER_PATTERN);
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
index 0000000,0000000..c803e4f
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsComponent.java
@@@ -1,0 -1,0 +1,121 @@@
++package org.apache.camel.metrics;
++
++import java.util.Map;
++import java.util.concurrent.TimeUnit;
++
++import org.apache.camel.Endpoint;
++import org.apache.camel.RuntimeCamelException;
++import org.apache.camel.impl.DefaultComponent;
++import org.apache.camel.metrics.counter.CounterEndpoint;
++import org.apache.camel.metrics.histogram.HistogramEndpoint;
++import org.apache.camel.metrics.meter.MeterEndpoint;
++import org.apache.camel.metrics.timer.TimerEndpoint;
++import org.apache.camel.spi.Registry;
++import org.apache.camel.util.ObjectHelper;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
++
++import com.codahale.metrics.MetricRegistry;
++import com.codahale.metrics.Slf4jReporter;
++
++/**
++ * Represents the component that manages {@link MetricsEndpoint}.
++ */
++public class MetricsComponent extends DefaultComponent {
++
++ public static final String METRIC_REGISTRY_NAME = "metricRegistry";
++ public static final MetricsType DEFAULT_METRICS_TYPE = MetricsType.METER;
++ public static final long DEFAULT_REPORTING_INTERVAL_SECONDS = 60L;
++ public static final String HEADER_PERFIX = "CamelMetrics";
++ public static final String HEADER_METRIC_NAME = HEADER_PERFIX + "Name";
++ public static final String HEADER_COUNTER_INCREMENT = HEADER_PERFIX + "CounterIncrement";
++ public static final String HEADER_COUNTER_DECREMENT = HEADER_PERFIX + "CounterDecrement";
++ public static final String HEADER_HISTOGRAM_VALUE = HEADER_PERFIX + "HistogramValue";
++ public static final String HEADER_METER_MARK = HEADER_PERFIX + "MeterMark";
++ public static final String HEADER_TIMER_ACTION = HEADER_PERFIX + "TimerAction";
++
++ private static final Logger LOG = LoggerFactory.getLogger(MetricsComponent.class);
++
++ private MetricRegistry metricRegistry;
++
++ @Override
++ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
++ if (metricRegistry == null) {
++ Registry camelRegistry = getCamelContext().getRegistry();
++ metricRegistry = getOrCreateMetricRegistry(camelRegistry, METRIC_REGISTRY_NAME);
++ }
++ String metricsName = getMetricsName(remaining);
++ MetricsType metricsType = getMetricsType(remaining);
++ LOG.info("Metrics type: {}; name: {}", metricsType, metricsName);
++ Endpoint endpoint = createNewEndpoint(metricRegistry, metricsType, metricsName);
++ setProperties(endpoint, parameters);
++ return endpoint;
++ }
++
++ String getMetricsName(String remaining) {
++ String name = ObjectHelper.after(remaining, ":");
++ return name == null ? remaining : name;
++ }
++
++ Endpoint createNewEndpoint(MetricRegistry registry, MetricsType type, String metricsName) {
++ Endpoint endpoint;
++ switch (type) {
++ case COUNTER:
++ endpoint = new CounterEndpoint(registry, metricsName);
++ break;
++ case METER:
++ endpoint = new MeterEndpoint(registry, metricsName);
++ break;
++ case HISTOGRAM:
++ endpoint = new HistogramEndpoint(registry, metricsName);
++ break;
++ case TIMER:
++ endpoint = new TimerEndpoint(registry, metricsName);
++ break;
++ default:
++ throw new RuntimeCamelException("Metrics type \"" + type.toString() + "\" not supported");
++ }
++ return endpoint;
++ }
++
++ MetricsType getMetricsType(String remaining) {
++ String name = ObjectHelper.before(remaining, ":");
++ MetricsType type;
++ if (name == null) {
++ type = DEFAULT_METRICS_TYPE;
++ }
++ else {
++ type = MetricsType.getByName(name);
++ }
++ if (type == null) {
++ throw new RuntimeCamelException("Unknow metrics type \"" + name + "\"");
++ }
++ return type;
++ }
++
++ MetricRegistry getOrCreateMetricRegistry(Registry camelRegistry, String registryName) {
++ LOG.debug("Looking up MetricRegistry from Camel Registry for name \"{}\"", registryName);
++ MetricRegistry result = getMetricRegistryFromCamelRegistry(camelRegistry, registryName);
++ if (result == null) {
++ LOG.debug("MetricRegistry not found from Camel Registry for name \"{}\"", registryName);
++ LOG.info("Creating new default MetricRegistry");
++ result = createMetricRegistry();
++ }
++ return result;
++ }
++
++ MetricRegistry getMetricRegistryFromCamelRegistry(Registry camelRegistry, String registryName) {
++ return camelRegistry.lookupByNameAndType(registryName, MetricRegistry.class);
++ }
++
++ MetricRegistry createMetricRegistry() {
++ MetricRegistry registry = new MetricRegistry();
++ final Slf4jReporter reporter = Slf4jReporter.forRegistry(registry)
++ .outputTo(LOG)
++ .convertRatesTo(TimeUnit.SECONDS)
++ .convertDurationsTo(TimeUnit.MILLISECONDS)
++ .build();
++ reporter.start(DEFAULT_REPORTING_INTERVAL_SECONDS, TimeUnit.SECONDS);
++ return registry;
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java
index 0000000,0000000..f602647
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/MetricsType.java
@@@ -1,0 -1,0 +1,37 @@@
++package org.apache.camel.metrics;
++
++import java.util.EnumSet;
++import java.util.HashMap;
++import java.util.Map;
++
++public enum MetricsType {
++
++ GAUGE("gauge"),
++ COUNTER("counter"),
++ HISTOGRAM("histogram"),
++ METER("meter"),
++ TIMER("timer"), ;
++
++ private static final Map<String, MetricsType> map = new HashMap<String, MetricsType>();
++
++ private final String name;
++
++ static {
++ for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
++ map.put(type.name, type);
++ }
++ }
++
++ private MetricsType(String name) {
++ this.name = name;
++ }
++
++ @Override
++ public String toString() {
++ return name;
++ }
++
++ public static MetricsType getByName(String name) {
++ return map.get(name);
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
index 0000000,0000000..8d0b34e
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterEndpoint.java
@@@ -1,0 -1,0 +1,50 @@@
++package org.apache.camel.metrics.counter;
++
++import org.apache.camel.Producer;
++import org.apache.camel.metrics.AbstractMetricsEndpoint;
++import org.apache.camel.spi.UriEndpoint;
++import org.apache.camel.spi.UriParam;
++
++import com.codahale.metrics.MetricRegistry;
++
++@UriEndpoint(scheme = "metrics:counter")
++public class CounterEndpoint extends AbstractMetricsEndpoint {
++
++ public static final String ENDPOINT_URI = "metrics:counter";
++
++ @UriParam
++ private Long increment;
++
++ @UriParam
++ private Long decrement;
++
++ public CounterEndpoint(MetricRegistry registry, String metricsName) {
++ super(registry, metricsName);
++ }
++
++ @Override
++ public Producer createProducer() throws Exception {
++ return new CounterProducer(this);
++ }
++
++ public Long getIncrement() {
++ return increment;
++ }
++
++ public void setIncrement(Long increment) {
++ this.increment = increment;
++ }
++
++ public Long getDecrement() {
++ return decrement;
++ }
++
++ public void setDecrement(Long decrement) {
++ this.decrement = decrement;
++ }
++
++ @Override
++ protected String createEndpointUri() {
++ return ENDPOINT_URI;
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
index 0000000,0000000..2d9431c
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/counter/CounterProducer.java
@@@ -1,0 -1,0 +1,37 @@@
++package org.apache.camel.metrics.counter;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
++
++import org.apache.camel.Exchange;
++import org.apache.camel.Message;
++import org.apache.camel.metrics.AbstractMetricsProducer;
++
++import com.codahale.metrics.Counter;
++import com.codahale.metrics.MetricRegistry;
++
++public class CounterProducer extends AbstractMetricsProducer<CounterEndpoint> {
++
++ public CounterProducer(CounterEndpoint endpoint) {
++ super(endpoint);
++ }
++
++ @Override
++ protected void doProcess(Exchange exchange, CounterEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
++ Message in = exchange.getIn();
++ Counter counter = registry.counter(metricsName);
++ Long increment = endpoint.getIncrement();
++ Long decrement = endpoint.getDecrement();
++ Long finalIncrement = getLongHeader(in, HEADER_COUNTER_INCREMENT, increment);
++ Long finalDecrement = getLongHeader(in, HEADER_COUNTER_DECREMENT, decrement);
++ if (finalIncrement != null) {
++ counter.inc(finalIncrement);
++ }
++ else if (finalDecrement != null) {
++ counter.dec(finalDecrement);
++ }
++ else {
++ counter.inc();
++ }
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
index 0000000,0000000..8024289
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramEndpoint.java
@@@ -1,0 -1,0 +1,39 @@@
++package org.apache.camel.metrics.histogram;
++
++import org.apache.camel.Producer;
++import org.apache.camel.metrics.AbstractMetricsEndpoint;
++import org.apache.camel.spi.UriEndpoint;
++import org.apache.camel.spi.UriParam;
++
++import com.codahale.metrics.MetricRegistry;
++
++@UriEndpoint(scheme = "metrics:histogram")
++public class HistogramEndpoint extends AbstractMetricsEndpoint {
++
++ public static String ENDPOINT_URI = "metrics:histogram";
++
++ @UriParam
++ private Long value;
++
++ public HistogramEndpoint(MetricRegistry registry, String metricsName) {
++ super(registry, metricsName);
++ }
++
++ @Override
++ public Producer createProducer() throws Exception {
++ return new HistogramProducer(this);
++ }
++
++ public Long getValue() {
++ return value;
++ }
++
++ public void setValue(Long value) {
++ this.value = value;
++ }
++
++ @Override
++ protected String createEndpointUri() {
++ return ENDPOINT_URI;
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
index 0000000,0000000..46c586d
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/histogram/HistogramProducer.java
@@@ -1,0 -1,0 +1,35 @@@
++package org.apache.camel.metrics.histogram;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
++
++import org.apache.camel.Exchange;
++import org.apache.camel.Message;
++import org.apache.camel.metrics.AbstractMetricsProducer;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
++
++import com.codahale.metrics.Histogram;
++import com.codahale.metrics.MetricRegistry;
++
++public class HistogramProducer extends AbstractMetricsProducer<HistogramEndpoint> {
++
++ private static final Logger LOG = LoggerFactory.getLogger(HistogramProducer.class);
++
++ public HistogramProducer(HistogramEndpoint endpoint) {
++ super(endpoint);
++ }
++
++ @Override
++ protected void doProcess(Exchange exchange, HistogramEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
++ Message in = exchange.getIn();
++ Histogram histogram = registry.histogram(metricsName);
++ Long value = endpoint.getValue();
++ Long finalValue = getLongHeader(in, HEADER_HISTOGRAM_VALUE, value);
++ if (finalValue != null) {
++ histogram.update(finalValue);
++ }
++ else {
++ LOG.warn("Cannot update histogram \"{}\" with null value", metricsName);
++ }
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
index 0000000,0000000..d0b609e
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterEndpoint.java
@@@ -1,0 -1,0 +1,39 @@@
++package org.apache.camel.metrics.meter;
++
++import org.apache.camel.Producer;
++import org.apache.camel.metrics.AbstractMetricsEndpoint;
++import org.apache.camel.spi.UriEndpoint;
++import org.apache.camel.spi.UriParam;
++
++import com.codahale.metrics.MetricRegistry;
++
++@UriEndpoint(scheme = "metrics:meter")
++public class MeterEndpoint extends AbstractMetricsEndpoint {
++
++ public static final String ENDPOINT_URI = "metrics:meter";
++
++ @UriParam
++ private Long mark;
++
++ public MeterEndpoint(MetricRegistry registry, String metricsName) {
++ super(registry, metricsName);
++ }
++
++ @Override
++ public Producer createProducer() throws Exception {
++ return new MeterProducer(this);
++ }
++
++ public Long getMark() {
++ return mark;
++ }
++
++ public void setMark(Long mark) {
++ this.mark = mark;
++ }
++
++ @Override
++ protected String createEndpointUri() {
++ return ENDPOINT_URI;
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
index 0000000,0000000..7622112
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/meter/MeterProducer.java
@@@ -1,0 -1,0 +1,31 @@@
++package org.apache.camel.metrics.meter;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_METER_MARK;
++
++import org.apache.camel.Exchange;
++import org.apache.camel.Message;
++import org.apache.camel.metrics.AbstractMetricsProducer;
++
++import com.codahale.metrics.Meter;
++import com.codahale.metrics.MetricRegistry;
++
++public class MeterProducer extends AbstractMetricsProducer<MeterEndpoint> {
++
++ public MeterProducer(MeterEndpoint endpoint) {
++ super(endpoint);
++ }
++
++ @Override
++ protected void doProcess(Exchange exchange, MeterEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
++ Message in = exchange.getIn();
++ Meter meter = registry.meter(metricsName);
++ Long mark = endpoint.getMark();
++ Long finalMark = getLongHeader(in, HEADER_METER_MARK, mark);
++ if (finalMark == null) {
++ meter.mark();
++ }
++ else {
++ meter.mark(finalMark);
++ }
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
index 0000000,0000000..6de4e32
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerEndpoint.java
@@@ -1,0 -1,0 +1,44 @@@
++package org.apache.camel.metrics.timer;
++
++import org.apache.camel.Producer;
++import org.apache.camel.metrics.AbstractMetricsEndpoint;
++import org.apache.camel.spi.UriEndpoint;
++import org.apache.camel.spi.UriParam;
++
++import com.codahale.metrics.MetricRegistry;
++
++@UriEndpoint(scheme = "metrics:timer")
++public class TimerEndpoint extends AbstractMetricsEndpoint {
++
++ public static final String ENDPOINT_URI = "metrics:timer";
++
++ public enum TimerAction {
++ start,
++ stop;
++ }
++
++ @UriParam
++ private TimerAction action;
++
++ public TimerEndpoint(MetricRegistry registry, String metricsName) {
++ super(registry, metricsName);
++ }
++
++ @Override
++ public Producer createProducer() throws Exception {
++ return new TimerProducer(this);
++ }
++
++ public TimerAction getAction() {
++ return action;
++ }
++
++ public void setAction(TimerAction action) {
++ this.action = action;
++ }
++
++ @Override
++ protected String createEndpointUri() {
++ return ENDPOINT_URI;
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
index 0000000,0000000..9586bbd
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/metrics/timer/TimerProducer.java
@@@ -1,0 -1,0 +1,75 @@@
++package org.apache.camel.metrics.timer;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_TIMER_ACTION;
++import static org.apache.camel.metrics.timer.TimerEndpoint.ENDPOINT_URI;
++
++import org.apache.camel.Exchange;
++import org.apache.camel.Message;
++import org.apache.camel.metrics.AbstractMetricsProducer;
++import org.apache.camel.metrics.timer.TimerEndpoint.TimerAction;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
++
++import com.codahale.metrics.MetricRegistry;
++import com.codahale.metrics.Timer;
++
++public class TimerProducer extends AbstractMetricsProducer<TimerEndpoint> {
++
++ private static final Logger LOG = LoggerFactory.getLogger(TimerProducer.class);
++
++ public TimerProducer(TimerEndpoint endpoint) {
++ super(endpoint);
++ }
++
++ @Override
++ protected void doProcess(Exchange exchange, TimerEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
++ Message in = exchange.getIn();
++ TimerAction action = endpoint.getAction();
++ TimerAction finalAction = in.getHeader(HEADER_TIMER_ACTION, action, TimerAction.class);
++ if (finalAction == TimerAction.start) {
++ handleStart(exchange, registry, metricsName);
++ }
++ else if (finalAction == TimerAction.stop) {
++ handleStop(exchange, registry, metricsName);
++ }
++ else {
++ LOG.warn("No action provided for timer \"{}\"", metricsName);
++ }
++ }
++
++ void handleStart(Exchange exchange, MetricRegistry registry, String metricsName) {
++ String propertyName = getPropertyName(metricsName);
++ Timer.Context context = getTimerContextFromExchange(exchange, propertyName);
++ if (context == null) {
++ Timer timer = registry.timer(metricsName);
++ context = timer.time();
++ exchange.setProperty(propertyName, context);
++ }
++ else {
++ LOG.warn("Timer \"{}\" already running", metricsName);
++ }
++ }
++
++ void handleStop(Exchange exchange, MetricRegistry registry, String metricsName) {
++ String propertyName = getPropertyName(metricsName);
++ Timer.Context context = getTimerContextFromExchange(exchange, propertyName);
++ if (context != null) {
++ context.stop();
++ exchange.removeProperty(propertyName);
++ }
++ else {
++ LOG.warn("Timer \"{}\" not found", metricsName);
++ }
++ }
++
++ String getPropertyName(String metricsName) {
++ return new StringBuilder(ENDPOINT_URI)
++ .append(":")
++ .append(metricsName)
++ .toString();
++ }
++
++ Timer.Context getTimerContextFromExchange(Exchange exchange, String propertyName) {
++ return exchange.getProperty(propertyName, Timer.Context.class);
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/main/resources/META-INF/services/org/apache/camel/component/metrics
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/main/resources/META-INF/services/org/apache/camel/component/metrics
index 0000000,0000000..debbe31
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/main/resources/META-INF/services/org/apache/camel/component/metrics
@@@ -1,0 -1,0 +1,1 @@@
++class=org.apache.camel.metrics.MetricsComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
index 0000000,0000000..1a7543e
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsEndpointTest.java
@@@ -1,0 -1,0 +1,96 @@@
++package org.apache.camel.metrics;
++
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.MatcherAssert.assertThat;
++import static org.mockito.Mockito.when;
++
++import org.apache.camel.Exchange;
++import org.apache.camel.Message;
++import org.apache.camel.Processor;
++import org.apache.camel.Producer;
++import org.apache.camel.RuntimeCamelException;
++import org.junit.After;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mock;
++import org.mockito.Mockito;
++import org.mockito.runners.MockitoJUnitRunner;
++
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(MockitoJUnitRunner.class)
++public class AbstractMetricsEndpointTest {
++
++ private static final String METRICS_NAME = "metrics.name";
++ private static final String HEADER = "header";
++ private static final String STRING_VALUE = "string-value";
++ private static final String DEFAULT_STRING_VALUE = "default-value";
++ private static final Long LONG_VALUE = System.currentTimeMillis();
++ private static final Long DEFAULT_LONG_VALUE = -10101L;
++
++ @Mock
++ private MetricRegistry registry;
++
++ @Mock
++ private Processor processor;
++
++ @Mock
++ private Exchange exchange;
++
++ @Mock
++ private Message in;
++
++ private AbstractMetricsEndpoint endpoint;
++
++ private InOrder inOrder;
++
++ @Before
++ public void setUp() throws Exception {
++ endpoint = new AbstractMetricsEndpoint(registry, METRICS_NAME) {
++ @Override
++ public Producer createProducer() throws Exception {
++ return null;
++ }
++
++ @Override
++ protected String createEndpointUri() {
++ return "not real endpoint";
++ }
++ };
++ inOrder = Mockito.inOrder(registry, processor, exchange, in);
++ when(exchange.getIn()).thenReturn(in);
++ }
++
++ @After
++ public void tearDown() throws Exception {
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testAbstractMetricsEndpoint() throws Exception {
++ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
++ assertThat(endpoint.getRegistry(), is(registry));
++ }
++
++ @Test(expected = RuntimeCamelException.class)
++ public void testCreateConsumer() throws Exception {
++ endpoint.createConsumer(processor);
++ }
++
++ @Test
++ public void testIsSingleton() throws Exception {
++ assertThat(endpoint.isSingleton(), is(false));
++ }
++
++ @Test
++ public void testGetRegistry() throws Exception {
++ assertThat(endpoint.getRegistry(), is(registry));
++ }
++
++ @Test
++ public void testGetMetricsName() throws Exception {
++ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
index 0000000,0000000..3435247
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/AbstractMetricsProducerTest.java
@@@ -1,0 -1,0 +1,172 @@@
++package org.apache.camel.metrics;
++
++import static org.apache.camel.metrics.AbstractMetricsProducer.HEADER_PATTERN;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.MatcherAssert.assertThat;
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.when;
++
++import org.apache.camel.Exchange;
++import org.apache.camel.Message;
++import org.apache.camel.impl.DefaultMessage;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mock;
++import org.mockito.Mockito;
++import org.mockito.runners.MockitoJUnitRunner;
++
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(MockitoJUnitRunner.class)
++public class AbstractMetricsProducerTest {
++
++ public static final String METRIC_NAME = "a metric";
++
++ @Mock
++ private AbstractMetricsEndpoint endpoint;
++
++ @Mock
++ private Exchange exchange;
++
++ @Mock
++ private Message in;
++
++ @Mock
++ private MetricRegistry registry;
++
++ private AbstractMetricsProducer<AbstractMetricsEndpoint> okProducer;
++
++ private AbstractMetricsProducer<AbstractMetricsEndpoint> failProducer;
++
++ private InOrder inOrder;
++
++ @Before
++ public void setUp() throws Exception {
++ okProducer = new AbstractMetricsProducer<AbstractMetricsEndpoint>(endpoint) {
++ @Override
++ protected void doProcess(Exchange exchange, AbstractMetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
++ }
++ };
++ failProducer = new AbstractMetricsProducer<AbstractMetricsEndpoint>(endpoint) {
++
++ @Override
++ protected void doProcess(Exchange exchange, AbstractMetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
++ throw new Exception("Muchos problemos");
++ }
++ };
++ inOrder = Mockito.inOrder(endpoint, exchange, in, registry);
++ when(exchange.getIn()).thenReturn(in);
++ when(endpoint.getMetricsName()).thenReturn(METRIC_NAME);
++ when(endpoint.getRegistry()).thenReturn(registry);
++ }
++
++ @Test
++ public void testDoProcess() throws Exception {
++ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
++ when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
++ okProducer.process(exchange);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(endpoint, times(1)).getMetricsName();
++ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
++ inOrder.verify(endpoint, times(1)).getRegistry();
++ inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testDoProcessWithException() throws Exception {
++ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
++ when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
++ failProducer.process(exchange);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(endpoint, times(1)).getMetricsName();
++ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
++ inOrder.verify(endpoint, times(1)).getRegistry();
++ inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetMetricsName() throws Exception {
++ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("A");
++ assertThat(okProducer.getMetricsName(in, "value"), is("A"));
++ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetMetricsNameNotSet() throws Exception {
++ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
++ assertThat(okProducer.getMetricsName(in, "name"), is("name"));
++ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetStringHeader() throws Exception {
++ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("A");
++ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("A"));
++ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetStringHeaderWithNullValue() throws Exception {
++ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null);
++ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
++ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetStringHeaderWithWhiteSpaces() throws Exception {
++ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(" ");
++ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
++ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetStringHeaderWithEmptySrting() throws Exception {
++ when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("");
++ assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value"));
++ inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetLongHeader() throws Exception {
++ when(in.getHeader(HEADER_HISTOGRAM_VALUE, 19L, Long.class)).thenReturn(201L);
++ assertThat(okProducer.getLongHeader(in, HEADER_HISTOGRAM_VALUE, 19L), is(201L));
++ inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, 19L, Long.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testClearMetricsHeaders() throws Exception {
++ when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true);
++ assertThat(okProducer.clearMetricsHeaders(in), is(true));
++ inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testClearRealHeaders() throws Exception {
++ Message msg = new DefaultMessage();
++ Object val = new Object();
++ msg.setHeader(HEADER_HISTOGRAM_VALUE, 109L);
++ msg.setHeader(HEADER_METRIC_NAME, "the metric");
++ msg.setHeader("notRemoved", val);
++ assertThat(msg.getHeaders().size(), is(3));
++ assertThat(msg.getHeader(HEADER_HISTOGRAM_VALUE, Long.class), is(109L));
++ assertThat(msg.getHeader(HEADER_METRIC_NAME, String.class), is("the metric"));
++ assertThat(msg.getHeader("notRemoved"), is(val));
++ okProducer.clearMetricsHeaders(msg);
++ assertThat(msg.getHeaders().size(), is(1));
++ assertThat(msg.getHeader("notRemoved"), is(val));
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
index 0000000,0000000..a6590c5
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricComponentSpringTest.java
@@@ -1,0 -1,0 +1,77 @@@
++package org.apache.camel.metrics;
++
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.when;
++
++import org.apache.camel.EndpointInject;
++import org.apache.camel.Produce;
++import org.apache.camel.ProducerTemplate;
++import org.apache.camel.builder.RouteBuilder;
++import org.apache.camel.component.mock.MockEndpoint;
++import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
++import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
++import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
++import org.apache.camel.test.spring.MockEndpoints;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mockito;
++import org.springframework.context.annotation.Bean;
++import org.springframework.context.annotation.Configuration;
++import org.springframework.test.context.ContextConfiguration;
++
++import com.codahale.metrics.Counter;
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(CamelSpringJUnit4ClassRunner.class)
++@ContextConfiguration(
++ classes = { MetricComponentSpringTest.TestConfig.class },
++ loader = CamelSpringDelegatingTestContextLoader.class)
++@MockEndpoints
++public class MetricComponentSpringTest {
++
++ @EndpointInject(uri = "mock:out")
++ private MockEndpoint endpoint;
++
++ @Produce(uri = "direct:in")
++ private ProducerTemplate producer;
++
++ @Configuration
++ public static class TestConfig extends SingleRouteCamelConfiguration {
++
++ @Bean
++ @Override
++ public RouteBuilder route() {
++ return new RouteBuilder() {
++
++ @Override
++ public void configure() throws Exception {
++ from("direct:in")
++ .to("metrics:counter:A?increment=512")
++ .to("mock:out");
++ }
++ };
++ }
++
++ @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
++ public MetricRegistry getMetricRegistry() {
++ return Mockito.mock(MetricRegistry.class);
++ }
++ }
++
++ @Test
++ public void testMetricsRegistryFromCamelRegistry() throws Exception {
++ // TODO - 12.05.2014, Lauri - is there any better way to set this up?
++ MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
++ Counter mockCounter = Mockito.mock(Counter.class);
++ InOrder inOrder = Mockito.inOrder(mockRegistry, mockCounter);
++ when(mockRegistry.counter("A")).thenReturn(mockCounter);
++
++ endpoint.expectedMessageCount(1);
++ producer.sendBody(new Object());
++ endpoint.assertIsSatisfied();
++ inOrder.verify(mockRegistry, times(1)).counter("A");
++ inOrder.verify(mockCounter, times(1)).inc(512L);
++ inOrder.verifyNoMoreInteractions();
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
index 0000000,0000000..4ef44f3
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentRouteTest.java
@@@ -1,0 -1,0 +1,99 @@@
++package org.apache.camel.metrics;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_HISTOGRAM_VALUE;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_METRIC_NAME;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_PERFIX;
++
++import java.util.Date;
++import java.util.HashMap;
++import java.util.Map;
++
++import org.apache.camel.Produce;
++import org.apache.camel.ProducerTemplate;
++import org.apache.camel.builder.RouteBuilder;
++import org.apache.camel.component.mock.MockEndpoint;
++import org.apache.camel.test.junit4.CamelTestSupport;
++import org.junit.Test;
++
++public class MetricsComponentRouteTest extends CamelTestSupport {
++
++ @Produce(uri = "direct:start-1")
++ protected ProducerTemplate template1;
++
++ @Produce(uri = "direct:start-2")
++ protected ProducerTemplate template2;
++
++ @Test
++ public void testMetrics() throws Exception {
++ MockEndpoint mock = getMockEndpoint("mock:result");
++ mock.expectedMinimumMessageCount(1);
++ template1.sendBody(new Object());
++ assertMockEndpointsSatisfied();
++ }
++
++ @Test
++ public void testMessageContentDelivery() throws Exception {
++ MockEndpoint mock = getMockEndpoint("mock:result");
++ String body = "Message Body";
++ String header1 = "Header 1";
++ String header2 = "Header 2";
++ Object value1 = new Date();
++ Object value2 = System.currentTimeMillis();
++ mock.expectedBodiesReceived(body);
++ mock.expectedHeaderReceived(header1, value1);
++ mock.expectedHeaderReceived(header2, value2);
++ Map<String, Object> headers = new HashMap<String, Object>();
++ headers.put(header1, value1);
++ headers.put(header2, value2);
++ template1.sendBodyAndHeaders(body, headers);
++ assertMockEndpointsSatisfied();
++ }
++
++ @Test
++ public void testHeaderRemoval() throws Exception {
++ MockEndpoint mock = getMockEndpoint("mock:result");
++ Object body = new Object();
++ Date now = new Date();
++
++ mock.expectedBodiesReceived(body);
++ mock.expectedHeaderReceived("." + HEADER_PERFIX, "value");
++ mock.expectedHeaderReceived("date", now);
++
++ Map<String, Object> headers = new HashMap<String, Object>();
++ headers.put(HEADER_METRIC_NAME, "a name");
++ headers.put(HEADER_HISTOGRAM_VALUE, 34L);
++ headers.put(HEADER_PERFIX + "notExistingHeader", "?");
++ headers.put("." + HEADER_PERFIX, "value");
++ headers.put("date", now);
++
++ template2.sendBodyAndHeaders(body, headers);
++ assertMockEndpointsSatisfied();
++ }
++
++ @Override
++ protected RouteBuilder createRouteBuilder() throws Exception {
++ return new RouteBuilder() {
++ @Override
++ public void configure() {
++ from("direct:start-1")
++ .to("metrics:timer:T?action=start")
++ .to("metrics:A")
++ .to("metrics:counter://B")
++ .to("metrics:counter:C?increment=19291")
++ .to("metrics:counter:C?decrement=19292")
++ .to("metrics:counter:C")
++ .to("metrics:meter:D")
++ .to("metrics:meter:D?mark=90001")
++ .to("metrics:histogram:E")
++ .to("metrics:timer:T")
++ .to("metrics:histogram:E?value=12000000031")
++ .to("metrics:timer:T?action=stop")
++ .to("mock:result");
++
++ from("direct:start-2")
++ .to("metrics:meter:F?mark=88")
++ .to("mock:result");
++ }
++ };
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
index 0000000,0000000..74d91c2
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsComponentTest.java
@@@ -1,0 -1,0 +1,204 @@@
++package org.apache.camel.metrics;
++
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.Matchers.instanceOf;
++import static org.hamcrest.Matchers.not;
++import static org.hamcrest.Matchers.notNullValue;
++import static org.junit.Assert.assertThat;
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.when;
++
++import java.util.EnumSet;
++import java.util.HashMap;
++import java.util.Map;
++
++import org.apache.camel.CamelContext;
++import org.apache.camel.Endpoint;
++import org.apache.camel.RuntimeCamelException;
++import org.apache.camel.metrics.counter.CounterEndpoint;
++import org.apache.camel.metrics.histogram.HistogramEndpoint;
++import org.apache.camel.metrics.meter.MeterEndpoint;
++import org.apache.camel.metrics.timer.TimerEndpoint;
++import org.apache.camel.spi.Registry;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mock;
++import org.mockito.Mockito;
++import org.mockito.runners.MockitoJUnitRunner;
++
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(MockitoJUnitRunner.class)
++public class MetricsComponentTest {
++
++ @Mock
++ private CamelContext camelContext;
++
++ @Mock
++ private Registry camelRegistry;
++
++ @Mock
++ private MetricRegistry metricRegistry;
++
++ private InOrder inOrder;
++
++ private MetricsComponent component;
++
++ @Before
++ public void setUp() throws Exception {
++ component = new MetricsComponent();
++ inOrder = Mockito.inOrder(camelContext, camelRegistry, metricRegistry);
++
++ }
++
++ @Test
++ public void testCreateEndpoint() throws Exception {
++ component.setCamelContext(camelContext);
++ when(camelContext.getRegistry()).thenReturn(camelRegistry);
++ when(camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class)).thenReturn(metricRegistry);
++ Map<String, Object> params = new HashMap<String, Object>();
++ Long value = System.currentTimeMillis();
++ params.put("mark", value);
++ Endpoint result = component.createEndpoint("metrics:meter:long.meter", "meter:long.meter", params);
++ assertThat(result, is(notNullValue()));
++ assertThat(result, is(instanceOf(MeterEndpoint.class)));
++ MeterEndpoint me = (MeterEndpoint) result;
++ assertThat(me.getMark(), is(value));
++ assertThat(me.getMetricsName(), is("long.meter"));
++ assertThat(me.getRegistry(), is(metricRegistry));
++ inOrder.verify(camelContext, times(1)).getRegistry();
++ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
++ inOrder.verify(camelContext, times(1)).getTypeConverter();
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testCreateEndpoints() throws Exception {
++ component.setCamelContext(camelContext);
++ when(camelContext.getRegistry()).thenReturn(camelRegistry);
++ when(camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class)).thenReturn(metricRegistry);
++ Map<String, Object> params = new HashMap<String, Object>();
++ Long value = System.currentTimeMillis();
++ params.put("mark", value);
++ Endpoint result = component.createEndpoint("metrics:meter:long.meter", "meter:long.meter", params);
++ assertThat(result, is(notNullValue()));
++ assertThat(result, is(instanceOf(MeterEndpoint.class)));
++ MeterEndpoint me = (MeterEndpoint) result;
++ assertThat(me.getMark(), is(value));
++ assertThat(me.getMetricsName(), is("long.meter"));
++ assertThat(me.getRegistry(), is(metricRegistry));
++
++ params = new HashMap<String, Object>();
++ params.put("increment", value + 1);
++ params.put("decrement", value - 1);
++
++ result = component.createEndpoint("metrics:counter:long.counter", "counter:long.counter", params);
++ assertThat(result, is(notNullValue()));
++ assertThat(result, is(instanceOf(CounterEndpoint.class)));
++ CounterEndpoint ce = (CounterEndpoint) result;
++ assertThat(ce.getIncrement(), is(value + 1));
++ assertThat(ce.getDecrement(), is(value - 1));
++ assertThat(ce.getMetricsName(), is("long.counter"));
++ assertThat(ce.getRegistry(), is(metricRegistry));
++
++ inOrder.verify(camelContext, times(1)).getRegistry();
++ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
++ inOrder.verify(camelContext, times(2)).getTypeConverter();
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetMetricsName() throws Exception {
++ assertThat(component.getMetricsName("meter:metric-a"), is("metric-a"));
++ assertThat(component.getMetricsName("meter:metric-a:sub-b"), is("metric-a:sub-b"));
++ assertThat(component.getMetricsName("metric-a"), is("metric-a"));
++ assertThat(component.getMetricsName("//metric-a"), is("//metric-a"));
++ assertThat(component.getMetricsName("meter://metric-a"), is("//metric-a"));
++ }
++
++ @Test
++ public void testCreateNewEndpointForCounter() throws Exception {
++ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.COUNTER, "a name");
++ assertThat(endpoint, is(notNullValue()));
++ assertThat(endpoint, is(instanceOf(CounterEndpoint.class)));
++ }
++
++ @Test
++ public void testCreateNewEndpointForMeter() throws Exception {
++ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.METER, "a name");
++ assertThat(endpoint, is(notNullValue()));
++ assertThat(endpoint, is(instanceOf(MeterEndpoint.class)));
++ }
++
++ @Test(expected = RuntimeCamelException.class)
++ public void testCreateNewEndpointForGauge() throws Exception {
++ component.createNewEndpoint(metricRegistry, MetricsType.GAUGE, "a name");
++ }
++
++ @Test
++ public void testCreateNewEndpointForHistogram() throws Exception {
++ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.HISTOGRAM, "a name");
++ assertThat(endpoint, is(notNullValue()));
++ assertThat(endpoint, is(instanceOf(HistogramEndpoint.class)));
++ }
++
++ @Test
++ public void testCreateNewEndpointForTimer() throws Exception {
++ Endpoint endpoint = component.createNewEndpoint(metricRegistry, MetricsType.TIMER, "a name");
++ assertThat(endpoint, is(notNullValue()));
++ assertThat(endpoint, is(instanceOf(TimerEndpoint.class)));
++ }
++
++ @Test
++ public void testGetMetricsType() throws Exception {
++ for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
++ assertThat(component.getMetricsType(type.toString() + ":metrics-name"), is(type));
++ }
++ }
++
++ @Test
++ public void testGetMetricsTypeNotSet() throws Exception {
++ assertThat(component.getMetricsType("no-metrics-type"), is(MetricsComponent.DEFAULT_METRICS_TYPE));
++ }
++
++ @Test(expected = RuntimeCamelException.class)
++ public void testGetMetricsTypeNotFound() throws Exception {
++ component.getMetricsType("unknown-metrics:metrics-name");
++ }
++
++ @Test
++ public void testGetOrCreateMetricRegistryFoundInCamelRegistry() throws Exception {
++ when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(metricRegistry);
++ MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
++ assertThat(result, is(metricRegistry));
++ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetOrCreateMetricRegistryNotFoundInCamelRegistry() throws Exception {
++ when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(null);
++ MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
++ assertThat(result, is(notNullValue()));
++ assertThat(result, is(not(metricRegistry)));
++ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testGetMetricRegistryFromCamelRegistry() throws Exception {
++ when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(metricRegistry);
++ MetricRegistry result = component.getMetricRegistryFromCamelRegistry(camelRegistry, "name");
++ assertThat(result, is(metricRegistry));
++ inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testCreateMetricRegistry() throws Exception {
++ MetricRegistry registry = component.createMetricRegistry();
++ assertThat(registry, is(notNullValue()));
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
index 0000000,0000000..2d0d28d
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/MetricsTypeTest.java
@@@ -1,0 -1,0 +1,19 @@@
++package org.apache.camel.metrics;
++
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.MatcherAssert.assertThat;
++
++import java.util.EnumSet;
++
++import org.junit.Test;
++
++public class MetricsTypeTest {
++
++ @Test
++ public void testGetByName() throws Exception {
++ for (MetricsType type : EnumSet.allOf(MetricsType.class)) {
++ MetricsType t = MetricsType.getByName(type.toString());
++ assertThat(t, is(type));
++ }
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
index 0000000,0000000..8f713a2
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterEndpointTest.java
@@@ -1,0 -1,0 +1,88 @@@
++package org.apache.camel.metrics.counter;
++
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.MatcherAssert.assertThat;
++import static org.hamcrest.Matchers.instanceOf;
++import static org.hamcrest.Matchers.notNullValue;
++import static org.hamcrest.Matchers.nullValue;
++
++import org.apache.camel.Producer;
++import org.junit.After;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mock;
++import org.mockito.Mockito;
++import org.mockito.runners.MockitoJUnitRunner;
++
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(MockitoJUnitRunner.class)
++public class CounterEndpointTest {
++
++ private static final String METRICS_NAME = "metrics.name";
++ private static final Long VALUE = System.currentTimeMillis();
++
++ @Mock
++ private MetricRegistry registry;
++
++ private CounterEndpoint endpoint;
++
++ private InOrder inOrder;
++
++ @Before
++ public void setUp() throws Exception {
++ endpoint = new CounterEndpoint(registry, METRICS_NAME);
++ inOrder = Mockito.inOrder(registry);
++ }
++
++ @After
++ public void tearDown() {
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testCounterEndpoint() throws Exception {
++ assertThat(endpoint.getRegistry(), is(registry));
++ assertThat(endpoint.getMetricsName(), is(METRICS_NAME));
++ assertThat(endpoint.getIncrement(), is(nullValue()));
++ assertThat(endpoint.getDecrement(), is(nullValue()));
++ }
++
++ @Test
++ public void testCreateProducer() throws Exception {
++ Producer producer = endpoint.createProducer();
++ assertThat(producer, is(notNullValue()));
++ assertThat(producer, is(instanceOf(CounterProducer.class)));
++ }
++
++ @Test
++ public void testGetIncrement() throws Exception {
++ assertThat(endpoint.getIncrement(), is(nullValue()));
++ }
++
++ @Test
++ public void testSetIncrement() throws Exception {
++ assertThat(endpoint.getIncrement(), is(nullValue()));
++ endpoint.setIncrement(VALUE);
++ assertThat(endpoint.getIncrement(), is(VALUE));
++ }
++
++ @Test
++ public void testGetDecrement() throws Exception {
++ assertThat(endpoint.getDecrement(), is(nullValue()));
++ }
++
++ @Test
++ public void testSetDecrement() throws Exception {
++ assertThat(endpoint.getDecrement(), is(nullValue()));
++ endpoint.setDecrement(VALUE);
++ assertThat(endpoint.getDecrement(), is(VALUE));
++ }
++
++ @Test
++ public void testCreateEndpointUri() throws Exception {
++ assertThat(endpoint.createEndpointUri(), is(CounterEndpoint.ENDPOINT_URI));
++ }
++}
http://git-wip-us.apache.org/repos/asf/camel/blob/641de098/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
----------------------------------------------------------------------
diff --cc components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
index 0000000,0000000..6351814
new file mode 100644
--- /dev/null
+++ b/components/camel-metrics/src/test/java/org/apache/camel/metrics/counter/CounterProducerTest.java
@@@ -1,0 -1,0 +1,181 @@@
++package org.apache.camel.metrics.counter;
++
++import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_DECREMENT;
++import static org.apache.camel.metrics.MetricsComponent.HEADER_COUNTER_INCREMENT;
++import static org.hamcrest.CoreMatchers.is;
++import static org.hamcrest.MatcherAssert.assertThat;
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.when;
++
++import org.apache.camel.Exchange;
++import org.apache.camel.Message;
++import org.junit.Before;
++import org.junit.Test;
++import org.junit.runner.RunWith;
++import org.mockito.InOrder;
++import org.mockito.Mock;
++import org.mockito.Mockito;
++import org.mockito.runners.MockitoJUnitRunner;
++
++import com.codahale.metrics.Counter;
++import com.codahale.metrics.MetricRegistry;
++
++@RunWith(MockitoJUnitRunner.class)
++public class CounterProducerTest {
++
++ private static final String METRICS_NAME = "metrics.name";
++ private static final Long INCREMENT = 100000L;
++ private static final Long DECREMENT = 91929199L;
++
++ @Mock
++ private CounterEndpoint endpoint;
++
++ @Mock
++ private Exchange exchange;
++
++ @Mock
++ private MetricRegistry registry;
++
++ @Mock
++ private Counter counter;
++
++ @Mock
++ private Message in;
++
++ private CounterProducer producer;
++
++ private InOrder inOrder;
++
++ @Before
++ public void setUp() throws Exception {
++ producer = new CounterProducer(endpoint);
++ inOrder = Mockito.inOrder(endpoint, exchange, registry, counter, in);
++ when(endpoint.getRegistry()).thenReturn(registry);
++ when(registry.counter(METRICS_NAME)).thenReturn(counter);
++ when(exchange.getIn()).thenReturn(in);
++ }
++
++ @Test
++ public void testCounterProducer() throws Exception {
++ assertThat(producer.getEndpoint().equals(endpoint), is(true));
++ }
++
++ @Test
++ public void testProcessWithIncrementOnly() throws Exception {
++ when(endpoint.getIncrement()).thenReturn(INCREMENT);
++ when(endpoint.getDecrement()).thenReturn(null);
++ when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT);
++ when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(null);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getIncrement();
++ inOrder.verify(endpoint, times(1)).getDecrement();
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
++ inOrder.verify(counter, times(1)).inc(INCREMENT);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessWithDecrementOnly() throws Exception {
++ when(endpoint.getIncrement()).thenReturn(null);
++ when(endpoint.getDecrement()).thenReturn(DECREMENT);
++ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
++ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getIncrement();
++ inOrder.verify(endpoint, times(1)).getDecrement();
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
++ inOrder.verify(counter, times(1)).dec(DECREMENT);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testDoProcessWithIncrementAndDecrement() throws Exception {
++ when(endpoint.getIncrement()).thenReturn(INCREMENT);
++ when(endpoint.getDecrement()).thenReturn(DECREMENT);
++ when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT);
++ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getIncrement();
++ inOrder.verify(endpoint, times(1)).getDecrement();
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
++ inOrder.verify(counter, times(1)).inc(INCREMENT);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessWithOutIncrementAndDecrement() throws Exception {
++ when(endpoint.getIncrement()).thenReturn(null);
++ when(endpoint.getDecrement()).thenReturn(null);
++ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
++ when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(null);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getIncrement();
++ inOrder.verify(endpoint, times(1)).getDecrement();
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
++ inOrder.verify(counter, times(1)).inc();
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessWithHeaderValuesOnly() throws Exception {
++ when(endpoint.getIncrement()).thenReturn(null);
++ when(endpoint.getDecrement()).thenReturn(null);
++ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(INCREMENT + 1);
++ when(in.getHeader(HEADER_COUNTER_DECREMENT, null, Long.class)).thenReturn(DECREMENT - 1);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getIncrement();
++ inOrder.verify(endpoint, times(1)).getDecrement();
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, null, Long.class);
++ inOrder.verify(counter, times(1)).inc(INCREMENT + 1);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessOverridingIncrement() throws Exception {
++ when(endpoint.getIncrement()).thenReturn(INCREMENT);
++ when(endpoint.getDecrement()).thenReturn(DECREMENT);
++ when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class)).thenReturn(INCREMENT + 1);
++ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getIncrement();
++ inOrder.verify(endpoint, times(1)).getDecrement();
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Long.class);
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
++ inOrder.verify(counter, times(1)).inc(INCREMENT + 1);
++ inOrder.verifyNoMoreInteractions();
++ }
++
++ @Test
++ public void testProcessOverridingDecrement() throws Exception {
++ when(endpoint.getIncrement()).thenReturn(null);
++ when(endpoint.getDecrement()).thenReturn(DECREMENT);
++ when(in.getHeader(HEADER_COUNTER_INCREMENT, null, Long.class)).thenReturn(null);
++ when(in.getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class)).thenReturn(DECREMENT - 1);
++ producer.doProcess(exchange, endpoint, registry, METRICS_NAME);
++ inOrder.verify(exchange, times(1)).getIn();
++ inOrder.verify(registry, times(1)).counter(METRICS_NAME);
++ inOrder.verify(endpoint, times(1)).getIncrement();
++ inOrder.verify(endpoint, times(1)).getDecrement();
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_INCREMENT, null, Long.class);
++ inOrder.verify(in, times(1)).getHeader(HEADER_COUNTER_DECREMENT, DECREMENT, Long.class);
++ inOrder.verify(counter, times(1)).dec(DECREMENT - 1);
++ inOrder.verifyNoMoreInteractions();
++ }
++}