camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvah...@apache.org
Subject git commit: Added tests verifying the IN headers get propagated through the Synchronization callback API. Also cleaned-up SedaUnitOfWorkTest a bit to NOT make use of static member variables for test assertions.
Date Wed, 21 May 2014 08:29:49 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.13.x 14469f35b -> 5acd9b2fd


Added tests verifying the IN headers get propagated through the Synchronization callback API.
Also cleaned-up SedaUnitOfWorkTest a bit to NOT make use of static member variables for test
assertions.


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

Branch: refs/heads/camel-2.13.x
Commit: 5acd9b2fd204b903f9ffe98480fb3233793ffca5
Parents: 14469f3
Author: Babak Vahdat <bvahdat@apache.org>
Authored: Wed May 21 10:25:39 2014 +0200
Committer: Babak Vahdat <bvahdat@apache.org>
Committed: Wed May 21 10:27:32 2014 +0200

----------------------------------------------------------------------
 .../component/seda/SedaUnitOfWorkTest.java      | 45 ++++++++++++++++----
 .../apache/camel/processor/UnitOfWorkTest.java  |  4 ++
 2 files changed, 40 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5acd9b2f/camel-core/src/test/java/org/apache/camel/component/seda/SedaUnitOfWorkTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/seda/SedaUnitOfWorkTest.java
b/camel-core/src/test/java/org/apache/camel/component/seda/SedaUnitOfWorkTest.java
index cd00fec..f8c0aa1 100644
--- a/camel-core/src/test/java/org/apache/camel/component/seda/SedaUnitOfWorkTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/seda/SedaUnitOfWorkTest.java
@@ -32,8 +32,10 @@ import org.apache.camel.spi.Synchronization;
  */
 public class SedaUnitOfWorkTest extends ContextTestSupport {
 
-    private static volatile String sync;
-    private static volatile String lastOne;
+    private volatile Object foo;
+    private volatile Object kaboom;
+    private volatile String sync;
+    private volatile String lastOne;
 
     public void testSedaUOW() throws Exception {
         NotifyBuilder notify = new NotifyBuilder(context).whenDone(2).create();
@@ -41,13 +43,26 @@ public class SedaUnitOfWorkTest extends ContextTestSupport {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "bar");
 
         assertMockEndpointsSatisfied();
         notify.matchesMockWaitTime();
 
         assertEquals("onCompleteA", sync);
         assertEquals("onCompleteA", lastOne);
+        assertEquals("Should have propagated the header inside the Synchronization.onComplete()
callback", "bar", foo);
+    }
+
+    public void testSedaUOWWithException() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(2).create();
+
+        template.sendBodyAndHeader("direct:start", "Hello World", "kaboom", "yes");
+
+        notify.matchesMockWaitTime();
+
+        assertEquals("onFailureA", sync);
+        assertEquals("onFailureA", lastOne);
+        assertEquals("Should have propagated the header inside the Synchronization.onFailure()
callback", "yes", kaboom);
     }
 
     @Override
@@ -58,7 +73,7 @@ public class SedaUnitOfWorkTest extends ContextTestSupport {
                 context.setTracing(true);
 
                 from("direct:start")
-                        .process(new MyUOWProcessor("A"))
+                        .process(new MyUOWProcessor(SedaUnitOfWorkTest.this, "A"))
                         .to("seda:foo");
 
                 from("seda:foo")
@@ -72,6 +87,14 @@ public class SedaUnitOfWorkTest extends ContextTestSupport {
                                 lastOne = "processor";
                             }
                         })
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {   

+                                if ("yes".equals(exchange.getIn().getHeader("kaboom"))) {
+                                    throw new IllegalStateException("kaboom done!");
+                                }
+                                lastOne = "processor2";
+                            }
+                        })
                         .to("mock:result");
             }
         };
@@ -79,22 +102,26 @@ public class SedaUnitOfWorkTest extends ContextTestSupport {
 
     private static final class MyUOWProcessor implements Processor {
 
+        private SedaUnitOfWorkTest test;
         private String id;
 
-        private MyUOWProcessor(String id) {
+        private MyUOWProcessor(SedaUnitOfWorkTest test, String id) {
+            this.test = test;
             this.id = id;
         }
 
         public void process(Exchange exchange) throws Exception {
             exchange.getUnitOfWork().addSynchronization(new Synchronization() {
                 public void onComplete(Exchange exchange) {
-                    sync = "onComplete" + id;
-                    lastOne = sync;
+                    test.sync = "onComplete" + id;
+                    test.lastOne = test.sync;
+                    test.foo = exchange.getIn().getHeader("foo");
                 }
 
                 public void onFailure(Exchange exchange) {
-                    sync = "onFailure" + id;
-                    lastOne = sync;
+                    test.sync = "onFailure" + id;
+                    test.lastOne = test.sync;
+                    test.kaboom = exchange.getIn().getHeader("kaboom");
                 }
             });
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/5acd9b2f/camel-core/src/test/java/org/apache/camel/processor/UnitOfWorkTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/UnitOfWorkTest.java b/camel-core/src/test/java/org/apache/camel/processor/UnitOfWorkTest.java
index 736507e..bf84501 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/UnitOfWorkTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/UnitOfWorkTest.java
@@ -41,6 +41,7 @@ public class UnitOfWorkTest extends ContextTestSupport {
         assertTrue("Exchange did not complete.", doneLatch.await(5, TimeUnit.SECONDS));
         assertNull("Should not have failed", failed);
         assertNotNull("Should have received completed notification", completed);
+        assertEquals("Should have propagated the header inside the Synchronization.onComplete()
callback", "bar", completed.getIn().getHeader("foo"));
 
         log.info("Received completed: " + completed);
     }
@@ -51,6 +52,7 @@ public class UnitOfWorkTest extends ContextTestSupport {
         assertTrue("Exchange did not complete.", doneLatch.await(5, TimeUnit.SECONDS));
         assertNull("Should not have completed", completed);
         assertNotNull("Should have received failed notification", failed);
+        assertEquals("Should have propagated the header inside the Synchronization.onFailure()
callback", "bar", failed.getIn().getHeader("foo"));
 
         log.info("Received fail: " + failed);
     }
@@ -61,6 +63,7 @@ public class UnitOfWorkTest extends ContextTestSupport {
         assertTrue("Exchange did not complete.", doneLatch.await(5, TimeUnit.SECONDS));
         assertNull("Should not have completed", completed);
         assertNotNull("Should have received failed notification", failed);
+        assertEquals("Should have propagated the header inside the Synchronization.onFailure()
callback", "bar", failed.getIn().getHeader("foo"));
 
         log.info("Received fail: " + failed);
     }
@@ -86,6 +89,7 @@ public class UnitOfWorkTest extends ContextTestSupport {
         
         template.send(uri, new Processor() {
             public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader("foo", "bar");
                 exchange.getIn().setBody("<hello>world!</hello>");
             }
         });


Mime
View raw message