This is an automated email from the ASF dual-hosted git repository.

aldettinger pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new 22e72ec  Add test for camel.faulttolerance.* properties #2780
22e72ec is described below

commit 22e72ec7ae7de7f7699905c3de1f8fd519cefcb6
Author: aldettinger <aldettin...@gmail.com>
AuthorDate: Fri Jul 2 10:41:49 2021 +0200

    Add test for camel.faulttolerance.* properties #2780
---
 .../foundation/core-fault-tolerance/pom.xml        | 119 +++++++++++++++++++++
 .../quarkus/core/CoreFaultToleranceProducers.java  |  57 ++++++++++
 .../quarkus/core/CoreFaultToleranceResource.java   |  71 ++++++++++++
 .../quarkus/core/CoreFaultToleranceRoutes.java     |  39 +++++++
 .../src/main/resources/application.properties      |  32 ++++++
 .../camel/quarkus/core/CoreFaultToleranceIT.java   |  23 ++++
 .../camel/quarkus/core/CoreFaultToleranceTest.java |  47 ++++++++
 integration-test-groups/foundation/pom.xml         |   1 +
 integration-tests/foundation-grouped/pom.xml       |  17 +++
 9 files changed, 406 insertions(+)

diff --git a/integration-test-groups/foundation/core-fault-tolerance/pom.xml 
b/integration-test-groups/foundation/core-fault-tolerance/pom.xml
new file mode 100644
index 0000000..3be4e4b
--- /dev/null
+++ b/integration-test-groups/foundation/core-fault-tolerance/pom.xml
@@ -0,0 +1,119 @@
+<?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";>
+    <parent>
+        <groupId>org.apache.camel.quarkus</groupId>
+        <artifactId>camel-quarkus-integration-tests-foundation</artifactId>
+        <version>2.1.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>camel-quarkus-integration-test-core-faulttolerance</artifactId>
+    <name>Camel Quarkus :: Integration Tests :: Core Fault Tolerance :: 
Tests</name>
+    <description>The camel quarkus integration tests for 
camel.faulttolerance.* properties</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-direct</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-microprofile-fault-tolerance</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-resteasy-jsonb</artifactId>
+        </dependency>
+
+
+        <!-- test dependencies -->
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.rest-assured</groupId>
+            <artifactId>rest-assured</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <!-- The following dependencies guarantee that this module is built 
after them. You can update them by running `mvn process-resources -Pformat -N` 
from the source tree root directory -->
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-direct-deployment</artifactId>
+            <version>${project.version}</version>
+            <type>pom</type>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>*</groupId>
+                    <artifactId>*</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            
<artifactId>camel-quarkus-microprofile-fault-tolerance-deployment</artifactId>
+            <version>${project.version}</version>
+            <type>pom</type>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>*</groupId>
+                    <artifactId>*</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+    </dependencies>
+
+    <profiles>
+        <profile>
+            <id>native</id>
+            <activation>
+                <property>
+                    <name>native</name>
+                </property>
+            </activation>
+            <properties>
+                <quarkus.package.type>native</quarkus.package.type>
+            </properties>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>integration-test</goal>
+                                    <goal>verify</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>
diff --git 
a/integration-test-groups/foundation/core-fault-tolerance/src/main/java/org/apache/camel/quarkus/core/CoreFaultToleranceProducers.java
 
