[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/replicated ...
Manik Surtani
msurtani at jboss.com
Fri Dec 8 08:10:42 EST 2006
User: msurtani
Date: 06/12/08 08:10:42
Modified: tests/functional/org/jboss/cache/replicated Tag:
Branch_JBossCache_1_4_0 SyncReplTxTest.java
Log:
Fixed broken test
Revision Changes Path
No revision
No revision
1.9.2.3 +59 -14 JBossCache/tests/functional/org/jboss/cache/replicated/SyncReplTxTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SyncReplTxTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/replicated/SyncReplTxTest.java,v
retrieving revision 1.9.2.2
retrieving revision 1.9.2.3
diff -u -b -r1.9.2.2 -r1.9.2.3
--- SyncReplTxTest.java 4 Nov 2006 04:29:58 -0000 1.9.2.2
+++ SyncReplTxTest.java 8 Dec 2006 13:10:41 -0000 1.9.2.3
@@ -18,19 +18,27 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.TreeCache;
import org.jboss.cache.TreeCacheMBean;
-import org.jboss.cache.aop.AOPInstance;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.lock.TimeoutException;
import org.jboss.cache.transaction.DummyTransactionManager;
import javax.naming.Context;
-import javax.transaction.*;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.List;
+import java.util.ArrayList;
/**
* Replicated unit test for sync transactional TreeCache
* Note: we use DummyTransactionManager for Tx purpose instead of relying on
* jta.
*
- * @version $Revision: 1.9.2.2 $
+ * @version $Revision: 1.9.2.3 $
*/
public class SyncReplTxTest extends TestCase {
private static Log log = LogFactory.getLog(SyncReplTxTest.class);
@@ -158,7 +166,7 @@
cache1.releaseAllLocks("/");
Transaction tx=beginTransaction();
cache1.put("/bela/ban", "name", "Bela Ban");
- assertEquals(2, cache1.getNumberOfLocksHeld());
+ assertEquals(3, cache1.getNumberOfLocksHeld());
assertEquals(0, cache2.getNumberOfLocksHeld());
tx.commit();
assertEquals(0, cache1.getNumberOfLocksHeld());
@@ -259,15 +267,19 @@
}
}
+
public void testSyncReplWithModficationsOnBothCaches() throws Exception {
Integer age;
Transaction tx;
final Fqn NODE1=Fqn.fromString("/one/two/three");
final Fqn NODE2=Fqn.fromString("/eins/zwei/drei");
- try {
initCaches(TreeCache.REPL_SYNC);
+ // create roots first
+ cache1.put("/one/two", null);
+ cache2.put("/eins/zwei", null);
+
cache1.setSyncCommitPhase(true);
cache2.setSyncCommitPhase(true);
@@ -281,11 +293,20 @@
System.out.println("cache1 before commit:\n" + cache1.printLockInfo());
System.out.println("cache2 before commit:\n" + cache2.printLockInfo());
+ try
+ {
tx.commit();
+ fail("Should not succeed with SERIALIZABLE semantics");
+ }
+ catch (Exception e)
+ {
+ //should be a classic deadlock here.
+ }
System.out.println("cache1 after commit:\n" + cache1.printLockInfo());
System.out.println("cache2 after commit:\n" + cache2.printLockInfo());
+ /*
assertTrue(cache1.exists(NODE1));
assertTrue(cache1.exists(NODE2));
assertTrue(cache1.exists(NODE1));
@@ -306,16 +327,13 @@
age=(Integer)cache2.get(NODE2, "age");
assertNotNull("\"age\" obtained from cache2 for " + NODE2 + " must be non-null ", age);
assertTrue("\"age\" must be 39", age.intValue() == 39);
+ */
assertEquals(0, cache1.getNumberOfLocksHeld());
assertEquals(0, cache2.getNumberOfLocksHeld());
System.out.println("TransactionTable for cache1:\n" + cache1.getTransactionTable().toString(true));
System.out.println("TransactionTable for cache2:\n" + cache2.getTransactionTable().toString(true));
}
- catch(Exception e) {
- fail(e.toString());
- }
- }
public void testSyncReplWithModficationsOnBothCachesSameData() throws Exception {
Transaction tx;
@@ -323,6 +341,13 @@
try {
initCaches(TreeCache.REPL_SYNC);
+
+ // sync commit + rollback?
+ cache1.setSyncCommitPhase(true);
+ cache1.setSyncRollbackPhase(true);
+ cache2.setSyncCommitPhase(true);
+ cache2.setSyncRollbackPhase(true);
+
tx=beginTransaction();
cache1.put(NODE, "age", new Integer(38));
System.out.println("TransactionTable for cache1 after cache1.put():\n" + cache1.getTransactionTable().toString(true));
@@ -757,6 +782,8 @@
c2.setCacheMode(TreeCache.REPL_SYNC);
c1.setSyncCommitPhase(true);
c2.setSyncCommitPhase(true);
+ c1.setSyncRollbackPhase(true);
+ c2.setSyncRollbackPhase(true);
c1.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
c2.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
c1.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
@@ -765,6 +792,7 @@
c2.setLockAcquisitionTimeout(5000);
c1.start();
c2.start();
+ final List exceptions = new ArrayList();
class MyThread extends Thread {
Object mutex;
@@ -775,7 +803,7 @@
}
public void run() {
- Transaction tx;
+ Transaction tx = null;
try {
tx=beginTransaction();
@@ -790,7 +818,17 @@
System.out.println("Thread " + getName() + " committed successfully");
}
catch(Exception e) {
- ex=e;
+ exceptions.add(e);
+ }
+ finally {
+ try
+ {
+ if (tx != null) tx.rollback();
+ }
+ catch (Exception e)
+ {
+
+ }
}
}
}
@@ -831,8 +869,15 @@
c1.stop();
c2.stop();
- if(ex != null)
- fail("Thread failed: " + ex);
+// if(ex != null)
+// {
+// ex.printStackTrace();
+// fail("Thread failed: " + ex);
+// }
+
+ // we can only expect 1 thread to succeed. The others will fail. So, threads.length -1 exceptions.
+ assertEquals(threads.length - 1, exceptions.size());
+ for (int i=0; i<exceptions.size(); i++) assertEquals(TimeoutException.class, exceptions.get(i).getClass());
}
More information about the jboss-cvs-commits
mailing list