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

davsclaus pushed a commit to branch camel-3.4.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.4.x by this push:
     new ecf8602  CAMEL-15928: Fix not invoking fallback for resilience4j 
circuit breaker and not triggering circuit breaker for timeout exceptions 
(#4809)
ecf8602 is described below

commit ecf860285e5c81dc30a7799674bfb53cce58e82e
Author: Liroyd <[email protected]>
AuthorDate: Wed Dec 23 10:31:24 2020 +0200

    CAMEL-15928: Fix not invoking fallback for resilience4j circuit breaker and 
not triggering circuit breaker for timeout exceptions (#4809)
---
 .../resilience4j/ResilienceProcessor.java          | 111 +++++++++------------
 .../ResilienceExistingCircuitBreakerTest.java      |  15 ++-
 .../ResilienceInheritErrorHandlerTest.java         |  18 +++-
 .../resilience4j/ResilienceManagementTest.java     |  21 +++-
 .../ResilienceRouteBulkheadFallbackTest.java       |  16 ++-
 .../ResilienceRouteBulkheadOkTest.java             |  14 ++-
 .../resilience4j/ResilienceRouteFallbackTest.java  |  16 ++-
 .../resilience4j/ResilienceRouteOkTest.java        |  13 ++-
 .../resilience4j/ResilienceRouteRejectedTest.java  |  15 ++-
 .../SpringResilienceRouteFallbackTest.java         |  12 ++-
 .../resilience4j/SpringResilienceRouteOkTest.java  |  11 +-
 .../SpringResilienceRouteFallbackTest.xml          |  17 ++++
 .../resilience4j/SpringResilienceRouteOkTest.xml   |  17 ++++
 13 files changed, 217 insertions(+), 79 deletions(-)

diff --git 
a/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessor.java
 
b/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessor.java
index 97439bf..749ee23 100644
--- 
a/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessor.java
+++ 
b/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessor.java
@@ -353,32 +353,62 @@ public class ResilienceProcessor extends 
AsyncProcessorSupport implements CamelC
         // Camel error handler
         exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
 
-        Callable<Exchange> task = 
CircuitBreaker.decorateCallable(circuitBreaker, new 
CircuitBreakerTask(processor, exchange));
-        Function<Throwable, Exchange> fallbackTask = new 
CircuitBreakerFallbackTask(fallback, exchange);
-        if (bulkheadConfig != null) {
-            Bulkhead bh = Bulkhead.of(id, bulkheadConfig);
-            task = Bulkhead.decorateCallable(bh, task);
-        }
+        Callable<Exchange> task;
 
         if (timeLimiterConfig != null) {
             // timeout handling is more complex with thread-pools
-            final CircuitBreakerTimeoutTask timeoutTask = new 
CircuitBreakerTimeoutTask(task, exchange);
+
+            TimeLimiter tl = TimeLimiter.of(id, timeLimiterConfig);
             Supplier<CompletableFuture<Exchange>> futureSupplier;
             if (executorService == null) {
-                futureSupplier = () -> 
CompletableFuture.supplyAsync(timeoutTask::get);
+                futureSupplier = () -> CompletableFuture.supplyAsync(() -> 
processInCopy(exchange));
             } else {
-                futureSupplier = () -> 
CompletableFuture.supplyAsync(timeoutTask::get, executorService);
+                futureSupplier = () -> CompletableFuture.supplyAsync(() -> 
processInCopy(exchange), executorService);
             }
+            task = TimeLimiter.decorateFutureSupplier (tl, futureSupplier);
+        } else {
+            task = new CircuitBreakerTask(() -> processInCopy(exchange));
+        }
 
-            TimeLimiter tl = TimeLimiter.of(id, timeLimiterConfig);
-            task = TimeLimiter.decorateFutureSupplier(tl, futureSupplier);
+        if (bulkheadConfig != null) {
+            Bulkhead bh = Bulkhead.of(id, bulkheadConfig);
+            task = Bulkhead.decorateCallable(bh, task);
         }
 
-        Try.ofCallable(task).recover(fallbackTask).andFinally(() -> 
callback.done(false)).get();
+        task = CircuitBreaker.decorateCallable(circuitBreaker, task);
 
+        Function<Throwable, Exchange> fallbackTask = new 
CircuitBreakerFallbackTask(this.fallback, exchange);
+        Try.ofCallable(task).recover(fallbackTask).andFinally(() -> 
callback.done(false)).get();
         return false;
     }
 
+    private Exchange processInCopy(Exchange exchange) {
+        try {
+            LOG.debug("Running processor: {} with exchange: {}", processor, 
exchange);
+            // prepare a copy of exchange so downstream processors don't
+            // cause side-effects if they mutate the exchange
+            // in case timeout processing and continue with the fallback etc
+            Exchange copy = ExchangeHelper.createCorrelatedCopy(exchange, 
false, false);
+            // process the processor until its fully done
+            processor.process(copy);
+            if (copy.getException() != null) {
+                exchange.setException(copy.getException());
+            } else {
+                // copy the result as its regarded as success
+                ExchangeHelper.copyResults(exchange, copy);
+                
exchange.setProperty(CircuitBreakerConstants.RESPONSE_SUCCESSFUL_EXECUTION, 
true);
+                
exchange.setProperty(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK, false);
+            }
+        } catch (Throwable e) {
+            exchange.setException(e);
+        }
+        if (exchange.getException() != null) {
+            // throw exception so resilient4j know it was a failure
+            throw 
RuntimeExchangeException.wrapRuntimeException(exchange.getException());
+        }
+        return exchange;
+    }
+
     @Override
     protected void doStart() throws Exception {
         ObjectHelper.notNull(camelContext, "CamelContext", this);
@@ -396,40 +426,15 @@ public class ResilienceProcessor extends 
AsyncProcessorSupport implements CamelC
 
     private static final class CircuitBreakerTask implements 
Callable<Exchange> {
 
-        private final Processor processor;
-        private final Exchange exchange;
+        Supplier<Exchange> supplier;
 
-        private CircuitBreakerTask(Processor processor, Exchange exchange) {
-            this.processor = processor;
-            this.exchange = exchange;
+        public CircuitBreakerTask(Supplier<Exchange> supplier) {
+            this.supplier = supplier;
         }
 
         @Override
         public Exchange call() throws Exception {
-            try {
-                LOG.debug("Running processor: {} with exchange: {}", 
processor, exchange);
-                // prepare a copy of exchange so downstream processors don't
-                // cause side-effects if they mutate the exchange
-                // in case timeout processing and continue with the fallback 
etc
-                Exchange copy = ExchangeHelper.createCorrelatedCopy(exchange, 
false, false);
-                // process the processor until its fully done
-                processor.process(copy);
-                if (copy.getException() != null) {
-                    exchange.setException(copy.getException());
-                } else {
-                    // copy the result as its regarded as success
-                    ExchangeHelper.copyResults(exchange, copy);
-                    
exchange.setProperty(CircuitBreakerConstants.RESPONSE_SUCCESSFUL_EXECUTION, 
true);
-                    
exchange.setProperty(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK, false);
-                }
-            } catch (Throwable e) {
-                exchange.setException(e);
-            }
-            if (exchange.getException() != null) {
-                // throw exception so resilient4j know it was a failure
-                throw 
RuntimeExchangeException.wrapRuntimeException(exchange.getException());
-            }
-            return exchange;
+            return supplier.get();
         }
     }
 
@@ -461,7 +466,7 @@ public class ResilienceProcessor extends 
AsyncProcessorSupport implements CamelC
                     
exchange.setProperty(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK, false);
                     
exchange.setProperty(CircuitBreakerConstants.RESPONSE_SHORT_CIRCUITED, true);
                     
exchange.setProperty(CircuitBreakerConstants.RESPONSE_REJECTED, true);
-                    return exchange;
+                    throw 
RuntimeExchangeException.wrapRuntimeException(throwable);
                 } else {
                     // throw exception so resilient4j know it was a failure
                     throw 
RuntimeExchangeException.wrapRuntimeException(throwable);
@@ -498,26 +503,4 @@ public class ResilienceProcessor extends 
AsyncProcessorSupport implements CamelC
             return exchange;
         }
     }
-
-    private static final class CircuitBreakerTimeoutTask implements 
Supplier<Exchange> {
-
-        private final Callable<Exchange> future;
-        private final Exchange exchange;
-
-        private CircuitBreakerTimeoutTask(Callable<Exchange> future, Exchange 
exchange) {
-            this.future = future;
-            this.exchange = exchange;
-        }
-
-        @Override
-        public Exchange get() {
-            try {
-                return future.call();
-            } catch (Exception e) {
-                exchange.setException(e);
-            }
-            return exchange;
-        }
-    }
-
 }
