You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/10/23 20:59:52 UTC
svn commit: r707447 - in /servicemix/smx3/branches/servicemix-3.2: ./
core/servicemix-core/
core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/
core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/
Author: gertv
Date: Thu Oct 23 11:59:52 2008
New Revision: 707447
URL: http://svn.apache.org/viewvc?rev=707447&view=rev
Log:
SM-1657: Auto-enlistment should only occur when transaction is ACTIVE
Modified:
servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/pom.xml
servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java
servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImplTest.java
servicemix/smx3/branches/servicemix-3.2/pom.xml
Modified: servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/pom.xml?rev=707447&r1=707446&r2=707447&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/pom.xml (original)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/pom.xml Thu Oct 23 11:59:52 2008
@@ -263,6 +263,11 @@
<artifactId>howl</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Modified: servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java?rev=707447&r1=707446&r2=707447&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java Thu Oct 23 11:59:52 2008
@@ -35,6 +35,7 @@
import javax.jbi.messaging.MessageExchangeFactory;
import javax.jbi.messaging.MessagingException;
import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.transaction.Status;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.xml.namespace.QName;
@@ -784,7 +785,7 @@
if (transactionManager != null && container.isAutoEnlistInTransaction()) {
try {
Transaction tx = transactionManager.getTransaction();
- if (tx != null) {
+ if (tx != null && tx.getStatus() == Status.STATUS_ACTIVE) {
Object oldTx = me.getTransactionContext();
if (oldTx == null) {
me.setTransactionContext(tx);
Modified: servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImplTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImplTest.java?rev=707447&r1=707446&r2=707447&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImplTest.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImplTest.java Thu Oct 23 11:59:52 2008
@@ -18,12 +18,17 @@
import java.util.concurrent.atomic.AtomicBoolean;
+import javax.jbi.JBIException;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.InOut;
import javax.jbi.messaging.MessageExchangeFactory;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
@@ -35,6 +40,8 @@
import org.apache.servicemix.jbi.container.JBIContainer;
import org.apache.servicemix.jbi.jaxp.StringSource;
+import static org.easymock.EasyMock.*;
+
public class DeliveryChannelImplTest extends TestCase {
private static final Log LOG = LogFactory.getLog(DeliveryChannelImplTest.class);
@@ -127,6 +134,57 @@
assertTrue("Secondary thread didn't finish", done.get());
assertTrue("Exception in secondary thread", success.get());
}
+
+ public void testAutoEnlistInActiveTx() throws JBIException, SystemException {
+ // set up a mock TransactionManager for the container
+ final TransactionManager manager = createMock(TransactionManager.class);
+ container.setTransactionManager(manager);
+ container.setAutoEnlistInTransaction(true);
+
+ // create DeliveryChannel and MessageExchange
+ final DeliveryChannelImpl channel = createDeliveryChannel();
+ MessageExchangeImpl exchange = createMessageExchange(channel);
+
+ // auto-enlistment should only occur when Transaction status is ACTIVE
+ final Transaction transaction = createMock(Transaction.class);
+ expect(manager.getTransaction()).andReturn(transaction);
+ expect(transaction.getStatus()).andReturn(Status.STATUS_ACTIVE);
+ replay(manager);
+ replay(transaction);
+ channel.autoEnlistInTx(exchange);
+ assertSame(transaction, exchange.getTransactionContext());
+ }
+
+ public void testNoAutoEnlistInNonActiveTx() throws JBIException, SystemException {
+ // set up a mock TransactionManager for the container
+ final TransactionManager manager = createMock(TransactionManager.class);
+ container.setTransactionManager(manager);
+ container.setAutoEnlistInTransaction(true);
+ final Transaction transaction = createMock(Transaction.class);
+
+ // create DeliveryChannel and MessageExchange
+ final DeliveryChannelImpl channel = createDeliveryChannel();
+ MessageExchangeImpl exchange = createMessageExchange(channel);
+
+ // auto-enlistment should not occur when Transaction status is NO_TRANSACTION or any other status (not tested)
+ expect(manager.getTransaction()).andReturn(transaction);
+ expect(transaction.getStatus()).andReturn(Status.STATUS_NO_TRANSACTION);
+ replay(manager);
+ replay(transaction);
+ channel.autoEnlistInTx(exchange);
+ assertNull(exchange.getTransactionContext());
+ }
+
+ private MessageExchangeImpl createMessageExchange(final DeliveryChannelImpl channel) throws MessagingException {
+ MessageExchangeFactory factory = channel.createExchangeFactoryForService(new QName("service"));
+ return (MessageExchangeImpl) factory.createInOutExchange();
+ }
+
+ private DeliveryChannelImpl createDeliveryChannel() throws JBIException, MessagingException {
+ TestComponent component = new TestComponent(new QName("service"), "endpoint");
+ container.activateComponent(new ActivationSpec("component", component));
+ return (DeliveryChannelImpl) component.getChannel();
+ }
public static class TestComponent extends ComponentSupport {
public TestComponent(QName service, String endpoint) {
Modified: servicemix/smx3/branches/servicemix-3.2/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/pom.xml?rev=707447&r1=707446&r2=707447&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/pom.xml (original)
+++ servicemix/smx3/branches/servicemix-3.2/pom.xml Thu Oct 23 11:59:52 2008
@@ -1971,6 +1971,11 @@
<artifactId>jmock</artifactId>
<version>2.5.0</version>
</dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.0</version>
+ </dependency>
</dependencies>
</dependencyManagement>