This is an automated email from the ASF dual-hosted git repository. nfilotto pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
The following commit(s) were added to refs/heads/main by this push: new 0a77d8cb Ref #465: Add disruptor integration test (#466) 0a77d8cb is described below commit 0a77d8cbcc82b6bb61f4ff799dceec7d384c7d69 Author: Stefan Tataru <stefan.tatar...@gmail.com> AuthorDate: Wed Jul 24 19:07:43 2024 +0200 Ref #465: Add disruptor integration test (#466) --- tests/features/camel-disruptor/pom.xml | 32 +++++++++ .../camel/test/CamelDisruptorRouteSupplier.java | 49 ++++++++++++++ .../camel/test/CamelDisruptorvmRouteSupplier.java | 49 ++++++++++++++ .../karaf/camel/itest/CamelDisruptorTest.java | 75 ++++++++++++++++++++++ tests/features/pom.xml | 1 + 5 files changed, 206 insertions(+) diff --git a/tests/features/camel-disruptor/pom.xml b/tests/features/camel-disruptor/pom.xml new file mode 100644 index 00000000..a32db8ec --- /dev/null +++ b/tests/features/camel-disruptor/pom.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.karaf</groupId> + <artifactId>camel-karaf-features-test</artifactId> + <version>4.7.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-disruptor-test</artifactId> + <name>Apache Camel :: Karaf :: Tests :: Features :: Disruptor</name> +</project> \ No newline at end of file diff --git a/tests/features/camel-disruptor/src/main/java/org/apache/karaf/camel/test/CamelDisruptorRouteSupplier.java b/tests/features/camel-disruptor/src/main/java/org/apache/karaf/camel/test/CamelDisruptorRouteSupplier.java new file mode 100644 index 00000000..a3c1c7a8 --- /dev/null +++ b/tests/features/camel-disruptor/src/main/java/org/apache/karaf/camel/test/CamelDisruptorRouteSupplier.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.karaf.camel.test; + +import static org.apache.camel.builder.Builder.constant; + +import java.util.function.Function; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.RouteDefinition; +import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier; +import org.osgi.service.component.annotations.Component; + +@Component( + name = "karaf-camel-disruptor-test", + immediate = true, + service = CamelDisruptorRouteSupplier.class +) +public class CamelDisruptorRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier { + + @Override + protected Function<RouteBuilder, RouteDefinition> consumerRoute() { + return builder -> builder.from("disruptor:next") + .log("Received from disruptor next: ${body}") + .setBody(constant("OK")); + } + + @Override + protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) { + producerRoute.setBody(constant("Hello Disruptor")) + .log("Will send to disruptor next: ${body}") + // send it to the disruptor that is async + .to("disruptor:next") + .log("Sent to disruptor next: ${body}"); + } +} \ No newline at end of file diff --git a/tests/features/camel-disruptor/src/main/java/org/apache/karaf/camel/test/CamelDisruptorvmRouteSupplier.java b/tests/features/camel-disruptor/src/main/java/org/apache/karaf/camel/test/CamelDisruptorvmRouteSupplier.java new file mode 100644 index 00000000..4edfc78b --- /dev/null +++ b/tests/features/camel-disruptor/src/main/java/org/apache/karaf/camel/test/CamelDisruptorvmRouteSupplier.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.karaf.camel.test; + +import static org.apache.camel.builder.Builder.constant; + +import java.util.function.Function; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.RouteDefinition; +import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier; +import org.osgi.service.component.annotations.Component; + +@Component( + name = "karaf-camel-disruptor-vm-test", + immediate = true, + service = CamelDisruptorvmRouteSupplier.class +) +public class CamelDisruptorvmRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier { + + @Override + protected Function<RouteBuilder, RouteDefinition> consumerRoute() { + return builder -> builder.from("disruptor-vm:next") + .log("Received from disruptor-vm next: ${body}") + .setBody(constant("OK")); + } + + @Override + protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) { + producerRoute.setBody(constant("Hello Disruptor VM")) + .log("Will send to disruptor-vm next: ${body}") + // send it to the disruptor-vm that is async + .to("disruptor-vm:next") + .log("Sent to disruptor-vm next: ${body}"); + } +} \ No newline at end of file diff --git a/tests/features/camel-disruptor/src/test/java/org/apache/karaf/camel/itest/CamelDisruptorTest.java b/tests/features/camel-disruptor/src/test/java/org/apache/karaf/camel/itest/CamelDisruptorTest.java new file mode 100644 index 00000000..18b7b02d --- /dev/null +++ b/tests/features/camel-disruptor/src/test/java/org/apache/karaf/camel/itest/CamelDisruptorTest.java @@ -0,0 +1,75 @@ +/* + * Licensed 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.karaf.camel.itest; + +import java.util.List; + +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.karaf.camel.itests.AbstractCamelRouteWithBundleITest; +import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRoute; +import org.apache.karaf.camel.itests.CamelContextProvider; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; + +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerClass.class) +public class CamelDisruptorTest extends AbstractCamelRouteWithBundleITest { + + @Override + protected String getTestBundleName() { + return "camel-disruptor-test"; + } + + @Override + protected List<String> getRequiredFeatures() { + return List.of("camel-disruptor"); + } + + @Test + public void testCamelDisruptor() throws Exception { + new CamelDisruptorITest(this).testRoutes(); + } + + @Test + public void testCamelDisruptorvm() throws Exception { + new CamelDisruptorvmITest(this).testRoutes(); + } + + public static class CamelDisruptorITest extends AbstractCamelSingleFeatureResultMockBasedRoute { + + public CamelDisruptorITest(CamelContextProvider provider) { + super(provider); + } + + @Override + public void configureMock(MockEndpoint mock) { + mock.expectedBodiesReceived("OK"); + } + } + + public static class CamelDisruptorvmITest extends AbstractCamelSingleFeatureResultMockBasedRoute { + + public CamelDisruptorvmITest(CamelContextProvider provider) { + super(provider); + } + + @Override + public void configureMock(MockEndpoint mock) { + mock.expectedBodiesReceived("OK"); + } + } +} \ No newline at end of file diff --git a/tests/features/pom.xml b/tests/features/pom.xml index cd127f68..f6f0f1e6 100644 --- a/tests/features/pom.xml +++ b/tests/features/pom.xml @@ -61,6 +61,7 @@ <module>camel-core</module> <module>camel-crypto</module> <module>camel-csv</module> + <module>camel-disruptor</module> <module>camel-dns</module> <!-- TODO: Fix the integration test and re-add it https://github.com/apache/camel-karaf/issues/438 --> <!--module>camel-docker</module-->