From: Bela B. <bel...@jb...> - 2005-09-06 23:05:55
|
User: bela Date: 05/09/06 19:05:52 Modified: tests/functional/org/jboss/cache/lock LockTest.java Log: uncommented test case testReadUncommitted() Revision Changes Path 1.2 +67 -66 JBossCache/tests/functional/org/jboss/cache/lock/LockTest.java (In the diff below, changes in quantity of whitespace are not shown.) Index: LockTest.java =================================================================== RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/lock/LockTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- LockTest.java 8 Jul 2005 05:58:11 -0000 1.1 +++ LockTest.java 6 Sep 2005 23:05:52 -0000 1.2 @@ -6,13 +6,12 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import org.jboss.cache.lock.*; /** * Various tests that test isolation level semantics provided by locks * * @author Bela Ban - * @version $Id: LockTest.java,v 1.1 2005/07/08 05:58:11 msurtani Exp $ + * @version $Id: LockTest.java,v 1.2 2005/09/06 23:05:52 bela Exp $ */ public class LockTest extends TestCase { int value=10; @@ -163,71 +162,73 @@ * T1 sees T2's committed modification - 20 * </ol> * <em>Commented for now, until we get the right semantics</em> + * See http://www-128.ibm.com/developerworks/java/library/j-jtp0514.html for a discussion of + * isolation levels */ -// public void testReadCommitted() throws Throwable { -// final LockStrategy s=new LockStrategyReadCommitted(); -// -// Thread t1=new Thread("t1") { -// Sync lock=null; -// -// public void run() { -// try { -// lock=s.readLock(); -// lock.attempt(TIMEOUT); -// log("1st read: value is " + value); -// assertEquals(10, value); -// _sleep(SLEEP); -// -// log("2nd read: value is " + value + "; we should *not* see t2's uncommitted change (20)"); -// assertEquals(10, value); // we're seeing the modification by t2 before t2 committed (a.k.a. released the lock) -// _sleep(SLEEP); -// -// log("3rd read: value is still " + value + "; we should see t2's committed change"); -// assertEquals(20, value); -// } -// catch(Throwable ex) { -// t1_ex=ex; -// } -// finally { -// lock.release(); -// } -// } -// }; -// -// -// Thread t2=new Thread("t2") { -// Sync lock=null; -// -// public void run() { -// try { -// _sleep(100); -// lock=s.writeLock(); -// lock.attempt(TIMEOUT); -// log("changing value from " + value + " to 20"); -// value=20; -// _sleep(SLEEP); -// -// log("committing the TX"); -// lock.release(); -// } -// catch(Throwable ex) { -// t2_ex=ex; -// } -// finally { -// lock.release(); -// } -// } -// }; -// -// t1.start(); -// t2.start(); -// t1.join(); -// t2.join(); -// if(t1_ex != null) -// throw t1_ex; -// if(t2_ex != null) -// throw t2_ex; -// } + public void testReadCommitted() throws Throwable { + final LockStrategy s=new LockStrategyReadCommitted(); + + Thread t1=new Thread("t1") { + Sync lock=null; + + public void run() { + try { + lock=s.readLock(); + lock.attempt(TIMEOUT); + log("1st read: value is " + value); + assertEquals(10, value); + _sleep(SLEEP); + + log("2nd read: value is " + value + "; we should *not* see t2's uncommitted change (20)"); + assertEquals(10, value); // we're seeing the modification by t2 before t2 committed (a.k.a. released the lock) + _sleep(SLEEP); + + log("3rd read: value is still " + value + "; we should see t2's committed change"); + assertEquals(20, value); + } + catch(Throwable ex) { + t1_ex=ex; + } + finally { + lock.release(); + } + } + }; + + + Thread t2=new Thread("t2") { + Sync lock=null; + + public void run() { + try { + _sleep(100); + lock=s.writeLock(); + lock.attempt(TIMEOUT); + log("changing value from " + value + " to 20"); + value=20; + _sleep(SLEEP * 2); + + log("committing the TX"); + lock.release(); + } + catch(Throwable ex) { + t2_ex=ex; + } + finally { + lock.release(); + } + } + }; + + t1.start(); + t2.start(); + t1.join(); + t2.join(); + if(t1_ex != null) + throw t1_ex; + if(t2_ex != null) + throw t2_ex; + } |