You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/04/19 08:50:18 UTC
[1/3] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Repository: camel
Updated Branches:
refs/heads/hys c534ac287 -> 4fbc6cb17
CAMEL-9879: Circuit Breaker EIP - That is using hystrix
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/22d83714
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/22d83714
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/22d83714
Branch: refs/heads/hys
Commit: 22d837149123433246c5f4439ee9d744cc38ee42
Parents: c534ac2
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 08:17:00 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 08:17:00 2016 +0200
----------------------------------------------------------------------
.../model/HystrixCircuitBreakerDefinition.java | 105 -------------------
.../apache/camel/model/HystrixDefinition.java | 94 +++++++++++++++++
.../apache/camel/model/ProcessorDefinition.java | 10 +-
.../HystrixCircuitBreakerProcessor.java | 96 -----------------
.../resources/org/apache/camel/model/jaxb.index | 2 +-
.../processor/HystrixCircuitBreakerTest.java | 50 ---------
.../component/hystrix/HystrixProcessor.java | 5 +-
.../hystrix/HystrixProcessorCommand.java | 4 +-
.../hystrix/HystrixProcessorFactory.java | 9 +-
.../camel/model/HystrixCircuitBreakerDefinition | 18 ----
.../org/apache/camel/model/HystrixDefinition | 18 ++++
.../HystrixCircuitBreakerFallbackTest.java | 53 ----------
.../hystrix/HystrixCircuitBreakerOkTest.java | 53 ----------
.../hystrix/HystrixRouteFallbackTest.java | 53 ++++++++++
.../component/hystrix/HystrixRouteOkTest.java | 53 ++++++++++
15 files changed, 238 insertions(+), 385 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
deleted file mode 100644
index 3228596..0000000
--- a/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * 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>
- * 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.model;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.apache.camel.Processor;
-import org.apache.camel.processor.HystrixCircuitBreakerProcessor;
-import org.apache.camel.spi.Metadata;
-import org.apache.camel.spi.RouteContext;
-
-@Metadata(label = "eip,routing,circuitbreaker")
-@XmlRootElement(name = "hystrixCircuitBreaker")
-@XmlAccessorType(XmlAccessType.FIELD)
-public class HystrixCircuitBreakerDefinition extends OutputDefinition<HystrixCircuitBreakerDefinition> {
-
- // TODO: we can rename to circuitBreaker and then deprecated the CB in the load balancer
- // the trick is to avoid a clash in the generated xml schema
- // so for know we call it hystrixCircuitBreaker
-
- @XmlElement
- private FallbackDefinition fallback;
-
- public HystrixCircuitBreakerDefinition() {
- }
-
- @Override
- public String toString() {
- return "HystrixCircuitBreaker[" + getOutputs() + "]";
- }
-
- @Override
- public String getLabel() {
- return "hystrixCircuitBreaker";
- }
-
- @Override
- public Processor createProcessor(RouteContext routeContext) throws Exception {
- Processor children = this.createChildProcessor(routeContext, true);
-
- Processor fallbackProcessor = null;
- if (fallback != null) {
- fallbackProcessor = createProcessor(routeContext, fallback);
- }
- return new HystrixCircuitBreakerProcessor(children, fallbackProcessor);
- }
-
- @Override
- public void addOutput(ProcessorDefinition<?> output) {
- if (fallback != null) {
- fallback.addOutput(output);
- } else {
- super.addOutput(output);
- }
- }
-
- @Override
- public ProcessorDefinition<?> end() {
- if (fallback != null) {
- // end fallback as well
- fallback.end();
- }
- return super.end();
- }
-
- public FallbackDefinition getFallback() {
- return fallback;
- }
-
- public void setFallback(FallbackDefinition fallback) {
- this.fallback = fallback;
- }
-
- // Fluent API
- // -------------------------------------------------------------------------
-
- /**
- * Sets the otherwise node
- *
- * @return the builder
- */
- public HystrixCircuitBreakerDefinition fallback() {
- fallback = new FallbackDefinition();
- fallback.setParent(this);
- return this;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/camel-core/src/main/java/org/apache/camel/model/HystrixDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/HystrixDefinition.java b/camel-core/src/main/java/org/apache/camel/model/HystrixDefinition.java
new file mode 100644
index 0000000..054aa1c
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/HystrixDefinition.java
@@ -0,0 +1,94 @@
+/**
+ * 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>
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.Processor;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.RouteContext;
+
+@Metadata(label = "eip,routing,circuitbreaker")
+@XmlRootElement(name = "hystrix")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class HystrixDefinition extends OutputDefinition<HystrixDefinition> {
+
+ @XmlElement
+ private FallbackDefinition fallback;
+
+ public HystrixDefinition() {
+ }
+
+ @Override
+ public String toString() {
+ return "Hystrix[" + getOutputs() + "]";
+ }
+
+ @Override
+ public String getLabel() {
+ return "hystrix";
+ }
+
+ @Override
+ public Processor createProcessor(RouteContext routeContext) throws Exception {
+ throw new IllegalStateException("Cannot find camel-hystrix on the classpath.");
+ }
+
+ @Override
+ public void addOutput(ProcessorDefinition<?> output) {
+ if (fallback != null) {
+ fallback.addOutput(output);
+ } else {
+ super.addOutput(output);
+ }
+ }
+
+ @Override
+ public ProcessorDefinition<?> end() {
+ if (fallback != null) {
+ // end fallback as well
+ fallback.end();
+ }
+ return super.end();
+ }
+
+ public FallbackDefinition getFallback() {
+ return fallback;
+ }
+
+ public void setFallback(FallbackDefinition fallback) {
+ this.fallback = fallback;
+ }
+
+ // Fluent API
+ // -------------------------------------------------------------------------
+
+ /**
+ * Sets the otherwise node
+ *
+ * @return the builder
+ */
+ public HystrixDefinition fallback() {
+ fallback = new FallbackDefinition();
+ fallback.setParent(this);
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 2cdfa02..2270ef3 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -287,7 +287,7 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
} else if (defn instanceof OnExceptionDefinition || ProcessorDefinitionHelper.isParentOfType(OnExceptionDefinition.class, defn, true)) {
log.trace("{} is part of OnException so no error handler is applied", defn);
// do not use error handler for onExceptions blocks as it will handle errors itself
- } else if (defn instanceof HystrixCircuitBreakerDefinition || ProcessorDefinitionHelper.isParentOfType(HystrixCircuitBreakerDefinition.class, defn, true)) {
+ } else if (defn instanceof HystrixDefinition || ProcessorDefinitionHelper.isParentOfType(HystrixDefinition.class, defn, true)) {
log.trace("{} is part of HystrixCircuitBreaker so no error handler is applied", defn);
// do not use error handler for hystrixCircuitBreaker blocks as it will handle errors itself
} else if (defn instanceof MulticastDefinition) {
@@ -1473,12 +1473,14 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
}
/**
- * Creates a Circuit Breaker EIP that is using Hystrix.
+ * Creates a Hystrix Circuit Breaker EIP.
+ * <p/>
+ * This requires having camel-hystrix on the classpath.
*
* @return the builder
*/
- public HystrixCircuitBreakerDefinition hystrixCircuitBreaker() {
- HystrixCircuitBreakerDefinition answer = new HystrixCircuitBreakerDefinition();
+ public HystrixDefinition hystrix() {
+ HystrixDefinition answer = new HystrixDefinition();
addOutput(answer);
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java
deleted file mode 100644
index 79d5037..0000000
--- a/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * 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.processor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.AsyncProcessor;
-import org.apache.camel.Exchange;
-import org.apache.camel.Navigate;
-import org.apache.camel.Processor;
-import org.apache.camel.spi.IdAware;
-import org.apache.camel.support.ServiceSupport;
-import org.apache.camel.util.AsyncProcessorHelper;
-
-public class HystrixCircuitBreakerProcessor extends ServiceSupport implements AsyncProcessor, Navigate<Processor>, org.apache.camel.Traceable, IdAware {
-
- private String id;
- private final Processor processor;
- private final Processor fallback;
-
- public HystrixCircuitBreakerProcessor(Processor processor, Processor fallback) {
- this.processor = processor;
- this.fallback = fallback;
- }
-
- @Override
- public void setId(String id) {
- this.id = id;
- }
-
- @Override
- public String getId() {
- return id;
- }
-
- @Override
- public String getTraceLabel() {
- return "hystrixCircuitBreaker";
- }
-
- @Override
- public List<Processor> next() {
- if (!hasNext()) {
- return null;
- }
- List<Processor> answer = new ArrayList<Processor>();
- answer.add(processor);
- if (fallback != null) {
- answer.add(fallback);
- }
- return answer;
- }
-
- @Override
- public boolean hasNext() {
- return true;
- }
-
- @Override
- public void process(Exchange exchange) throws Exception {
- AsyncProcessorHelper.process(this, exchange);
- }
-
- @Override
- public boolean process(Exchange exchange, AsyncCallback callback) {
- // TODO: use camel-hystrix to process this
- callback.done(true);
- return true;
- }
-
- @Override
- protected void doStart() throws Exception {
- // noop
- }
-
- @Override
- protected void doStop() throws Exception {
- // noop
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
index 6232753..1d80346 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
@@ -31,7 +31,7 @@ FallbackDefinition
FilterDefinition
FinallyDefinition
FromDefinition
-HystrixCircuitBreakerDefinition
+HystrixDefinition
IdempotentConsumerDefinition
InOnlyDefinition
InOutDefinition
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java b/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java
deleted file mode 100644
index a44ddd5..0000000
--- a/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * 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>
- * 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.processor;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-
-public class HystrixCircuitBreakerTest extends ContextTestSupport {
-
- public void testHystrixCircuitBreaker() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .hystrixCircuitBreaker()
- .to("direct:foo")
- .fallback()
- .transform().constant("Fallback message")
- .end()
- .to("mock:result");
-
- from("direct:foo")
- .throwException(new IllegalArgumentException("Forced"));
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
index 0a9f708..81b09e4 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
@@ -30,6 +30,9 @@ import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.AsyncProcessorConverterHelper;
import org.apache.camel.util.AsyncProcessorHelper;
+/**
+ * Implementation of the Hystrix EIP.
+ */
public class HystrixProcessor extends ServiceSupport implements AsyncProcessor, Navigate<Processor>, org.apache.camel.Traceable, IdAware {
private String id;
@@ -54,7 +57,7 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
@Override
public String getTraceLabel() {
- return "hystrixCircuitBreaker";
+ return "hystrix";
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
index 39d64d1..66a8150 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
@@ -21,8 +21,10 @@ import com.netflix.hystrix.HystrixCommandGroupKey;
import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
+/**
+ * Hystrix Command for the Camel Hystrix EIP.
+ */
public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
private final Exchange exchange;
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
index 40b5eb0..5d4cf99 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
@@ -17,11 +17,14 @@
package org.apache.camel.component.hystrix;
import org.apache.camel.Processor;
-import org.apache.camel.model.HystrixCircuitBreakerDefinition;
+import org.apache.camel.model.HystrixDefinition;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.spi.ProcessorFactory;
import org.apache.camel.spi.RouteContext;
+/**
+ * To integrate camel-hystrix with the Camel routes using the Hystrix EIP.
+ */
public class HystrixProcessorFactory implements ProcessorFactory {
@Override
@@ -32,8 +35,8 @@ public class HystrixProcessorFactory implements ProcessorFactory {
@Override
public Processor createProcessor(RouteContext routeContext, ProcessorDefinition<?> definition) throws Exception {
- if (definition instanceof HystrixCircuitBreakerDefinition) {
- HystrixCircuitBreakerDefinition cb = (HystrixCircuitBreakerDefinition) definition;
+ if (definition instanceof HystrixDefinition) {
+ HystrixDefinition cb = (HystrixDefinition) definition;
String id = cb.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
// create the regular processor
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition b/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition
deleted file mode 100644
index 0e00349..0000000
--- a/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# 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.
-#
-
-class=org.apache.camel.component.hystrix.HystrixProcessorFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition b/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition
new file mode 100644
index 0000000..0e00349
--- /dev/null
+++ b/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.hystrix.HystrixProcessorFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.java
deleted file mode 100644
index 3c7e45a..0000000
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.component.hystrix;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class HystrixCircuitBreakerFallbackTest extends CamelTestSupport {
-
- @Test
- public void testHystrixCircuitBreaker() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .hystrixCircuitBreaker()
- .to("direct:foo")
- .fallback()
- .transform().constant("Fallback message")
- .end()
- .to("mock:result");
-
- from("direct:foo")
- .throwException(new IllegalArgumentException("Forced"));
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.java
deleted file mode 100644
index b34c6c2..0000000
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.component.hystrix;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class HystrixCircuitBreakerOkTest extends CamelTestSupport {
-
- @Test
- public void testHystrixCircuitBreaker() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .hystrixCircuitBreaker()
- .to("direct:foo")
- .fallback()
- .transform().constant("Fallback message")
- .end()
- .to("mock:result");
-
- from("direct:foo")
- .transform().constant("Bye World");
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
new file mode 100644
index 0000000..43aa817
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.component.hystrix;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class HystrixRouteFallbackTest extends CamelTestSupport {
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .hystrix()
+ .to("direct:foo")
+ .fallback()
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo")
+ .throwException(new IllegalArgumentException("Forced"));
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/22d83714/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.java
new file mode 100644
index 0000000..d5a2d5c
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.component.hystrix;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class HystrixRouteOkTest extends CamelTestSupport {
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .hystrix()
+ .to("direct:foo")
+ .fallback()
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+
+}
[3/3] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
CAMEL-9879: Circuit Breaker EIP - That is using hystrix
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4fbc6cb1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4fbc6cb1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4fbc6cb1
Branch: refs/heads/hys
Commit: 4fbc6cb17a830c019048523a34952f5ffd198a5c
Parents: 39663b2
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 08:49:34 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 08:49:34 2016 +0200
----------------------------------------------------------------------
.../component/hystrix/HystrixProcessor.java | 29 +-------------------
.../hystrix/HystrixProcessorCommand.java | 13 +++++----
2 files changed, 9 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4fbc6cb1/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
index 495706f..22d48af 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
@@ -85,20 +85,13 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
@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
- exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
-
- // use our callback that does some cleanup when done
- AsyncCallback hystrixCallback = new HystrixAsyncCallback(exchange, callback);
-
HystrixCommandGroupKey key = HystrixCommandGroupKey.Factory.asKey(id);
- HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, hystrixCallback, processor, fallback);
+ HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, callback, processor, fallback);
try {
command.queue();
} catch (Throwable e) {
// error adding to queue, so set as error and we are done
exchange.setException(e);
- exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
callback.done(true);
return true;
}
@@ -116,24 +109,4 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
// noop
}
- private static final class HystrixAsyncCallback implements AsyncCallback {
-
- private final Exchange exchange;
- private final AsyncCallback delegate;
-
- public HystrixAsyncCallback(Exchange exchange, AsyncCallback delegate) {
- this.exchange = exchange;
- this.delegate = delegate;
- }
-
- @Override
- public void done(boolean doneSync) {
- if (doneSync) {
- return;
- }
- // we are only done when called with false
- exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
- delegate.done(doneSync);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4fbc6cb1/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
index 299819e..1eec854 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
@@ -54,6 +54,7 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
try {
if (fallback != null) {
+ LOG.debug("Error occurred processing. Will now run fallback. Exception class: {} message: {}.", exception.getClass().getName(), exception.getMessage());
// store the last to endpoint as the failure endpoint
if (exchange.getProperty(Exchange.FAILURE_ENDPOINT) == null) {
exchange.setProperty(Exchange.FAILURE_ENDPOINT, exchange.getProperty(Exchange.TO_ENDPOINT));
@@ -66,14 +67,15 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
exchange.removeProperty(Exchange.REDELIVERY_EXHAUSTED);
// run the fallback processor
try {
- LOG.debug("Running fallback: {}", exchange);
+ LOG.debug("Running fallback: {} with exchange: {}", fallback, exchange);
fallback.process(exchange, callback);
} catch (Exception e) {
exchange.setException(e);
}
}
} finally {
- LOG.debug("Running fallback: {} success", exchange);
+ LOG.debug("Running fallback: {} with exchange: {} done", fallback, exchange);
+ exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
callback.done(false);
}
@@ -82,9 +84,9 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
@Override
protected Exchange run() throws Exception {
- LOG.debug("Running processor: {}", exchange);
+ LOG.debug("Running processor: {} with exchange: {}", processor, exchange);
- exchange.setProperty(Exchange.EXCEPTION_HANDLED, null);
+ // run this as if we run inside try .. catch so there is no regular Camel error handler
exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
try {
processor.process(exchange, callback);
@@ -98,7 +100,8 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
}
// no errors we are done
try {
- LOG.debug("Running processor: {} success", exchange);
+ LOG.debug("Running processor: {} with exchange: {} done", processor, exchange);
+ exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
callback.done(false);
} catch (Throwable e) {
exchange.setException(e);
[2/3] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
CAMEL-9879: Circuit Breaker EIP - That is using hystrix
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/39663b27
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/39663b27
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/39663b27
Branch: refs/heads/hys
Commit: 39663b279eb48d64155bea3654f5ca53f027171b
Parents: 22d8371
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 08:42:07 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 08:42:07 2016 +0200
----------------------------------------------------------------------
.../component/hystrix/HystrixProcessor.java | 37 +++++++++++---
.../hystrix/HystrixProcessorCommand.java | 50 ++++++++++++------
.../hystrix/HystrixRouteFallbackTest.java | 2 +-
.../camel/component/hystrix/TryCatchTest.java | 53 ++++++++++++++++++++
.../src/test/resources/log4j.properties | 2 +-
5 files changed, 121 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/39663b27/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
index 81b09e4..495706f 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
@@ -88,18 +88,22 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
// run this as if we run inside try .. catch so there is no regular Camel error handler
exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
+ // use our callback that does some cleanup when done
+ AsyncCallback hystrixCallback = new HystrixAsyncCallback(exchange, callback);
+
HystrixCommandGroupKey key = HystrixCommandGroupKey.Factory.asKey(id);
- HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, callback, processor, fallback);
+ HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, hystrixCallback, processor, fallback);
try {
- command.execute();
+ command.queue();
} catch (Throwable e) {
+ // error adding to queue, so set as error and we are done
exchange.setException(e);
+ exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
+ callback.done(true);
+ return true;
}
- exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
-
- callback.done(true);
- return true;
+ return false;
}
@Override
@@ -111,4 +115,25 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
protected void doStop() throws Exception {
// noop
}
+
+ private static final class HystrixAsyncCallback implements AsyncCallback {
+
+ private final Exchange exchange;
+ private final AsyncCallback delegate;
+
+ public HystrixAsyncCallback(Exchange exchange, AsyncCallback delegate) {
+ this.exchange = exchange;
+ this.delegate = delegate;
+ }
+
+ @Override
+ public void done(boolean doneSync) {
+ if (doneSync) {
+ return;
+ }
+ // we are only done when called with false
+ exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
+ delegate.done(doneSync);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/39663b27/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
index 66a8150..299819e 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
@@ -21,12 +21,15 @@ import com.netflix.hystrix.HystrixCommandGroupKey;
import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Hystrix Command for the Camel Hystrix EIP.
*/
public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
+ private static final Logger LOG = LoggerFactory.getLogger(HystrixProcessorCommand.class);
private final Exchange exchange;
private final AsyncCallback callback;
private final AsyncProcessor processor;
@@ -43,46 +46,63 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
@Override
protected Exchange getFallback() {
- if (fallback != null) {
- try {
- Exception e = exchange.getException();
+ // only run fallback if there was an exception
+ Exception exception = exchange.getException();
+ if (exception == null) {
+ return exchange;
+ }
+
+ try {
+ if (fallback != null) {
// store the last to endpoint as the failure endpoint
if (exchange.getProperty(Exchange.FAILURE_ENDPOINT) == null) {
exchange.setProperty(Exchange.FAILURE_ENDPOINT, exchange.getProperty(Exchange.TO_ENDPOINT));
}
// give the rest of the pipeline another chance
exchange.setProperty(Exchange.EXCEPTION_HANDLED, true);
- exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e);
+ exchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
exchange.setException(null);
// and we should not be regarded as exhausted as we are in a try .. catch block
exchange.removeProperty(Exchange.REDELIVERY_EXHAUSTED);
-
- fallback.process(exchange, callback);
- } catch (Exception e) {
- exchange.setException(e);
- } finally {
- callback.done(true);
+ // run the fallback processor
+ try {
+ LOG.debug("Running fallback: {}", exchange);
+ fallback.process(exchange, callback);
+ } catch (Exception e) {
+ exchange.setException(e);
+ }
}
- return exchange;
- } else {
- return null;
+ } finally {
+ LOG.debug("Running fallback: {} success", exchange);
+ callback.done(false);
}
+
+ return exchange;
}
@Override
protected Exchange run() throws Exception {
+ LOG.debug("Running processor: {}", exchange);
+
+ exchange.setProperty(Exchange.EXCEPTION_HANDLED, null);
+ exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
try {
processor.process(exchange, callback);
} catch (Exception e) {
exchange.setException(e);
- } finally {
- callback.done(true);
}
// if we failed then throw an exception
if (exchange.getException() != null) {
throw exchange.getException();
}
+ // no errors we are done
+ try {
+ LOG.debug("Running processor: {} success", exchange);
+ callback.done(false);
+ } catch (Throwable e) {
+ exchange.setException(e);
+ }
return exchange;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/39663b27/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
index 43aa817..dc7c766 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
@@ -44,7 +44,7 @@ public class HystrixRouteFallbackTest extends CamelTestSupport {
.end()
.to("mock:result");
- from("direct:foo")
+ from("direct:foo").errorHandler(noErrorHandler())
.throwException(new IllegalArgumentException("Forced"));
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/39663b27/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/TryCatchTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/TryCatchTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/TryCatchTest.java
new file mode 100644
index 0000000..089b3b8
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/TryCatchTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.component.hystrix;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class TryCatchTest extends CamelTestSupport {
+
+ @Test
+ public void testTryCatch() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .doTry()
+ .to("direct:foo")
+ .doCatch(Exception.class)
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo").errorHandler(noErrorHandler())
+ .throwException(new IllegalArgumentException("Forced"));
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/39663b27/components/camel-hystrix/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/log4j.properties b/components/camel-hystrix/src/test/resources/log4j.properties
index be664b3..2d541ed 100644
--- a/components/camel-hystrix/src/test/resources/log4j.properties
+++ b/components/camel-hystrix/src/test/resources/log4j.properties
@@ -18,7 +18,7 @@
#
# The logging properties used for testing.
#
-log4j.rootLogger=DEBUG, file
+log4j.rootLogger=INFO, file
# uncomment the following to enable camel debugging
#log4j.logger.org.apache.camel.component.hystrix=DEBUG