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/ea917730 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ea917730 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ea917730 Branch: refs/heads/master Commit: ea917730ed80ee34e877729eda34bc3751e81f09 Parents: ad18d61 Author: Claus Ibsen <[email protected]> Authored: Tue Apr 19 08:17:00 2016 +0200 Committer: Claus Ibsen <[email protected]> Committed: Tue Apr 19 18:16:45 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/ea917730/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/ea917730/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/ea917730/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/ea917730/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/ea917730/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/ea917730/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/ea917730/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/ea917730/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/ea917730/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/ea917730/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/ea917730/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/ea917730/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/ea917730/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/ea917730/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/ea917730/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"); + } + }; + } + +}