diff --git 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceExistingCircuitBreakerTest.java
 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceExistingCircuitBreakerTest.java
index be25d08..b1b810e 100644
--- 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceExistingCircuitBreakerTest.java
+++ 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceExistingCircuitBreakerTest.java
@@ -32,11 +32,20 @@ public class ResilienceExistingCircuitBreakerTest extends 
CamelTestSupport {
 
     @Test
     public void testResilience() throws Exception {
+        test("direct:start");
+    }
+
+    @Test
+    public void testResilienceWithTimeOut() throws Exception {
+        test("direct:start.with.timeout.enabled");
+    }
+
+    private void test(String endPointUri) throws InterruptedException {
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback 
message");
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_SUCCESSFUL_EXECUTION,
 false);
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK,
 true);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody(endPointUri, "Hello World");
 
         assertMockEndpointsSatisfied();
 
@@ -54,6 +63,10 @@ public class ResilienceExistingCircuitBreakerTest extends 
CamelTestSupport {
             public void configure() throws Exception {
                 
from("direct:start").to("log:start").circuitBreaker().resilience4jConfiguration().circuitBreakerRef("myCircuitBreaker").end()
                     .throwException(new 
IllegalArgumentException("Forced")).onFallback().transform().constant("Fallback 
message").end().to("log:result").to("mock:result");
+
+                
from("direct:start.with.timeout.enabled").to("log:start.with.timeout.enabled").circuitBreaker().resilience4jConfiguration().circuitBreakerRef("myCircuitBreaker")
+                        .timeoutEnabled(true).timeoutDuration(2000).end()
+                        .throwException(new 
IllegalArgumentException("Forced")).onFallback().transform().constant("Fallback 
message").end().to("log:result").to("mock:result");
             }
         };
     }
diff --git 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceInheritErrorHandlerTest.java
 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceInheritErrorHandlerTest.java
index 268379a..57a7d9b 100644
--- 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceInheritErrorHandlerTest.java
+++ 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceInheritErrorHandlerTest.java
@@ -24,11 +24,20 @@ public class ResilienceInheritErrorHandlerTest extends 
CamelTestSupport {
 
     @Test
     public void testResilience() throws Exception {
+        test("direct:start");
+    }
+
+    @Test
+    public void testResilienceWithTimeOut() throws Exception {
+        test("direct:start.with.timeout.enabled");
+    }
+
+    private void test(String endPointUri) throws InterruptedException {
         getMockEndpoint("mock:a").expectedMessageCount(3 + 1);
         getMockEndpoint("mock:dead").expectedMessageCount(1);
         getMockEndpoint("mock:result").expectedMessageCount(0);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody(endPointUri, "Hello World");
 
         assertMockEndpointsSatisfied();
     }
@@ -44,6 +53,13 @@ public class ResilienceInheritErrorHandlerTest extends 
CamelTestSupport {
                     // turn on Camel's error handler on hystrix so it can do
                     // redeliveries
                     
.circuitBreaker().inheritErrorHandler(true).to("mock:a").throwException(new 
IllegalArgumentException("Forced")).end().to("log:result").to("mock:result");
+
+                
from("direct:start.with.timeout.enabled").to("log:start.with.timeout.enabled")
+                        // turn on Camel's error handler on hystrix so it can 
do
+                        // redeliveries
+                        
.circuitBreaker().inheritErrorHandler(true).resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).end()
+                        .to("mock:a").throwException(new 
IllegalArgumentException("Forced")).end().to("log:result").to("mock:result");
+
             }
         };
     }
