servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r707451 - in /servicemix/smx3/trunk/core/servicemix-core: pom.xml src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java src/test/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImplTest.java
Date Thu, 23 Oct 2008 19:08:59 GMT
Author: gertv
Date: Thu Oct 23 12:08:59 2008
New Revision: 707451

URL: http://svn.apache.org/viewvc?rev=707451&view=rev
Log:
SM-1657: Auto-enlistment should only occur when transaction is ACTIVE

Modified:
    servicemix/smx3/trunk/core/servicemix-core/pom.xml
    servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java
    servicemix/smx3/trunk/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImplTest.java

Modified: servicemix/smx3/trunk/core/servicemix-core/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/core/servicemix-core/pom.xml?rev=707451&r1=707450&r2=707451&view=diff
==============================================================================
--- servicemix/smx3/trunk/core/servicemix-core/pom.xml (original)
+++ servicemix/smx3/trunk/core/servicemix-core/pom.xml Thu Oct 23 12:08:59 2008
@@ -202,11 +202,6 @@
       <artifactId>hsqldb</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <scope>test</scope>
-    </dependency>
 
     <dependency>
       <groupId>commons-lang</groupId>
@@ -238,6 +233,12 @@
       <artifactId>howl</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <version>2.0</version>
+      <scope>test</scope>
+    </dependency>    
   </dependencies>
 
   <build>

Modified: servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java?rev=707451&r1=707450&r2=707451&view=diff
==============================================================================
--- servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java
(original)
+++ servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java
Thu Oct 23 12:08:59 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() &&
!container.isUseNewTransactionModel()) {
             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/trunk/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImplTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImplTest.java?rev=707451&r1=707450&r2=707451&view=diff
==============================================================================
--- servicemix/smx3/trunk/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImplTest.java
(original)
+++ servicemix/smx3/trunk/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImplTest.java
Thu Oct 23 12:08:59 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) {



Mime
View raw message