This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-3.20.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit 51fd6aae5ec471ba4eef293dc8ed1a15381be49d Author: Babak Vahdat <bvah...@apache.org> AuthorDate: Fri Dec 16 13:20:21 2022 +0100 CAMEL-18661: clean-ups --- .../camel/cdi/test/CamelEventNotifierTest.java | 30 +++++++++------- .../camel/opentelemetry/CurrentSpanTest.java | 42 ++++++++++++---------- .../main/java/org/apache/camel/tracing/Tracer.java | 6 ++-- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/CamelEventNotifierTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/CamelEventNotifierTest.java index ca889a10242..cca199e7fe6 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/CamelEventNotifierTest.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/CamelEventNotifierTest.java @@ -31,7 +31,8 @@ import org.apache.camel.cdi.CdiCamelExtension; import org.apache.camel.cdi.Uri; import org.apache.camel.cdi.bean.SimpleCamelRoute; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.spi.CamelEvent; +import org.apache.camel.spi.CamelEvent.CamelContextInitializedEvent; +import org.apache.camel.spi.CamelEvent.CamelContextInitializingEvent; import org.apache.camel.spi.CamelEvent.CamelContextStartedEvent; import org.apache.camel.spi.CamelEvent.CamelContextStartingEvent; import org.apache.camel.spi.CamelEvent.CamelContextStoppedEvent; @@ -55,6 +56,7 @@ import org.junit.runner.RunWith; import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; @RunWith(Arquillian.class) public class CamelEventNotifierTest { @@ -71,12 +73,12 @@ public class CamelEventNotifierTest { @ApplicationScoped private List<Class> firedEvents = new ArrayList<>(); - private void onCamelContextStartingEvent(@Observes CamelEvent.CamelContextInitializingEvent event, List<Class> events) { - events.add(CamelEvent.CamelContextInitializingEvent.class); + private void onCamelContextStartingEvent(@Observes CamelContextInitializingEvent event, List<Class> events) { + events.add(CamelContextInitializingEvent.class); } - private void onCamelContextStartingEvent(@Observes CamelEvent.CamelContextInitializedEvent event, List<Class> events) { - events.add(CamelEvent.CamelContextInitializedEvent.class); + private void onCamelContextStartingEvent(@Observes CamelContextInitializedEvent event, List<Class> events) { + events.add(CamelContextInitializedEvent.class); } private void onCamelContextStartingEvent(@Observes CamelContextStartingEvent event, List<Class> events) { @@ -115,8 +117,8 @@ public class CamelEventNotifierTest { public void startedCamelContext(List<Class> events) { assertThat("Events fired are incorrect!", events, contains( - CamelEvent.CamelContextInitializingEvent.class, - CamelEvent.CamelContextInitializedEvent.class, + CamelContextInitializingEvent.class, + CamelContextInitializedEvent.class, CamelContextStartingEvent.class, CamelContextStartedEvent.class)); } @@ -131,10 +133,11 @@ public class CamelEventNotifierTest { assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); - assertThat("Events fired are incorrect!", events, + assertThat("Events count is incorrect!", events.size(), equalTo(12)); + assertThat("Events types are incorrect!", events, contains( - CamelEvent.CamelContextInitializingEvent.class, - CamelEvent.CamelContextInitializedEvent.class, + CamelContextInitializingEvent.class, + CamelContextInitializedEvent.class, CamelContextStartingEvent.class, CamelContextStartedEvent.class, ExchangeSendingEvent.class, @@ -152,10 +155,11 @@ public class CamelEventNotifierTest { public void stopCamelContext(CamelContext context, List<Class> events) { context.stop(); - assertThat("Events fired are incorrect!", events, + assertThat("Events count is incorrect!", events.size(), equalTo(14)); + assertThat("Events types are incorrect!", events, contains( - CamelEvent.CamelContextInitializingEvent.class, - CamelEvent.CamelContextInitializedEvent.class, + CamelContextInitializingEvent.class, + CamelContextInitializedEvent.class, CamelContextStartingEvent.class, CamelContextStartedEvent.class, ExchangeSendingEvent.class, diff --git a/components/camel-opentelemetry/src/test/java/org/apache/camel/opentelemetry/CurrentSpanTest.java b/components/camel-opentelemetry/src/test/java/org/apache/camel/opentelemetry/CurrentSpanTest.java index 9caf8792b16..c5157e14506 100644 --- a/components/camel-opentelemetry/src/test/java/org/apache/camel/opentelemetry/CurrentSpanTest.java +++ b/components/camel-opentelemetry/src/test/java/org/apache/camel/opentelemetry/CurrentSpanTest.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; -import java.util.concurrent.Executors; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; @@ -29,6 +28,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.sdk.trace.ReadableSpan; import io.opentelemetry.sdk.trace.data.SpanData; import org.apache.camel.AsyncCallback; +import org.apache.camel.CamelContext; import org.apache.camel.Consumer; import org.apache.camel.Endpoint; import org.apache.camel.Exchange; @@ -49,18 +49,28 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; class CurrentSpanTest extends CamelOpenTelemetryTestSupport { - private static final Executor DELAYED = CompletableFuture.delayedExecutor(10L, TimeUnit.MILLISECONDS, new ForkJoinPool(3)); CurrentSpanTest() { super(new SpanTestData[0]); } + @Override + protected CamelContext createCamelContext() throws Exception { + CamelContext context = super.createCamelContext(); + context.addComponent("asyncmock1", new AsyncMockComponent()); + context.addComponent("asyncmock2", new AsyncMockComponent()); + context.addComponent("asyncmock3", new AsyncMockComponent()); + context.addComponent("syncmock", new SyncMockComponent()); + + return context; + } + @Test void testSync() { SpanTestData[] expectedSpans = { new SpanTestData().setLabel("syncmock:result").setUri("syncmock://result").setOperation("syncmock") .setKind(SpanKind.CLIENT), - new SpanTestData().setLabel("direct:bar").setUri("direct://bar").setOperation("bar").setKind(SpanKind.INTERNAL), + new SpanTestData().setLabel("direct:bar").setUri("direct://bar").setOperation("bar") }; // sync pipeline @@ -78,7 +88,7 @@ class CurrentSpanTest extends CamelOpenTelemetryTestSupport { SpanTestData[] expectedSpans = { new SpanTestData().setLabel("asyncmock1:result").setUri("asyncmock1://result").setOperation("asyncmock1") .setKind(SpanKind.CLIENT), - new SpanTestData().setLabel("direct:foo").setUri("direct://foo").setOperation("foo").setKind(SpanKind.INTERNAL), + new SpanTestData().setLabel("direct:foo").setUri("direct://foo").setOperation("foo") }; // sync to async pipeline @@ -97,8 +107,7 @@ class CurrentSpanTest extends CamelOpenTelemetryTestSupport { SpanTestData[] expectedSpans = { new SpanTestData().setLabel("syncmock:result").setUri("syncmock://result").setOperation("syncmock") .setKind(SpanKind.CLIENT), - new SpanTestData().setLabel("asyncmock1:start").setUri("asyncmock1://start").setOperation("asyncmock1") - .setKind(SpanKind.INTERNAL), + new SpanTestData().setLabel("asyncmock1:start").setUri("asyncmock1://start").setOperation("asyncmock1"), new SpanTestData().setLabel("asyncmock1:start").setUri("asyncmock1://start").setOperation("asyncmock1") .setKind(SpanKind.CLIENT), }; @@ -116,8 +125,7 @@ class CurrentSpanTest extends CamelOpenTelemetryTestSupport { SpanTestData[] expectedSpans = { new SpanTestData().setLabel("asyncmock2:result").setUri("asyncmock2://result").setOperation("asyncmock2") .setKind(SpanKind.CLIENT), - new SpanTestData().setLabel("asyncmock2:start").setUri("asyncmock2://start").setOperation("asyncmock2") - .setKind(SpanKind.INTERNAL), + new SpanTestData().setLabel("asyncmock2:start").setUri("asyncmock2://start").setOperation("asyncmock2"), new SpanTestData().setLabel("asyncmock2:start").setUri("asyncmock2://start").setOperation("asyncmock2") .setKind(SpanKind.CLIENT), }; @@ -140,7 +148,6 @@ class CurrentSpanTest extends CamelOpenTelemetryTestSupport { new SpanTestData().setLabel("syncmock:result").setUri("syncmock://result").setOperation("syncmock") .setKind(SpanKind.CLIENT), new SpanTestData().setLabel("direct:start").setUri("direct://start").setOperation("start") - .setKind(SpanKind.INTERNAL) }; // sync pipeline @@ -168,11 +175,6 @@ class CurrentSpanTest extends CamelOpenTelemetryTestSupport { return new RouteBuilder() { @Override public void configure() { - context.addComponent("asyncmock1", new AsyncMockComponent()); - context.addComponent("asyncmock2", new AsyncMockComponent()); - context.addComponent("asyncmock3", new AsyncMockComponent()); - context.addComponent("syncmock", new SyncMockComponent()); - // sync pipeline from("direct:bar").to("syncmock:result"); @@ -221,8 +223,7 @@ class CurrentSpanTest extends CamelOpenTelemetryTestSupport { } return newExchange; }) - .executorService(Executors.newFixedThreadPool(10)) - .parallelProcessing() + .executorService(context.getExecutorServiceManager().newFixedThreadPool(this, "CurrentSpanTest", 10)) .streaming() .delay(10) .to("log:line", "asyncmock1:start") @@ -233,7 +234,7 @@ class CurrentSpanTest extends CamelOpenTelemetryTestSupport { }; } - private class AsyncMockComponent extends MockComponent { + private static class AsyncMockComponent extends MockComponent { @Override protected Endpoint createEndpoint(String uri, String key, Map<String, Object> parameters) { @@ -242,6 +243,9 @@ class CurrentSpanTest extends CamelOpenTelemetryTestSupport { } private static class AsyncMockEndpoint extends MockEndpoint { + private static final Executor DELAYED + = CompletableFuture.delayedExecutor(10L, TimeUnit.MILLISECONDS, new ForkJoinPool(3)); + private Consumer consumer; private final String key; @@ -299,7 +303,7 @@ class CurrentSpanTest extends CamelOpenTelemetryTestSupport { } } - private class SyncMockComponent extends MockComponent { + private static class SyncMockComponent extends MockComponent { @Override protected Endpoint createEndpoint(String uri, String key, Map<String, Object> parameters) { @@ -307,7 +311,7 @@ class CurrentSpanTest extends CamelOpenTelemetryTestSupport { } } - private class SyncMockEndpoint extends MockEndpoint { + private static class SyncMockEndpoint extends MockEndpoint { public SyncMockEndpoint(SyncMockComponent component, String uri, String key) { super(uri, component); } diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java index bf1662c06f7..c7ef133c491 100644 --- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java +++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java @@ -238,7 +238,7 @@ public abstract class Tracer extends ServiceSupport implements RoutePolicyFactor if (event instanceof CamelEvent.ExchangeSendingEvent) { CamelEvent.ExchangeSendingEvent ese = (CamelEvent.ExchangeSendingEvent) event; SpanDecorator sd = getSpanDecorator(ese.getEndpoint()); - if (exclude(sd, ese.getExchange(), ese.getEndpoint())) { + if (shouldExclude(sd, ese.getExchange(), ese.getEndpoint())) { return; } @@ -254,7 +254,7 @@ public abstract class Tracer extends ServiceSupport implements RoutePolicyFactor } else if (event instanceof CamelEvent.ExchangeSentEvent) { CamelEvent.ExchangeSentEvent ese = (CamelEvent.ExchangeSentEvent) event; SpanDecorator sd = getSpanDecorator(ese.getEndpoint()); - if (exclude(sd, ese.getExchange(), ese.getEndpoint())) { + if (shouldExclude(sd, ese.getExchange(), ese.getEndpoint())) { return; } @@ -283,7 +283,7 @@ public abstract class Tracer extends ServiceSupport implements RoutePolicyFactor } } - private boolean exclude(SpanDecorator sd, Exchange exchange, Endpoint endpoint) { + private boolean shouldExclude(SpanDecorator sd, Exchange exchange, Endpoint endpoint) { return sd instanceof AbstractInternalSpanDecorator || !sd.newSpan() || isExcluded(exchange, endpoint); }