Author: mircea.markus
Date: 2008-02-05 10:45:44 -0500 (Tue, 05 Feb 2008)
New Revision: 5293
Modified:
core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java
Log:
added a test to check that if a timeout happens, locks are being released
Modified: core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java 2008-02-05 15:42:05
UTC (rev 5292)
+++ core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java 2008-02-05 15:45:44
UTC (rev 5293)
@@ -12,14 +12,22 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeNotExistsException;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.transaction.TransactionSetup;
-import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import javax.transaction.UserTransaction;
+import javax.transaction.Transaction;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* Verifies that there are no read locks held when a transaction ends.
@@ -225,4 +233,63 @@
tx.commit();
assertEquals("we should have released all 3 write locks: ", 0,
cache.getNumberOfLocksHeld());
}
+
+ /**
+ * Tests that when an acquisition timeout occurs locks are being released.
+ */
+ @Test(invocationCount = 100)
+ public void testNodeReleaseOnAcquisitionTimeout() throws Exception
+ {
+ cache = createCache(IsolationLevel.REPEATABLE_READ);
+ cache.put("/a/b","key","value");
+ cache.put("/c","key","value");
+ final Object rLockAcquired = new Object();
+ final Object wlTimeouted = new Object();
+ final Object txLocksReleased = new Object();
+ Thread thread = new Thread() {
+ public void run()
+ {
+ try
+ {
+ cache.getTransactionManager().begin();
+ cache.get("/a/b", "key"); //at this point we have an
RL on /c and /c/d
+ synchronized (rLockAcquired)
+ {
+ rLockAcquired.notify();
+ }
+ synchronized ( wlTimeouted)
+ {
+ wlTimeouted.wait(50000); //wait a long time but die eventually
+ }
+ cache.getTransactionManager().commit();//here we are releasing locks
+ synchronized (txLocksReleased)
+ {
+ txLocksReleased.notify();
+ }
+ }
+ catch(Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ };
+ thread.start();
+ synchronized (rLockAcquired) { rLockAcquired.wait(50000); }
+ try
+ {
+ cache.move("/a/b","c"); //acquired RL on /a and /a/b
+ fail("expected timeout here");
+ } catch (TimeoutException e)
+ {
+ synchronized (wlTimeouted)
+ {
+ wlTimeouted.notify();
+ }
+ }
+ synchronized (txLocksReleased)
+ {
+ txLocksReleased.wait();//wait for tx locks to be released
+ }
+ assertEquals(0, cache.getNumberOfLocksHeld());
+ }
}
Show replies by date