Author: manik.surtani(a)jboss.com
Date: 2008-04-07 05:48:44 -0400 (Mon, 07 Apr 2008)
New Revision: 5505
Modified:
core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java
Log:
Improved test accuracy
Modified: core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java 2008-04-07 08:45:18
UTC (rev 5504)
+++ core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java 2008-04-07 09:48:44
UTC (rev 5505)
@@ -12,19 +12,14 @@
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.*;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.fail;
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;
@@ -241,55 +236,51 @@
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() {
+ cache.put("/a/b", "key", "value");
+ cache.put("/c", "key", "value");
+ final CountDownLatch rLockAcquired = new CountDownLatch(1);
+ final CountDownLatch wlTimeouted = new CountDownLatch(1);
+ final CountDownLatch txLocksReleased = new CountDownLatch(1);
+
+
+ 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
- }
+ rLockAcquired.countDown();
+ wlTimeouted.await(60, TimeUnit.SECONDS); //wait a long time but die
eventually
+
cache.getTransactionManager().commit();//here we are releasing locks
- synchronized (txLocksReleased)
- {
- txLocksReleased.notify();
- }
- }
- catch(Exception ex)
+
+ txLocksReleased.countDown();
+ }
+ catch (Exception ex)
{
ex.printStackTrace();
}
}
};
+
thread.start();
- synchronized (rLockAcquired) { rLockAcquired.wait(50000); }
+
+ rLockAcquired.await();
+
try
{
- cache.move("/a/b","c"); //acquired RL on /a and /a/b
+ 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)
+ catch (TimeoutException e)
{
- txLocksReleased.wait();//wait for tx locks to be released
+ wlTimeouted.countDown();
}
+
+ txLocksReleased.await(); //wait for tx locks to be released
+
assertEquals(0, cache.getNumberOfLocksHeld());
System.out.println("LockReleaseTest.testNodeReleaseOnAcquisitionTimeout
finished!");
}
Show replies by date