diff --git 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceManagementTest.java
 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceManagementTest.java
index 1765709..c922a74 100644
--- 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceManagementTest.java
+++ 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceManagementTest.java
@@ -36,9 +36,18 @@ public class ResilienceManagementTest extends 
CamelTestSupport {
 
     @Test
     public void testResilience() throws Exception {
+        test("start", "myResilience");
+    }
+
+    @Test
+    public void testResilienceWithTimeOut() throws Exception {
+        test("start.with.timeout.enabled", "myResilienceWithTimeout");
+    }
+
+    public void test(String routId, String circuitBreakerName) throws 
Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody("direct:"+ routId, "Hello World");
 
         assertMockEndpointsSatisfied();
 
@@ -50,11 +59,11 @@ public class ResilienceManagementTest extends 
CamelTestSupport {
         String name = context.getManagementName();
 
         // get the object name for the delayer
-        ObjectName on = ObjectName.getInstance("org.apache.camel:context=" + 
name + ",type=processors,name=\"myResilience\"");
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=" + 
name + ",type=processors,name=\"" + circuitBreakerName + "\"");
 
         // should be on start
-        String routeId = (String)mbeanServer.getAttribute(on, "RouteId");
-        assertEquals("start", routeId);
+        String currentRouteId = (String)mbeanServer.getAttribute(on, 
"RouteId");
+        assertEquals(routId, currentRouteId);
 
         Integer num = (Integer)mbeanServer.getAttribute(on, 
"CircuitBreakerMinimumNumberOfCalls");
         assertEquals("100", num.toString());
@@ -81,6 +90,10 @@ public class ResilienceManagementTest extends 
CamelTestSupport {
                 
from("direct:start").routeId("start").circuitBreaker().id("myResilience").to("direct:foo").onFallback().transform().constant("Fallback
 message").end()
                     .to("mock:result");
 
+                
from("direct:start.with.timeout.enabled").routeId("start.with.timeout.enabled").circuitBreaker().id("myResilienceWithTimeout").resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).end()
+                        
.to("direct:foo").onFallback().transform().constant("Fallback message").end()
+                        .to("mock:result");
+
                 from("direct:foo").transform().constant("Bye World");
             }
         };
