You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/11/19 08:13:04 UTC
[camel] branch master updated: Camel-Resilience4j: Fixed CS
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 02d60fe Camel-Resilience4j: Fixed CS
02d60fe is described below
commit 02d60fe64c6df90b398ac8408eb14f67c5fb6cf1
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Nov 19 09:12:13 2019 +0100
Camel-Resilience4j: Fixed CS
---
.../resilience4j/ResilienceProcessor.java | 26 ++++++++--------
.../resilience4j/ResilienceProcessorFactory.java | 3 +-
.../component/resilience4j/ResilienceReifier.java | 13 +++-----
.../ResilienceExistingCircuitBreakerTest.java | 11 ++-----
.../ResilienceInheritErrorHandlerTest.java | 13 +++-----
.../resilience4j/ResilienceManagementTest.java | 30 ++++++++-----------
.../ResilienceRouteBulkheadFallbackTest.java | 11 ++-----
.../ResilienceRouteBulkheadOkTest.java | 16 +++-------
.../resilience4j/ResilienceRouteFallbackTest.java | 11 ++-----
.../ResilienceRouteFallbackViaNetworkTest.java | 11 ++-----
.../resilience4j/ResilienceRouteOkTest.java | 15 ++--------
.../resilience4j/ResilienceRouteRejectedTest.java | 13 ++------
.../resilience4j/ResilienceTimeoutTest.java | 29 +++++++-----------
.../ResilienceTimeoutThreadPoolTest.java | 30 +++++++------------
.../ResilienceTimeoutWithFallbackTest.java | 35 +++++++---------------
15 files changed, 84 insertions(+), 183 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 93eea8e..6be5c9d 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
@@ -70,8 +70,8 @@ public class ResilienceProcessor extends AsyncProcessorSupport implements CamelC
private boolean shutdownExecutorService;
private ExecutorService executorService;
- public ResilienceProcessor(CircuitBreakerConfig circuitBreakerConfig, BulkheadConfig bulkheadConfig, TimeLimiterConfig timeLimiterConfig,
- Processor processor, Processor fallback) {
+ public ResilienceProcessor(CircuitBreakerConfig circuitBreakerConfig, BulkheadConfig bulkheadConfig, TimeLimiterConfig timeLimiterConfig, Processor processor,
+ Processor fallback) {
this.circuitBreakerConfig = circuitBreakerConfig;
this.bulkheadConfig = bulkheadConfig;
this.timeLimiterConfig = timeLimiterConfig;
@@ -348,7 +348,8 @@ public class ResilienceProcessor extends AsyncProcessorSupport implements CamelC
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
- // run this as if we run inside try .. catch so there is no regular Camel error handler
+ // run this as if we run inside try .. catch so there is no regular
+ // Camel error handler
exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
Callable<Exchange> task = CircuitBreaker.decorateCallable(circuitBreaker, new CircuitBreakerTask(processor, exchange));
@@ -372,9 +373,7 @@ public class ResilienceProcessor extends AsyncProcessorSupport implements CamelC
task = TimeLimiter.decorateFutureSupplier(tl, futureSupplier);
}
- Try.ofCallable(task)
- .recover(fallbackTask)
- .andFinally(() -> callback.done(false)).get();
+ Try.ofCallable(task).recover(fallbackTask).andFinally(() -> callback.done(false)).get();
return false;
}
@@ -394,7 +393,7 @@ public class ResilienceProcessor extends AsyncProcessorSupport implements CamelC
}
}
- private static class CircuitBreakerTask implements Callable<Exchange> {
+ private static final class CircuitBreakerTask implements Callable<Exchange> {
private final Processor processor;
private final Exchange exchange;
@@ -408,7 +407,8 @@ public class ResilienceProcessor extends AsyncProcessorSupport implements CamelC
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
+ // 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
@@ -432,7 +432,7 @@ public class ResilienceProcessor extends AsyncProcessorSupport implements CamelC
}
}
- private static class CircuitBreakerFallbackTask implements Function<Throwable, Exchange> {
+ private static final class CircuitBreakerFallbackTask implements Function<Throwable, Exchange> {
private final Processor processor;
private final Exchange exchange;
@@ -446,7 +446,8 @@ public class ResilienceProcessor extends AsyncProcessorSupport implements CamelC
public Exchange apply(Throwable throwable) {
if (processor == null) {
if (throwable instanceof TimeoutException) {
- // the circuit breaker triggered a timeout (and there is no fallback) so lets mark the exchange as failed
+ // the circuit breaker triggered a timeout (and there is no
+ // fallback) so lets mark the exchange as failed
exchange.setProperty(CircuitBreakerConstants.RESPONSE_SUCCESSFUL_EXECUTION, false);
exchange.setProperty(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK, false);
exchange.setProperty(CircuitBreakerConstants.RESPONSE_SHORT_CIRCUITED, false);
@@ -480,7 +481,8 @@ public class ResilienceProcessor extends AsyncProcessorSupport implements CamelC
exchange.setProperty(Exchange.EXCEPTION_CAUGHT, exchange.getException());
exchange.removeProperty(Exchange.ROUTE_STOP);
exchange.setException(null);
- // and we should not be regarded as exhausted as we are in a try .. catch block
+ // and we should not be regarded as exhausted as we are in a try ..
+ // catch block
exchange.removeProperty(Exchange.REDELIVERY_EXHAUSTED);
// run the fallback processor
try {
@@ -496,7 +498,7 @@ public class ResilienceProcessor extends AsyncProcessorSupport implements CamelC
}
}
- private static class CircuitBreakerTimeoutTask implements Supplier<Exchange> {
+ private static final class CircuitBreakerTimeoutTask implements Supplier<Exchange> {
private final Callable<Exchange> future;
private final Exchange exchange;
diff --git a/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessorFactory.java b/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessorFactory.java
index 7da89e8..03c0f22 100644
--- a/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessorFactory.java
+++ b/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessorFactory.java
@@ -22,7 +22,8 @@ import org.apache.camel.model.CircuitBreakerDefinition;
import org.apache.camel.spi.RouteContext;
/**
- * To integrate camel-resilience4j with the Camel routes using the Circuit Breaker EIP.
+ * To integrate camel-resilience4j with the Camel routes using the Circuit
+ * Breaker EIP.
*/
public class ResilienceProcessorFactory extends TypedProcessorFactory<CircuitBreakerDefinition> {
diff --git a/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceReifier.java b/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceReifier.java
index 00817f4..63fe3a5 100644
--- a/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceReifier.java
+++ b/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceReifier.java
@@ -25,7 +25,6 @@ import java.util.concurrent.ExecutorService;
import io.github.resilience4j.bulkhead.BulkheadConfig;
import io.github.resilience4j.circuitbreaker.CircuitBreaker;
import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
-
import io.github.resilience4j.timelimiter.TimeLimiterConfig;
import org.apache.camel.CamelContext;
import org.apache.camel.ExtendedCamelContext;
@@ -170,20 +169,16 @@ public class ResilienceReifier extends ProcessorReifier<CircuitBreakerDefinition
// Extract properties from default configuration, the one configured on
// camel context takes the precedence over those in the registry
- loadProperties(camelContext, properties, Suppliers.firstNotNull(
- () -> camelContext.getExtension(Model.class).getResilience4jConfiguration(null),
- () -> lookup(camelContext, "Camel", Resilience4jConfigurationDefinition.class))
- );
+ loadProperties(camelContext, properties, Suppliers.firstNotNull(() -> camelContext.getExtension(Model.class).getResilience4jConfiguration(null),
+ () -> lookup(camelContext, "Camel", Resilience4jConfigurationDefinition.class)));
// Extract properties from referenced configuration, the one configured
// on camel context takes the precedence over those in the registry
if (definition.getConfigurationRef() != null) {
final String ref = definition.getConfigurationRef();
- loadProperties(camelContext, properties, Suppliers.firstNotNull(
- () -> camelContext.getExtension(Model.class).getResilience4jConfiguration(ref),
- () -> mandatoryLookup(camelContext, ref, Resilience4jConfigurationDefinition.class))
- );
+ loadProperties(camelContext, properties, Suppliers.firstNotNull(() -> camelContext.getExtension(Model.class).getResilience4jConfiguration(ref),
+ () -> mandatoryLookup(camelContext, ref, Resilience4jConfigurationDefinition.class)));
}
// Extract properties from local configuration
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 8892659..be25d08 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
@@ -52,15 +52,8 @@ public class ResilienceExistingCircuitBreakerTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
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").to("log:start").circuitBreaker().resilience4jConfiguration().circuitBreakerRef("myCircuitBreaker").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 0974ce4..268379a 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
@@ -40,15 +40,10 @@ public class ResilienceInheritErrorHandlerTest extends CamelTestSupport {
public void configure() throws Exception {
errorHandler(deadLetterChannel("mock:dead").maximumRedeliveries(3).redeliveryDelay(0));
- from("direct:start")
- .to("log:start")
- // 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").to("log:start")
+ // 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");
}
};
}
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 388c4d5..1765709 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
@@ -1,13 +1,13 @@
-/**
+/*
* 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ * 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.
@@ -53,23 +53,23 @@ public class ResilienceManagementTest extends CamelTestSupport {
ObjectName on = ObjectName.getInstance("org.apache.camel:context=" + name + ",type=processors,name=\"myResilience\"");
// should be on start
- String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+ String routeId = (String)mbeanServer.getAttribute(on, "RouteId");
assertEquals("start", routeId);
- Integer num = (Integer) mbeanServer.getAttribute(on, "CircuitBreakerMinimumNumberOfCalls");
+ Integer num = (Integer)mbeanServer.getAttribute(on, "CircuitBreakerMinimumNumberOfCalls");
assertEquals("100", num.toString());
- Integer totalRequests = (Integer) mbeanServer.getAttribute(on, "NumberOfSuccessfulCalls");
+ Integer totalRequests = (Integer)mbeanServer.getAttribute(on, "NumberOfSuccessfulCalls");
assertEquals(1, totalRequests.intValue());
- Integer errorCount = (Integer) mbeanServer.getAttribute(on, "NumberOfFailedCalls");
+ Integer errorCount = (Integer)mbeanServer.getAttribute(on, "NumberOfFailedCalls");
assertEquals(0, errorCount.intValue());
- String state = (String) mbeanServer.getAttribute(on, "CircuitBreakerState");
+ String state = (String)mbeanServer.getAttribute(on, "CircuitBreakerState");
assertEquals("CLOSED", state);
mbeanServer.invoke(on, "transitionToOpenState", null, null);
- state = (String) mbeanServer.getAttribute(on, "CircuitBreakerState");
+ state = (String)mbeanServer.getAttribute(on, "CircuitBreakerState");
assertEquals("OPEN", state);
}
@@ -78,16 +78,10 @@ public class ResilienceManagementTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start").routeId("start")
- .circuitBreaker().id("myResilience")
- .to("direct:foo")
- .onFallback()
- .transform().constant("Fallback message")
- .end()
+ from("direct:start").routeId("start").circuitBreaker().id("myResilience").to("direct:foo").onFallback().transform().constant("Fallback message").end()
.to("mock:result");
- from("direct:foo")
- .transform().constant("Bye World");
+ 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 8591c36..3186bce 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
@@ -39,15 +39,8 @@ public class ResilienceRouteBulkheadFallbackTest extends CamelTestSupport {
return new RouteBuilder() {
@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");
+ 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");
}
};
}
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 d85c463..c08467a 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
@@ -39,18 +39,10 @@ public class ResilienceRouteBulkheadOkTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- 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:foo")
- .transform().constant("Bye World");
+ 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: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 b3bb081..1c4674e 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
@@ -39,15 +39,8 @@ public class ResilienceRouteFallbackTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
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").to("log:start").circuitBreaker().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/ResilienceRouteFallbackViaNetworkTest.java b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteFallbackViaNetworkTest.java
index 012c219..f093b1f 100644
--- a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteFallbackViaNetworkTest.java
+++ b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceRouteFallbackViaNetworkTest.java
@@ -44,15 +44,8 @@ public class ResilienceRouteFallbackViaNetworkTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start")
- .to("log:start")
- .circuitBreaker()
- .throwException(new IllegalArgumentException("Forced"))
- .onFallbackViaNetwork()
- .transform().constant("Fallback message")
- .end()
- .to("log:result")
- .to("mock:result");
+ from("direct:start").to("log:start").circuitBreaker().throwException(new IllegalArgumentException("Forced")).onFallbackViaNetwork().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 dc1d23d..b30d832 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
@@ -39,18 +39,9 @@ public class ResilienceRouteOkTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
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:foo")
- .transform().constant("Bye World");
+ from("direct:start").circuitBreaker().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 80b87bd..c5fcf8b 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
@@ -47,7 +47,7 @@ public class ResilienceRouteRejectedTest extends CamelTestSupport {
// force it into open state
mbeanServer.invoke(on, "transitionToForcedOpenState", null, null);
- String state = (String) mbeanServer.getAttribute(on, "CircuitBreakerState");
+ String state = (String)mbeanServer.getAttribute(on, "CircuitBreakerState");
assertEquals("FORCED_OPEN", state);
// send message which should get rejected, so the message is not changed
@@ -63,16 +63,9 @@ public class ResilienceRouteRejectedTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
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").circuitBreaker().id("myResilience").to("direct:foo").to("log:foo").end().to("log:result").to("mock:result");
- from("direct:foo")
- .transform().constant("Bye World");
+ from("direct:foo").transform().constant("Bye World");
}
};
}
diff --git a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutTest.java b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutTest.java
index 9545b1f..8d8e888 100644
--- a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutTest.java
+++ b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutTest.java
@@ -37,7 +37,8 @@ public class ResilienceTimeoutTest extends CamelTestSupport {
@Test
public void testSlow() throws Exception {
- // this calls the slow route and therefore causes a timeout which triggers an exception
+ // this calls the slow route and therefore causes a timeout which
+ // triggers an exception
try {
template.requestBody("direct:start", "slow");
fail("Should fail due to timeout");
@@ -49,7 +50,8 @@ public class ResilienceTimeoutTest extends CamelTestSupport {
@Test
public void testSlowLoop() throws Exception {
- // this calls the slow route and therefore causes a timeout which triggers an exception
+ // this calls the slow route and therefore causes a timeout which
+ // triggers an exception
for (int i = 0; i < 10; i++) {
try {
log.info(">>> test run " + i + " <<<");
@@ -67,29 +69,18 @@ public class ResilienceTimeoutTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start")
- .circuitBreaker()
- // enable and use 2 second timeout
- .resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).end()
- .log("Resilience processing start: ${threadName}")
- .toD("direct:${body}")
- .log("Resilience processing end: ${threadName}")
- .end()
- .log("After Resilience ${body}");
+ from("direct:start").circuitBreaker()
+ // enable and use 2 second timeout
+ .resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).end().log("Resilience processing start: ${threadName}").toD("direct:${body}")
+ .log("Resilience processing end: ${threadName}").end().log("After Resilience ${body}");
from("direct:fast")
// this is a fast route and takes 1 second to respond
- .log("Fast processing start: ${threadName}")
- .delay(1000)
- .transform().constant("Fast response")
- .log("Fast processing end: ${threadName}");
+ .log("Fast processing start: ${threadName}").delay(1000).transform().constant("Fast response").log("Fast processing end: ${threadName}");
from("direct:slow")
// this is a slow route and takes 3 second to respond
- .log("Slow processing start: ${threadName}")
- .delay(3000)
- .transform().constant("Slow response")
- .log("Slow processing end: ${threadName}");
+ .log("Slow processing start: ${threadName}").delay(3000).transform().constant("Slow response").log("Slow processing end: ${threadName}");
}
};
}
diff --git a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutThreadPoolTest.java b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutThreadPoolTest.java
index 58e0c33..01c891d 100644
--- a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutThreadPoolTest.java
+++ b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutThreadPoolTest.java
@@ -42,7 +42,6 @@ public class ResilienceTimeoutThreadPoolTest extends CamelTestSupport {
Object out = template.requestBody("direct:start", "fast");
assertEquals("Fast response", out);
-
ThreadPoolExecutor pte = context().getRegistry().lookupByNameAndType("myThreadPool", ThreadPoolExecutor.class);
assertNotNull(pte);
assertEquals(2, pte.getCorePoolSize());
@@ -53,7 +52,8 @@ public class ResilienceTimeoutThreadPoolTest extends CamelTestSupport {
@Test
public void testSlow() throws Exception {
- // this calls the slow route and therefore causes a timeout which triggers an exception
+ // this calls the slow route and therefore causes a timeout which
+ // triggers an exception
try {
template.requestBody("direct:start", "slow");
fail("Should fail due to timeout");
@@ -76,7 +76,8 @@ public class ResilienceTimeoutThreadPoolTest extends CamelTestSupport {
@Test
public void testSlowLoop() throws Exception {
- // this calls the slow route and therefore causes a timeout which triggers an exception
+ // this calls the slow route and therefore causes a timeout which
+ // triggers an exception
for (int i = 0; i < 10; i++) {
try {
log.info(">>> test run " + i + " <<<");
@@ -94,29 +95,18 @@ public class ResilienceTimeoutThreadPoolTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start")
- .circuitBreaker()
- // enable and use 2 second timeout
- .resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).timeoutExecutorServiceRef("myThreadPool").end()
- .log("Resilience processing start: ${threadName}")
- .toD("direct:${body}")
- .log("Resilience processing end: ${threadName}")
- .end()
- .log("After Resilience ${body}");
+ from("direct:start").circuitBreaker()
+ // enable and use 2 second timeout
+ .resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).timeoutExecutorServiceRef("myThreadPool").end()
+ .log("Resilience processing start: ${threadName}").toD("direct:${body}").log("Resilience processing end: ${threadName}").end().log("After Resilience ${body}");
from("direct:fast")
// this is a fast route and takes 1 second to respond
- .log("Fast processing start: ${threadName}")
- .delay(1000)
- .transform().constant("Fast response")
- .log("Fast processing end: ${threadName}");
+ .log("Fast processing start: ${threadName}").delay(1000).transform().constant("Fast response").log("Fast processing end: ${threadName}");
from("direct:slow")
// this is a slow route and takes 3 second to respond
- .log("Slow processing start: ${threadName}")
- .delay(3000)
- .transform().constant("Slow response")
- .log("Slow processing end: ${threadName}");
+ .log("Slow processing start: ${threadName}").delay(3000).transform().constant("Slow response").log("Slow processing end: ${threadName}");
}
};
}
diff --git a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutWithFallbackTest.java b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutWithFallbackTest.java
index ef6f5bf..69da12e 100644
--- a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutWithFallbackTest.java
+++ b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceTimeoutWithFallbackTest.java
@@ -35,7 +35,8 @@ public class ResilienceTimeoutWithFallbackTest extends CamelTestSupport {
@Test
public void testSlow() throws Exception {
- // this calls the slow route and therefore causes a timeout which triggers the fallback
+ // this calls the slow route and therefore causes a timeout which
+ // triggers the fallback
Object out = template.requestBody("direct:start", "slow");
assertEquals("LAST CHANGE", out);
}
@@ -45,37 +46,21 @@ public class ResilienceTimeoutWithFallbackTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start")
- .circuitBreaker()
+ from("direct:start").circuitBreaker()
// enable and use 2 second timeout
- .resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).end()
- .log("Resilience processing start: ${threadName}")
- .toD("direct:${body}")
- .log("Resilience processing end: ${threadName}")
- .onFallback()
- // use fallback if there was an exception or timeout
- .log("Resilience fallback start: ${threadName}")
- .transform().constant("Fallback response")
- .log("Resilience fallback end: ${threadName}")
- .end()
- .log("After Resilience ${body}")
- .transform(simple("A CHANGE"))
- .transform(simple("LAST CHANGE"))
- .log("End ${body}");
+ .resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).end().log("Resilience processing start: ${threadName}").toD("direct:${body}")
+ .log("Resilience processing end: ${threadName}").onFallback()
+ // use fallback if there was an exception or timeout
+ .log("Resilience fallback start: ${threadName}").transform().constant("Fallback response").log("Resilience fallback end: ${threadName}").end()
+ .log("After Resilience ${body}").transform(simple("A CHANGE")).transform(simple("LAST CHANGE")).log("End ${body}");
from("direct:fast")
// this is a fast route and takes 1 second to respond
- .log("Fast processing start: ${threadName}")
- .delay(1000)
- .transform().constant("Fast response")
- .log("Fast processing end: ${threadName}");
+ .log("Fast processing start: ${threadName}").delay(1000).transform().constant("Fast response").log("Fast processing end: ${threadName}");
from("direct:slow")
// this is a slow route and takes 3 second to respond
- .log("Slow processing start: ${threadName}")
- .delay(3000)
- .transform().constant("Slow response")
- .log("Slow processing end: ${threadName}");
+ .log("Slow processing start: ${threadName}").delay(3000).transform().constant("Slow response").log("Slow processing end: ${threadName}");
}
};
}