[jboss-cvs] JBossAS SVN: r111562 - in projects/jboss-jca/trunk: core/src/main/java/org/jboss/jca/core/connectionmanager/listener and 10 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 9 10:14:25 EDT 2011


Author: jesper.pedersen
Date: 2011-06-09 10:14:25 -0400 (Thu, 09 Jun 2011)
New Revision: 111562

Added:
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/InterleavingTestCase.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/GlobalXID.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnection.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnectionFactory.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnectionRequestInfo.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestManagedConnection.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestManagedConnectionFactory.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/package.html
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/package.html
Modified:
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ccm/CachedConnectionManagerImpl.java
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/TxConnectionListener.java
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolStatisticsImpl.java
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/TransactionSynchronizer.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/ccm/CachedConnectionManagerTestCase.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/unit/AbstractConnectionManagerTestCase.java
   projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml
   projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml
Log:
[JBJCA-594] Use interposed synchronization

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ccm/CachedConnectionManagerImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ccm/CachedConnectionManagerImpl.java	2011-06-09 13:48:38 UTC (rev 111561)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ccm/CachedConnectionManagerImpl.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -49,6 +49,7 @@
 import javax.transaction.SystemException;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
+import javax.transaction.TransactionSynchronizationRegistry;
 
 import org.jboss.logging.Logger;
 import org.jboss.logging.Messages;
@@ -76,8 +77,10 @@
    private boolean error = false;
 
    /** Transaction Manager instance */
-   private final TransactionManager transactionManager;
+   private TransactionManager transactionManager;
 
+   private TransactionSynchronizationRegistry transactionSynchronizationRegistry;
+
    /**
     * ThreadLocal that holds current calling meta-programming aware
     * object, used in case someone is idiotic enough to cache a
@@ -105,10 +108,13 @@
    /**
     * Creates a new instance.
     * @param transactionManager The transaction manager
+    * @param transactionSynchronizationRegistry the transaction synchronization registry
     */
-   public CachedConnectionManagerImpl(final TransactionManager transactionManager)
+   public CachedConnectionManagerImpl(TransactionManager transactionManager,
+                                      TransactionSynchronizationRegistry transactionSynchronizationRegistry)
    {
       this.transactionManager = transactionManager;
+      this.transactionSynchronizationRegistry = transactionSynchronizationRegistry;
    }
 
    /**
@@ -121,6 +127,15 @@
    }
 
    /**
+    * Gets transaction synchronization registry
+    * @return TransactionSynchronizationRegistry
+    */
+   public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry()
+   {
+      return transactionSynchronizationRegistry;
+   }
+
+   /**
     * Set debug flag
     * @param v The value
     */
@@ -198,10 +213,12 @@
       if (trace)
          log.tracef("popped object: %s", oldKey);
 
+      /*
       if (!stack.contains(oldKey))
       {
          disconnect(oldKey, unsharableResources);
       }
+      */
 
       if (debug)
       {
@@ -330,10 +347,12 @@
       }
 
       KeyConnectionAssociation key = new KeyConnectionAssociation(rawKey);
+      /*
       if (!stack.contains(key))
       {
          reconnect(key, unsharableResources);
       }
+      */
 
       stack.addLast(key);
    }
@@ -493,7 +512,7 @@
                if (cas == null && createIfNotFound && TxUtils.isActive(tx))
                {
                   cas = new CloseConnectionSynchronization();
-                  TransactionSynchronizer.registerCCMSynchronization(tx, cas);
+                  TransactionSynchronizer.registerCCMSynchronization(tx, cas, transactionSynchronizationRegistry);
                }
 
                return cas;

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/TxConnectionListener.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/TxConnectionListener.java	2011-06-09 13:48:38 UTC (rev 111561)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/TxConnectionListener.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -226,7 +226,9 @@
                log.trace("Get synchronizer " + this + " threadTx=" + threadTx);
             }
 
-            synchronizer = TransactionSynchronizer.getRegisteredSynchronizer(threadTx);
+            synchronizer =
+               TransactionSynchronizer.getRegisteredSynchronizer(threadTx,
+                  getConnectionManager().getTransactionIntegration().getTransactionSynchronizationRegistry());
          }
          catch (Throwable t)
          {
@@ -298,9 +300,15 @@
             transactionSynchronization = null;
             if (TxUtils.isUncommitted(tx))
             {
-               TransactionSynchronizer synchronizer = TransactionSynchronizer.getRegisteredSynchronizer(tx);
+               TransactionSynchronizer synchronizer =
+                  TransactionSynchronizer.getRegisteredSynchronizer(tx,
+                                                                    getConnectionManager().
+                                                                    getTransactionIntegration().
+                                                                    getTransactionSynchronizationRegistry());
+
                if (synchronization.enlisted)
                   synchronizer.removeEnlisted(synchronization);
+
                if (!tx.delistResource(getXAResource(), XAResource.TMSUSPEND))
                {
                   throw new ResourceException(bundle.failureDelistResource(this));

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolStatisticsImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolStatisticsImpl.java	2011-06-09 13:48:38 UTC (rev 111561)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolStatisticsImpl.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -540,4 +540,47 @@
          mcp.getStatistics().clear();
       }
    }
+
+   /**
+    * toString
+    * @return The value
+    */
+   public String toString()
+   {
+      StringBuilder sb = new StringBuilder();
+
+      sb.append("PoolStatistics@").append(Integer.toHexString(System.identityHashCode(this)));
+
+      sb.append("[");
+
+      sb.append(ACTIVE_COUNT).append("=").append(getActiveCount());
+      sb.append(",");
+      sb.append(AVAILABLE_COUNT).append("=").append(getAvailableCount());
+      sb.append(",");
+      sb.append(AVERAGE_BLOCKING_TIME).append("=").append(getAverageBlockingTime());
+      sb.append(",");
+      sb.append(AVERAGE_CREATION_TIME).append("=").append(getAverageCreationTime());
+      sb.append(",");
+      sb.append(CREATED_COUNT).append("=").append(getCreatedCount());
+      sb.append(",");
+      sb.append(DESTROYED_COUNT).append("=").append(getDestroyedCount());
+      sb.append(",");
+      sb.append(MAX_CREATION_TIME).append("=").append(getMaxCreationTime());
+      sb.append(",");
+      sb.append(MAX_USED_COUNT).append("=").append(getMaxUsedCount());
+      sb.append(",");
+      sb.append(MAX_WAIT_COUNT).append("=").append(getMaxWaitCount());
+      sb.append(",");
+      sb.append(MAX_WAIT_TIME).append("=").append(getMaxWaitTime());
+      sb.append(",");
+      sb.append(TIMED_OUT).append("=").append(getTimedOut());
+      sb.append(",");
+      sb.append(TOTAL_BLOCKING_TIME).append("=").append(getTotalBlockingTime());
+      sb.append(",");
+      sb.append(TOTAL_CREATION_TIME).append("=").append(getTotalCreationTime());
+
+      sb.append("]");
+      
+      return sb.toString();
+   }
 }

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java	2011-06-09 13:48:38 UTC (rev 111561)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -456,4 +456,47 @@
    {
       // No-op
    }
