Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 85014 invoked from network); 10 Dec 2008 15:53:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Dec 2008 15:53:09 -0000 Received: (qmail 39603 invoked by uid 500); 10 Dec 2008 15:53:21 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 39541 invoked by uid 500); 10 Dec 2008 15:53:21 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 39532 invoked by uid 99); 10 Dec 2008 15:53:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Dec 2008 07:53:21 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Dec 2008 15:53:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 805FD23888A2; Wed, 10 Dec 2008 07:52:45 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: scm@geronimo.apache.org From: linsun@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081210155245.805FD23888A2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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; + } } }