diff --git 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteBulkheadFallbackTest.java
 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteBulkheadFallbackTest.java
index 3186bce..ddd5e2f 100644
--- 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteBulkheadFallbackTest.java
+++ 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteBulkheadFallbackTest.java
@@ -25,11 +25,20 @@ public class ResilienceRouteBulkheadFallbackTest extends 
CamelTestSupport {
 
     @Test
     public void testResilience() throws Exception {
+        test("direct:start");
+    }
+
+    @Test
+    public void testResilienceWithTimeOut() throws Exception {
+        test("direct:start.with.timeout.enabled");
+    }
+
+    private void test(String endPointUri) throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback 
message");
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_SUCCESSFUL_EXECUTION,
 false);
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK,
 true);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody(endPointUri, "Hello World");
 
         assertMockEndpointsSatisfied();
     }
@@ -40,7 +49,10 @@ public class ResilienceRouteBulkheadFallbackTest extends 
CamelTestSupport {
             @Override
             public void configure() throws Exception {
                 
from("direct:start").to("log:start").circuitBreaker().resilience4jConfiguration().bulkheadEnabled(true).end().throwException(new
 IllegalArgumentException("Forced"))
-                    .onFallback().transform().constant("Fallback 
message").end().to("log:result").to("mock:result");
+                        .onFallback().transform().constant("Fallback 
message").end().to("log:result").to("mock:result");
+
+                
from("direct:start.with.timeout.enabled").to("log:start.with.timeout.enabled").circuitBreaker().resilience4jConfiguration().bulkheadEnabled(true).timeoutEnabled(true).timeoutDuration(2000).end().throwException(new
 IllegalArgumentException("Forced"))
+                        .onFallback().transform().constant("Fallback 
message").end().to("log:result").to("mock:result");
             }
         };
     }
diff --git 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteBulkheadOkTest.java
 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteBulkheadOkTest.java
index c08467a..93ef438 100644
--- 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteBulkheadOkTest.java
+++ 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteBulkheadOkTest.java
@@ -25,11 +25,20 @@ public class ResilienceRouteBulkheadOkTest extends 
CamelTestSupport {
 
     @Test
     public void testResilience() throws Exception {
+        test("direct:start");
+    }
+
+    @Test
+    public void testResilienceWithTimeOut() throws Exception {
+        test("direct:start.with.timeout.enabled");
+    }
+
+    private void test(String endPointUri) throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_SUCCESSFUL_EXECUTION,
 true);
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK,
 false);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody(endPointUri, "Hello World");
 
         assertMockEndpointsSatisfied();
     }