+
+   /**
+    * toString
+    * @return The value
+    */
+   public String toString()
+   {
+      StringBuilder sb = new StringBuilder();
+
+      sb.append("ManagedConnectionPoolStatistics@").append(Integer.toHexString(System.identityHashCode(this)));
+
+      sb.append("[");
+
+      sb.append(ACTIVE_COUNT).append("=").append(getActiveCount());
+      sb.append(",");
+      sb.append(AVAILABLE_COUNT).append("=").append(getAvailableCount());
+      sb.append(",");
+      sb.append(AVERAGE_BLOCKING_TIME).append("=").append(getAverageBlockingTime());
+      sb.append(",");
+      sb.append(AVERAGE_CREATION_TIME).append("=").append(getAverageCreationTime());
+      sb.append(",");
+      sb.append(CREATED_COUNT).append("=").append(getCreatedCount());
+      sb.append(",");
+      sb.append(DESTROYED_COUNT).append("=").append(getDestroyedCount());
+      sb.append(",");
+      sb.append(MAX_CREATION_TIME).append("=").append(getMaxCreationTime());
+      sb.append(",");
+      sb.append(MAX_USED_COUNT).append("=").append(getMaxUsedCount());
+      sb.append(",");
+      sb.append(MAX_WAIT_COUNT).append("=").append(getMaxWaitCount());
+      sb.append(",");
+      sb.append(MAX_WAIT_TIME).append("=").append(getMaxWaitTime());
+      sb.append(",");
+      sb.append(TIMED_OUT).append("=").append(getTimedOut());
+      sb.append(",");
+      sb.append(TOTAL_BLOCKING_TIME).append("=").append(getTotalBlockingTime());
+      sb.append(",");
+      sb.append(TOTAL_CREATION_TIME).append("=").append(getTotalCreationTime());
+
+      sb.append("]");
+      
+      return sb.toString();
+   }
 }

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/TransactionSynchronizer.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/TransactionSynchronizer.java	2011-06-09 13:48:38 UTC (rev 111561)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/TransactionSynchronizer.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -34,6 +34,7 @@
 import javax.transaction.Synchronization;
 import javax.transaction.SystemException;
 import javax.transaction.Transaction;
+import javax.transaction.TransactionSynchronizationRegistry;
 
 import org.jboss.logging.Logger;
 
@@ -182,11 +183,13 @@
     * Get a registered transaction synchronizer.
     *
     * @param tx the transaction
+    * @param tsr the transaction synchronization registry
     * @throws SystemException sys. exception
     * @throws RollbackException rollback exception
     * @return the registered transaction synchronizer for this transaction
     */
-   public static TransactionSynchronizer getRegisteredSynchronizer(Transaction tx) 
+   public static TransactionSynchronizer getRegisteredSynchronizer(Transaction tx, 
+                                                                   TransactionSynchronizationRegistry tsr)
       throws SystemException, RollbackException
    {
       TransactionSynchronizer result = txSynchs.get(tx);
@@ -197,12 +200,19 @@
          if (result == null)
          {
             result = newResult;
-            tx.registerSynchronization(result);
+            if (tsr != null)
+            {
+               tsr.registerInterposedSynchronization(result);
+            }
+            else
+            {
+               tx.registerSynchronization(result);
+            }
          }
       }
       return result;
    }
-   
+
    /**
     * Check whether we have a CCM synchronization
     * 
@@ -220,18 +230,21 @@
    
    /**
     * Register a new CCM synchronization
-    * 
+    *
     * @param tx the transaction
     * @param synch the synchronization
+    * @param tsr the transaction synchronization registry
     * @throws Exception e
     */
-   public static void registerCCMSynchronization(Transaction tx, Synchronization synch) 
+   public static void registerCCMSynchronization(Transaction tx,
+                                                 Synchronization synch,
+                                                 TransactionSynchronizationRegistry tsr)
       throws Exception
    {
-      TransactionSynchronizer ts = getRegisteredSynchronizer(tx);
+      TransactionSynchronizer ts = getRegisteredSynchronizer(tx, tsr);
       ts.ccmSynch = synch;
    }
