[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/transaction ...
Brian Stansberry
brian.stansberry at jboss.com
Tue Nov 21 18:33:41 EST 2006
User: bstansberry
Date: 06/11/21 18:33:41
Modified: tests/functional/org/jboss/cache/transaction
IsolationLevelReadCommittedTest.java
Log:
[JBCACHE-871] Add tests for JBCACHE-871
Revision Changes Path
1.8 +91 -1 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.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- IsolationLevelReadCommittedTest.java 6 Sep 2006 15:31:00 -0000 1.7
+++ IsolationLevelReadCommittedTest.java 21 Nov 2006 23:33:41 -0000 1.8
@@ -20,7 +20,7 @@
* Tests READ_COMMITED isolation level.
*
* @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
- * @version $Id: IsolationLevelReadCommittedTest.java,v 1.7 2006/09/06 15:31:00 msurtani Exp $
+ * @version $Id: IsolationLevelReadCommittedTest.java,v 1.8 2006/11/21 23:33:41 bstansberry Exp $
*/
public class IsolationLevelReadCommittedTest extends TestCase
@@ -206,6 +206,96 @@
}
}
+ /**
+ * Test creates a cache node then starts a separate thread that removes
+ * the node inside a tx. Test confirms that the removal cannot be seen
+ * before the test commits.
+ *
+ * @throws Exception
+ */
+ public void testNodeRemoved() throws Exception
+ {
+ final Latch readerCanRead = new Latch();
+ final Latch readerDone = new Latch();
+ final Latch writerDone = new Latch();
+
+ cache.put(FQN, KEY, VALUE);
+ assertEquals(VALUE, cache.get(FQN, KEY));
+
+ // start a writer thread and a transaction
+
+ Thread writerThread = new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ Transaction tx = startTransaction();
+
+ // change VALUE in a transaction
+ cache.remove(FQN);
+
+ // notify the reading thread
+ readerCanRead.release();
+
+ readerDone.acquire();
+
+ tx.commit();
+ }
+ catch (AssertionFailedError e)
+ {
+ writerError = e;
+ }
+ catch(Throwable t)
+ {
+ t.printStackTrace();
+ writerFailed = true;
+ }
+ finally
+ {
+ System.out.println("writer thread exits");
+ readerCanRead.release();
+ writerDone.release();
+ }
+ }
+ }, "WRITER");
+ writerThread.start();
+
+ try
+ {
+ // wait until the writer thread changes the value in a transaction,
+ // but it did not yet commit or roll back.
+ readerCanRead.acquire();
+
+ // I shouldn't be able to see the "dirty" value
+ assertEquals("2nd thread cannot see uncommitted changes",
+ VALUE, cache.get(FQN, KEY));
+ }
+ finally
+ {
+ System.out.println("reader thread exits");
+ readerDone.release();
+ }
+
+ // wait for the writer to finish
+ writerDone.acquire();
+
+ assertNull("Node was removed", cache.get(FQN));
+
+ // If any assertion failed, throw on the AssertionFailedError
+
+ if (writerError != null)
+ {
+ throw writerError;
+ }
+
+ if (writerFailed)
+ {
+ fail("The writer thread exited incorrectly. Watch the log for previous stack traces");
+ }
+
+ }
+
private Transaction startTransaction() throws SystemException, NotSupportedException
{
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
More information about the jboss-cvs-commits
mailing list