Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x 4f0d96e73 -> 94ff981fd
  refs/heads/camel-2.19.x 5ab2c8d83 -> 921fa67da
  refs/heads/master e10e261f0 -> c54adec80


CAMEL-11279: Polished


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/74eaa520
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/74eaa520
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/74eaa520

Branch: refs/heads/master
Commit: 74eaa5208cf00f7d296c56566cc39b3ba68f8650
Parents: 6fb40e2
Author: Claus Ibsen <davscl...@apache.org>
Authored: Tue May 16 11:00:47 2017 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue May 16 12:27:59 2017 +0200

----------------------------------------------------------------------
 .../processor/HystrixProcessorCommand.java      |   6 +-
 .../processor/HystrixCircuitOpenTest.java       | 128 +++++++++++++++++++
 .../processor/HystrixCircutExceptionTest.java   | 126 ------------------
 3 files changed, 129 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/74eaa520/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git 
a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
 
b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
index ab3b696..842dccd 100644
--- 
a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
+++ 
b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
@@ -139,9 +139,6 @@ public class HystrixProcessorCommand extends HystrixCommand 
{
             // and copy the result
             ExchangeHelper.copyResults(exchange, copy);
 
-            // is fallback enabled
-            Boolean fallbackEnabled = getProperties().fallbackEnabled().get();
-
             // execution exception must take precedence over exchange exception
             // because hystrix may have caused this command to fail due 
timeout or something else
             if (hystrixExecutionException != null) {
@@ -149,12 +146,11 @@ public class HystrixProcessorCommand extends 
HystrixCommand {
             }
 
             // in case of an exception in the exchange
-            // we need to trigger this by throwing the exception so Hystrix 
will execute the fallback
+            // we need to trigger this by throwing the exception so hystrix 
will execute the fallback
             // or open the circuit
             if (hystrixExecutionException == null && camelExchangeException != 
null) {
                 throw camelExchangeException;
             }
-            //}
 
             LOG.debug("Running processor: {} with exchange: {} done", 
processor, exchange);
             return exchange.hasOut() ? exchange.getOut() : exchange.getIn();

http://git-wip-us.apache.org/repos/asf/camel/blob/74eaa520/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixCircuitOpenTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixCircuitOpenTest.java
 
b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixCircuitOpenTest.java
new file mode 100644
index 0000000..6312056
--- /dev/null
+++ 
b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixCircuitOpenTest.java
@@ -0,0 +1,128 @@
+/**
+ * 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.processor;
+
+import java.io.IOException;
+import org.apache.camel.CamelExecutionException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.camel.component.hystrix.processor.HystrixConstants.HYSTRIX_RESPONSE_SHORT_CIRCUITED;
+import static 
org.apache.camel.component.hystrix.processor.HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION;
+
+public class HystrixCircuitOpenTest extends CamelTestSupport {
+    public static final Integer REQUEST_VOLUME_THRESHOLD = 4;
+    private static final Logger LOG = 
LoggerFactory.getLogger(HystrixCircuitOpenTest.class);
+    
+    private HystrixExceptionRoute route = new HystrixExceptionRoute();
+
+    @Test
+    public void testCircuitOpen() throws Exception {
+        LOG.info("testCircuitOpen start");
+        // failing requests
+        route.throwException = true;
+        for (int i = 0; i < 2 * REQUEST_VOLUME_THRESHOLD; i++) {
+            try {
+                template.asyncRequestBody("direct:start", "Request Body");
+            } catch (CamelExecutionException e) {
+                LOG.info(e.toString());
+            }
+        }
+        Thread.sleep(1500);
+
+        route.throwException = false;
+        try {
+            template.requestBody("direct:start", "Request Body");
+            LOG.info("Instead circuit open expected");
+        } catch (CamelExecutionException e) {
+            LOG.info("Circuit open expected ", e);
+        }
+
+        // notice this can be flaky due timing when using thread sleeps in 
unit tests
+        
getMockEndpoint("mock:result").expectedPropertyReceived(HYSTRIX_RESPONSE_SHORT_CIRCUITED,
 true);
+
+        assertMockEndpointsSatisfied();
+
+        // wait for the circuit to try an other request
+        Thread.sleep(500);
+        for (int i = 0; i < 2 * REQUEST_VOLUME_THRESHOLD; i++) {
+            try {
+                template.requestBody("direct:start", "Request Body");
+                LOG.info("Circuit has closed");
+            } catch (CamelExecutionException e) {
+                Thread.sleep(i * 100);
+                LOG.info("Circuit will be closed soon " + e.toString());
+            }
+        }
+
+        resetMocks();
+
+        
getMockEndpoint("mock:result").expectedPropertyReceived(HYSTRIX_RESPONSE_SHORT_CIRCUITED,
 false);
+        
getMockEndpoint("mock:result").expectedPropertyReceived(HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION,
 true);
+
+        template.requestBody("direct:start", "Request Body");
+
+        assertMockEndpointsSatisfied();
+    }
+    
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return route;
+    }
+
+    class HystrixExceptionRoute extends RouteBuilder {
+        volatile boolean throwException = true; 
+        
+        @Override
+        public void configure() throws Exception {
+            from("direct:start")
+            .hystrix()
+                .hystrixConfiguration()
+                    .executionTimeoutInMilliseconds(100)
+                    
.circuitBreakerRequestVolumeThreshold(REQUEST_VOLUME_THRESHOLD)
+                    .metricsRollingStatisticalWindowInMilliseconds(1000)
+                    .circuitBreakerSleepWindowInMilliseconds(2000)
+                .end()
+                .log("Hystrix processing start: ${threadName}")
+                .process(new Processor() {
+                    @Override
+                    public void process(Exchange exchange) throws Exception {
+                        if (throwException) {
+                            LOG.info("Will throw exception");
+                            throw new IOException("Route has failed");
+                        } else {
+                            LOG.info("Will NOT throw exception");
+                        }
+                    }
+                })
+                .log("Hystrix processing end: ${threadName}")
+            .end()
+            .log(HYSTRIX_RESPONSE_SHORT_CIRCUITED + " = ${exchangeProperty." + 
HYSTRIX_RESPONSE_SHORT_CIRCUITED + "}")
+            .to("mock:result");
+            
+        }
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/74eaa520/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixCircutExceptionTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixCircutExceptionTest.java
 
b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixCircutExceptionTest.java
deleted file mode 100644
index 641aacd..0000000
--- 
a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixCircutExceptionTest.java
+++ /dev/null
@@ -1,126 +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.processor;
-
-import java.io.IOException;
-import org.apache.camel.CamelExecutionException;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static 
org.apache.camel.component.hystrix.processor.HystrixConstants.HYSTRIX_RESPONSE_SHORT_CIRCUITED;
-import static 
org.apache.camel.component.hystrix.processor.HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION;
-
-/**
- * Hystrix using timeout with Java DSL
- */
-public class HystrixCircutExceptionTest extends CamelTestSupport {
-    public static final Integer REQUEST_VOLUME_THRESHOLD = 4;
-    private static final Logger LOG = 
LoggerFactory.getLogger(HystrixCircutExceptionTest.class);
-    
-    HystrixExceptionRoute route = new HystrixExceptionRoute();
- 
-    
-    @Test
-    public void testCurcuitOpen() throws Exception {
-        LOG.info("testCurcuitOpen start");
-        // failing requests
-        route.throwException = true;
-        for (int i = 0; i < 2 * REQUEST_VOLUME_THRESHOLD; i++) {
-            try {
-                template.asyncRequestBody("direct:start", "Request Body");
-            } catch (CamelExecutionException e) {
-                LOG.info(e.toString());
-            }
-        }
-        Thread.sleep(1500);
-        route.throwException = false;
-        try {
-            template.requestBody("direct:start", "Request Body");
-            LOG.info("Instead curcuit open expected");
-        } catch (CamelExecutionException e) {
-            LOG.info("Curcuit open expected ", e);
-        }
-        
getMockEndpoint("mock:result").expectedPropertyReceived(HYSTRIX_RESPONSE_SHORT_CIRCUITED,
 true);
-        assertMockEndpointsSatisfied();
-        // wait for the circuit to try an other request
-        Thread.sleep(500);
-        for (int i = 0; i < 2 * REQUEST_VOLUME_THRESHOLD; i++) {
-            try {
-                template.requestBody("direct:start", "Request Body");
-                LOG.info("Curcuit has closed");
-            } catch (CamelExecutionException e) {
-                Thread.sleep(i * 100);
-                LOG.info("Curcuit will be closed soon " + e.toString());
-            }
-        }
-        template.requestBody("direct:start", "Request Body");
-        
getMockEndpoint("mock:result").expectedPropertyReceived(HYSTRIX_RESPONSE_SHORT_CIRCUITED,
 false);
-        
getMockEndpoint("mock:result").expectedPropertyReceived(HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION,
 true);
-        assertMockEndpointsSatisfied();
-    }
-    
-    @Override
-    protected RoutesBuilder createRouteBuilder() throws Exception {
-        return route;
-    }
-
- 
-    
-    class HystrixExceptionRoute extends RouteBuilder {
-        volatile boolean throwException = true; 
-        
-        @Override
-        public void configure() throws Exception {
-            from("direct:start")
-            .hystrix()
-                .hystrixConfiguration()
-                    .executionTimeoutInMilliseconds(100)
-                    
.circuitBreakerRequestVolumeThreshold(REQUEST_VOLUME_THRESHOLD)
-                    .metricsRollingStatisticalWindowInMilliseconds(1000)
-                    .circuitBreakerSleepWindowInMilliseconds(2000)
-                .end()
-                .log("Hystrix processing start: ${threadName}")
-                .process(new Processor() {
-                    @Override
-                    public void process(Exchange exchange) throws Exception {
-                        if (throwException) {
-                            LOG.info("Will throw exception");
-                            throw new IOException("Route has failed");
-                            //Thread.sleep(200);
-                        } else {
-                            LOG.info("Will NOT throw exception");
-                        }
-                    }
-                })
-                .log("Hystrix processing end: ${threadName}")
-            .end()
-            .log(HYSTRIX_RESPONSE_SHORT_CIRCUITED
-                    + " = ${exchangeProperty." + 
HYSTRIX_RESPONSE_SHORT_CIRCUITED + "}")
-                .to("mock:result");
-            
-        }
-    }
-}
-

Reply via email to