Author: davsclaus
Date: Wed Jun 30 18:08:49 2010
New Revision: 959391
URL: http://svn.apache.org/viewvc?rev=959391&view=rev
Log:
CAMEL-2877: transacted Exchange must be routed synchronously so the transaction
manager can orhestrate the TX in the same thread context (required by Spring
TM).
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncComponent.java
(with props)
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncEndpoint.java
(with props)
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncProducer.java
(with props)
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.java
(with props)
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransactedTest.java
- copied, changed from r959281,
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/TransactedPipelineTest.java
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.xml
(with props)
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransactedTest.xml
- copied, changed from r959281,
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/TransactedPipelineTest.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/AsyncProcessor.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/LoadBalancerDefinition.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ChoiceProcessor.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateAsyncProcessor.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/InterceptorToAsyncProcessorBridge.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/QueueLoadBalancer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/AsyncProcessorHelper.java
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTX2Test.java
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXRollback2Test.java
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXRollbackTest.java
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXTest.java
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/AsyncProcessor.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/AsyncProcessor.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/AsyncProcessor.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/AsyncProcessor.java
Wed Jun 30 18:08:49 2010
@@ -23,6 +23,11 @@ package org.apache.camel;
* Any processor can be coerced to have an {...@link AsyncProcessor} interface
by using the
* {...@link
org.apache.camel.impl.converter.AsyncProcessorTypeConverter#convert
AsyncProcessorTypeConverter.covert}
* method.
+ * <p/>
+ * <b>Important:<b/> Use the {...@link
org.apache.camel.util.AsyncProcessorHelper#process(AsyncProcessor, Exchange,
AsyncCallback)}
+ * method to invoke the process method, which ensure Camel have a chance to
interweave and invoke it in a reliable manner.
+ * For example when using transactions all the invocations has to occur in
synchronous manner to ensure the transaction
+ * work is done in the same thread, which is required by Spring
TransactionMananger.
*
* @version $Revision$
*/
@@ -39,6 +44,7 @@ public interface AsyncProcessor extends
* If the exchange is completed synchronously, then the
callback is also invoked synchronously.
* The callback should therefore be careful of starting
recursive loop.
* @return (doneSync) <tt>true</tt> to continue execute synchronously,
<tt>false</tt> to continue being executed asynchronously
+ * @see {...@link
org.apache.camel.util.AsyncProcessorHelper#process(AsyncProcessor, Exchange,
AsyncCallback)}
*/
boolean process(Exchange exchange, AsyncCallback callback);
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java
Wed Jun 30 18:08:49 2010
@@ -22,6 +22,7 @@ import org.apache.camel.CamelExchangeExc
import org.apache.camel.Exchange;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.impl.converter.AsyncProcessorTypeConverter;
+import org.apache.camel.util.AsyncProcessorHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -57,7 +58,7 @@ public class DirectProducer extends Defa
return true;
} else {
AsyncProcessor processor =
AsyncProcessorTypeConverter.convert(endpoint.getConsumer().getProcessor());
- return processor.process(exchange, callback);
+ return AsyncProcessorHelper.process(processor, exchange, callback);
}
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
Wed Jun 30 18:08:49 2010
@@ -35,6 +35,7 @@ import org.apache.camel.impl.converter.A
import org.apache.camel.processor.MulticastProcessor;
import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.spi.ShutdownAware;
+import org.apache.camel.util.AsyncProcessorHelper;
import org.apache.camel.util.ServiceHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -159,14 +160,14 @@ public class SedaConsumer extends Servic
MulticastProcessor mp = getMulticastProcessor();
// and use the asynchronous routing engine to support it
- mp.process(exchange, new AsyncCallback() {
+ AsyncProcessorHelper.process(mp, exchange, new AsyncCallback() {
public void done(boolean doneSync) {
// noop
}
});
} else {
// use the regular processor and use the asynchronous routing
engine to support it
- processor.process(exchange, new AsyncCallback() {
+ AsyncProcessorHelper.process(processor, exchange, new
AsyncCallback() {
public void done(boolean doneSync) {
// noop
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/LoadBalancerDefinition.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/LoadBalancerDefinition.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/model/LoadBalancerDefinition.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/model/LoadBalancerDefinition.java
Wed Jun 30 18:08:49 2010
@@ -27,6 +27,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.processor.loadbalancer.LoadBalancer;
import org.apache.camel.spi.RouteContext;
+import org.apache.camel.util.AsyncProcessorHelper;
import org.apache.camel.util.IntrospectionSupport;
import org.apache.camel.util.ObjectHelper;
@@ -131,7 +132,7 @@ public class LoadBalancerDefinition exte
public boolean process(Exchange exchange, final AsyncCallback callback) {
ObjectHelper.notNull(loadBalancer, "loadBalancer");
- return loadBalancer.process(exchange, new AsyncCallback() {
+ return AsyncProcessorHelper.process(loadBalancer, exchange, new
AsyncCallback() {
public void done(boolean doneSync) {
// only handle the async case
if (doneSync) {
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ChoiceProcessor.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ChoiceProcessor.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ChoiceProcessor.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ChoiceProcessor.java
Wed Jun 30 18:08:49 2010
@@ -73,7 +73,7 @@ public class ChoiceProcessor extends Ser
}
}
if (otherwise != null) {
- return otherwise.process(exchange, callback);
+ return AsyncProcessorHelper.process(otherwise, exchange, callback);
} else {
callback.done(true);
return true;
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateAsyncProcessor.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateAsyncProcessor.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateAsyncProcessor.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateAsyncProcessor.java
Wed Jun 30 18:08:49 2010
@@ -95,7 +95,7 @@ public class DelegateAsyncProcessor exte
callback.done(true);
return true;
}
- return processor.process(exchange, callback);
+ return AsyncProcessorHelper.process(processor, exchange, callback);
}
public boolean hasNext() {
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/InterceptorToAsyncProcessorBridge.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/InterceptorToAsyncProcessorBridge.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/InterceptorToAsyncProcessorBridge.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/InterceptorToAsyncProcessorBridge.java
Wed Jun 30 18:08:49 2010
@@ -22,6 +22,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.impl.ServiceSupport;
import org.apache.camel.impl.converter.AsyncProcessorTypeConverter;
+import org.apache.camel.util.AsyncProcessorHelper;
/**
* A bridge to have regular interceptors implemented as {...@link
org.apache.camel.Processor}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
Wed Jun 30 18:08:49 2010
@@ -325,7 +325,7 @@ public class MulticastProcessor extends
// let the prepared process it, remember to begin the exchange pair
AsyncProcessor async =
AsyncProcessorTypeConverter.convert(processor);
pair.begin();
- sync = async.process(exchange, new AsyncCallback() {
+ sync = AsyncProcessorHelper.process(async, exchange, new
AsyncCallback() {
public void done(boolean doneSync) {
// we are done with the exchange pair
pair.done();
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java
Wed Jun 30 18:08:49 2010
@@ -77,6 +77,8 @@ public class Pipeline extends MulticastP
AsyncProcessor async =
AsyncProcessorTypeConverter.convert(processor);
boolean sync = process(exchange, nextExchange, callback,
processors, async);
+ // are we transacted
+
// continue as long its being processed synchronously
if (!sync) {
if (LOG.isTraceEnabled()) {
@@ -140,7 +142,7 @@ public class Pipeline extends MulticastP
// implement asynchronous routing logic in callback so we can have the
callback being
// triggered and then continue routing where we left
- boolean sync = asyncProcessor.process(exchange, new AsyncCallback() {
+ boolean sync = AsyncProcessorHelper.process(asyncProcessor, exchange,
new AsyncCallback() {
public void done(boolean doneSync) {
// we only have to handle async completion of the pipeline
if (doneSync) {
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
Wed Jun 30 18:08:49 2010
@@ -113,7 +113,7 @@ public class RecipientList extends Servi
rlp.setIgnoreInvalidEndpoints(isIgnoreInvalidEndpoints());
// now let the multicast process the exchange
- return rlp.process(exchange, callback);
+ return AsyncProcessorHelper.process(rlp, exchange, callback);
}
protected Endpoint resolveEndpoint(Exchange exchange, Object recipient) {
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
Wed Jun 30 18:08:49 2010
@@ -108,7 +108,7 @@ public abstract class RedeliveryErrorHan
}
// process the exchange (also redelivery)
- boolean sync = outputAsync.process(exchange, new AsyncCallback() {
+ boolean sync = AsyncProcessorHelper.process(outputAsync, exchange,
new AsyncCallback() {
public void done(boolean sync) {
if (log.isTraceEnabled()) {
log.trace("Redelivering exchangeId: " +
exchange.getExchangeId() + " done");
@@ -223,7 +223,7 @@ public abstract class RedeliveryErrorHan
}
// process the exchange (also redelivery)
- boolean sync = outputAsync.process(exchange, new AsyncCallback() {
+ boolean sync = AsyncProcessorHelper.process(outputAsync, exchange,
new AsyncCallback() {
public void done(boolean sync) {
// this callback should only handle the async case
if (sync) {
@@ -512,7 +512,7 @@ public abstract class RedeliveryErrorHan
// the failure processor could also be asynchronous
AsyncProcessor afp =
AsyncProcessorTypeConverter.convert(processor);
- sync = afp.process(exchange, new AsyncCallback() {
+ sync = AsyncProcessorHelper.process(afp, exchange, new
AsyncCallback() {
public void done(boolean sync) {
if (log.isTraceEnabled()) {
log.trace("Failure processor done: " + processor + "
processing Exchange: " + exchange);
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
Wed Jun 30 18:08:49 2010
@@ -258,7 +258,7 @@ public class RoutingSlip extends Service
ExchangePattern exchangePattern,
final AsyncCallback callback) {
// set property which endpoint we send to
exchange.setProperty(Exchange.TO_ENDPOINT,
producer.getEndpoint().getEndpointUri());
- boolean sync = asyncProducer.process(exchange, new
AsyncCallback() {
+ boolean sync = AsyncProcessorHelper.process(asyncProducer,
exchange, new AsyncCallback() {
public void done(boolean doneSync) {
// we only have to handle async completion of the
routing slip
if (doneSync) {
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
Wed Jun 30 18:08:49 2010
@@ -28,7 +28,7 @@ import org.apache.camel.ProducerCallback
import org.apache.camel.impl.InterceptSendToEndpoint;
import org.apache.camel.impl.ProducerCache;
import org.apache.camel.impl.ServiceSupport;
-import org.apache.camel.impl.converter.AsyncProcessorTypeConverter;
+import org.apache.camel.util.AsyncProcessorHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ServiceHelper;
import org.apache.commons.logging.Log;
@@ -101,7 +101,7 @@ public class SendProcessor extends Servi
if (log.isDebugEnabled()) {
log.debug(">>>> " + destination + " " + exchange);
}
- return asyncProducer.process(exchange, callback);
+ return AsyncProcessorHelper.process(asyncProducer, exchange,
callback);
}
});
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
Wed Jun 30 18:08:49 2010
@@ -108,7 +108,7 @@ public class TryProcessor extends Servic
// implement asynchronous routing logic in callback so we can have the
callback being
// triggered and then continue routing where we left
- boolean sync = processor.process(exchange, new AsyncCallback() {
+ boolean sync = AsyncProcessorHelper.process(processor, exchange, new
AsyncCallback() {
public void done(boolean doneSync) {
// we only have to handle async completion of the pipeline
if (doneSync) {
@@ -238,7 +238,7 @@ public class TryProcessor extends Servic
// this processor just lookup the right catch clause to use
and then let the
// HandleDoCatchProcessor do all the hard work (separate of
concerns)
HandleDoCatchProcessor cool = new
HandleDoCatchProcessor(processor);
- return cool.process(exchange, callback);
+ return AsyncProcessorHelper.process(cool, exchange, callback);
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("This TryProcessor does not catch the exception:
" + e.getClass().getName() + " caused by: " + e.getMessage());
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
Wed Jun 30 18:08:49 2010
@@ -25,6 +25,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.impl.converter.AsyncProcessorTypeConverter;
import org.apache.camel.processor.Traceable;
+import org.apache.camel.util.AsyncProcessorHelper;
import org.apache.camel.util.ObjectHelper;
/**
@@ -208,7 +209,7 @@ public class FailOverLoadBalancer extend
}
AsyncProcessor albp = AsyncProcessorTypeConverter.convert(processor);
- return albp.process(exchange, new FailOverAsyncCallback(exchange,
attempts, index, callback, processors));
+ return AsyncProcessorHelper.process(albp, exchange, new
FailOverAsyncCallback(exchange, attempts, index, callback, processors));
}
/**
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/QueueLoadBalancer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/QueueLoadBalancer.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/QueueLoadBalancer.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/QueueLoadBalancer.java
Wed Jun 30 18:08:49 2010
@@ -45,7 +45,7 @@ public abstract class QueueLoadBalancer
throw new IllegalStateException("No processors could be chosen to
process " + exchange);
} else {
AsyncProcessor albp =
AsyncProcessorTypeConverter.convert(processor);
- sync = albp.process(exchange, new AsyncCallback() {
+ sync = AsyncProcessorHelper.process(albp, exchange, new
AsyncCallback() {
public void done(boolean doneSync) {
// only handle the async case
if (doneSync) {
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/util/AsyncProcessorHelper.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/AsyncProcessorHelper.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/util/AsyncProcessorHelper.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/util/AsyncProcessorHelper.java
Wed Jun 30 18:08:49 2010
@@ -40,6 +40,44 @@ public final class AsyncProcessorHelper
}
/**
+ * Calls the async version of the processor's process method.
+ * <p/>
+ * This implementation supports transacted {...@link Exchange}s which
ensure those are run in a synchronous fashion.
+ * See more details at {...@link org.apache.camel.AsyncProcessor}.
+ *
+ * @param processor the processor
+ * @param exchange the exchange
+ * @param callback the callback
+ * @return <tt>true</tt> to continue execute synchronously, <tt>false</tt>
to continue being executed asynchronously
+ */
+ public static boolean process(final AsyncProcessor processor, final
Exchange exchange, final AsyncCallback callback) {
+ boolean sync;
+
+ if (exchange.isTransacted()) {
+ // must be synchronized for transacted exchanges
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Transacted Exchange must be routed synchronously
for exchangeId: " + exchange.getExchangeId() + " -> " + exchange);
+ }
+ try {
+ process(processor, exchange);
+ } catch (Throwable e) {
+ exchange.setException(e);
+ }
+ callback.done(true);
+ sync = true;
+ } else {
+ // we support asynchronous routing so invoke it
+ sync = processor.process(exchange, callback);
+ }
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Exchange processed and is continued routed " + (sync ?
"synchronously" : "asynchronously")
+ + " for exchangeId: " + exchange.getExchangeId() + " -> " +
exchange);
+ }
+ return sync;
+ }
+
+ /**
* Calls the async version of the processor's process method and waits
* for it to complete before returning. This can be used by {...@link
AsyncProcessor}
* objects to implement their sync version of the process method.
Modified:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTX2Test.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTX2Test.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTX2Test.java
(original)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTX2Test.java
Wed Jun 30 18:08:49 2010
@@ -54,7 +54,8 @@ public class AsyncEndpointJmsTX2Test ext
assertMockEndpointsSatisfied();
- assertFalse("Should use different threads",
beforeThreadName.equalsIgnoreCase(afterThreadName));
+ // we are synchronous due to TX so the we are using same threads
during the routing
+ assertTrue("Should use same threads",
beforeThreadName.equalsIgnoreCase(afterThreadName));
}
@Override
Modified:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXRollback2Test.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXRollback2Test.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXRollback2Test.java
(original)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXRollback2Test.java
Wed Jun 30 18:08:49 2010
@@ -58,7 +58,8 @@ public class AsyncEndpointJmsTXRollback2
assertMockEndpointsSatisfied();
- assertFalse("Should use different threads",
beforeThreadName.equalsIgnoreCase(afterThreadName));
+ // we are synchronous due to TX so the we are using same threads
during the routing
+ assertTrue("Should use same threads",
beforeThreadName.equalsIgnoreCase(afterThreadName));
}
@Override
Modified:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXRollbackTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXRollbackTest.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXRollbackTest.java
(original)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXRollbackTest.java
Wed Jun 30 18:08:49 2010
@@ -58,7 +58,8 @@ public class AsyncEndpointJmsTXRollbackT
assertMockEndpointsSatisfied();
- assertFalse("Should use different threads",
beforeThreadName.equalsIgnoreCase(afterThreadName));
+ // we are synchronous due to TX so the we are using same threads
during the routing
+ assertTrue("Should use same threads",
beforeThreadName.equalsIgnoreCase(afterThreadName));
}
@Override
Modified:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXTest.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXTest.java
(original)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/AsyncEndpointJmsTXTest.java
Wed Jun 30 18:08:49 2010
@@ -54,7 +54,8 @@ public class AsyncEndpointJmsTXTest exte
assertMockEndpointsSatisfied();
- assertFalse("Should use different threads",
beforeThreadName.equalsIgnoreCase(afterThreadName));
+ // we are synchronous due to TX so the we are using same threads
during the routing
+ assertTrue("Should use same threads",
beforeThreadName.equalsIgnoreCase(afterThreadName));
}
@Override
Modified:
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java?rev=959391&r1=959390&r2=959391&view=diff
==============================================================================
---
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
(original)
+++
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
Wed Jun 30 18:08:49 2010
@@ -191,41 +191,18 @@ public class TransactionErrorHandler ext
* @param exchange the exchange
*/
protected void processByErrorHandler(final Exchange exchange) {
- final CountDownLatch latch = new CountDownLatch(1);
- boolean sync = super.process(exchange, new AsyncCallback() {
+ // must invoke the async method with empty callback to have it invoke
the
+ // super.processErrorHandler
+ // we are transacted so we have to route synchronously so don't worry
about returned
+ // value from the process method
+ // and the camel routing engine will detect this is an transacted
Exchange and route
+ // it fully synchronously so we don't have to wait here if we hit an
async endpoint
+ // all that is taken care of in the camel-core
+ super.process(exchange, new AsyncCallback() {
public void done(boolean doneSync) {
- if (!doneSync) {
- if (log.isTraceEnabled()) {
- log.trace("Asynchronous callback received for
exchangeId: " + exchange.getExchangeId());
- }
- latch.countDown();
- }
- }
-
- @Override
- public String toString() {
- return "Done TransactionErrorHandler";
+ // noop
}
});
- if (!sync) {
- if (log.isTraceEnabled()) {
- log.trace("Waiting for asynchronous callback before continuing
for exchangeId: " + exchange.getExchangeId() + " -> " + exchange);
- }
- try {
- latch.await();
- } catch (InterruptedException e) {
- if (log.isDebugEnabled()) {
- log.debug("Interrupted while waiting for asynchronous
callback for exchangeId: " + exchange.getExchangeId(), e);
- }
- // we may be shutting down etc., so set exception
- if (exchange.getException() == null) {
- exchange.setException(e);
- }
- }
- if (log.isTraceEnabled()) {
- log.trace("Asynchronous callback received, will continue
routing exchangeId: " + exchange.getExchangeId() + " -> " + exchange);
- }
- }
}
private static String propagationBehaviorToString(int propagationBehavior)
{
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncComponent.java?rev=959391&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncComponent.java
(added)
+++
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncComponent.java
Wed Jun 30 18:08:49 2010
@@ -0,0 +1,37 @@
+/**
+ * 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.itest.async;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * @version $Revision$
+ */
+public class MyAsyncComponent extends DefaultComponent {
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
+ MyAsyncEndpoint answer = new MyAsyncEndpoint(uri, this);
+ answer.setReply(remaining);
+ setProperties(answer, parameters);
+ return answer;
+ }
+
+}
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncComponent.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncEndpoint.java?rev=959391&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncEndpoint.java
(added)
+++
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncEndpoint.java
Wed Jun 30 18:08:49 2010
@@ -0,0 +1,73 @@
+/**
+ * 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.itest.async;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class MyAsyncEndpoint extends DefaultEndpoint {
+
+ private String reply;
+ private long delay = 1000;
+ private int failFirstAttempts;
+
+ public MyAsyncEndpoint(String endpointUri, Component component) {
+ super(endpointUri, component);
+ }
+
+ public Producer createProducer() throws Exception {
+ return new MyAsyncProducer(this);
+ }
+
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("Consumer not supported");
+ }
+
+ public boolean isSingleton() {
+ return false;
+ }
+
+ public String getReply() {
+ return reply;
+ }
+
+ public void setReply(String reply) {
+ this.reply = reply;
+ }
+
+ public long getDelay() {
+ return delay;
+ }
+
+ public void setDelay(long delay) {
+ this.delay = delay;
+ }
+
+ public int getFailFirstAttempts() {
+ return failFirstAttempts;
+ }
+
+ public void setFailFirstAttempts(int failFirstAttempts) {
+ this.failFirstAttempts = failFirstAttempts;
+ }
+}
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncEndpoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncProducer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncProducer.java?rev=959391&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncProducer.java
(added)
+++
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncProducer.java
Wed Jun 30 18:08:49 2010
@@ -0,0 +1,77 @@
+/**
+ * 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.itest.async;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultAsyncProducer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Revision$
+ */
+public class MyAsyncProducer extends DefaultAsyncProducer {
+
+ private static final Log LOG = LogFactory.getLog(MyAsyncProducer.class);
+ private final ExecutorService executor = Executors.newCachedThreadPool();
+ private final AtomicInteger counter = new AtomicInteger();
+
+ public MyAsyncProducer(MyAsyncEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ public MyAsyncEndpoint getEndpoint() {
+ return (MyAsyncEndpoint) super.getEndpoint();
+ }
+
+ public boolean process(final Exchange exchange, final AsyncCallback
callback) {
+ executor.submit(new Callable<Object>() {
+ public Object call() throws Exception {
+ LOG.info("Simulating a task which takes " +
getEndpoint().getDelay() + " millis to reply");
+ Thread.sleep(getEndpoint().getDelay());
+
+ int count = counter.incrementAndGet();
+ if (getEndpoint().getFailFirstAttempts() >= count) {
+ LOG.info("Simulating a failure at attempt " + count);
+ exchange.setException(new
CamelExchangeException("Simulated error at attempt " + count, exchange));
+ } else {
+ String reply = getEndpoint().getReply();
+ exchange.getOut().setBody(reply);
+ // propagate headers
+
exchange.getOut().setHeaders(exchange.getIn().getHeaders());
+ LOG.info("Setting reply " + reply);
+ }
+
+ LOG.info("Callback done(false)");
+ callback.done(false);
+ return null;
+ }
+ });
+
+ // indicate from this point forward its being routed asynchronously
+ LOG.info("Task submitted, now tell Camel routing engine to that this
Exchange is being continued asynchronously");
+ return false;
+ }
+
+}
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncProducer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.java?rev=959391&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.java
(added)
+++
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.java
Wed Jun 30 18:08:49 2010
@@ -0,0 +1,97 @@
+/**
+ * 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.itest.ibatis;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class AsyncEndpointTransacted2Test extends CamelSpringTestSupport {
+
+ private DummyTable table;
+
+ @EndpointInject(uri = "direct:start")
+ ProducerTemplate producer;
+
+ @EndpointInject(uri = "mock:end")
+ private MockEndpoint end;
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.xml");
+ }
+
+ @Before
+ public void createTable() {
+ table = context.getRegistry().lookup("table", DummyTable.class);
+ table.create();
+ }
+
+ @After
+ public void dropTable() {
+ table.drop();
+ }
+
+ @Test
+ public void testAsyncEndpointOK() throws InterruptedException {
+ end.expectedBodiesReceived("Bye Camel");
+
+ producer.sendBody(3);
+
+ Collection<Integer> values = table.values();
+ assertEquals(2, values.size());
+
+ Iterator<Integer> it = values.iterator();
+ assertEquals(Integer.valueOf(3), it.next());
+ assertEquals(Integer.valueOf(4), it.next());
+
+ end.assertIsSatisfied();
+ }
+
+ @Test
+ public void testAsyncEndpointRollback() {
+ end.whenAnyExchangeReceived(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ throw new IllegalArgumentException("Damn");
+ }
+ });
+
+ try {
+ producer.sendBody(3);
+ fail("Should have thrown exception");
+ } catch (CamelExecutionException e) {
+ assertIsInstanceOf(IllegalArgumentException.class,
e.getCause().getCause());
+ assertEquals(0, table.values().size());
+ }
+ }
+
+}
\ No newline at end of file
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransactedTest.java
(from r959281,
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/TransactedPipelineTest.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransactedTest.java?p2=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransactedTest.java&p1=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/TransactedPipelineTest.java&r1=959281&r2=959391&rev=959391&view=diff
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/TransactedPipelineTest.java
(original)
+++
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ibatis/AsyncEndpointTransactedTest.java
Wed Jun 30 18:08:49 2010
@@ -32,17 +32,9 @@ import org.springframework.context.suppo
/**
* @version $Revision$
*/
-public class TransactedPipelineTest extends CamelSpringTestSupport {
+public class AsyncEndpointTransactedTest extends CamelSpringTestSupport {
- private class MyException extends Exception {
- private static final long serialVersionUID = -221148660533176643L;
-
- public MyException() {
- super("my exception");
- }
- }
-
- DummyTable table;
+ private DummyTable table;
@EndpointInject(uri = "direct:start")
ProducerTemplate producer;
@@ -52,7 +44,7 @@ public class TransactedPipelineTest exte
@Override
protected AbstractXmlApplicationContext createApplicationContext() {
- return new
ClassPathXmlApplicationContext("org/apache/camel/itest/ibatis/TransactedPipelineTest.xml");
+ return new
ClassPathXmlApplicationContext("org/apache/camel/itest/ibatis/AsyncEndpointTransactedTest.xml");
}
@Before
@@ -67,28 +59,31 @@ public class TransactedPipelineTest exte
}
@Test
- public void pipelineCompletes() {
- end.expectedMessageCount(1);
+ public void testAsyncEndpointOK() throws InterruptedException {
+ end.expectedBodiesReceived("Bye Camel");
+
producer.sendBody(3);
assertEquals(1, table.values().size());
assertEquals(3, (int) table.iterator().next());
+
+ end.assertIsSatisfied();
}
@Test
- public void pipelineAborts() {
- end.expectedMessageCount(1);
+ public void testAsyncEndpointRollback() {
end.whenAnyExchangeReceived(new Processor() {
public void process(Exchange exchange) throws Exception {
- throw new MyException();
+ throw new IllegalArgumentException("Damn");
}
});
+
try {
producer.sendBody(3);
- assertFalse(true);
+ fail("Should have thrown exception");
} catch (CamelExecutionException e) {
- assertEquals(MyException.class,
e.getCause().getCause().getClass());
+ assertIsInstanceOf(IllegalArgumentException.class,
e.getCause().getCause());
assertEquals(0, table.values().size());
}
}
-}
+}
\ No newline at end of file
Added:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.xml?rev=959391&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.xml
(added)
+++
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.xml
Wed Jun 30 18:08:49 2010
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <import resource="hsqldb-context.xml"/>
+
+ <bean id="async" class="org.apache.camel.itest.async.MyAsyncComponent"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <transacted/>
+ <to uri="log:ibatis3"/>
+ <to uri="ibatis:table.add?statementType=Insert"/>
+ <to uri="direct:foo"/>
+ <to uri="async:Bye Camel"/>
+ <to uri="log:end"/>
+ <to uri="mock:end"/>
+ </route>
+
+ <route>
+ <from uri="direct:foo"/>
+ <transacted/>
+ <to uri="async:Hi Camel"/>
+ <setBody><constant>4</constant></setBody>
+ <convertBodyTo type="int"/>
+ <to uri="log:ibatis4"/>
+ <to uri="ibatis:table.add?statementType=Insert"/>
+ </route>
+ </camelContext>
+
+</beans>
Propchange:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransacted2Test.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Copied:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransactedTest.xml
(from r959281,
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/TransactedPipelineTest.xml)
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransactedTest.xml?p2=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransactedTest.xml&p1=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/TransactedPipelineTest.xml&r1=959281&r2=959391&rev=959391&view=diff
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/TransactedPipelineTest.xml
(original)
+++
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ibatis/AsyncEndpointTransactedTest.xml
Wed Jun 30 18:08:49 2010
@@ -8,11 +8,16 @@
<import resource="hsqldb-context.xml"/>
+ <bean id="async" class="org.apache.camel.itest.async.MyAsyncComponent"/>
+
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<transacted/>
<to uri="ibatis:table.add?statementType=Insert"/>
+ <to uri="log:before"/>
+ <to uri="async:Bye Camel"/>
+ <to uri="log:after"/>
<to uri="mock:end"/>
</route>
</camelContext>