Fix unit tests after GERONIMO-6372
git-svn-id: https://svn.apache.org/repos/asf/geronimo/components/txmanager/trunk@1365070 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/log/HOWLLogTest.java b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/log/HOWLLogTest.java
index 93da6ec..87c10cd 100644
--- a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/log/HOWLLogTest.java
+++ b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/log/HOWLLogTest.java
@@ -47,7 +47,7 @@
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",
diff --git a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/AbstractRecoveryTest.java b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/AbstractRecoveryTest.java
index ba64e26..946a349 100644
--- a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/AbstractRecoveryTest.java
+++ b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/AbstractRecoveryTest.java
@@ -35,9 +35,6 @@
* */
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 @@
@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 @@
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 @@
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 @@
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 @@
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()));
}
diff --git a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HOWLLogRecoveryTest.java b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HOWLLogRecoveryTest.java
index 4b22e87..a240a3d 100644
--- a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HOWLLogRecoveryTest.java
+++ b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HOWLLogRecoveryTest.java
@@ -19,10 +19,10 @@
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,6 +37,18 @@
private static final String targetDir = new File(basedir, "target").getAbsolutePath();
private static final File txlogDir = new File(basedir, "target/" + logFileDir);
+ @Override
+ public void setUp() throws Exception {
+ // Deletes the previous transaction log files.
+ File[] files = txlogDir.listFiles();
+ if ( null != files ) {
+ for (int i = 0; i < files.length; i++) {
+ files[i].delete();
+ }
+ }
+ super.setUp();
+ }
+
public void test2Again() throws Exception {
test2ResOnlineAfterRecoveryStart();
}
@@ -45,19 +57,9 @@
test3ResOnlineAfterRecoveryStart();
}
- protected void setUp() throws Exception {
- // Deletes the previous transaction log files.
- File[] files = txlogDir.listFiles();
- if ( null != files ) {
- for (int i = 0; i < files.length; i++) {
- files[i].delete();
- }
- }
- setUpHowlLog();
- super.setUp();
- }
-
- private void setUpHowlLog() throws Exception {
+ @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 @@
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() {
diff --git a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockLogRecoveryTest.java b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockLogRecoveryTest.java
index 9b1e097..a5bb435 100644
--- a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockLogRecoveryTest.java
+++ b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockLogRecoveryTest.java
@@ -25,16 +25,21 @@
* */
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();
}
}
diff --git a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java
index 62bd727..e5ff07e 100644
--- a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java
+++ b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java
@@ -35,7 +35,6 @@
* */
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 @@
@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 @@
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 @@
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 @@
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 @@
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 @@
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;
}
diff --git a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
index fed029d..4f65c4e 100644
--- a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
+++ b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
@@ -23,6 +23,7 @@
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 @@
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 @@
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 @@
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());