[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/transaction ...

Manik Surtani msurtani at jboss.com
Thu Dec 14 12:52:29 EST 2006


  User: msurtani
  Date: 06/12/14 12:52:29

  Modified:    tests/functional/org/jboss/cache/transaction     
                        IsolationLevelReadCommittedTest.java
                        PrepareTxTest.java DeadlockTest.java
                        IsolationLevelNoneTest.java SuspendTxTest.java
  Log:
  Tests fixed to be compliant with JBCACHE-871 and JBCACHE-875
  
  Revision  Changes    Path
  1.11      +15 -3     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.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- IsolationLevelReadCommittedTest.java	14 Dec 2006 17:18:48 -0000	1.10
  +++ IsolationLevelReadCommittedTest.java	14 Dec 2006 17:52:29 -0000	1.11
  @@ -13,6 +13,7 @@
   import org.jboss.cache.config.Configuration.CacheMode;
   import org.jboss.cache.factories.DefaultCacheFactory;
   import org.jboss.cache.lock.IsolationLevel;
  +import org.jboss.cache.lock.TimeoutException;
   
   import javax.transaction.NotSupportedException;
   import javax.transaction.SystemException;
  @@ -23,7 +24,7 @@
    * Tests READ_COMMITED isolation level.
    *
    * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  - * @version $Id: IsolationLevelReadCommittedTest.java,v 1.10 2006/12/14 17:18:48 msurtani Exp $
  + * @version $Id: IsolationLevelReadCommittedTest.java,v 1.11 2006/12/14 17:52:29 msurtani Exp $
    */
   
   public class IsolationLevelReadCommittedTest extends TestCase
  @@ -107,8 +108,15 @@
                  // yet commit or roll back.
                  readerCanRead.acquire();
   
  +               try
  +               {
                  // I shouldn't be able to see the "dirty" value
                  assertEquals("thread w/ read lock can see subsequent uncommitted changes!!", VALUE, cache.get(FQN, KEY));
  +               }
  +               catch (TimeoutException good)
  +               {
  +                  // this is what should happen due to writer's WL
  +               }
   
                  // let the writer know it can rollback
                  writerCanRollback.release();
  @@ -276,6 +284,10 @@
            assertEquals("2nd thread cannot see uncommitted changes",
                    VALUE, cache.get(FQN, KEY));
         }
  +      catch (TimeoutException t)
  +      {
  +         // ignore, this is good
  +      }
         finally
         {
            System.out.println("reader thread exits");
  
  
  
  1.4       +2 -2      JBossCache/tests/functional/org/jboss/cache/transaction/PrepareTxTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PrepareTxTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/transaction/PrepareTxTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- PrepareTxTest.java	6 Sep 2006 15:31:00 -0000	1.3
  +++ PrepareTxTest.java	14 Dec 2006 17:52:29 -0000	1.4
  @@ -57,7 +57,7 @@
         cache.put("/one/two/three", "key1", "val1");
         System.out.println("before commit:\n" + cache.printLockInfo());
         numLocks = cache.getNumberOfLocksHeld();
  -      assertEquals(3, numLocks);
  +      assertEquals(4, numLocks);
   
         // we register *second*
         tx.registerSynchronization(new Synchronization()
  @@ -115,7 +115,7 @@
         cache.put("/one/two/three", "key1", "val1");
         System.out.println("before commit:\n" + cache.printLockInfo());
         numLocks = cache.getNumberOfLocksHeld();
  -      assertEquals(3, numLocks);
  +      assertEquals(4, numLocks);
   
         // we register *second*
         tx.registerSynchronization(new Synchronization()
  
  
  
  1.7       +75 -59    JBossCache/tests/functional/org/jboss/cache/transaction/DeadlockTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DeadlockTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/transaction/DeadlockTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- DeadlockTest.java	6 Sep 2006 15:31:00 -0000	1.6
  +++ DeadlockTest.java	14 Dec 2006 17:52:29 -0000	1.7
  @@ -30,7 +30,7 @@
    * Tests transactional access to a local TreeCache, with concurrent (deadlock-prone) access.
    * Note: we use DummpyTranasctionManager to replace jta
    *
  - * @version $Id: DeadlockTest.java,v 1.6 2006/09/06 15:31:00 msurtani Exp $
  + * @version $Id: DeadlockTest.java,v 1.7 2006/12/14 17:52:29 msurtani Exp $
    */
   public class DeadlockTest extends TestCase
   {
  @@ -70,10 +70,14 @@
      {
         super.tearDown();
         if (cache != null)
  +      {
            cache.stop();
  +      }
         if (thread_ex != null)
  +      {
            throw thread_ex;
      }
  +   }
   
   
      public void testConcurrentUpgrade() throws CacheException, InterruptedException
  @@ -90,14 +94,14 @@
   
         synchronized (t1)
         {
  -         t1.notify(); // t1 will now try to upgrade RL to WL, but fails b/c t2 still has a RL
  +         t1.notify();// t1 will now try to upgrade RL to WL, but fails b/c t2 still has a RL
         }
   
         TestingUtil.sleepThread((long) 5000);
   
         synchronized (t2)
         {
  -         t2.notify(); // t1 should now be able to upgrade because t1 was rolled back (RL was removed)
  +         t2.notify();// t1 should now be able to upgrade because t1 was rolled back (RL was removed)
         }
   
         t1.join();
  @@ -124,20 +128,23 @@
   
         synchronized (t1)
         {
  -         t1.notify(); // t1 will now try to acquire WL on /1/2/3 (held by t2) - this will time out
  +         t1.notify();// t1 will now try to acquire WL on /1/2/3 (held by t2) - this will time out
         }
   
         TestingUtil.sleepThread((long) 1000);
   
         synchronized (t2)
         {
  -         t2.notify(); // t2 tries to acquire WL on /a/b/c (held by t1)
  +         t2.notify();// t2 tries to acquire WL on /a/b/c (held by t1)
         }
   
         t1.join();
         t2.join();
      }
   
  +   /*
  +
  +    Commented out since JBCACHE-875 onwards, this will end up in a classic deadlock since we lock parent when removing a child.
   
      public void testCreateIfNotExistsLogic() throws CacheException, InterruptedException
      {
  @@ -202,6 +209,7 @@
         t1.join();
      }
   
  +   */
   
      public void testMoreThanOneUpgrader() throws Exception
      {
  @@ -310,11 +318,15 @@
            {
               System.out.println(getName() + ": " + t);
               if (thread_ex == null)
  +            {
                  thread_ex = t;
            }
  +         }
            if (log.isTraceEnabled())
  +         {
               log.trace("Thread " + getName() + " terminated");
         }
  +      }
   
         protected void _run() throws Exception
         {
  @@ -341,7 +353,9 @@
               try
               {
                  if (interrupted())
  +               {
                     break;
  +               }
                  tx = startTransaction();
                  log("remove(" + fqn + ")");
                  cache.remove(fqn);
  @@ -380,7 +394,9 @@
               try
               {
                  if (interrupted())
  +               {
                     break;
  +               }
                  tx = startTransaction();
                  log("put(" + fqn + ")");
                  cache.put(fqn, "foo", "bar");
  @@ -422,13 +438,13 @@
         {
            tx = startTransaction();
            log("get(" + fqn + ")");
  -         cache.get(fqn, "bla"); // acquires RL
  +         cache.get(fqn, "bla");// acquires RL
            log("done, locks: " + cache.printLockInfo());
   
            synchronized (this) {wait();}
   
            log("put(" + fqn + ")");
  -         cache.put(fqn, "key", "val"); // need to upgrade RL to WL
  +         cache.put(fqn, "key", "val");// need to upgrade RL to WL
            log("done, locks: " + cache.printLockInfo());
            tx.commit();
            log("committed TX, locks: " + cache.printLockInfo());
  @@ -458,12 +474,12 @@
            {
               log("get(" + fqn + ")");
   
  -            cache.get(fqn, "bla"); // acquires RL
  +            cache.get(fqn, "bla");// acquires RL
   
               synchronized (lock) {lock.wait();}
   
               log("put(" + fqn + ")");
  -            cache.put(fqn, "key", "val"); // need to upgrade RL to WL
  +            cache.put(fqn, "key", "val");// need to upgrade RL to WL
               log("done, locks: " + cache.printLockInfo());
               tx.commit();
               log("committed TX, locks: " + cache.printLockInfo());
  @@ -521,11 +537,11 @@
         {
            tx = startTransaction();
            log("put(" + fqn1 + ")");
  -         cache.put(fqn1, "key", "val"); // need to upgrade RL to WL
  +         cache.put(fqn1, "key", "val");// need to upgrade RL to WL
            log("done, locks: " + cache.printLockInfo());
            synchronized (this) {wait();}
            log("put(" + fqn2 + ")");
  -         cache.put(fqn2, "key", "val"); // need to upgrade RL to WL
  +         cache.put(fqn2, "key", "val");// need to upgrade RL to WL
            log("done, locks: " + cache.printLockInfo());
            tx.commit();
            log("committed TX, locks: " + cache.printLockInfo());
  
  
  
  1.5       +2 -2      JBossCache/tests/functional/org/jboss/cache/transaction/IsolationLevelNoneTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: IsolationLevelNoneTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/transaction/IsolationLevelNoneTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- IsolationLevelNoneTest.java	6 Sep 2006 15:31:00 -0000	1.4
  +++ IsolationLevelNoneTest.java	14 Dec 2006 17:52:29 -0000	1.5
  @@ -17,7 +17,7 @@
    * Tests whether modifications within callbacks (TreeCacheListener) are handled correctly
    *
    * @author Bela Ban
  - * @version $Id: IsolationLevelNoneTest.java,v 1.4 2006/09/06 15:31:00 msurtani Exp $
  + * @version $Id: IsolationLevelNoneTest.java,v 1.5 2006/12/14 17:52:29 msurtani Exp $
    */
   public class IsolationLevelNoneTest extends TestCase
   {
  @@ -90,7 +90,7 @@
         assertTrue(cache.exists(FQN, KEY));
         assertEquals(VALUE, cache.get(FQN, KEY));
         System.out.println("cache: " + cache.toString(true) + ", locks: " + cache.printLockInfo());
  -      assertEquals(4, cache.getNumberOfLocksHeld());
  +      assertEquals(5, cache.getNumberOfLocksHeld());
         tx.commit();
      }
   
  
  
  
  1.3       +4 -1      JBossCache/tests/functional/org/jboss/cache/transaction/SuspendTxTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SuspendTxTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/transaction/SuspendTxTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- SuspendTxTest.java	11 Oct 2006 13:56:31 -0000	1.2
  +++ SuspendTxTest.java	14 Dec 2006 17:52:29 -0000	1.3
  @@ -47,6 +47,9 @@
       */
      public void testSuspendedLocks() throws Exception
      {
  +      // create /one first
  +      cache.put("/one", null);
  +      cache.put("/a", null);
         mgr.begin();
   
         cache.put("/one/two", "key1", "val1");
  @@ -71,7 +74,7 @@
         cache.put("/one/two", "key1", "val1");
         int numLocksBefore = cache.getNumberOfLocksHeld();
   
  -      cache.getInvocationContext().getOptionOverrides().setFailSilently(true); // will cause any current txs to be suspended for the duration of this call.
  +      cache.getInvocationContext().getOptionOverrides().setFailSilently(true);// will cause any current txs to be suspended for the duration of this call.
         cache.put(Fqn.fromString("/a/b"), "key1", "val1");
   
         assertEquals(numLocksBefore, cache.getNumberOfLocksHeld());
  
  
  



More information about the jboss-cvs-commits mailing list