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

Manik Surtani manik at jboss.org
Wed Jul 18 11:40:39 EDT 2007


  User: msurtani
  Date: 07/07/18 11:40:39

  Modified:    tests/functional/org/jboss/cache/optimistic   Tag:
                        Branch_JBossCache_1_4_0
                        ConcurrentTransactionTest.java
  Removed:     tests/functional/org/jboss/cache/optimistic   Tag:
                        Branch_JBossCache_1_4_0 ConcurrentCreationTest.java
  Log:
  consolidated JBCACHE-1026 tests
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +88 -5     JBossCache/tests/functional/org/jboss/cache/optimistic/ConcurrentTransactionTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConcurrentTransactionTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/optimistic/ConcurrentTransactionTest.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -b -r1.1.2.2 -r1.1.2.3
  --- ConcurrentTransactionTest.java	20 Apr 2007 13:09:41 -0000	1.1.2.2
  +++ ConcurrentTransactionTest.java	18 Jul 2007 15:40:38 -0000	1.1.2.3
  @@ -6,17 +6,21 @@
    */
   package org.jboss.cache.optimistic;
   
  +import EDU.oswego.cs.dl.util.concurrent.Latch;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.OptimisticTreeNode;
   import org.jboss.cache.TreeCache;
  +import org.jboss.cache.interceptors.Interceptor;
  +import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
  +import org.jboss.cache.misc.TestingUtil;
  +import org.jgroups.blocks.MethodCall;
   
   import javax.transaction.Transaction;
   import javax.transaction.TransactionManager;
  -import java.util.List;
  -import java.util.LinkedList;
   import java.util.Iterator;
  -
  -import EDU.oswego.cs.dl.util.concurrent.Latch;
  +import java.util.LinkedList;
  +import java.util.List;
  +import java.util.concurrent.CopyOnWriteArrayList;
   
   /**
    *
  @@ -25,6 +29,9 @@
   public class ConcurrentTransactionTest extends AbstractOptimisticTestCase
   {
       private TreeCache cache;
  +   private Fqn f = Fqn.fromString("/a/b");
  +   private List exceptions = new CopyOnWriteArrayList();
  +
   
       public ConcurrentTransactionTest(String name)
       {
  @@ -53,6 +60,7 @@
               cache.stopService();
               cache = null;
           }
  +       exceptions.clear();
       }
   
       public void testConcurrentTransactions() throws Exception
  @@ -194,4 +202,79 @@
   
         assertTrue("Should not have caught any exceptions!!", exceptions.isEmpty());
      }
  +   
  +   public void testConcurrentCreationWithoutTx() throws Exception
  +     {
  +        Interceptor in = new Interceptor()
  +        {
  +           public Object invoke(MethodCall c) throws Throwable
  +           {
  +              String threadName = Thread.currentThread().getName();
  +              System.out.println("Called by " + threadName);
  +              if (threadName.equals("SLOWPUT"))
  +              {
  +                 System.out.println("Delaying " + threadName);
  +                 Thread.sleep(1000);
  +                 System.out.println("Delayed " + threadName);
  +              }
  +              System.out.println("Passing up " + threadName);
  +              Object o = super.invoke(c);
  +              System.out.println("Returning " + threadName);
  +              return o;
  +           }
  +        };
  +
  +        List interceptors = cache.getInterceptors();
  +        int i=0;
  +        for (i=0; i<interceptors.size(); i++)
  +        {
  +           if (interceptors.get(i) instanceof OptimisticCreateIfNotExistsInterceptor) break;
  +        }
  +
  +        Interceptor prev = (Interceptor) interceptors.get(i);
  +        Interceptor next = (Interceptor) interceptors.get(i+1);
  +
  +        in.setNext(next);
  +        prev.setNext(in);
  +
  +        cache.setInterceptorChain((Interceptor) interceptors.get(0));
  +
  +        System.out.println(cache.getInterceptorChain());
  +
  +        // now create 2 threads to do concurrent puts.
  +        Putter slow = new Putter("SLOWPUT");
  +        Putter fast = new Putter("FASTPUT");
  +
  +        // start the slow putter first
  +        slow.start();
  +        TestingUtil.sleepThread(200);
  +        fast.start();
  +
  +        fast.join();
  +        slow.join();
  +
  +        for (Iterator e = exceptions.iterator() ; e.hasNext() ;) ((Exception) e.next()).printStackTrace();
  +        assertEquals(0, exceptions.size());
  +     }
  +
  +   public class Putter extends Thread
  +     {
  +        public Putter(String name)
  +        {
  +           super(name);
  +        }
  +
  +        public void run()
  +        {
  +           try
  +           {
  +              cache.put(new Fqn(f, getName()), "a", "b");
  +           }
  +           catch (Exception e)
  +           {
  +              exceptions.add(e);
  +           }
  +        }
  +     }
  +
   }
  
  
  



More information about the jboss-cvs-commits mailing list