Author: djencks Date: Tue Nov 2 14:20:51 2004 New Revision: 56427 Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/TransactionManagerProxy.java geronimo/trunk/modules/transaction/src/test/org/apache/geronimo/transaction/context/TransactionContextManagerTest.java Log: Need to propagate the suspend/resume calls to the underlying tx manager for RequiresNew ejb calls to work. Also need to end all txs in tests to avoid later InterruptedExceptions later in the build
Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/TransactionManagerProxy.java ============================================================================== --- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/TransactionManagerProxy.java (original) +++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/TransactionManagerProxy.java Tue Nov 2 14:20:51 2004 @@ -62,7 +62,6 @@ private final ExtendedTransactionManager delegate; private final XidImporter importer; - private final ThreadLocal threadTx = new ThreadLocal(); private final Recovery recovery; private final ReferenceCollection resourceManagers; private List recoveryErrors = new ArrayList(); @@ -151,7 +150,6 @@ public Transaction begin(long transactionTimeoutMilliseconds) throws NotSupportedException, SystemException { Transaction tx = delegate.begin(transactionTimeoutMilliseconds); - threadTx.set(tx); return tx; } @@ -165,52 +163,27 @@ } public Transaction getTransaction() throws SystemException { - return (Transaction) threadTx.get(); + return delegate.getTransaction(); } public Transaction suspend() throws SystemException { - Transaction tx = getTransaction(); - threadTx.set(null); - return tx; + return delegate.suspend(); } public void resume(Transaction tx) throws IllegalStateException, InvalidTransactionException, SystemException { - if (threadTx.get() != null) { - throw new IllegalStateException("Transaction already associated with current thread"); - } - threadTx.set(tx); + delegate.resume(tx); } public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException { - Transaction tx = getTransaction(); - if (tx == null) { - throw new IllegalStateException("No transaction associated with current thread"); - } - try { - tx.commit(); - } finally { - threadTx.set(null); - } + delegate.commit(); } public void rollback() throws IllegalStateException, SecurityException, SystemException { - Transaction tx = getTransaction(); - if (tx == null) { - throw new IllegalStateException("No transaction associated with current thread"); - } - try { - tx.rollback(); - } finally { - threadTx.set(null); - } + delegate.rollback(); } public void setRollbackOnly() throws IllegalStateException, SystemException { - Transaction tx = getTransaction(); - if (tx == null) { - throw new IllegalStateException("No transaction associated with current thread"); - } - tx.setRollbackOnly(); + delegate.setRollbackOnly(); } Modified: geronimo/trunk/modules/transaction/src/test/org/apache/geronimo/transaction/context/TransactionContextManagerTest.java ============================================================================== --- geronimo/trunk/modules/transaction/src/test/org/apache/geronimo/transaction/context/TransactionContextManagerTest.java (original) +++ geronimo/trunk/modules/transaction/src/test/org/apache/geronimo/transaction/context/TransactionContextManagerTest.java Tue Nov 2 14:20:51 2004 @@ -38,7 +38,7 @@ private XidFactory xidFactory = new XidFactoryImpl("geronimo.test.tm".getBytes()); protected void setUp() throws Exception { - TransactionManagerProxy tm = new GeronimoTransactionManager(10, null, null); + TransactionManagerProxy tm = new GeronimoTransactionManager(1000, null, null); transactionContextManager = new TransactionContextManager(tm, tm, tm); } @@ -48,9 +48,9 @@ public void testImportedTxLifecycle() throws Exception { Xid xid = xidFactory.createXid(); - transactionContextManager.begin(xid, 0); + transactionContextManager.begin(xid, 1000); transactionContextManager.end(xid); - transactionContextManager.begin(xid, 0); + transactionContextManager.begin(xid, 1000); transactionContextManager.end(xid); transactionContextManager.prepare(xid); transactionContextManager.commit(xid, false); @@ -58,24 +58,30 @@ public void testNoConcurrentWorkSameXid() throws Exception { Xid xid = xidFactory.createXid(); - transactionContextManager.begin(xid, 0); + transactionContextManager.begin(xid, 1000); try { - transactionContextManager.begin(xid, 0); + transactionContextManager.begin(xid, 1000); fail("should not be able begin same xid twice"); } catch (ImportedTransactionActiveException e) { //expected + } finally { + transactionContextManager.end(xid); + transactionContextManager.rollback(xid); } } public void testOnlyOneImportedTxAtATime() throws Exception { Xid xid1 = xidFactory.createXid(); Xid xid2 = xidFactory.createXid(); - transactionContextManager.begin(xid1, 0); + transactionContextManager.begin(xid1, 1000); try { - transactionContextManager.begin(xid2, 0); + transactionContextManager.begin(xid2, 1000); fail("should not be able to begin a 2nd tx without ending the first"); } catch (IllegalStateException e) { //expected + } finally { + transactionContextManager.end(xid1); + transactionContextManager.rollback(xid1); } } }