1 17 18 package org.apache.geronimo.transaction.context; 19 20 import javax.transaction.xa.Xid ; 21 import javax.transaction.xa.XAResource ; 22 23 import junit.framework.TestCase; 24 import org.apache.geronimo.transaction.ImportedTransactionActiveException; 25 import org.apache.geronimo.transaction.manager.TransactionManagerImpl; 26 import org.apache.geronimo.transaction.manager.XidFactory; 27 import org.apache.geronimo.transaction.manager.XidFactoryImpl; 28 29 35 public class TransactionContextManagerTest extends TestCase { 36 37 private TransactionContextManager transactionContextManager; 38 private XidFactory xidFactory = new XidFactoryImpl("geronimo.test.tm".getBytes()); 39 40 protected void setUp() throws Exception { 41 TransactionManagerImpl tm = new TransactionManagerImpl(1000, null, null); 42 transactionContextManager = new TransactionContextManager(tm, tm); 43 } 44 45 protected void tearDown() throws Exception { 46 transactionContextManager = null; 47 } 48 49 public void testImportedTxLifecycle() throws Exception { 50 Xid xid = xidFactory.createXid(); 51 transactionContextManager.begin(xid, 1000); 52 transactionContextManager.end(xid); 53 transactionContextManager.begin(xid, 1000); 54 transactionContextManager.end(xid); 55 int readOnly = transactionContextManager.prepare(xid); 56 assertEquals(XAResource.XA_RDONLY, readOnly); 57 } 59 60 public void testNoConcurrentWorkSameXid() throws Exception { 61 Xid xid = xidFactory.createXid(); 62 transactionContextManager.begin(xid, 1000); 63 try { 64 transactionContextManager.begin(xid, 1000); 65 fail("should not be able begin same xid twice"); 66 } catch (ImportedTransactionActiveException e) { 67 } finally { 69 transactionContextManager.end(xid); 70 transactionContextManager.rollback(xid); 71 } 72 } 73 74 public void testOnlyOneImportedTxAtATime() throws Exception { 75 Xid xid1 = xidFactory.createXid(); 76 Xid xid2 = xidFactory.createXid(); 77 transactionContextManager.begin(xid1, 1000); 78 try { 79 transactionContextManager.begin(xid2, 1000); 80 fail("should not be able to begin a 2nd tx without ending the first"); 81 } catch (IllegalStateException e) { 82 } finally { 84 transactionContextManager.end(xid1); 85 transactionContextManager.rollback(xid1); 86 } 87 } 88 } 89 | Popular Tags |