camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] git commit: CAMEL-7568: OnComplete did not work with rollback
Date Mon, 01 Sep 2014 11:06:44 GMT
CAMEL-7568: OnComplete did not work with rollback

Conflicts:
	camel-core/src/test/java/org/apache/camel/issues/OnCompletionIssueTest.java


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

Branch: refs/heads/camel-2.13.x
Commit: b3df68b6326a9012db126a1d5285fa97dbdd5639
Parents: 7d1cf3d
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Sep 1 13:02:19 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Sep 1 13:06:13 2014 +0200

----------------------------------------------------------------------
 .../camel/processor/OnCompletionProcessor.java  |  8 ++++
 .../camel/issues/OnCompletionIssueTest.java     | 49 ++++++++++++++++----
 2 files changed, 49 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b3df68b6/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
b/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
index 235a513..9b91603 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
@@ -117,6 +117,8 @@ public class OnCompletionProcessor extends ServiceSupport implements AsyncProces
         Object failureHandled = exchange.removeProperty(Exchange.FAILURE_HANDLED);
         Object caught = exchange.removeProperty(Exchange.EXCEPTION_CAUGHT);
         Object errorhandlerHandled = exchange.removeProperty(Exchange.ERRORHANDLER_HANDLED);
+        Object rollbackOnly = exchange.removeProperty(Exchange.ROLLBACK_ONLY);
+        Object rollbackOnlyLast = exchange.removeProperty(Exchange.ROLLBACK_ONLY_LAST);
 
         Exception cause = exchange.getException();
         exchange.setException(null);
@@ -139,6 +141,12 @@ public class OnCompletionProcessor extends ServiceSupport implements
AsyncProces
             if (errorhandlerHandled != null) {
                 exchange.setProperty(Exchange.ERRORHANDLER_HANDLED, errorhandlerHandled);
             }
+            if (rollbackOnly != null) {
+                exchange.setProperty(Exchange.ROLLBACK_ONLY, rollbackOnly);
+            }
+            if (rollbackOnlyLast != null) {
+                exchange.setProperty(Exchange.ROLLBACK_ONLY, rollbackOnlyLast);
+            }
             if (cause != null) {
                 exchange.setException(cause);
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/b3df68b6/camel-core/src/test/java/org/apache/camel/issues/OnCompletionIssueTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/OnCompletionIssueTest.java b/camel-core/src/test/java/org/apache/camel/issues/OnCompletionIssueTest.java
index 5fa5df0..fdb743b 100644
--- a/camel-core/src/test/java/org/apache/camel/issues/OnCompletionIssueTest.java
+++ b/camel-core/src/test/java/org/apache/camel/issues/OnCompletionIssueTest.java
@@ -16,7 +16,9 @@
  */
 package org.apache.camel.issues;
 
+import org.apache.camel.CamelExecutionException;
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.RollbackExchangeException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 
@@ -27,12 +29,30 @@ public class OnCompletionIssueTest extends ContextTestSupport {
         end.expectedMessageCount(1);
 
         MockEndpoint complete = getMockEndpoint("mock:complete");
-        complete.expectedBodiesReceived("finish", "stop", "faulted", "except");
+        complete.expectedBodiesReceivedInAnyOrder("finish", "stop", "ile", "markRollback");
+
+        MockEndpoint failed = getMockEndpoint("mock:failed");
+        failed.expectedBodiesReceivedInAnyOrder("faulted", "npe", "rollback");
 
         template.sendBody("direct:input", "finish");
         template.sendBody("direct:input", "stop");
         template.sendBody("direct:input", "fault");
-        template.sendBody("direct:input", "except");
+        template.sendBody("direct:input", "ile");
+        template.sendBody("direct:input", "markRollback");
+
+        try {
+            template.sendBody("direct:input", "npe");
+            fail("Should have thrown exception");
+        } catch (CamelExecutionException e) {
+            assertEquals("Darn NPE", e.getCause().getMessage());
+        }
+
+        try {
+            template.sendBody("direct:input", "rollback");
+            fail("Should have thrown exception");
+        } catch (CamelExecutionException e) {
+            assertIsInstanceOf(RollbackExchangeException.class, e.getCause());
+        }
 
         setAssertPeriod(2000);
 
@@ -44,12 +64,16 @@ public class OnCompletionIssueTest extends ContextTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                onCompletion()
+                onCompletion().onFailureOnly()
+                    .log("failing ${body}")
+                    .to("mock:failed");
+
+                onCompletion().onCompleteOnly()
                     .log("completing ${body}")
                     .to("mock:complete");
 
                 from("direct:input")
-                    .onException(Exception.class)
+                    .onException(IllegalArgumentException.class)
                         .handled(true)
                     .end()
                     .choice()
@@ -59,12 +83,21 @@ public class OnCompletionIssueTest extends ContextTestSupport {
                         .when(simple("${body} == 'fault'"))
                             .log("faulting")
                             .setFaultBody(constant("faulted"))
-                        .when(simple("${body} == 'except'"))
+                        .when(simple("${body} == 'ile'"))
+                            .log("excepting")
+                            .throwException(new IllegalArgumentException("Exception requested"))
+                        .when(simple("${body} == 'npe'"))
                             .log("excepting")
-                            .throwException(new Exception("Exception requested"))
+                            .throwException(new NullPointerException("Darn NPE"))
+                        .when(simple("${body} == 'rollback'"))
+                            .log("rollback")
+                            .rollback()
+                        .when(simple("${body} == 'markRollback'"))
+                            .log("markRollback")
+                            .markRollbackOnly()
                         .end()
-                        .log("finishing")
-                        .to("mock:end");
+                    .log("finishing")
+                    .to("mock:end");
             }
         };
     }


Mime
View raw message