-   
+
    /**
     * Lock for the given transaction
     * 

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/ccm/CachedConnectionManagerTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/ccm/CachedConnectionManagerTestCase.java	2011-06-09 13:48:38 UTC (rev 111561)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/ccm/CachedConnectionManagerTestCase.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -34,6 +34,7 @@
 
 import javax.resource.spi.ConnectionRequestInfo;
 import javax.transaction.TransactionManager;
+import javax.transaction.TransactionSynchronizationRegistry;
 
 import org.junit.Test;
 
@@ -66,7 +67,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
       ConnectionCacheListener cm0 = mock(ConnectionCacheListener.class);
       ConnectionCacheListener cm1 = mock(ConnectionCacheListener.class);
       ConnectionRecord cr0 = mock(ConnectionRecord.class);
@@ -108,7 +110,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
 
       ccm.getCurrentObjects().set(null);
       //then
@@ -126,7 +129,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
       ConnectionCacheListener cm0 = mock(ConnectionCacheListener.class);
       ConnectionCacheListener cm1 = mock(ConnectionCacheListener.class);
       ConnectionRecord cr0 = mock(ConnectionRecord.class);
@@ -170,7 +174,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
 
       ccm.getCurrentObjects().set(null);
       //then (parameters are not important the key of this test is that given ccm have no associations
@@ -188,7 +193,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
       ConnectionCacheListener cm0 = mock(ConnectionCacheListener.class);
       ConnectionCacheListener cm1 = mock(ConnectionCacheListener.class);
       ConnectionRecord cr0 = mock(ConnectionRecord.class);
@@ -234,7 +240,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
       ConnectionCacheListener cm0 = mock(ConnectionCacheListener.class);
       ConnectionCacheListener cm1 = mock(ConnectionCacheListener.class);
       ConnectionCacheListener cm2 = mock(ConnectionCacheListener.class);
@@ -284,7 +291,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
 
       ccm.getCurrentObjects().set(null);
       //then (parameters are not important the key of this test is that given ccm have no associations
@@ -302,7 +310,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
       ConnectionCacheListener cm0 = mock(ConnectionCacheListener.class);
       ConnectionCacheListener cm1 = mock(ConnectionCacheListener.class);
       ConnectionRecord cr0 = mock(ConnectionRecord.class);
@@ -347,7 +356,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
       ConnectionCacheListener cm0 = mock(ConnectionCacheListener.class);
       ConnectionCacheListener cm1 = mock(ConnectionCacheListener.class);
       ConnectionRecord cr0 = mock(ConnectionRecord.class);
@@ -394,7 +404,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
 
       //when
       ccm.pushMetaAwareObject(mock(Object.class), null);
@@ -415,7 +426,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
 
       ConnectionCacheListener cm0 = mock(ConnectionCacheListener.class);
       ConnectionCacheListener cm1 = mock(ConnectionCacheListener.class);
@@ -464,7 +476,8 @@
    {
       //given
       TransactionManager tm = mock(TransactionManager.class);
-      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm);
+      TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
+      CachedConnectionManagerImpl ccm = new CachedConnectionManagerImpl(tm, tsr);
 
       ConnectionCacheListener cm0 = mock(ConnectionCacheListener.class);
       ConnectionCacheListener cm1 = mock(ConnectionCacheListener.class);

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/InterleavingTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/InterleavingTestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/InterleavingTestCase.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -0,0 +1,447 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.connections;
+
+import org.jboss.jca.common.api.metadata.common.FlushStrategy;
+import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager;
+import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration;
+import org.jboss.jca.core.connectionmanager.ConnectionManagerFactory;
+import org.jboss.jca.core.connectionmanager.connections.adapter.TestConnection;
+import org.jboss.jca.core.connectionmanager.connections.adapter.TestManagedConnection;
+import org.jboss.jca.core.connectionmanager.connections.adapter.TestManagedConnectionFactory;
+import org.jboss.jca.core.connectionmanager.pool.api.Pool;
+import org.jboss.jca.core.connectionmanager.pool.api.PoolFactory;
+import org.jboss.jca.core.connectionmanager.pool.api.PoolStrategy;
+import org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl;
+import org.jboss.jca.core.spi.transaction.TransactionIntegration;
+import org.jboss.jca.embedded.Embedded;
+import org.jboss.jca.embedded.EmbeddedFactory;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.TransactionSupport.TransactionSupportLevel;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAException;
+
+import org.jboss.logging.Logger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * InterleavinfTestCase
+ */
+public class InterleavingTestCase 
+{
+   private static Logger log = Logger.getLogger(InterleavingTestCase.class);
+
+   private static final int POOL_SIZE = 5;
+
+   private Embedded embedded = null;
+
+   private TransactionManager tm;
+   private CachedConnectionManager ccm;
+   private TestManagedConnectionFactory mcf;
+   private TxConnectionManagerImpl cm;
+   private ConnectionRequestInfo cri;
+
+   /**
+    * Test: Get connection
+    * @exception Exception If error
+    */
+   @Test
+   public void testGetConnection() throws Exception
+   {
+      TestConnection c = (TestConnection)cm.allocateConnection(mcf, cri);
+      assertTrue("Connection is null", c != null);
+      c.close();
+   }
+
+   /**
+    * Test: Enlist in existing tx
+    * @exception Exception If error
+    */
+   @Test
+   public void testEnlistInExistingTx() throws Exception
+   {
+      tm.begin();
+      TestConnection c = null;
+      try
+      {
+         c = (TestConnection)cm.allocateConnection(mcf, cri);
+         try
+         {
+            assertTrue("Connection not enlisted in tx!", c.isInTx());
+         }
+         finally
+         {
+            c.close();
+         }
+         assertTrue("Connection still enlisted in tx!", !c.isInTx());
+      }
+      finally
+      {
+         if (tm.getStatus() == Status.STATUS_ACTIVE)
+            tm.commit();
+         else
+            tm.rollback();
+      }
+      assertTrue("Connection still enlisted in tx!", !c.isInTx());
+   }
+
+   /**
+    * Test: Enlist checked out connection in new transaction
+    * @exception Exception If error
+    */
+   @Ignore
+   public void testEnlistCheckedOutConnectionInNewTx() throws Exception
+   {
+      Object key = this;
+      Set unshared = new HashSet();
+      ccm.pushMetaAwareObject(key, unshared);
+      try
+      {
+         TestConnection c = (TestConnection)cm.allocateConnection(mcf, cri);
+         try
+         {
+            assertTrue("Connection already enlisted in tx!", !c.isInTx());
+            tm.begin();
+            try
+            {
+               assertTrue("Connection not enlisted in tx!", c.isInTx());
+            }
+            finally
+            {
+               if (tm.getStatus() == Status.STATUS_ACTIVE)
+                  tm.commit();
+               else
+                  tm.rollback();
+            }
+            assertTrue("Connection still enlisted in tx!", !c.isInTx());
+         }
+         finally
+         {
+            c.close();
+         }
+      }
+      finally
+      {
+         ccm.popMetaAwareObject(unshared);
+      }
+   }
+
+   /** 
+    * Tests the spec required behavior of reconnecting connection
+    * handles left open on return from an ejb method call.
+    *
+    * @exception Exception If error
+    */
+   @Ignore
+   public void testReconnectConnectionHandlesOnNotification() throws Exception
+   {
+      //ccm.setSpecCompliant(true);
+
+      Object key1 = new Object();
+      Object key2 = new Object();
+      Set unshared = new HashSet();
+      ccm.pushMetaAwareObject(key1, unshared);
+      try
+      {
+         TestConnection c = null;
+         tm.begin();
+         try
+         {
+            ccm.pushMetaAwareObject(key2, unshared);
+            try
+            {
+               c = (TestConnection)cm.allocateConnection(mcf, cri);
+               assertTrue("Connection not enlisted in tx!", c.isInTx());
+            }
+            finally
+            {
+               ccm.popMetaAwareObject(unshared);
+            }
+         }
+         finally
+         {
+            if (tm.getStatus() == Status.STATUS_ACTIVE)
+               tm.commit();
+            else
+               tm.rollback();
+         }
+         tm.begin();
+         try
+         {
+            ccm.pushMetaAwareObject(key2, unshared);
+            try
+            {
+               assertTrue("Connection not enlisted in tx!", c.isInTx());
+            }
+            finally
+            {
+               ccm.popMetaAwareObject(unshared);
+            }
+         }
+         finally
+         {
+            if (tm.getStatus() == Status.STATUS_ACTIVE)
+               tm.commit();
+            else
+               tm.rollback();
+         }
+         assertTrue("Connection still enlisted in tx!", !c.isInTx());
+         ccm.pushMetaAwareObject(key2, unshared);
+         try
+         {
+            if (c != null)
+               c.close();
+         }
+         finally
+         {
+            ccm.popMetaAwareObject(unshared);
+         }
+      }
+      finally
+      {
+         ccm.popMetaAwareObject(unshared);
+      }
+   }
+
+   /** 
+    * Test: Enlist after mark rollback
+    * @exception Exception If error
+    */
+   @Test
+   public void testEnlistAfterMarkRollback() throws Exception
+   {
+      // Get a transaction and mark it for rollback
+      tm.begin();
+      try
+      {
+         tm.setRollbackOnly();
+         // Allocate a connection upto the pool size all should fail
+         for (int i = 0; i < POOL_SIZE; i++)
+         {
+            try
+            {
+               cm.allocateConnection(mcf, cri);
+               fail("Should not be allowed to allocate a connection with setRollbackOnly()");
+            }
+            catch (Exception e)
+            {
+               log.debug("Error allocating connection", e);
+            }
+         }
+      }
+      finally
+      {
+         tm.rollback();
+      }
+
+      // We should be able to get a connection now
+      testGetConnection();
+   }
+
+   /** 
+    * Test: Broken connection and track-by-tx
+    * @exception Exception If error
+    */
+   @Test
+   public void testBrokenConnectionAndTrackByTx() throws Exception
+   {
+      //cm.setTrackConnectionByTx(true);
+      tm.begin();
+      TestConnection c = (TestConnection)cm.allocateConnection(mcf, cri);
+      c.fireConnectionError();
+      try
+      {
+         c.close();
+      }
+      catch (Exception e)
+      {
+         // Ignore
+      }
+      try
+      {
+         tm.commit();
+         fail("Should not be here");
+      }
+      catch (RollbackException re)
+      {
+         // Expected
+      }
+      assertTrue("Connection still enlisted in tx!", !c.isInTx());
+   }
+  
+   /** 
+    * Test: Failed start transaction
+    * @exception Exception If error
+    */
+   @Test
+   public void testFailedStartTx() throws Exception
+   {
+      TestManagedConnection.setFailInStart(false, XAException.XAER_RMFAIL);
+      tm.begin();
+      TestConnection conn = null;
+      TestConnection conn2 = null;
+      
+      try
+      {
+         assertTrue("Connection in pool!", cm.getPool().getStatistics().getActiveCount() == 0);
+         conn = (TestConnection)cm.allocateConnection(mcf, cri);
+         
+         //One should have been created
+         assertTrue(cm.getPool().getStatistics().getActiveCount() == 1);
+
+         TestManagedConnection.setFailInStart(true, XAException.XAER_RMFAIL);
+        
+         conn2 = (TestConnection)cm.allocateConnection(mcf, cri);
+        
+         fail("Should not be here.");
+      }
+      catch (Throwable t)
+      {
+         // Ignore
+      }      
+      conn.close();
+      tm.rollback();
+      assertNull(conn2);            
+      //assertTrue("Count: " + cm.getPool().getStatistics().getCreatedCount(),
+      //           cm.getPool().getStatistics().getCreatedCount() == 1);
+   }
+  
+   /** 
+    * Test: Failed end transaction
+    * @exception Exception If error
+    */
+   @Test
+   public void testFailedEndTx() throws Exception
+   {
+      TestManagedConnection.setFailInStart(false, XAException.XAER_RMFAIL);
+      TestManagedConnection.setFailInEnd(false, XAException.XAER_RMFAIL);
+      tm.begin();
+      TestConnection conn = null;
+      TestConnection conn2 = null;
+     
+      try
+      {
+         assertTrue("Connection in pool!", cm.getPool().getStatistics().getActiveCount() == 0);
+         conn = (TestConnection)cm.allocateConnection(mcf, cri);
+         
+         // One should have been created
+         assertTrue(cm.getPool().getStatistics().getActiveCount() == 1);
+         conn.close();
+         
+         TestManagedConnection.setFailInEnd(true, XAException.XAER_RMFAIL);
+         
+         conn2 = (TestConnection)cm.allocateConnection(mcf, cri);
+         conn2.close();
+         tm.commit();
+        
+         fail("Should not be here.");
+      }
+      catch (Throwable t)
+      {
+         log.debug(t.getMessage(), t);
+      }      
+     
+      TestManagedConnection.setFailInEnd(false, 0);
+      TestManagedConnection.setFailInStart(false, 0);
+      
+      assertNotNull(conn2);
+      assertTrue(conn2.getMCIsNull());     
+      assertTrue("Connection count" + cm.getPool().getStatistics().getActiveCount(), 
+                 cm.getPool().getStatistics().getActiveCount() == 0);
+      assertTrue("Failed endTx should destroy Connection", 
+                 cm.getPool().getStatistics().getDestroyedCount() > 0);
+   }
+  
+   /**
+    * Lifecycle start, before the suite is executed
+    * @throws Throwable throwable exception
+    */
+   @Before
+   public void before() throws Throwable
+   {
+      // Create and set an embedded JCA instance
+      embedded = EmbeddedFactory.create();
+
+      // Startup
+      embedded.startup();
+      
+      tm = embedded.lookup("RealTransactionManager", TransactionManager.class);
+
+      ccm = embedded.lookup("CCM", CachedConnectionManager.class);
+      
+      mcf = new TestManagedConnectionFactory();
+      cm = buildTxConnectionManager(mcf);
+   }
+
+   private TxConnectionManagerImpl buildTxConnectionManager(ManagedConnectionFactory mcf) throws Throwable
+   {
+      TransactionIntegration ti = embedded.lookup("TransactionIntegration", TransactionIntegration.class);
+      assertNotNull(ti);
+      
+      PoolConfiguration pc = new PoolConfiguration();
+      pc.setMaxSize(POOL_SIZE);
+
+      PoolFactory pf = new PoolFactory();
+    
+      Pool pool = pf.create(PoolStrategy.ONE_POOL, mcf, pc, true);
+      
+      ConnectionManagerFactory cmf = new ConnectionManagerFactory();
+      TxConnectionManagerImpl tcm =
+         (TxConnectionManagerImpl)cmf.createTransactional(TransactionSupportLevel.XATransaction, pool,
+                                                          null, null, false, null,
+                                                          FlushStrategy.FAILING_CONNECTION_ONLY,
+                                                          null, null, ti, null, null, null, null, null);
+      tcm.setInterleaving(true);
+
+      return tcm;
+   }
+
+   /**
+    * Lifecycle stop, after the suite is executed
+    * @throws Throwable throwable exception
+    */
+   @After
+   public void after() throws Throwable
+   {
+      // Shutdown embedded
+      embedded.shutdown();
+
+      // Set embedded to null
+      embedded = null;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/GlobalXID.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/GlobalXID.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/GlobalXID.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.connections.adapter;
+
+import javax.transaction.xa.Xid;
+
+/**
+ * Xid
+ */
+public class GlobalXID
+{
+   private byte[] gid;
+   private int hashCode;
+   private String toString;
+   
+   /**
+    * Constructor
+    * @param xid The Xid
+    */
+   public GlobalXID(Xid xid)
+   {
+      gid = xid.getGlobalTransactionId();
+      
+      for (int i = 0; i < gid.length; ++i)
+         hashCode += 37 * gid[i];
+
+      toString = new String(gid).trim();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int hashCode()
+   {
+      return hashCode;
+   }
+   
+   /**
+    * {@inheritDoc}
+    */
+   public String toString()
+   {
+      return toString;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean equals(Object obj)
+   {
+      if (obj == null || (!(obj instanceof GlobalXID)))
+         return false;
+      
+      GlobalXID other = (GlobalXID) obj;
+      return toString.equals(other.toString);
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnection.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnection.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnection.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -0,0 +1,217 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.connections.adapter;
+
+import javax.resource.ResourceException;
+import javax.resource.cci.Connection;
+import javax.resource.cci.ConnectionMetaData;
+import javax.resource.cci.Interaction;
+import javax.resource.cci.LocalTransaction;
+import javax.resource.cci.ResultSetInfo;
+
+/**
+ * TestConnection
+ */
+public class TestConnection implements Connection
+{
+   private TestManagedConnection mc = null;
+   private boolean mcIsNull = true;
+
+   /**
+    * Constructor
+    * @param mc The managed connection
+    */
+   public TestConnection(TestManagedConnection mc)
+   {
+      this.mc = mc;
+      this.mcIsNull = false;
+   }
+
+   /**
+    * Is MC null
+    * @return The result
+    */
+   public boolean getMCIsNull()
+   {
+      return mcIsNull;
+   }
+
+   /**
+    * Set fail in prepare
+    * @param fail fail
+    * @param xaCode xaCode
+    */
+   public void setFailInPrepare(boolean fail, int xaCode)
+   {
+      mc.setFailInPrepare(fail, xaCode);
+   }
+   
+   /**
+    * Set fail in start
+    * @param fail fail
+    * @param xaCode xaCode
+    */
+   public void setFailInStart(boolean fail, int xaCode)
+   {
+   }
+
+   /**
+    * Set fail in commit
+    * @param fail fail
+    * @param xaCode xaCode
+    */
+   public void setFailInCommit(boolean fail, int xaCode)
+   {
+      mc.setFailInCommit(fail, xaCode);
+   }
+
+   /**
+    * Fire connection error
+    */
+   public void fireConnectionError()
+   {
+      mc.connectionError(this, new Exception("ConnectionError"));
+   }
+
+   /**
+    * Is in Tx
+    * @return The result
+    */
+   public boolean isInTx()
+   {
+      return mc.isInTx();
+   }
+
+   /**
+    * Set the MC
+    * @param mc The mc
+    */
+   void setMc(TestManagedConnection mc)
+   {
+      if (mc == null)
+      {
+         this.mcIsNull = true;
+         // We don't touch this.mc
+      }
+      else
+      {
+         this.mc = mc;
+      }
+   }
+
+   /**
+    * Get local state
+    * @return The value
+    */
+   public String getLocalState()
+   {
+      return mc.getLocalState();
+   }
+   
+   /**
+    * Begin
+    * @exception Exception If error
+    */
+   public void begin() throws Exception
+   {
+      mc.sendBegin();
+   }
+   
+   /**
+    * Commit
+    * @exception Exception If error
+    */
+   public void commit() throws Exception
+   {
+      mc.sendCommit();
+   }
+   
+   /**
+    * Rollback
+    * @exception Exception If error
+    */
+   public void rollback() throws Exception
+   {
+      mc.sendRollback();
+   }
+   
+   /**
+    * Close
+    */
+   public void close()
+   {
+      mc.connectionClosed(this);
+      // We don't touch this.mc
+   }
+
+   /**
+    * Get MC
+    * @return The value
+    */
+   public TestManagedConnection getMC()
+   {
+      return mc;
+   }
+
+   /**
+    * Similate a connection error
+    * @exception Exception The exception
+    */
+   public void simulateConnectionError() throws Exception
+   {
+      Exception e = new Exception("Simulated exception");
+      mc.connectionError(this, e);
+      throw e;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Interaction createInteraction() throws ResourceException
+   {
+      return null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public LocalTransaction getLocalTransaction() throws ResourceException
+   {
+      return null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public ConnectionMetaData getMetaData() throws ResourceException
+   {
+      return null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public ResultSetInfo getResultSetInfo() throws ResourceException
+   {
+      return null;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnectionFactory.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnectionFactory.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnectionFactory.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.connections.adapter;
+
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.resource.Referenceable;
+import javax.resource.ResourceException;
+import javax.resource.cci.Connection;
+import javax.resource.cci.ConnectionFactory;
+import javax.resource.cci.ConnectionSpec;
+import javax.resource.cci.RecordFactory;
+import javax.resource.cci.ResourceAdapterMetaData;
+import javax.resource.spi.ConnectionManager;
+
+/**
+ * TestConnectionFactory
+ */
+public class TestConnectionFactory implements ConnectionFactory, Referenceable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   private ConnectionManager cm;
+
+   private TestManagedConnectionFactory mcf;
+
+   private Reference ref;
+   
+   /**
+    * Constructor
+    * @param cm The CM
+    * @param mcf The MCF
+    */
+   public TestConnectionFactory(ConnectionManager cm, TestManagedConnectionFactory mcf)
+   {
+      this.cm = cm;
+      this.mcf = mcf;
+   }
+
+   /**
+    * Set failure
+    * @param failure failure
+    */
+   public void setFailure(String failure)
+   {
+      mcf.setFailure(failure);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setReference(Reference ref)
+   {
+      this.ref = ref;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Reference getReference() throws NamingException
+   {
+      return ref;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Connection getConnection() throws ResourceException
+   {
+      return (Connection)cm.allocateConnection(mcf, null);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Connection getConnection(ConnectionSpec ignore) throws ResourceException
+   {
+      return (Connection)cm.allocateConnection(mcf, null);
+   }
+
+   /**
+    * Get connection
+    * @param failure The failure
+    * @return The connection
+    * @exception ResourceException If error
+    */
+   public Connection getConnection(String failure) throws ResourceException
+   {
+      return (Connection)cm.allocateConnection(mcf, new TestConnectionRequestInfo(failure));
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public RecordFactory getRecordFactory() throws ResourceException
+   {
+      return null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public ResourceAdapterMetaData getMetaData() throws ResourceException
+   {
+      return null;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnectionRequestInfo.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnectionRequestInfo.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestConnectionRequestInfo.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.connections.adapter;
+
+import javax.resource.spi.ConnectionRequestInfo;
+
+/**
+ * TestConnectionRequestInfo
+ */
+public class TestConnectionRequestInfo implements ConnectionRequestInfo
+{
+   private String failure;
+
+   /**
+    * Constructor
+    */
+   public TestConnectionRequestInfo()
+   {
+      this.failure = "nowhere";
+   }
+
+   /**
+    * Constructor
+    * @param failure failure
+    */
+   public TestConnectionRequestInfo(String failure)
+   {
+      this.failure = failure;
+   }
+
+   /**
+    * Get failure
+    * @return The value
+    */
+   public String getFailure()
+   {
+      return failure;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int hashCode()
+   {
+      return failure.hashCode();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean equals(Object param1)
+   {
+      if (param1 == this)
+         return true;
+
+      if (param1 == null || (!(param1 instanceof TestConnectionRequestInfo)))
+         return false;
+
+      TestConnectionRequestInfo other = (TestConnectionRequestInfo)param1;
+      return failure.equals(other.failure);
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestManagedConnection.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestManagedConnection.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestManagedConnection.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -0,0 +1,840 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.connections.adapter;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionEvent;
+import javax.resource.spi.ConnectionEventListener;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.LocalTransaction;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionMetaData;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.security.auth.Subject;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.jboss.logging.Logger;
+
+/**
+ * TestManagedConnection
+ */
+public class TestManagedConnection  implements ManagedConnection, XAResource, LocalTransaction
+{
+   private static final String STARTED = "STARTED";
+   private static final String SUSPENDED = "SUSPENDED";
+   private static final String ENDED = "ENDED";
+   private static final String PREPARED = "PREPARED";
+
+   private static final String LOCAL_NONE = "LOCAL_NONE";
+   private static final String LOCAL_TRANSACTION = "LOCAL_TRANSACTION";
+   private static final String LOCAL_COMMITTED = "LOCAL_COMMITTED";
+   private static final String LOCAL_ROLLEDBACK = "LOCAL_ROLLEDBACK";
+
+   private int id;
+
+   private Logger log = Logger.getLogger(getClass());
+   private TestManagedConnectionFactory mcf;
+   private HashSet<TestConnection> handles = new HashSet<TestConnection>();
+   private HashSet<ConnectionEventListener> listeners = new HashSet<ConnectionEventListener>();
+
+   private GlobalXID currentXid;
+
+   private AtomicBoolean destroyed = new AtomicBoolean(false);
+
+   private boolean failInPrepare = false;
+   private boolean failInCommit = false;
+
+   private static boolean failInStart = false;
+   private static boolean failInEnd = false;
+   private static int xaCode;
+
+   private String localState = LOCAL_NONE;
+
+   /**
+    * Constructor
+    * @param mcf The MCF
+    * @param id The id
+    */
+   public TestManagedConnection(TestManagedConnectionFactory mcf, int id)
+   {
+      this.mcf = mcf;
+      this.id = id;
+   }
+
+   /**
+    * Fail in start
+    * @param fis value
+    * @param xa the code
+    */
+   public static void setFailInStart(boolean fis, int xa)
+   {
+      failInStart = fis;
+      xaCode = xa;
+   }
+
+   /**
+    * Fail in end
+    * @param fie value
+    * @param xa the code
+    */
+   public static void setFailInEnd(boolean fie, int xa)
+   {
+      failInEnd = fie;
+      xaCode = xa;
+   }
+
+   /**
+    * Fail in prepare
+    * @param fail value
+    * @param xaCode the code
+    */
+   void setFailInPrepare(boolean fail, int xaCode)
+   {
+      this.failInPrepare = fail;
+      this.xaCode = xaCode;
+   }
+
+   /**
+    * Fail in commit
+    * @param fail value
+    * @param xaCode the code
+    */
+   void setFailInCommit(boolean fail, int xaCode)
+   {
+      this.failInCommit = fail;
+      this.xaCode = xaCode;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized void destroy() throws ResourceException
+   {
+      if (destroyed.get())
+         return;
+
+      cleanup();
+
+      destroyed.set(true);
+      currentXid = null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized void cleanup() throws ResourceException
+   {
+      checkDestroyedResourceException();
+
+      for (TestConnection c : handles)
+      {
+         c.setMc(null);
+      }
+
+      handles.clear();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized Object getConnection(Subject param1, ConnectionRequestInfo param2) throws ResourceException
+   {
+      checkDestroyedResourceException();
+
+      if (param2 != null && ((TestConnectionRequestInfo) param2).getFailure().equals("getConnectionResource"))
+         throw new ResourceException(this.toString());
+
+      if (param2 != null && ((TestConnectionRequestInfo) param2).getFailure().equals("getConnectionRuntime"))
+         throw new RuntimeException(this.toString());
+
+      TestConnection c =  new TestConnection(this);
+      handles.add(c);
+
+      return c;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized void associateConnection(Object p) throws ResourceException
+   {
+      checkDestroyedResourceException();
+
+      if (p instanceof TestConnection)
+      {
+         TestConnection tc = (TestConnection)p;
+         tc.setMc(this);
+         handles.add(tc);
+      }
+      else
+      {
+         throw new ResourceException("Wrong kind of Connection " + p);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized void addConnectionEventListener(ConnectionEventListener cel)
+   {
+      listeners.add(cel);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized void removeConnectionEventListener(ConnectionEventListener cel)
+   {
+      listeners.remove(cel);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized XAResource getXAResource() throws ResourceException
+   {
+      checkDestroyedResourceException();
+      return this;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public LocalTransaction getLocalTransaction() throws ResourceException
+   {
+      return this;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public ManagedConnectionMetaData getMetaData() throws ResourceException
+   {
+      return null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setLogWriter(PrintWriter param1) throws ResourceException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public PrintWriter getLogWriter() throws ResourceException
+   {
+      return null;
+   }
+
+   /**
+    * Get listeners
+    * @return The value
+    */
+   public List<ConnectionEventListener> getListeners()
+   {
+      List<ConnectionEventListener> result = null;
+
+      synchronized (listeners)
+      {
+         result = new ArrayList<ConnectionEventListener>(listeners);
+      }
+
+      return result;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void start(Xid xid, int flags) throws XAException
+   {
+      long sleepInStart = mcf.getSleepInStart();
+      if (flags == TMNOFLAGS && sleepInStart != 0)
+         doSleep(sleepInStart);
+
+      synchronized (this)
+      {
+         if (failInStart)
+         {
+            XAException xaex = new XAException(xaCode + " for " + this);
+            xaex.errorCode = xaCode;
+            broadcastConnectionError(xaex);
+            throw xaex;
+         }
+
+         GlobalXID gid = new GlobalXID(xid);
+         String flagString = getXAResourceFlagsAsString(flags);
+         checkDestroyedXAException();
+         Map<GlobalXID, String> xids = getXids();
+         synchronized (xids)
+         {
+            String state = xids.get(gid);
+            if (state == null && flags != TMNOFLAGS)
+            {
+               XAException xaex = new XAException("Invalid start state=" + state + " xid=" + gid +
+                                                   " flags=" + flagString + " for " + this);
+               xaex.errorCode = XAException.XAER_PROTO;
+               throw xaex;
+            }
+            if (state != null && state != SUSPENDED && state != ENDED
+                && (state != STARTED || ((flags & TMJOIN) == 0))
+                && (state != STARTED || ((flags & TMRESUME) == 0)))
+            {
+               XAException xaex = new XAException("Invalid start state=" + state + " xid=" + gid +
+                                                  " flags=" + flagString + " for " + this);
+               xaex.errorCode = XAException.XAER_PROTO;
+               throw xaex;
+            }
+
+            if ((flags & TMJOIN) != 0 && mcf.getFailJoin())
+            {
+               XAException xaex = new XAException("Join is not allowed " + state + " xid=" + gid +
+                                                  " flags=" + flagString + " for " + this);
+               xaex.errorCode = XAException.XAER_PROTO;
+               throw xaex;
+            }
+            xids.put(gid, STARTED);
+         }
+
+         this.currentXid = gid;
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void end(final Xid xid, final int flags) throws XAException
+   {
+      if (failInEnd)
+      {
+         XAException xaex = new XAException(xaCode + " for " + this);
+         xaex.errorCode = xaCode;
+         broadcastConnectionError(xaex);
+         throw xaex;
+      }
+
+      long sleepInEnd = mcf.getSleepInEnd();
+      if (flags != TMSUCCESS && sleepInEnd != 0)
+         doSleep(sleepInEnd);
+
+      synchronized (this)
+      {
+         GlobalXID gid = new GlobalXID(xid);
+         String flagString = getXAResourceFlagsAsString(flags);
+         Map<GlobalXID, String> xids = getXids();
+         synchronized (xids)
+         {
+            String state = xids.get(gid);
+            if (state != STARTED && state != SUSPENDED && state != ENDED)
+            {
+               XAException xaex = new XAException("Invalid end state=" + state + " xid=" + gid + " " + this);
+               xaex.errorCode = XAException.XAER_PROTO;
+               throw xaex;
+            }
+            if ((flags & TMSUSPEND) == 0)
+            {
+               xids.put(gid, ENDED);
+            }
+            else
+            {
+               xids.put(gid, SUSPENDED);
+            }
+         }
+
+         this.currentXid = null;
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized void commit(Xid xid, boolean onePhase) throws XAException
+   {
+      GlobalXID gid = new GlobalXID(xid);
+      log.info("commit with xid=" + gid + " onePhase=" + onePhase + " for " + this);
+      checkDestroyedXAException();
+
+      if (failInCommit)
+      {
+         XAException xaex = new XAException(xaCode + " for " + this);
+         xaex.errorCode = xaCode;
+         throw xaex;
+      }
+
+      Map<GlobalXID, String> xids = getXids();
+      synchronized (xids)
+      {
+         String state = xids.get(gid);
+         if (onePhase)
+         {
+            if (state != SUSPENDED && state != ENDED)
+            {
+               XAException xaex = new XAException("Invalid one phase commit state=" + state +
+                                                  " xid=" + gid + " " + this);
+               xaex.errorCode = XAException.XAER_PROTO;
+               throw xaex;
+            }
+         }
+         else
+         {
+            if (state != PREPARED)
+            {
+               XAException xaex = new XAException("Invalid two phase commit state=" + state +
+                                                  " xid=" + gid + " " + this);
+               xaex.errorCode = XAException.XAER_PROTO;
+               throw xaex;
+            }
+         }
+         xids.remove(gid);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized void rollback(Xid xid) throws XAException
+   {
+      GlobalXID gid = new GlobalXID(xid);
+      checkDestroyedXAException();
+      Map<GlobalXID, String> xids = getXids();
+      synchronized (xids)
+      {
+         String state = xids.get(gid);
+         if (state != SUSPENDED && state != ENDED && state != PREPARED)
+         {
+            XAException xaex = new XAException("Invalid rollback state=" + state + " xid=" + gid + " " + this);
+            xaex.errorCode = XAException.XAER_PROTO;
+            throw xaex;
+         }
+         xids.remove(gid);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized int prepare(Xid xid) throws XAException
+   {
+      GlobalXID gid = new GlobalXID(xid);
+      checkDestroyedXAException();
+      Map<GlobalXID, String> xids = getXids();
+      synchronized (xids)
+      {
+         String state = xids.get(gid);
+         if (state != SUSPENDED && state != ENDED)
+         {
+            XAException xaex = new XAException("Invalid prepare state=" + state + " xid=" + gid + " " + this);
+            xaex.errorCode = XAException.XAER_PROTO;
+            throw xaex;
+         }
+         if (failInPrepare)
+         {
+            XAException xae = new XAException(xaCode + " for " + this);
+            xae.errorCode = xaCode;
+            throw xae;
+         }
+         xids.put(gid, PREPARED);
+         return XA_OK;
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized void forget(Xid xid) throws XAException
+   {
+      GlobalXID gid = new GlobalXID(xid);
+      checkDestroyedXAException();
+      Map<GlobalXID, String> xids = getXids();
+      synchronized (xids)
+      {
+         xids.remove(gid);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Xid[] recover(int param1) throws XAException
+   {
+      return null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean isSameRM(XAResource xar) throws XAException
+   {
+      if (xar == null || (!(xar instanceof TestManagedConnection)))
+         return false;
+
+      TestManagedConnection other = (TestManagedConnection) xar;
+      return (mcf == other.mcf);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int getTransactionTimeout() throws XAException
+   {
+      return 0;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean setTransactionTimeout(int param1) throws XAException
+   {
+      return false;
+   }
+
+   /**
+    * Get the local state
+    * @return The value
+    */
+   public String getLocalState()
+   {
+      return localState;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void begin() throws ResourceException
+   {
+      localState = LOCAL_TRANSACTION;
+   }
+
+   /**
+    * Send begin
+    * @exception ResourceException If error
+    */
+   public void sendBegin() throws ResourceException
+   {
+      begin();
+      ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_STARTED);
+      Collection<ConnectionEventListener> copy = new ArrayList<ConnectionEventListener>(listeners);
+      for (ConnectionEventListener cel : copy)
+      {
+         try
+         {
+            cel.localTransactionStarted(event);
+         }
+         catch (Throwable ignored)
+         {
+            log.warn("Ignored", ignored);
+         }
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void commit() throws ResourceException
+   {
+      localState = LOCAL_COMMITTED;
+   }
+
+   /**
+    * Send commit
+    * @exception ResourceException If error
+    */
+   public void sendCommit() throws ResourceException
+   {
+      commit();
+
+      ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_COMMITTED);
+      Collection<ConnectionEventListener> copy = new ArrayList<ConnectionEventListener>(listeners);
+      for (ConnectionEventListener cel : copy)
+      {
+         try
+         {
+            cel.localTransactionCommitted(event);
+         }
+         catch (Throwable ignored)
+         {
+            log.warn("Ignored", ignored);
+         }
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void rollback() throws ResourceException
+   {
+      localState = LOCAL_ROLLEDBACK;
+   }
+
+   /**
+    * Send rollback
+    * @exception ResourceException If error
+    */
+   public void sendRollback() throws ResourceException
+   {
+      rollback();
+
+      ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK);
+      Collection<ConnectionEventListener> copy = new ArrayList<ConnectionEventListener>(listeners);
+      for (ConnectionEventListener cel : copy)
+      {
+         try
+         {
+            cel.localTransactionRolledback(event);
+         }
+         catch (Throwable ignored)
+         {
+            log.warn("Ignored", ignored);
+         }
+      }
+   }
+
+   /**
+    * Is in tx
+    * @return The result
+    */
+   synchronized boolean isInTx()
+   {
+      return currentXid != null;
+   }
+
+   /**
+    * Get Xids
+    * @return The value
+    */
+   Map<GlobalXID, String> getXids()
+   {
+      return mcf.getXids();
+   }
+
+   /**
+    * Connection closed
+    * @param handle The handle
+    */
+   void connectionClosed(TestConnection handle)
+   {
+      if (destroyed.get())
+         return;
+
+      ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
+      ce.setConnectionHandle(handle);
+
+      Collection<ConnectionEventListener> copy = new ArrayList<ConnectionEventListener>(listeners);
+      for (ConnectionEventListener cel : copy)
+      {
+         try
+         {
+            cel.connectionClosed(ce);
+         }
+         catch (Throwable ignored)
+         {
+            log.warn("Ignored", ignored);
+         }
+      }
+      synchronized (this)
+      {
+         handles.remove(handle);
+      }
+   }
+
+   /**
+    * Broadcast connection error
+    * @param e The error
+    */
+   protected void broadcastConnectionError(Throwable e)
+   {
+      if (destroyed.get())
+         return;
+
+      Exception ex = null;
+      if (e instanceof Exception)
+         ex = (Exception) e;
+      else
+         ex = new ResourceAdapterInternalException("Unexpected error", e);
+
+      ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex);
+      Collection<ConnectionEventListener> copy = null;
+      synchronized (listeners)
+      {
+         copy = new ArrayList<ConnectionEventListener>(listeners);
+      }
+
+      for (ConnectionEventListener cel : copy)
+      {
+         try
+         {
+            cel.connectionErrorOccurred(ce);
+         }
+         catch (Throwable t)
+         {
+            // Ignore
+         }
+      }
+   }
+
+   /**
+    * Connection error
+    * @param handle The handle
+    * @param e The error
+    */
+   void connectionError(TestConnection handle, Exception e)
+   {
+      if (destroyed.get())
+         return;
+
+      ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, e);
+      ce.setConnectionHandle(handle);
+
+      Collection<ConnectionEventListener> copy = new ArrayList<ConnectionEventListener>(listeners);
+      for (ConnectionEventListener cel : copy)
+      {
+         try
+         {
+            cel.connectionErrorOccurred(ce);
+         }
+         catch (Throwable t)
+         {
+            // Ignore
+         }
+      }
+   }
+
+   /**
+    * Check destroyed
+    * @exception ResourceException If error
+    */
+   void checkDestroyedResourceException() throws ResourceException
+   {
+      if (destroyed.get())
+         throw new ResourceException("Already destroyed " + this);
+   }
+
+   /**
+    * Check destroyed
+    * @exception XAException If error
+    */
+   void checkDestroyedXAException() throws XAException
+   {
+      if (destroyed.get())
+      {
+         XAException xaex = new XAException("Already destroyed " + this);
+         xaex.errorCode = XAException.XAER_PROTO;
+         throw xaex;
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized String toString()
+   {
+      StringBuffer buffer = new StringBuffer();
+      buffer.append("TestManagedConnection#").append(id);
+      buffer.append("{");
+      buffer.append("xid=").append(currentXid);
+      buffer.append(" destroyed=").append(destroyed.get());
+      buffer.append("}");
+      return buffer.toString();
+   }
+
+   /**
+    * Sleep
+    * @param sleep Millis
+    */
+   public void doSleep(long sleep)
+   {
+      boolean interrupted = false;
+      try
+      {
+         Thread.sleep(sleep);
+      }
+      catch (InterruptedException e)
+      {
+         interrupted = true;
+      }
+
+      if (interrupted)
+         Thread.currentThread().interrupt();
+   }
+
+   /**
+    * Get XAResource
+    * @param flags flags
+    * @return The status
+    */
+   private static String getXAResourceFlagsAsString(int flags)
+   {
+      if (flags == XAResource.TMNOFLAGS)
+      {
+         return "|TMNOFLAGS";
+      }
+      else
+      {
+         StringBuffer sbuf = new StringBuffer(64);
+         
+         if ((flags & XAResource.TMONEPHASE) != 0)
+         {
+            sbuf.append("|TMONEPHASE");
+         }
+         if ((flags & XAResource.TMJOIN) != 0)
+         {
+            sbuf.append("|TMJOIN");
+         }
+         if ((flags & XAResource.TMRESUME) != 0)
+         {
+            sbuf.append("|TMRESUME");
+         }
+         if ((flags & XAResource.TMSUCCESS) != 0)
+         {
+            sbuf.append("|TMSUCCESS");
+         }
+         if ((flags & XAResource.TMFAIL) != 0)
+         {
+            sbuf.append("|TMFAIL");
+         }
+         if ((flags & XAResource.TMSUSPEND) != 0)
+         {
+            sbuf.append("|TMSUSPEND");
+         }
+         if ((flags & XAResource.TMSTARTRSCAN) != 0)
+         {
+            sbuf.append("|TMSTARTRSCAN");
+         }
+         if ((flags & XAResource.TMENDRSCAN) != 0)
+         {
+            sbuf.append("|TMENDRSCAN");
+         }
+         return sbuf.toString();
+      }
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestManagedConnectionFactory.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestManagedConnectionFactory.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/TestManagedConnectionFactory.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -0,0 +1,218 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.connections.adapter;
+
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.security.auth.Subject;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ManagedConnectionFactory
+ */
+public class TestManagedConnectionFactory implements ManagedConnectionFactory
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   private Logger log = Logger.getLogger(TestManagedConnectionFactory.class); 
+   
+   private AtomicInteger id = new AtomicInteger(0);
+
+   private String failure;
+
+   private boolean failJoin;
+
+   private long sleepInStart;
+
+   private long sleepInEnd;
+   
+   private Map<GlobalXID, String> xids = new HashMap<GlobalXID, String>();
+
+   /**
+    * Constructor
+    */
+   public TestManagedConnectionFactory()
+   {
+   }
+
+   /**
+    * Set failure
+    * @param failure failure
+    */
+   public void setFailure(String failure)
+   {
+      this.failure = failure;
+   }
+
+   /**
+    * Get fail join
+    * @return The value
+    */
+   public boolean getFailJoin()
+   {
+      return failJoin;
+   }
+   
+   /**
+    * Set fail join
+    * @param failJoin The value
+    */
+   public void setFailJoin(boolean failJoin)
+   {
+      this.failJoin = failJoin;
+   }
+
+   /**
+    * Get sleep in start
+    * @return The value
+    */
+   public long getSleepInStart()
+   {
+      return sleepInStart;
+   }
+   
+   /**
+    * Set sleep in start
+    * @param sleep The value
+    */
+   public void setSleepInStart(long sleep)
+   {
+      this.sleepInStart = sleep;
+   }
+
+   /**
+    * Get sleep in end
+    * @return The value
+    */
+   public long getSleepInEnd()
+   {
+      return sleepInEnd;
+   }
+   
+   /**
+    * Set sleep in end
+    * @param sleep The value
+    */
+   public void setSleepInEnd(long sleep)
+   {
+      this.sleepInEnd = sleep;
+   }
+   
+   /**
+    * {@inheritDoc}
+    */
+   public void setLogWriter(PrintWriter param1) throws ResourceException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public PrintWriter getLogWriter() throws ResourceException
+   {
+      return null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Object createConnectionFactory(ConnectionManager cm) throws ResourceException
+   {
+      return new TestConnectionFactory(cm, this);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Object createConnectionFactory() throws ResourceException
+   {
+      throw new ResourceException("NYI");
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cri) throws ResourceException
+   {
+      if (failure != null && failure.equals("createManagedConnectionResource"))
+         throw new ResourceException("");
+
+      if (failure != null && failure.equals("createManagedConnectionRuntime"))
+         throw new RuntimeException("");
+
+      return new TestManagedConnection(this, id.incrementAndGet());
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public ManagedConnection matchManagedConnections(Set candidates, Subject subject, ConnectionRequestInfo cri)
+      throws ResourceException
+   {
+      if (failure != null && failure.equals("matchManagedConnectionResource"))
+         throw new ResourceException("");
+
+      if (failure != null && failure.equals("matchManagedConnectionRuntime"))
+         throw new RuntimeException("");
+
+      if (candidates.isEmpty()) 
+         return null;
+
+      return (ManagedConnection)candidates.iterator().next();
+   }
+
+   /**
+    * Get the Xids
+    * @return The value
+    */
+   Map<GlobalXID, String> getXids()
+   {
+      return xids;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int hashCode()
+   {
+      return getClass().hashCode();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean equals(Object other)
+   {
+      return (other != null) && (other.getClass() == getClass());
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/package.html	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/adapter/package.html	2011-06-09 14:14:25 UTC (rev 111562)
@@ -0,0 +1,3 @@
+<body>
+A resource adapter for connection based test cases
+</body>

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/package.html	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/connections/package.html	2011-06-09 14:14:25 UTC (rev 111562)
@@ -0,0 +1,3 @@
+<body>
+Test cases for connection based test cases
+</body>

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/unit/AbstractConnectionManagerTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/unit/AbstractConnectionManagerTestCase.java	2011-06-09 13:48:38 UTC (rev 111561)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/unit/AbstractConnectionManagerTestCase.java	2011-06-09 14:14:25 UTC (rev 111562)
@@ -76,7 +76,7 @@
    {
       AbstractConnectionManager connectionManager = new MockConnectionManager();
       assertNull(connectionManager.getCachedConnectionManager());
-      connectionManager.setCachedConnectionManager(new CachedConnectionManagerImpl(null));
+      connectionManager.setCachedConnectionManager(new CachedConnectionManagerImpl(null, null));
       assertNotNull(connectionManager.getCachedConnectionManager());
    }
 

Modified: projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml
===================================================================
--- projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml	2011-06-09 13:48:38 UTC (rev 111561)
+++ projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml	2011-06-09 14:14:25 UTC (rev 111562)
@@ -147,6 +147,7 @@
         class="org.jboss.jca.core.connectionmanager.ccm.CachedConnectionManagerImpl">
     <constructor>
       <parameter><inject bean="TransactionIntegration" property="TransactionManager"/></parameter>
+      <parameter><inject bean="TransactionIntegration" property="TransactionSynchronizationRegistry"/></parameter>
     </constructor>
     <property name="Debug">false</property>
     <property name="Error">false</property>

Modified: projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml	2011-06-09 13:48:38 UTC (rev 111561)
+++ projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml	2011-06-09 14:14:25 UTC (rev 111562)
@@ -150,6 +150,7 @@
         class="org.jboss.jca.core.connectionmanager.ccm.CachedConnectionManagerImpl">
     <constructor>
       <parameter><inject bean="TransactionIntegration" property="TransactionManager"/></parameter>
+      <parameter><inject bean="TransactionIntegration" property="TransactionSynchronizationRegistry"/></parameter>
     </constructor>
     <property name="Debug">false</property>
     <property name="Error">false</property>



More information about the jboss-cvs-commits mailing list