@@ -42,6 +51,9 @@ public class ResilienceRouteBulkheadOkTest extends 
CamelTestSupport {
                 
from("direct:start").circuitBreaker().resilience4jConfiguration().bulkheadEnabled(true).end().to("direct:foo").to("log:foo").onFallback().transform()
                     .constant("Fallback 
message").end().to("log:result").to("mock:result");
 
+                
from("direct:start.with.timeout.enabled").circuitBreaker().resilience4jConfiguration().bulkheadEnabled(true).timeoutEnabled(true).timeoutDuration(2000).end().to("direct:foo").to("log:foo").onFallback().transform()
+                        .constant("Fallback 
message").end().to("log:result").to("mock:result");
+
                 from("direct:foo").transform().constant("Bye World");
             }
         };
diff --git 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteFallbackTest.java
 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteFallbackTest.java
index 1c4674e..8ae15a4 100644
--- 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteFallbackTest.java
+++ 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteFallbackTest.java
@@ -21,15 +21,26 @@ import org.apache.camel.spi.CircuitBreakerConstants;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
+import java.util.concurrent.TimeoutException;
+
 public class ResilienceRouteFallbackTest extends CamelTestSupport {
 
     @Test
     public void testResilience() throws Exception {
+        test("direct:start");
+    }
+
+    @Test
+    public void testResilienceWithTimeOut() throws Exception {
+        test("direct:start.with.timeout.enabled");
+    }
+
+    private void test(String endPointUri) throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback 
message");
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_SUCCESSFUL_EXECUTION,
 false);
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK,
 true);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody(endPointUri, "Hello World");
 
         assertMockEndpointsSatisfied();
     }
@@ -41,6 +52,9 @@ public class ResilienceRouteFallbackTest extends 
CamelTestSupport {
             public void configure() throws Exception {
                 
from("direct:start").to("log:start").circuitBreaker().throwException(new 
IllegalArgumentException("Forced")).onFallback().transform().constant("Fallback 
message")
                     .end().to("log:result").to("mock:result");
+
+                
from("direct:start.with.timeout.enabled").to("log:start.with.timeout.enabled").circuitBreaker().resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).end().throwException(new
 TimeoutException("Forced")).onFallback().transform().constant("Fallback 
message")
+                        .end().to("log:result").to("mock:result");
             }
         };
     }
diff --git 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteOkTest.java
 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteOkTest.java
