geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1365070 - in /geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction: log/ manager/
Date Tue, 24 Jul 2012 14:09:43 GMT
Author: gnodet
Date: Tue Jul 24 14:09:42 2012
New Revision: 1365070

URL: http://svn.apache.org/viewvc?rev=1365070&view=rev
Log:
Fix unit tests after GERONIMO-6372

Modified:
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/log/HOWLLogTest.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/AbstractRecoveryTest.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HOWLLogRecoveryTest.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockLogRecoveryTest.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/log/HOWLLogTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/log/HOWLLogTest.java?rev=1365070&r1=1365069&r2=1365070&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/log/HOWLLogTest.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/log/HOWLLogTest.java
Tue Jul 24 14:09:42 2012
@@ -47,7 +47,7 @@ public class HOWLLogTest extends Abstrac
 
 
     protected TransactionLog createTransactionLog() throws Exception {
-        XidFactory xidFactory = new XidFactoryImpl();
+        XidFactory xidFactory = new XidFactoryImpl("hi".getBytes());
         HOWLLog howlLog = new HOWLLog(
                 "org.objectweb.howl.log.BlockLogBuffer", //                "bufferClassName",
                 4, //                "bufferSizeKBytes",

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/AbstractRecoveryTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/AbstractRecoveryTest.java?rev=1365070&r1=1365069&r2=1365070&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/AbstractRecoveryTest.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/AbstractRecoveryTest.java
Tue Jul 24 14:09:42 2012
@@ -35,9 +35,6 @@ import junit.framework.TestCase;
  * */
 public abstract class AbstractRecoveryTest extends TestCase {
 
-    protected TransactionLog txLog;
-
-    protected final XidFactory xidFactory = new XidFactoryImpl();
     protected TransactionManagerImpl txManager;
     private static final String RM1 = "rm1";
     private static final String RM2 = "rm2";
@@ -47,7 +44,11 @@ public abstract class AbstractRecoveryTe
 
     @Override
     protected void setUp() throws Exception {
-        txManager = new TransactionManagerImpl(1, xidFactory, txLog);
+        txManager = createTransactionManager();
+    }
+
+    protected TransactionManagerImpl createTransactionManager() throws Exception {
+        return new TransactionManagerImpl(1, new XidFactoryImpl("hi".getBytes()), null);
     }
 
     public void test2ResOnlineAfterRecoveryStart() throws Exception {
@@ -57,7 +58,7 @@ public abstract class AbstractRecoveryTe
         MockTransactionInfo[] txInfos = makeTxInfos(xids);
         addBranch(txInfos, xares1);
         addBranch(txInfos, xares2);
-        prepareLog(txLog, txInfos);
+        prepareLog(txManager.getTransactionLog(), txInfos);
         prepareForReplay();
         Recovery recovery = txManager.recovery;
         assertTrue(!recovery.hasRecoveryErrors());
@@ -97,15 +98,15 @@ public abstract class AbstractRecoveryTe
         MockTransactionInfo[] txInfos12 = makeTxInfos(xids12);
         addBranch(txInfos12, xares1);
         addBranch(txInfos12, xares2);
-        prepareLog(txLog, txInfos12);
+        prepareLog(txManager.getTransactionLog(), txInfos12);
         MockTransactionInfo[] txInfos13 = makeTxInfos(xids13);
         addBranch(txInfos13, xares1);
         addBranch(txInfos13, xares3);
-        prepareLog(txLog, txInfos13);
+        prepareLog(txManager.getTransactionLog(), txInfos13);
         MockTransactionInfo[] txInfos23 = makeTxInfos(xids23);
         addBranch(txInfos23, xares2);
         addBranch(txInfos23, xares3);
-        prepareLog(txLog, txInfos23);
+        prepareLog(txManager.getTransactionLog(), txInfos23);
         prepareForReplay();
         Recovery recovery = txManager.recovery;
         assertTrue(!recovery.hasRecoveryErrors());
@@ -136,7 +137,7 @@ public abstract class AbstractRecoveryTe
     private Xid[] getXidArray(int i) {
         Xid[] xids = new Xid[i];
         for (int j = 0; j < xids.length; j++) {
-            xids[j] = xidFactory.createXid();
+            xids[j] = txManager.getXidFactory().createXid();
         }
         return xids;
     }
@@ -145,7 +146,7 @@ public abstract class AbstractRecoveryTe
         for (int i = 0; i < txInfos.length; i++) {
             MockTransactionInfo txInfo = txInfos[i];
             Xid globalXid = txInfo.globalXid;
-            Xid branchXid = xidFactory.createBranch(globalXid, branchCounter++);
+            Xid branchXid = txManager.getXidFactory().createBranch(globalXid, branchCounter++);
             xaRes.start(branchXid, 0);
             txInfo.branches.add(new TransactionBranchInfoImpl(branchXid, xaRes.getName()));
         }

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HOWLLogRecoveryTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HOWLLogRecoveryTest.java?rev=1365070&r1=1365069&r2=1365070&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HOWLLogRecoveryTest.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HOWLLogRecoveryTest.java
Tue Jul 24 14:09:42 2012
@@ -19,10 +19,10 @@ package org.apache.geronimo.transaction.
 
 import java.io.File;
 
-import org.apache.geronimo.transaction.log.HOWLLog;
+import junit.extensions.TestSetup;
 import junit.framework.Test;
 import junit.framework.TestSuite;
-import junit.extensions.TestSetup;
+import org.apache.geronimo.transaction.log.HOWLLog;
 
 /**
  *
@@ -37,15 +37,8 @@ public class HOWLLogRecoveryTest extends
     private static final String targetDir = new File(basedir, "target").getAbsolutePath();
     private static final File txlogDir = new File(basedir, "target/" + logFileDir);
 
-    public void test2Again() throws Exception {
-        test2ResOnlineAfterRecoveryStart();
-    }
-
-    public void test3Again() throws Exception {
-        test3ResOnlineAfterRecoveryStart();
-    }
-
-    protected void setUp() throws Exception {
+    @Override
+    public void setUp() throws Exception {
         // Deletes the previous transaction log files.
         File[] files = txlogDir.listFiles();
         if ( null != files ) {
@@ -53,11 +46,20 @@ public class HOWLLogRecoveryTest extends
                 files[i].delete();
             }
         }
-        setUpHowlLog();
         super.setUp();
     }
 
-    private void setUpHowlLog() throws Exception {
+    public void test2Again() throws Exception {
+        test2ResOnlineAfterRecoveryStart();
+    }
+
+    public void test3Again() throws Exception {
+        test3ResOnlineAfterRecoveryStart();
+    }
+
+    @Override
+    protected TransactionManagerImpl createTransactionManager() throws Exception {
+        XidFactory xidFactory = new XidFactoryImpl("hi".getBytes());
         HOWLLog howlLog = new HOWLLog(
                 "org.objectweb.howl.log.BlockLogBuffer", //                "bufferClassName",
                 4, //                "bufferSizeKBytes",
@@ -76,18 +78,17 @@ public class HOWLLogRecoveryTest extends
                 new File(targetDir)
         );
         howlLog.doStart();
-        txLog = howlLog;
+        return new TransactionManagerImpl(1, xidFactory, howlLog);
     }
 
     protected void tearDown() throws Exception {
-        ((HOWLLog)txLog).doStop();
-        txLog = null;
+        ((HOWLLog) txManager.getTransactionLog()).doStop();
     }
 
     protected void prepareForReplay() throws Exception {
+        Thread.sleep(100);
         tearDown();
-        setUpHowlLog();
-        super.setUp();
+        txManager = createTransactionManager();
     }
 
     public static Test suite() {

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockLogRecoveryTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockLogRecoveryTest.java?rev=1365070&r1=1365069&r2=1365070&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockLogRecoveryTest.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockLogRecoveryTest.java
Tue Jul 24 14:09:42 2012
@@ -25,16 +25,21 @@ package org.apache.geronimo.transaction.
  * */
 public class MockLogRecoveryTest extends AbstractRecoveryTest {
 
-    protected void setUp() throws Exception {
-        txLog = new MockLog();
+    private TransactionLog log;
+
+    @Override
+    public void setUp() throws Exception {
+        log = new MockLog();
         super.setUp();
     }
 
-    protected void tearDown() throws Exception {
-        txLog = null;
+    @Override
+    protected TransactionManagerImpl createTransactionManager() throws Exception {
+        return new TransactionManagerImpl(1, new XidFactoryImpl("hi".getBytes()), log);
     }
 
     protected void prepareForReplay() throws Exception {
-        txManager.recovery.recoverLog();
+        Thread.sleep(100);
+        txManager = createTransactionManager();
     }
 }

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java?rev=1365070&r1=1365069&r2=1365070&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java
Tue Jul 24 14:09:42 2012
@@ -35,7 +35,6 @@ import junit.framework.TestCase;
  * */
 public class RecoveryTest extends TestCase {
 
-    XidFactory xidFactory = new XidFactoryImpl();
     MockLog mockLog = new MockLog();
     protected TransactionManagerImpl txManager;
     private final String RM1 = "rm1";
@@ -45,7 +44,16 @@ public class RecoveryTest extends TestCa
 
     @Override
     protected void setUp() throws Exception {
-        txManager = new TransactionManagerImpl(1, xidFactory, mockLog);
+        txManager = createTransactionManager();
+    }
+
+    protected TransactionManagerImpl createTransactionManager() throws XAException, InterruptedException
{
+        return new TransactionManagerImpl(1, new XidFactoryImpl("hi".getBytes()), mockLog);
+    }
+
+    protected void prepareForReplay() throws Exception {
+        Thread.sleep(100);
+        txManager = createTransactionManager();
     }
 
     public void testCommittedRMToBeRecovered() throws Exception {
@@ -58,8 +66,8 @@ public class RecoveryTest extends TestCa
         MockTransactionInfo[] txInfos = makeTxInfos(xids);
         addBranch(txInfos, xares1);
         prepareLog(mockLog, txInfos);
-        Recovery recovery = new RecoveryImpl(txManager);
-        recovery.recoverLog();
+        prepareForReplay();
+        Recovery recovery = txManager.recovery;
         assertTrue(!recovery.hasRecoveryErrors());
         assertTrue(recovery.getExternalXids().isEmpty());
         assertTrue(!recovery.localRecoveryComplete());
@@ -77,8 +85,8 @@ public class RecoveryTest extends TestCa
         addBranch(txInfos, xares1);
         addBranch(txInfos, xares2);
         prepareLog(mockLog, txInfos);
-        Recovery recovery = new RecoveryImpl(txManager);
-        recovery.recoverLog();
+        prepareForReplay();
+        Recovery recovery = txManager.recovery;
         assertTrue(!recovery.hasRecoveryErrors());
         assertTrue(recovery.getExternalXids().isEmpty());
         assertTrue(!recovery.localRecoveryComplete());
@@ -87,14 +95,14 @@ public class RecoveryTest extends TestCa
         assertEquals(3, xares1.committed.size());
         recovery.recoverResourceManager(xares2);
         assertEquals(3, xares2.committed.size());
-        assertTrue(recovery.localRecoveryComplete());
+        assertTrue(txManager.recovery.localRecoveryComplete());
 
     }
 
     private void addBranch(MockTransactionInfo[] txInfos, MockXAResource xaRes) throws XAException
{
         for (int i = 0; i < txInfos.length; i++) {
             MockTransactionInfo txInfo = txInfos[i];
-            Xid xid = xidFactory.createBranch(txInfo.globalXid, count++);
+            Xid xid = txManager.getXidFactory().createBranch(txInfo.globalXid, count++);
             xaRes.start(xid, 0);
             txInfo.branches.add(new TransactionBranchInfoImpl(xid, xaRes.getName()));
         }
@@ -144,8 +152,8 @@ public class RecoveryTest extends TestCa
         addBranch(txInfos23, xares2);
         addBranch(txInfos23, xares3);
         prepareLog(mockLog, txInfos23);
-        Recovery recovery = new RecoveryImpl(txManager);
-        recovery.recoverLog();
+        prepareForReplay();
+        Recovery recovery = txManager.recovery;
         assertTrue(!recovery.hasRecoveryErrors());
         assertTrue(recovery.getExternalXids().isEmpty());
         assertEquals(9, recovery.localUnrecoveredCount());
@@ -172,7 +180,7 @@ public class RecoveryTest extends TestCa
     private Xid[] getXidArray(int i) {
         Xid[] xids = new Xid[i];
         for (int j = 0; j < xids.length; j++) {
-            xids[j] = xidFactory.createXid();
+            xids[j] = txManager.getXidFactory().createXid();
         }
         return xids;
     }

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java?rev=1365070&r1=1365069&r2=1365070&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
Tue Jul 24 14:09:42 2012
@@ -23,6 +23,7 @@ import javax.transaction.InvalidTransact
 import javax.transaction.RollbackException;
 import javax.transaction.Status;
 import javax.transaction.Transaction;
+import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
@@ -45,7 +46,11 @@ public class TransactionManagerImplTest 
     TransactionManagerImpl tm;
 
     protected void setUp() throws Exception {
-        tm = new TransactionManagerImpl(10,
+        tm = createTransactionManager();
+    }
+
+    private TransactionManagerImpl createTransactionManager() throws XAException {
+        return new TransactionManagerImpl(10,
                 new XidFactoryImpl("WHAT DO WE CALL IT?".getBytes()), transactionLog);
     }
 
@@ -255,7 +260,8 @@ public class TransactionManagerImplTest 
         tm.suspend();
         tm.prepare(tx);
         //recover
-        tm.recovery.recoverLog();
+        Thread.sleep(100); // Wait a bit for new XidFactoryImpl
+        tm = createTransactionManager();
         recover(r1_1);
         recover(r1_2);
         assertTrue(r1_2.isCommitted());
@@ -285,7 +291,8 @@ public class TransactionManagerImplTest 
         tm.suspend();
         tm.prepare(tx);
         //recover
-        tm.recovery.recoverLog();
+        Thread.sleep(100); // Wait a bit for new XidFactoryImpl
+        tm = createTransactionManager();
         recover(r1_1);
         recover(r1_2);
         assertTrue(!r1_2.isCommitted());



Mime
View raw message