You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2014/05/21 10:25:46 UTC
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.
Repository: camel
Updated Branches:
refs/heads/master 583af6954 -> b89a7597e
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/b89a7597
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b89a7597
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b89a7597
Branch: refs/heads/master
Commit: b89a7597eb1a5a14956399c2cc93c85318e2edf3
Parents: 583af69
Author: Babak Vahdat <bv...@apache.org>
Authored: Wed May 21 10:25:39 2014 +0200
Committer: Babak Vahdat <bv...@apache.org>
Committed: Wed May 21 10:25:39 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/b89a7597/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/b89a7597/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>");
}
});