index e890e2a..1777963 100644
--- 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteOkTest.java
+++ 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteOkTest.java
@@ -47,13 +47,22 @@ public class ResilienceRouteOkTest extends CamelTestSupport 
{
 
     @Test
     public void testResilience() throws Exception {
+        test("direct:start");
+    }
+
+    @Test
+    public void testResilienceWithTimeOut() throws Exception {
+        test("direct:start.with.timeout.enabled");
+    }
+
+    private void test(String endPointUri) throws Exception {
         assertEquals(0, bi.getInvokedCounter());
 
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_SUCCESSFUL_EXECUTION,
 true);
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK,
 false);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody(endPointUri, "Hello World");
 
         assertMockEndpointsSatisfied();
 
@@ -67,6 +76,8 @@ public class ResilienceRouteOkTest extends CamelTestSupport {
             public void configure() throws Exception {
                 
from("direct:start").circuitBreaker().to("direct:foo").to("log:foo").onFallback().transform().constant("Fallback
 message").end().to("log:result").to("mock:result");
 
+                
from("direct:start.with.timeout.enabled").circuitBreaker().resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).end().to("direct:foo").to("log:foo").onFallback().transform().constant("Fallback
 message").end().to("log:result").to("mock:result");
+
                 from("direct:foo").transform().constant("Bye World");
             }
         };
diff --git 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteRejectedTest.java
 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteRejectedTest.java
index c5fcf8b..b7e0ef3 100644
--- 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteRejectedTest.java
+++ 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteRejectedTest.java
@@ -36,6 +36,15 @@ public class ResilienceRouteRejectedTest extends 
CamelTestSupport {
 
     @Test
     public void testResilience() throws Exception {
+        test("direct:start", "myResilience");
+    }
+
+    @Test
+    public void testResilienceWithTimeOut() throws Exception {
+        test("direct:start.with.timeout.enabled", "myResilienceWithTimeout");
+    }
+
+    private void test(String endPointUri, String circuitBreakerName) throws 
Exception {
         // look inside jmx
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
@@ -43,7 +52,7 @@ public class ResilienceRouteRejectedTest extends 
CamelTestSupport {
         // context name
         String name = context.getManagementName();
 
-        ObjectName on = ObjectName.getInstance("org.apache.camel:context=" + 
name + ",type=processors,name=\"myResilience\"");
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=" + 
name + ",type=processors,name=\"" + circuitBreakerName + "\"");
 
         // force it into open state
         mbeanServer.invoke(on, "transitionToForcedOpenState", null, null);
@@ -53,7 +62,7 @@ public class ResilienceRouteRejectedTest extends 
CamelTestSupport {
         // send message which should get rejected, so the message is not 
changed
         getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody(endPointUri, "Hello World");
 
         assertMockEndpointsSatisfied();
     }
@@ -65,6 +74,8 @@ public class ResilienceRouteRejectedTest extends 
CamelTestSupport {
             public void configure() throws Exception {
                 
from("direct:start").circuitBreaker().id("myResilience").to("direct:foo").to("log:foo").end().to("log:result").to("mock:result");
 
+                
from("direct:start.with.timeout.enabled").circuitBreaker().resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).end().id("myResilienceWithTimeout").to("direct:foo").to("log:foo").end().to("log:result").to("mock:result");
+
                 from("direct:foo").transform().constant("Bye World");
             }
         };
diff --git 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/SpringResilienceRouteFallbackTest.java
 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/SpringResilienceRouteFallbackTest.java
index 53bff6c..d6bdd82 100644
--- 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/SpringResilienceRouteFallbackTest.java
+++ 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/SpringResilienceRouteFallbackTest.java
@@ -33,11 +33,21 @@ public class SpringResilienceRouteFallbackTest extends 
CamelSpringTestSupport {
 
     @Test
     public void testResilience() throws Exception {
+        test("direct:start");
+    }
+
+    @Test
+    public void testResilienceWithTimeOut() throws Exception {
+        test("direct:start.with.timeout.enabled");
+    }
+
+    private void test(String endPointUri) throws Exception {
+        // look inside jmx
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback 
message");
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_SUCCESSFUL_EXECUTION,
 false);
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK,
 true);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody(endPointUri, "Hello World");
 
         assertMockEndpointsSatisfied();
     }
diff --git 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/SpringResilienceRouteOkTest.java
 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/SpringResilienceRouteOkTest.java
index 07313b3..1b1243e 100644
--- 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/SpringResilienceRouteOkTest.java
+++ 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/SpringResilienceRouteOkTest.java
@@ -33,11 +33,20 @@ public class SpringResilienceRouteOkTest extends 
CamelSpringTestSupport {
 
     @Test
     public void testResilience() throws Exception {
+        test("direct:start");
+    }
+
+    @Test
+    public void testResilienceWithTimeOut() throws Exception {
+        test("direct:start.with.timeout.enabled");
+    }
+
+    private void test(String endPointUri) throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_SUCCESSFUL_EXECUTION,
 true);
         
getMockEndpoint("mock:result").expectedPropertyReceived(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK,
 false);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody(endPointUri, "Hello World");
 
         assertMockEndpointsSatisfied();
     }
