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