[jbosscache-commits] JBoss Cache SVN: r5506 - core/branches/2.1.X/src/test/java/org/jboss/cache/lock.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Apr 7 05:51:48 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-04-07 05:51:48 -0400 (Mon, 07 Apr 2008)
New Revision: 5506

Modified:
   core/branches/2.1.X/src/test/java/org/jboss/cache/lock/LockReleaseTest.java
Log:
Improved inter-thread comms in test

Modified: core/branches/2.1.X/src/test/java/org/jboss/cache/lock/LockReleaseTest.java
===================================================================
--- core/branches/2.1.X/src/test/java/org/jboss/cache/lock/LockReleaseTest.java	2008-04-07 09:48:44 UTC (rev 5505)
+++ core/branches/2.1.X/src/test/java/org/jboss/cache/lock/LockReleaseTest.java	2008-04-07 09:51:48 UTC (rev 5506)
@@ -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;
@@ -35,7 +30,7 @@
  * @author Bela Ban
  * @version $Id$
  */
- at Test(groups = {"functional"})
+ at Test(groups = "functional")
 public class LockReleaseTest
 {
    CacheSPI<Object, Object> cache = null;
@@ -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!");
    }




More information about the jbosscache-commits mailing list