geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lin...@apache.org
Subject svn commit: r725317 - /geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/
Date Wed, 10 Dec 2008 15:52:45 GMT
Author: linsun
Date: Wed Dec 10 07:52:45 2008
New Revision: 725317

URL: http://svn.apache.org/viewvc?rev=725317&view=rev
Log:
add some agreed upon test cases for GERONIMO-4448

Modified:
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TestTransactionManager.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionSynchronizationRegistryTest.java

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TestTransactionManager.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TestTransactionManager.java?rev=725317&r1=725316&r2=725317&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TestTransactionManager.java
(original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TestTransactionManager.java
Wed Dec 10 07:52:45 2008
@@ -18,6 +18,7 @@
 package org.apache.geronimo.transaction.manager;
 
 import javax.transaction.Status;
+import javax.transaction.InvalidTransactionException;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 import javax.transaction.xa.XAResource;

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java?rev=725317&r1=725316&r2=725317&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
(original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
Wed Dec 10 07:52:45 2008
@@ -19,6 +19,7 @@
 
 import java.util.Map;
 
+import javax.transaction.InvalidTransactionException;
 import javax.transaction.RollbackException;
 import javax.transaction.Status;
 import javax.transaction.Transaction;
@@ -290,28 +291,125 @@
         assertEquals(xid, recovered.keySet().iterator().next());
     }
 
-      public void testTimeout() throws Exception
-      {
-          long timeout = tm.getTransactionTimeoutMilliseconds(0L);
-          tm.setTransactionTimeout((int)timeout/4000);
-          tm.begin();
-          System.out.println("Test to sleep for " + timeout + " millisecs");
-          Thread.sleep(timeout);
-          try
-          {
-              tm.commit();
-              fail("Tx Should get Rollback exception");
-          }catch(RollbackException rex)
-          {
-              // Caught expected exception
-          }
-
-          // Now test if the default timeout is active
-          tm.begin();
-          System.out.println("Test to sleep for " + (timeout/2) + " millisecs");
-          Thread.sleep((timeout/2));
-          tm.commit();
-          // Its a failure if exception occurs.
-      }
+    public void testTimeout() throws Exception
+    {
+        long timeout = tm.getTransactionTimeoutMilliseconds(0L);
+        tm.setTransactionTimeout((int)timeout/4000);
+        tm.begin();
+        System.out.println("Test to sleep for " + timeout + " millisecs");
+        Thread.sleep(timeout);
+        try
+        {
+            tm.commit();
+            fail("Tx Should get Rollback exception");
+        }catch(RollbackException rex)
+        {
+            // Caught expected exception
+        }
+
+        // Now test if the default timeout is active
+        tm.begin();
+        System.out.println("Test to sleep for " + (timeout/2) + " millisecs");
+        Thread.sleep((timeout/2));
+        tm.commit();
+        // Its a failure if exception occurs.
+    }    
+      
+    // resume throws InvalidTransactionException on completed tx (via commit)
+    public void testResume1() throws Exception {
+        Transaction tx;
+        assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
+        tm.begin();   
+        assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
+        tx = tm.getTransaction();
+        assertNotNull(tx);
+        assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
+        
+        tm.commit();
+        assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
+        assertNull(tm.getTransaction());
+        
+        try {
+            tm.resume(tx);
+            fail();
+        } catch (InvalidTransactionException e) {
+            // expected
+        }        
+    }
+    
+    // resume throws InvalidTransactionException on completed tx (via rollback)
+    public void testResume2() throws Exception {
+        Transaction tx;
+        assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
+        tm.begin();
+        assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
+        tx = tm.getTransaction();
+        assertNotNull(tx);
+        assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
+
+        tx = tm.suspend();
+        assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
+        assertNull(tm.getTransaction());
+
+        tm.resume(tx);
+        assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
+        assertEquals(tx, tm.getTransaction());
+
+        tm.rollback();
+        assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
+        assertNull(tm.getTransaction());     
+        
+        try {
+            tm.resume(tx);
+            fail();
+        } catch (InvalidTransactionException e) {
+            // expected
+        }   
+    }
+    
+    // resume works on null tx
+    public void testResume3() throws Exception {
+        Transaction tx;
+        assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
+        tm.begin();
+        assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
+        tx = tm.getTransaction();
+        assertNotNull(tx);
+        assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
+
+        tm.commit();
+        assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
+        assertNull(tm.getTransaction());
 
+        // tx should be null
+        tx = tm.suspend();
+        assertNull(tx);
+        
+        try {
+            tm.resume(tx);
+        } catch (InvalidTransactionException e) {
+            // null is considered valid so we don't expect InvalidTransactionException here
+            e.printStackTrace();
+            fail();
+        }   
+    }
+    
+    // resume works on any valid tx
+    public void testResume4() throws Exception {
+        Transaction tx;
+        assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
+        tm.begin();
+        assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
+        tx = tm.getTransaction();
+        assertNotNull(tx);
+        assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
+
+        tm.resume(tx);
+        assertNotNull(tx);
+        assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
+
+        tm.commit();
+        assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
+        assertNull(tm.getTransaction()); 
+    }
 }

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionSynchronizationRegistryTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionSynchronizationRegistryTest.java?rev=725317&r1=725316&r2=725317&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionSynchronizationRegistryTest.java
(original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionSynchronizationRegistryTest.java
Wed Dec 10 07:52:45 2008
@@ -83,6 +83,15 @@
         tm.rollback();
         checkInterposedSyncCalled();
     }
+    
+    /*public void testNormalSynchIsNotCalledOnRollback() throws Exception {
+    	normalSync = new CountingSync();
+    	tm.begin();
+    	tm.getTransaction().registerSynchronization(normalSync);
+        tm.rollback();
+        assertFalse(normalSync.beforeCompletionCalled());
+        assertTrue(normalSync.afterCompletionCalled());
+    }*/
 
     public void testInterposedSynchIsCalledOnMarkRollback() throws Exception {
         setUpInterposedSync();
@@ -150,12 +159,16 @@
 
         private int beforeCount = -1;
         private int afterCount = -1;
+        private boolean beforeCalled = false;
+        private boolean afterCalled = false;
 
         public void beforeCompletion() {
+        	beforeCalled = true;
             beforeCount = beforeCounter++;
         }
 
         public void afterCompletion(int i) {
+        	afterCalled = true;
             afterCount = afterCounter++;
         }
 
@@ -166,6 +179,14 @@
         public int getAfterCount() {
             return afterCount;
         }
+        
+        public boolean beforeCompletionCalled() {
+        	return beforeCalled;
+        }
+        
+        public boolean afterCompletionCalled() {
+        	return afterCalled;
+        }
     }
 
 }



Mime
View raw message