[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/transaction ...
Manik Surtani
msurtani at jboss.com
Tue Jan 30 21:40:20 EST 2007
User: msurtani
Date: 07/01/30 21:40:20
Modified: tests/functional/org/jboss/cache/transaction
IsolationLevelReadCommittedNodeCreationRollbackTest.java
IsolationLevelSerializableTest.java
IsolationLevelReadCommittedTest.java
IsolationLevelRepeatableReadTest.java
Log:
Removed dependency on concurrent.jar
Revision Changes Path
1.6 +21 -20 JBossCache/tests/functional/org/jboss/cache/transaction/IsolationLevelReadCommittedNodeCreationRollbackTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: IsolationLevelReadCommittedNodeCreationRollbackTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/transaction/IsolationLevelReadCommittedNodeCreationRollbackTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- IsolationLevelReadCommittedNodeCreationRollbackTest.java 11 Jan 2007 13:49:06 -0000 1.5
+++ IsolationLevelReadCommittedNodeCreationRollbackTest.java 31 Jan 2007 02:40:20 -0000 1.6
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.transaction;
-import EDU.oswego.cs.dl.util.concurrent.Latch;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -22,12 +21,14 @@
import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* Tests READ_COMMITED isolation level.
*
* @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
- * @version $Id: IsolationLevelReadCommittedNodeCreationRollbackTest.java,v 1.5 2007/01/11 13:49:06 msurtani Exp $
+ * @version $Id: IsolationLevelReadCommittedNodeCreationRollbackTest.java,v 1.6 2007/01/31 02:40:20 msurtani Exp $
*/
public class IsolationLevelReadCommittedNodeCreationRollbackTest extends TestCase
@@ -73,11 +74,11 @@
public void testNodeCreationRollback() throws Exception
{
- final Latch secondCanWrite = new Latch();
- final Latch secondCanRead = new Latch();
- final Latch secondDone = new Latch();
- final Latch firstCanRollback = new Latch();
- final Latch firstDone = new Latch();
+ final CountDownLatch secondCanWrite = new CountDownLatch(1);
+ final CountDownLatch secondCanRead = new CountDownLatch(1);
+ final CountDownLatch secondDone = new CountDownLatch(1);
+ final CountDownLatch firstCanRollback = new CountDownLatch(1);
+ final CountDownLatch firstDone = new CountDownLatch(1);
final Fqn PARENT = Fqn.fromString("/a");
@@ -98,10 +99,10 @@
cache.put(a1, KEY, VALUE);
// notify the second thread it can write
- secondCanWrite.release();
+ secondCanWrite.countDown();
// wait until the second thread writes and allows me to rollback or until I timeout
- firstCanRollback.attempt(3000);
+ firstCanRollback.await(3000, TimeUnit.MILLISECONDS);
System.out.println("rolling back");
@@ -110,7 +111,7 @@
assertNull("a1 empty", cache.get(a1, KEY));
// notify the reading thread
- secondCanRead.release();
+ secondCanRead.countDown();
}
catch (AssertionFailedError e)
{
@@ -124,9 +125,9 @@
finally
{
System.out.println("first thread exits");
- secondCanWrite.release();
- secondCanRead.release();
- firstDone.release();
+ secondCanWrite.countDown();
+ secondCanRead.countDown();
+ firstDone.countDown();
}
}
}, "FIRST");
@@ -141,7 +142,7 @@
try
{
// wait until the first thread has created PARENT and a child
- secondCanWrite.acquire();
+ secondCanWrite.await();
System.out.println("writing a2");
@@ -160,10 +161,10 @@
}
// let the first thread know it can rollback
- firstCanRollback.release();
+ firstCanRollback.countDown();
// wait until the first thread rolls back.
- secondCanRead.acquire();
+ secondCanRead.await();
// I should still see the value I put
assertEquals("Known issue JBCACHE-407 -- write lock not acquired on " +
@@ -181,16 +182,16 @@
finally
{
System.out.println("second thread exits");
- firstCanRollback.release();
- secondDone.release();
+ firstCanRollback.countDown();
+ secondDone.countDown();
}
}
}, "SECOND");
secondThread.start();
// wait for both threads to finish
- secondDone.acquire();
- firstDone.acquire();
+ secondDone.await();
+ firstDone.await();
// If any assertion failed, throw on the AssertionFailedError
if (readerError != null)
1.6 +12 -13 JBossCache/tests/functional/org/jboss/cache/transaction/IsolationLevelSerializableTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: IsolationLevelSerializableTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/transaction/IsolationLevelSerializableTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- IsolationLevelSerializableTest.java 11 Jan 2007 13:49:06 -0000 1.5
+++ IsolationLevelSerializableTest.java 31 Jan 2007 02:40:20 -0000 1.6
@@ -1,7 +1,5 @@
package org.jboss.cache.transaction;
-
-import EDU.oswego.cs.dl.util.concurrent.Latch;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -19,13 +17,14 @@
import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
+import java.util.concurrent.CountDownLatch;
/**
* Tests READ_COMMITED isolation level.
*
* @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
- * @version $Id: IsolationLevelSerializableTest.java,v 1.5 2007/01/11 13:49:06 msurtani Exp $
+ * @version $Id: IsolationLevelSerializableTest.java,v 1.6 2007/01/31 02:40:20 msurtani Exp $
*/
public class IsolationLevelSerializableTest extends TestCase
@@ -74,9 +73,9 @@
*/
public void testNodeRemoved() throws Exception
{
- final Latch readerCanRead = new Latch();
- final Latch readerDone = new Latch();
- final Latch writerDone = new Latch();
+ final CountDownLatch readerCanRead = new CountDownLatch(1);
+ final CountDownLatch readerDone = new CountDownLatch(1);
+ final CountDownLatch writerDone = new CountDownLatch(1);
cache.put(FQN, KEY, VALUE);
assertEquals(VALUE, cache.get(FQN, KEY));
@@ -95,9 +94,9 @@
cache.removeNode(FQN);
// notify the reading thread
- readerCanRead.release();
+ readerCanRead.countDown();
- readerDone.acquire();
+ readerDone.await();
tx.commit();
}
@@ -113,8 +112,8 @@
finally
{
System.out.println("writer thread exits");
- readerCanRead.release();
- writerDone.release();
+ readerCanRead.countDown();
+ writerDone.countDown();
}
}
}, "WRITER");
@@ -124,7 +123,7 @@
{
// wait until the writer thread changes the value in a transaction,
// but it did not yet commit or roll back.
- readerCanRead.acquire();
+ readerCanRead.await();
// I shouldn't be able to see the "dirty" value
assertEquals("2nd thread cannot see uncommitted changes",
@@ -137,11 +136,11 @@
finally
{
System.out.println("reader thread exits");
- readerDone.release();
+ readerDone.countDown();
}
// wait for the writer to finish
- writerDone.acquire();
+ writerDone.await();
assertNull("Node was removed", ((CacheImpl) cache).get(FQN));
1.15 +32 -31 JBossCache/tests/functional/org/jboss/cache/transaction/IsolationLevelReadCommittedTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: IsolationLevelReadCommittedTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/transaction/IsolationLevelReadCommittedTest.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- IsolationLevelReadCommittedTest.java 11 Jan 2007 13:49:06 -0000 1.14
+++ IsolationLevelReadCommittedTest.java 31 Jan 2007 02:40:20 -0000 1.15
@@ -1,7 +1,5 @@
package org.jboss.cache.transaction;
-
-import EDU.oswego.cs.dl.util.concurrent.Latch;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -19,13 +17,15 @@
import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* Tests READ_COMMITED isolation level.
*
* @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
- * @version $Id: IsolationLevelReadCommittedTest.java,v 1.14 2007/01/11 13:49:06 msurtani Exp $
+ * @version $Id: IsolationLevelReadCommittedTest.java,v 1.15 2007/01/31 02:40:20 msurtani Exp $
*/
public class IsolationLevelReadCommittedTest extends TestCase
@@ -79,11 +79,11 @@
*/
public void testReadCommitted() throws Exception
{
- final Latch readerCanRead = new Latch();
- final Latch readerDone = new Latch();
- final Latch writerCanWrite = new Latch();
- final Latch writerCanRollback = new Latch();
- final Latch writerDone = new Latch();
+ final CountDownLatch readerCanRead = new CountDownLatch(1);
+ final CountDownLatch readerDone = new CountDownLatch(1);
+ final CountDownLatch writerCanWrite = new CountDownLatch(1);
+ final CountDownLatch writerCanRollback = new CountDownLatch(1);
+ final CountDownLatch writerDone = new CountDownLatch(1);
cache.put(FQN, KEY, VALUE);
assertEquals(VALUE, cache.get(FQN, KEY));
@@ -103,11 +103,11 @@
// Read the value, thus acquiring a read lock on FQN
assertEquals("Could not read node with expected value!", VALUE, cache.get(FQN, KEY));
- writerCanWrite.release();
+ writerCanWrite.countDown();
// wait until the writer thread changes the value in a transaction, but it did not
// yet commit or roll back.
- readerCanRead.acquire();
+ readerCanRead.await();
try
{
@@ -120,7 +120,7 @@
}
// let the writer know it can rollback
- writerCanRollback.release();
+ writerCanRollback.countDown();
// I should still be able to see the "clean" value
assertEquals("Could not read node with expected value!", VALUE, cache.get(FQN, KEY));
@@ -141,9 +141,9 @@
{
try { tx.commit(); } catch (Exception e) {}
}
- writerCanWrite.release();
- writerCanRollback.release();
- readerDone.release();
+ writerCanWrite.countDown();
+ writerCanRollback.countDown();
+ readerDone.countDown();
}
}
}, "READER");
@@ -158,7 +158,8 @@
try
{
// wait until the reader thread reads and allows me to start
- writerCanWrite.attempt(3000);
+
+ writerCanWrite.await(3, TimeUnit.SECONDS);
Transaction tx2 = startTransaction();
@@ -166,10 +167,10 @@
cache.put(FQN, KEY, "this-shouldnt-be-visible");
// notify the reading thread
- readerCanRead.release();
+ readerCanRead.countDown();
// wait until the reader thread reads and allows me to rollback or until I timeout
- writerCanRollback.attempt(3000);
+ writerCanWrite.await(3, TimeUnit.SECONDS);
System.out.println("rolling back");
@@ -187,16 +188,16 @@
finally
{
System.out.println("writer thread exits");
- readerCanRead.release();
- writerDone.release();
+ readerCanRead.countDown();
+ writerDone.countDown();
}
}
}, "WRITER");
writerThread.start();
// wait for both threads to finish
- readerDone.acquire();
- writerDone.acquire();
+ readerDone.await();
+ writerDone.await();
// If any assertion failed, throw on the AssertionFailedError
if (readerError != null)
@@ -229,9 +230,9 @@
*/
public void testNodeRemoved() throws Exception
{
- final Latch readerCanRead = new Latch();
- final Latch readerDone = new Latch();
- final Latch writerDone = new Latch();
+ final CountDownLatch readerCanRead = new CountDownLatch(1);
+ final CountDownLatch readerDone = new CountDownLatch(1);
+ final CountDownLatch writerDone = new CountDownLatch(1);
cache.put(FQN, KEY, VALUE);
assertEquals(VALUE, cache.get(FQN, KEY));
@@ -250,9 +251,9 @@
cache.removeNode(PARENT_FQN);
// notify the reading thread
- readerCanRead.release();
+ readerCanRead.countDown();
- readerDone.acquire();
+ readerDone.await();
tx.commit();
}
@@ -268,8 +269,8 @@
finally
{
System.out.println("writer thread exits");
- readerCanRead.release();
- writerDone.release();
+ readerCanRead.countDown();
+ writerDone.countDown();
}
}
}, "WRITER");
@@ -279,7 +280,7 @@
{
// wait until the writer thread changes the value in a transaction,
// but it did not yet commit or roll back.
- readerCanRead.acquire();
+ readerCanRead.await();
// I shouldn't be able to see the "dirty" value
assertEquals("2nd thread cannot see uncommitted changes",
@@ -292,11 +293,11 @@
finally
{
System.out.println("reader thread exits");
- readerDone.release();
+ readerDone.countDown();
}
// wait for the writer to finish
- writerDone.acquire();
+ writerDone.await();
assertNull("Node was removed", ((CacheImpl) cache).get(FQN));
1.5 +12 -12 JBossCache/tests/functional/org/jboss/cache/transaction/IsolationLevelRepeatableReadTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: IsolationLevelRepeatableReadTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/transaction/IsolationLevelRepeatableReadTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- IsolationLevelRepeatableReadTest.java 11 Jan 2007 13:49:06 -0000 1.4
+++ IsolationLevelRepeatableReadTest.java 31 Jan 2007 02:40:20 -0000 1.5
@@ -1,6 +1,5 @@
package org.jboss.cache.transaction;
-import EDU.oswego.cs.dl.util.concurrent.Latch;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -15,12 +14,13 @@
import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
+import java.util.concurrent.CountDownLatch;
/**
* Tests READ_COMMITED isolation level.
*
* @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
- * @version $Id: IsolationLevelRepeatableReadTest.java,v 1.4 2007/01/11 13:49:06 msurtani Exp $
+ * @version $Id: IsolationLevelRepeatableReadTest.java,v 1.5 2007/01/31 02:40:20 msurtani Exp $
*/
public class IsolationLevelRepeatableReadTest extends TestCase
@@ -65,9 +65,9 @@
*/
public void testNodeRemoved() throws Exception
{
- final Latch readerCanRead = new Latch();
- final Latch readerDone = new Latch();
- final Latch writerDone = new Latch();
+ final CountDownLatch readerCanRead = new CountDownLatch(1);
+ final CountDownLatch readerDone = new CountDownLatch(1);
+ final CountDownLatch writerDone = new CountDownLatch(1);
cache.put(FQN, KEY, VALUE);
assertEquals(VALUE, cache.get(FQN, KEY));
@@ -86,9 +86,9 @@
cache.remove(FQN);
// notify the reading thread
- readerCanRead.release();
+ readerCanRead.countDown();
- readerDone.acquire();
+ readerDone.await();
tx.commit();
}
@@ -104,8 +104,8 @@
finally
{
System.out.println("writer thread exits");
- readerCanRead.release();
- writerDone.release();
+ readerCanRead.countDown();
+ writerDone.countDown();
}
}
}, "WRITER");
@@ -115,7 +115,7 @@
{
// wait until the writer thread changes the value in a transaction,
// but it did not yet commit or roll back.
- readerCanRead.acquire();
+ readerCanRead.await();
// I shouldn't be able to see the "dirty" value
assertEquals("2nd thread cannot see uncommitted changes",
@@ -128,11 +128,11 @@
finally
{
System.out.println("reader thread exits");
- readerDone.release();
+ readerDone.countDown();
}
// wait for the writer to finish
- writerDone.acquire();
+ writerDone.await();
assertNull("Node was not removed", cache.get(FQN));
More information about the jboss-cvs-commits
mailing list