This is an automated email from the ASF dual-hosted git repository. jpoth pushed a commit to branch otel-cxf in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7d83a62b8e442dc9ac6fd79b153192add940301e Author: John Poth <poth.j...@gmail.com> AuthorDate: Wed Oct 2 11:02:47 2024 +0200 camel-opentelemetry: add async CXF reproducer AsyncCxfTest --- components/camel-opentelemetry/pom.xml | 37 +++++++++++ .../apache/camel/opentelemetry/AsyncCxfTest.java | 75 ++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/components/camel-opentelemetry/pom.xml b/components/camel-opentelemetry/pom.xml index 07aa444781a..f6c64b901a3 100644 --- a/components/camel-opentelemetry/pom.xml +++ b/components/camel-opentelemetry/pom.xml @@ -109,6 +109,43 @@ <version>${awaitility-version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-cxf-rest</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-cxf-common</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-transports-http-undertow</artifactId> + <version>${cxf-version}</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>io.undertow</groupId> + <artifactId>undertow-servlet</artifactId> + </exclusion> + <exclusion> + <groupId>io.undertow</groupId> + <artifactId>undertow-servlet-jakarta</artifactId> + </exclusion> + <exclusion> + <groupId>io.undertow</groupId> + <artifactId>undertow-core</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-undertow</artifactId> + <scope>test</scope> + </dependency> </dependencies> diff --git a/components/camel-opentelemetry/src/test/java/org/apache/camel/opentelemetry/AsyncCxfTest.java b/components/camel-opentelemetry/src/test/java/org/apache/camel/opentelemetry/AsyncCxfTest.java new file mode 100644 index 00000000000..a7d22656c96 --- /dev/null +++ b/components/camel-opentelemetry/src/test/java/org/apache/camel/opentelemetry/AsyncCxfTest.java @@ -0,0 +1,75 @@ +/* + * 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.opentelemetry; + +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.cxf.common.CXFTestSupport; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.jupiter.api.Test; + +class AsyncCxfTest extends CamelOpenTelemetryTestSupport { + + private static int port1 = CXFTestSupport.getPort1(); + + private static SpanTestData[] testdata = {}; // not used yet, fix context leak first + + AsyncCxfTest() { + super(testdata); + } + + @Test + void testRoute() throws InterruptedException { + MockEndpoint mock = getMockEndpoint("mock:end"); + mock.expectedMessageCount(4); + int num = 4; + for (int i = 0; i < num; i++) { + template.requestBody("direct:start", "foo"); + } + mock.assertIsSatisfied(5000); + verifyTraceSpanNumbers(num, 7); + } + + @Override + protected RoutesBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:start").routeId("myRoute") + .to("direct:send") + .end(); + + from("direct:send") + .log("message") + .to("cxfrs:http://localhost:" + port1 + + "/rest/helloservice/sayHello?synchronous=false"); // setting to 'true' resolves the issue + + restConfiguration() + .port(port1); + + rest("/rest/helloservice") + .post("/sayHello").routeId("rest-GET-say-hi") + .to("direct:sayHi"); + + from("direct:sayHi") + .routeId("mock-GET-say-hi") + .log("example") + .to("mock:end"); + } + }; + } +}