b/integration-test-groups/foundation/core-fault-tolerance/src/main/java/org/apache/camel/quarkus/core/CoreFaultToleranceProducers.java
new file mode 100644
index 0000000..3f6436a
--- /dev/null
+++ 
b/integration-test-groups/foundation/core-fault-tolerance/src/main/java/org/apache/camel/quarkus/core/CoreFaultToleranceProducers.java
@@ -0,0 +1,57 @@
+/*
+ * 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.quarkus.core;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Named;
+
+import io.smallrye.faulttolerance.core.FaultToleranceStrategy;
+import io.smallrye.faulttolerance.core.InvocationContext;
+import io.smallrye.faulttolerance.core.circuit.breaker.CircuitBreaker;
+import io.smallrye.faulttolerance.core.stopwatch.SystemStopwatch;
+import io.smallrye.faulttolerance.core.util.SetOfThrowables;
+
+public class CoreFaultToleranceProducers {
+
+    @ApplicationScoped
+    @Named("customCircuitBreaker")
+    CircuitBreaker<Integer> produceCustomCircuitBreaker() {
+        FaultToleranceStrategy<Integer> delegate = new 
FaultToleranceStrategy<Integer>() {
+            @Override
+            public Integer apply(InvocationContext<Integer> ctx) {
+                return null;
+            }
+        };
+        return new CircuitBreaker<Integer>(delegate, "description", 
SetOfThrowables.EMPTY, SetOfThrowables.EMPTY, 10, 40, 0.1,
+                2, new SystemStopwatch()) {
+            @Override
+            public String toString() {
+                return "customCircuitBreaker";
+            }
+        };
+    }
+
+    @ApplicationScoped
+    @Named("customBulkheadExecutorService")
+    ExecutorService produceCustomBulkheadExecutorService() {
+        return Executors.newFixedThreadPool(2);
+    }
+
+}
diff --git 
a/integration-test-groups/foundation/core-fault-tolerance/src/main/java/org/apache/camel/quarkus/core/CoreFaultToleranceResource.java
 
b/integration-test-groups/foundation/core-fault-tolerance/src/main/java/org/apache/camel/quarkus/core/CoreFaultToleranceResource.java
new file mode 100644
index 0000000..f17810a
--- /dev/null
+++ 
b/integration-test-groups/foundation/core-fault-tolerance/src/main/java/org/apache/camel/quarkus/core/CoreFaultToleranceResource.java
@@ -0,0 +1,71 @@
+/*
+ * 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.quarkus.core;
+
+import java.util.concurrent.ExecutorService;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.json.Json;
+import javax.json.JsonObject;
+import javax.json.JsonObjectBuilder;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import io.smallrye.faulttolerance.core.circuit.breaker.CircuitBreaker;
+import org.apache.camel.CamelContext;
+import 
org.apache.camel.component.microprofile.faulttolerance.FaultToleranceProcessor;
+
+@Path("/core")
+@ApplicationScoped
+public class CoreFaultToleranceResource {
+
+    @Inject
+    CamelContext context;
+
+    @Named("customCircuitBreaker")
+    CircuitBreaker<Integer> customCircuitBreaker;
+
+    @Named("customBulkheadExecutorService")
+    ExecutorService customBulkheadExecutorService;
+
+    @Path("/fault-tolerance-configurations")
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public JsonObject faultToleranceConfigurations() {
+        FaultToleranceProcessor ftp = context.getProcessor("ftp", 
FaultToleranceProcessor.class);
+
+        JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
+        objectBuilder.add("isCustomCircuitBreakerRef", ftp.getCircuitBreaker() 
== customCircuitBreaker);
+        objectBuilder.add("delay", ftp.getDelay());
+        objectBuilder.add("successThreshold", ftp.getSuccessThreshold());
+        objectBuilder.add("requestVolumeThreshold", 
ftp.getRequestVolumeThreshold());
+        objectBuilder.add("failureRatio", (int) (ftp.getFailureRate() * 100));
+        objectBuilder.add("timeoutEnabled", ftp.isTimeoutEnabled());
+        objectBuilder.add("timeoutDuration", ftp.getTimeoutDuration());
+        objectBuilder.add("timeoutPoolSize", ftp.getTimeoutPoolSize());
+        objectBuilder.add("bulkheadEnabled", ftp.isBulkheadEnabled());
+        objectBuilder.add("bulkheadMaxConcurrentCalls", 
ftp.getBulkheadMaxConcurrentCalls());
+        objectBuilder.add("bulkheadWaitingTaskQueue", 
ftp.getBulkheadWaitingTaskQueue());
+        objectBuilder.add("isCustomBulkheadExecutorServiceRef", 
ftp.getExecutorService() == customBulkheadExecutorService);
+
+        return objectBuilder.build();
+    }
+}
diff --git 
a/integration-test-groups/foundation/core-fault-tolerance/src/main/java/org/apache/camel/quarkus/core/CoreFaultToleranceRoutes.java
 
b/integration-test-groups/foundation/core-fault-tolerance/src/main/java/org/apache/camel/quarkus/core/CoreFaultToleranceRoutes.java
new file mode 100644
index 0000000..77968b6
--- /dev/null
+++ 
b/integration-test-groups/foundation/core-fault-tolerance/src/main/java/org/apache/camel/quarkus/core/CoreFaultToleranceRoutes.java
@@ -0,0 +1,39 @@
+/*
+ * 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.quarkus.core;
+
+import javax.enterprise.context.ApplicationScoped;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * No message is expected to flow through this route.
+ * The route definition is there only to test the camel fault tolerance 
configuration parsing.
+ */
+@ApplicationScoped
+public class CoreFaultToleranceRoutes extends RouteBuilder {
+
+    public static final String FALLBACK_RESULT = "Fallback response";
+    public static final String RESULT = "Hello Camel Quarkus Core Fault 
Tolerance";
+
+    @Override
+    public void configure() {
+        
from("direct:faultTolerance").circuitBreaker().id("ftp").process(exchange -> {
+            exchange.getMessage().setBody(RESULT);
+        }).onFallback().setBody().constant(FALLBACK_RESULT).end();
+    }
+}
diff --git 
a/integration-test-groups/foundation/core-fault-tolerance/src/main/resources/application.properties
 