diff --git 
a/components/camel-resilience4j/src/test/resources/org/apache/camel/component/resilience4j/SpringResilienceRouteFallbackTest.xml
 
b/components/camel-resilience4j/src/test/resources/org/apache/camel/component/resilience4j/SpringResilienceRouteFallbackTest.xml
index 39dbe97..573408c 100644
--- 
a/components/camel-resilience4j/src/test/resources/org/apache/camel/component/resilience4j/SpringResilienceRouteFallbackTest.xml
+++ 
b/components/camel-resilience4j/src/test/resources/org/apache/camel/component/resilience4j/SpringResilienceRouteFallbackTest.xml
@@ -37,6 +37,23 @@
       <to uri="mock:result"/>
     </route>
 
+    <route>
+      <from uri="direct:start.with.timeout.enabled"/>
+      <circuitBreaker>
+        <resilience4jConfiguration>
+          <timeoutEnabled>true</timeoutEnabled>
+          <timeoutDuration>2000</timeoutDuration>
+        </resilience4jConfiguration>
+        <throwException exceptionType="java.lang.IllegalArgumentException" 
message="Forced"/>
+        <onFallback>
+          <transform>
+            <constant>Fallback message</constant>
+          </transform>
+        </onFallback>
+      </circuitBreaker>
+      <to uri="mock:result"/>
+    </route>
+
   </camelContext>
 
 </beans>
\ No newline at end of file
diff --git 
a/components/camel-resilience4j/src/test/resources/org/apache/camel/component/resilience4j/SpringResilienceRouteOkTest.xml
 
b/components/camel-resilience4j/src/test/resources/org/apache/camel/component/resilience4j/SpringResilienceRouteOkTest.xml
index 1e2b139..c9d9778 100644
--- 
a/components/camel-resilience4j/src/test/resources/org/apache/camel/component/resilience4j/SpringResilienceRouteOkTest.xml
+++ 
b/components/camel-resilience4j/src/test/resources/org/apache/camel/component/resilience4j/SpringResilienceRouteOkTest.xml
@@ -38,6 +38,23 @@
     </route>
 
     <route>
+      <from uri="direct:start.with.timeout.enabled"/>
+      <circuitBreaker>
+        <resilience4jConfiguration>
+          <timeoutEnabled>true</timeoutEnabled>
+          <timeoutDuration>2000</timeoutDuration>
+        </resilience4jConfiguration>
+        <to uri="direct:foo"/>
+        <onFallback>
+          <transform>
+            <constant>Fallback message</constant>
+          </transform>
+        </onFallback>
+      </circuitBreaker>
+      <to uri="mock:result"/>
+    </route>
+    
+    <route>
       <from uri="direct:foo"/>
       <transform>
         <constant>Bye World</constant>

Reply via email to