camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/4] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is using hystrix.
Date Sat, 23 Apr 2016 09:04:38 GMT
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/15404ced
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/15404ced
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/15404ced

Branch: refs/heads/master
Commit: 15404ced23ca63a63a2f98796b8ce54d811e304e
Parents: 7cb35c4
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Apr 23 10:48:21 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Apr 23 10:48:21 2016 +0200

----------------------------------------------------------------------
 .../camel/component/hystrix/HystrixConstants.java      |  7 +++++++
 .../component/hystrix/processor/HystrixProcessor.java  | 13 +++++++++++++
 .../processor/BlueprintHystrixRouteFallbackTest.java   |  3 +++
 .../hystrix/processor/BlueprintHystrixRouteOkTest.java |  3 +++
 .../hystrix/processor/HystrixRouteFallbackTest.java    |  3 +++
 .../processor/HystrixRouteFallbackViaNetworkTest.java  |  3 +++
 .../hystrix/processor/HystrixRouteOkTest.java          |  3 +++
 .../processor/SpringHystrixRouteFallbackTest.java      |  3 +++
 .../hystrix/processor/SpringHystrixRouteOkTest.java    |  3 +++
 9 files changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConstants.java
b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConstants.java
index eeefe09..55f3b9b 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConstants.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConstants.java
@@ -18,6 +18,13 @@ package org.apache.camel.component.hystrix;
 
 public interface HystrixConstants {
 
+    // Hystrix EIP response properties
+    String HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION = "CamelHystrixSuccessfulExecution";
+    String HYSTRIX_RESPONSE_FROM_FALLBACK = "CamelHystrixResponseFromFallback";
+    String HYSTRIX_RESPONSE_SHORT_CIRCUITED = "CamelHystrixResponseShortCircuited";
+    String HYSTRIX_RESPONSE_TIMED_OUT = "CamelHystrixResponseTimedOut";
+    String HYSTRIX_RESPONSE_REJECTED = "CamelHystrixResponseRejected";
+
     // in message header
     String CAMEL_HYSTRIX_RUN_ENDPOINT = "CamelHystrixRunEndpoint";
     String CAMEL_HYSTRIX_FALLBACK_ENDPOINT = "CamelHystrixFallbackEndpoint";

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
index 15733e7..85f3f10 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
@@ -30,6 +30,7 @@ import org.apache.camel.Navigate;
 import org.apache.camel.Processor;
 import org.apache.camel.api.management.ManagedAttribute;
 import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.spi.IdAware;
 import org.apache.camel.support.ServiceSupport;
 import org.apache.camel.util.AsyncProcessorHelper;
@@ -194,6 +195,10 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
             }
             HystrixProcessorCommand command = new HystrixProcessorCommand(setter, exchange,
processor, fallback, fallbackCommand);
             command.execute();
+
+            // enrich exchange with details from hystrix about the command execution
+            commandResponse(exchange, command);
+
         } catch (Throwable e) {
             exchange.setException(e);
         }
@@ -203,6 +208,14 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
         return true;
     }
 
+    private void commandResponse(Exchange exchange, HystrixCommand command) {
+        exchange.setProperty(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION, command.isSuccessfulExecution());
+        exchange.setProperty(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK, command.isResponseFromFallback());
+        exchange.setProperty(HystrixConstants.HYSTRIX_RESPONSE_SHORT_CIRCUITED, command.isResponseShortCircuited());
+        exchange.setProperty(HystrixConstants.HYSTRIX_RESPONSE_TIMED_OUT, command.isResponseTimedOut());
+        exchange.setProperty(HystrixConstants.HYSTRIX_RESPONSE_REJECTED, command.isResponseRejected());
+    }
+
     @Override
     protected void doStart() throws Exception {
         // noop

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteFallbackTest.java
b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteFallbackTest.java
index 5ecb230..861a2ed 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteFallbackTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteFallbackTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.hystrix.processor;
 
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
 import org.junit.Test;
 
@@ -29,6 +30,8 @@ public class BlueprintHystrixRouteFallbackTest extends CamelBlueprintTestSupport
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION,
false);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK,
true);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteOkTest.java
b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteOkTest.java
index 044b326..21263fd 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteOkTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteOkTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.hystrix.processor;
 
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
 import org.junit.Test;
 
@@ -29,6 +30,8 @@ public class BlueprintHystrixRouteOkTest extends CamelBlueprintTestSupport
{
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION,
true);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK,
false);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
index 63f194d..8efe089 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.hystrix.processor;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -25,6 +26,8 @@ public class HystrixRouteFallbackTest extends CamelTestSupport {
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION,
false);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK,
true);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackViaNetworkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackViaNetworkTest.java
b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackViaNetworkTest.java
index caf7b69..a262813 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackViaNetworkTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackViaNetworkTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.hystrix.processor;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -25,6 +26,8 @@ public class HystrixRouteFallbackViaNetworkTest extends CamelTestSupport
{
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION,
false);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK,
true);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
index 4e03eec..a56c405 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.hystrix.processor;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -25,6 +26,8 @@ public class HystrixRouteOkTest extends CamelTestSupport {
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION,
true);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK,
false);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java
b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java
index 5f6064b..4bbff0e 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.hystrix.processor;
 
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.spring.CamelSpringTestSupport;
 import org.junit.Test;
 import org.springframework.context.support.AbstractApplicationContext;
@@ -31,6 +32,8 @@ public class SpringHystrixRouteFallbackTest extends CamelSpringTestSupport
{
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION,
false);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK,
true);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java
b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java
index fcffb27..5f408de 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.hystrix.processor;
 
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.spring.CamelSpringTestSupport;
 import org.junit.Test;
 import org.springframework.context.support.AbstractApplicationContext;
@@ -31,6 +32,8 @@ public class SpringHystrixRouteOkTest extends CamelSpringTestSupport {
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION,
true);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK,
false);
 
         template.sendBody("direct:start", "Hello World");
 


Mime
View raw message