You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2021/07/14 14:55:52 UTC
[camel-quarkus] 06/13: Test faultToleranceConfiguration() EIP DSL
method #2628
This is an automated email from the ASF dual-hosted git repository.
ppalaga pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 2add5cf4a390849535bd4700ad024a8b1bc6ba9a
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Thu May 20 15:24:04 2021 +0200
Test faultToleranceConfiguration() EIP DSL method #2628
---
.../MicroProfileFaultToleranceRoutes.java | 15 +++++++++++++
.../MicroprofileFaultToleranceResource.java | 10 +++++----
.../MicroprofileFaultToleranceTest.java | 25 ++++++++++++++++++++--
3 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/integration-tests/microprofile/src/main/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroProfileFaultToleranceRoutes.java b/integration-tests/microprofile/src/main/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroProfileFaultToleranceRoutes.java
index 271daab..3dca95a 100644
--- a/integration-tests/microprofile/src/main/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroProfileFaultToleranceRoutes.java
+++ b/integration-tests/microprofile/src/main/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroProfileFaultToleranceRoutes.java
@@ -25,6 +25,7 @@ public class MicroProfileFaultToleranceRoutes extends RouteBuilder {
public static final String FALLBACK_RESULT = "Fallback response";
public static final String RESULT = "Hello Camel Quarkus MicroProfile Fault Tolerance";
private static final AtomicInteger COUNTER = new AtomicInteger();
+ private static final AtomicInteger TIMEOUT_COUNTER = new AtomicInteger();
@Override
public void configure() throws Exception {
@@ -39,5 +40,19 @@ public class MicroProfileFaultToleranceRoutes extends RouteBuilder {
.onFallback()
.setBody().constant(FALLBACK_RESULT)
.end();
+
+ from("direct:faultToleranceWithTimeout")
+ .circuitBreaker()
+ .faultToleranceConfiguration().timeoutEnabled(true).timeoutDuration(500).end()
+ .process(exchange -> {
+ if (TIMEOUT_COUNTER.incrementAndGet() == 1) {
+ Thread.sleep(1000);
+ }
+ exchange.getMessage().setBody("Regular hi " + exchange.getMessage().getBody(String.class));
+ })
+ .onFallback()
+ .setBody().simple("Sorry ${body}, had to fallback!")
+ .end();
+
}
}
diff --git a/integration-tests/microprofile/src/main/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroprofileFaultToleranceResource.java b/integration-tests/microprofile/src/main/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroprofileFaultToleranceResource.java
index 2e2214f..348a870 100644
--- a/integration-tests/microprofile/src/main/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroprofileFaultToleranceResource.java
+++ b/integration-tests/microprofile/src/main/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroprofileFaultToleranceResource.java
@@ -17,8 +17,9 @@
package org.apache.camel.quarkus.component.microprofile.it.faulttolerance;
import javax.inject.Inject;
-import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@@ -30,9 +31,10 @@ public class MicroprofileFaultToleranceResource {
@Inject
ProducerTemplate producerTemplate;
- @GET
+ @Path("/route/{route}")
+ @POST
@Produces(MediaType.TEXT_PLAIN)
- public String triggerFaultToleranceRoute() {
- return producerTemplate.requestBody("direct:faultTolerance", null, String.class);
+ public String triggerFaultToleranceRoute(String body, @PathParam("route") String route) {
+ return producerTemplate.requestBody("direct:" + route, body, String.class);
}
}
diff --git a/integration-tests/microprofile/src/test/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroprofileFaultToleranceTest.java b/integration-tests/microprofile/src/test/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroprofileFaultToleranceTest.java
index d5bd0c5..ff610c2 100644
--- a/integration-tests/microprofile/src/test/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroprofileFaultToleranceTest.java
+++ b/integration-tests/microprofile/src/test/java/org/apache/camel/quarkus/component/microprofile/it/faulttolerance/MicroprofileFaultToleranceTest.java
@@ -28,15 +28,36 @@ class MicroprofileFaultToleranceTest {
public void testCamelMicroProfileFaultToleranceFallback() {
// First request should trigger the fallback response
- RestAssured.get("/microprofile-fault-tolerance")
+ RestAssured.post("/microprofile-fault-tolerance/route/faultTolerance")
.then()
.statusCode(200)
.body(Matchers.is(MicroProfileFaultToleranceRoutes.FALLBACK_RESULT));
// Next request(s) should trigger the expected response
- RestAssured.get("/microprofile-fault-tolerance")
+ RestAssured.post("/microprofile-fault-tolerance/route/faultTolerance")
.then()
.statusCode(200)
.body(Matchers.is(MicroProfileFaultToleranceRoutes.RESULT));
}
+
+ @Test
+ public void testCamelMicroProfileFaultToleranceFallbackWithTimeout() {
+
+ // First request should trigger the fallback response
+ RestAssured.given()
+ .body("Joe")
+ .post("/microprofile-fault-tolerance/route/faultToleranceWithTimeout")
+ .then()
+ .statusCode(200)
+ .body(Matchers.is("Sorry Joe, had to fallback!"));
+
+ // Next request(s) should trigger the expected response
+ RestAssured.given()
+ .body("Mary")
+ .post("/microprofile-fault-tolerance/route/faultToleranceWithTimeout")
+ .then()
+ .statusCode(200)
+ .body(Matchers.is("Regular hi Mary"));
+ }
+
}