b/integration-test-groups/foundation/core-fault-tolerance/src/main/resources/application.properties
new file mode 100644
index 0000000..865c0e0
--- /dev/null
+++ 
b/integration-test-groups/foundation/core-fault-tolerance/src/main/resources/application.properties
@@ -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.
+## ---------------------------------------------------------------------------
+
+#
+# Camel
+camel.faulttolerance.circuitBreakerRef = customCircuitBreaker
+camel.faulttolerance.delay = 15
+camel.faulttolerance.successThreshold = 4
+camel.faulttolerance.requestVolumeThreshold = 60
+camel.faulttolerance.failureRatio = 94
+camel.faulttolerance.timeoutEnabled = true
+camel.faulttolerance.timeoutDuration = 3000
+camel.faulttolerance.timeoutPoolSize = 3
+camel.faulttolerance.bulkheadEnabled = true
+camel.faulttolerance.bulkheadMaxConcurrentCalls = 20
+camel.faulttolerance.bulkheadWaitingTaskQueue = 21
+camel.faulttolerance.bulkheadExecutorServiceRef = customBulkheadExecutorService
+
diff --git 
a/integration-test-groups/foundation/core-fault-tolerance/src/test/java/org/apache/camel/quarkus/core/CoreFaultToleranceIT.java
 
b/integration-test-groups/foundation/core-fault-tolerance/src/test/java/org/apache/camel/quarkus/core/CoreFaultToleranceIT.java
new file mode 100644
index 0000000..774a128
--- /dev/null
+++ 
b/integration-test-groups/foundation/core-fault-tolerance/src/test/java/org/apache/camel/quarkus/core/CoreFaultToleranceIT.java
@@ -0,0 +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.quarkus.core;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+public class CoreFaultToleranceIT extends CoreFaultToleranceTest {
+}
diff --git 
a/integration-test-groups/foundation/core-fault-tolerance/src/test/java/org/apache/camel/quarkus/core/CoreFaultToleranceTest.java
 
b/integration-test-groups/foundation/core-fault-tolerance/src/test/java/org/apache/camel/quarkus/core/CoreFaultToleranceTest.java
new file mode 100644
index 0000000..82bef12
--- /dev/null
+++ 
b/integration-test-groups/foundation/core-fault-tolerance/src/test/java/org/apache/camel/quarkus/core/CoreFaultToleranceTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.quarkus.core;
+
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.get;
+import static org.hamcrest.Matchers.is;
+
+@QuarkusTest
+public class CoreFaultToleranceTest {
+
+    @Test
+    public void testFaultTolerancePropertiesAreApplied() {
+        get("/core/fault-tolerance-configurations")
+                .then()
+                .body(
+                        "isCustomCircuitBreakerRef", is(true),
+                        "delay", is(15),
+                        "successThreshold", is(4),
+                        "requestVolumeThreshold", is(60),
+                        "failureRatio", is(94),
+                        "timeoutEnabled", is(true),
+                        "timeoutDuration", is(3000),
+                        "timeoutPoolSize", is(3),
+                        "bulkheadEnabled", is(false),
+                        "bulkheadMaxConcurrentCalls", is(20),
+                        "bulkheadWaitingTaskQueue", is(21),
+                        "isCustomBulkheadExecutorServiceRef", is(true));
+    }
+
+}
diff --git a/integration-test-groups/foundation/pom.xml 
b/integration-test-groups/foundation/pom.xml
index 5c6a647..6d9c895 100644
--- a/integration-test-groups/foundation/pom.xml
+++ b/integration-test-groups/foundation/pom.xml
@@ -38,6 +38,7 @@
         <module>controlbus</module>
         <module>core</module>
         <module>core-annotations</module>
+        <module>core-fault-tolerance</module>
         <module>core-languages</module>
         <module>core-thread-pools</module>
         <module>customized-log-component</module>
diff --git a/integration-tests/foundation-grouped/pom.xml 
b/integration-tests/foundation-grouped/pom.xml
index cfd26ba..67a8a4b 100644
--- a/integration-tests/foundation-grouped/pom.xml
+++ b/integration-tests/foundation-grouped/pom.xml
@@ -97,6 +97,10 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-microprofile-fault-tolerance</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-mock</artifactId>
         </dependency>
         <dependency>
@@ -225,6 +229,19 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
+            
<artifactId>camel-quarkus-microprofile-fault-tolerance-deployment</artifactId>
+            <version>${project.version}</version>
+            <type>pom</type>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>*</groupId>
+                    <artifactId>*</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-mock-deployment</artifactId>
             <version>${project.version}</version>
             <type>pom</type>

Reply via email to