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

Manik Surtani manik at jboss.org
Thu Jul 19 08:56:21 EDT 2007


  User: msurtani
  Date: 07/07/19 08:56:21

  Modified:    tests/functional/org/jboss/cache/optimistic 
                        ConcurrentTransactionTest.java
  Log:
  JBCACHE-1067
  
  Revision  Changes    Path
  1.9       +88 -29    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.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- ConcurrentTransactionTest.java	18 Jul 2007 16:03:31 -0000	1.8
  +++ ConcurrentTransactionTest.java	19 Jul 2007 12:56:21 -0000	1.9
  @@ -12,6 +12,8 @@
   import org.jboss.cache.NodeSPI;
   import org.jboss.cache.interceptors.Interceptor;
   import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
  +import org.jboss.cache.interceptors.TxInterceptor;
  +import org.jboss.cache.marshall.MethodDeclarations;
   import org.jboss.cache.misc.TestingUtil;
   
   import javax.transaction.Transaction;
  @@ -204,51 +206,63 @@
         assertTrue("Should not have caught any exceptions!!", exceptions.isEmpty());
      }
   
  -   public class Putter extends Thread
  -   {
  -      public Putter(String name)
  +   public void testConcurrentPut() throws Exception
         {
  -         super(name);
  -      }
  -
  -      public void run()
  +      final String slowThreadName = "SLOW";
  +      final String fastThreadName = "FAST";
  +      Interceptor slowdownInterceptor = new Interceptor()
         {
  -         try
  +         public Object invoke(InvocationContext ctx) throws Throwable
            {
  -            cache.put(new Fqn(f, getName()), "a", "b");
  -         }
  -         catch (Exception e)
  +            if (Thread.currentThread().getName().equals(slowThreadName))
            {
  -            exceptions.add(e);
  +               Thread.sleep(1000);
            }
  +            return super.invoke(ctx);
         }
  +      };
  +
  +      TestingUtil.injectInterceptor(cache, slowdownInterceptor, OptimisticCreateIfNotExistsInterceptor.class);
  +
  +      // now create 2 threads to do concurrent puts.
  +      Putter slow = new Putter(slowThreadName);
  +      Putter fast = new Putter(fastThreadName);
  +
  +      // start the slow putter first
  +      slow.start();
  +      TestingUtil.sleepThread(200);
  +      fast.start();
  +
  +      fast.join();
  +      slow.join();
  +
  +      for (Exception e : exceptions) e.printStackTrace();
  +      assertEquals(0, exceptions.size());
      }
   
  -   public void testConcurrentPut() throws Exception
  +   public void testConcurrentRemove() throws Exception
      {
  -      Interceptor in = new Interceptor()
  +      final String slowThreadName = "SLOW";
  +      final String fastThreadName = "FAST";
  +      Interceptor slowdownInterceptor = new Interceptor()
         {
            public Object invoke(InvocationContext ctx) throws Throwable
            {
  -            if (Thread.currentThread().getName().equals("SLOWPUT")) Thread.sleep(1000);
  +            if (Thread.currentThread().getName().equals(slowThreadName) && ctx.getMethodCall().getMethodId() == MethodDeclarations.optimisticPrepareMethod_id)
  +            {
  +               Thread.sleep(1000);
  +            }
               return super.invoke(ctx);
            }
         };
   
  -      List interceptors = cache.getInterceptorChain();
  -      int i = 0;
  -      for (i = 0; i < interceptors.size(); i++)
  -      {
  -         if (interceptors.get(i) instanceof OptimisticCreateIfNotExistsInterceptor) break;
  -      }
  -
  -      cache.addInterceptor(in, i + 1);
  -
  -      System.out.println(cache.getInterceptorChain());
  +      TestingUtil.injectInterceptor(cache, slowdownInterceptor, TxInterceptor.class);
   
         // now create 2 threads to do concurrent puts.
  -      Putter slow = new Putter("SLOWPUT");
  -      Putter fast = new Putter("FASTPUT");
  +      Remover slow = new Remover(slowThreadName);
  +      Remover fast = new Remover(fastThreadName);
  +
  +      cache.put(f, "hello", "world");
   
         // start the slow putter first
         slow.start();
  @@ -261,4 +275,49 @@
         for (Exception e : exceptions) e.printStackTrace();
         assertEquals(0, exceptions.size());
      }
  +
  +   public class Putter extends Thread
  +   {
  +      public Putter(String name)
  +      {
  +         super(name);
  +      }
  +
  +      public void run()
  +      {
  +         try
  +         {
  +            cache.getTransactionManager().begin();
  +            cache.put(new Fqn(f, getName()), "a", "b");
  +            cache.getTransactionManager().commit();
  +         }
  +         catch (Exception e)
  +         {
  +            exceptions.add(e);
  +         }
  +      }
  +   }
  +
  +   public class Remover extends Thread
  +   {
  +      public Remover(String name)
  +      {
  +         super(name);
  +      }
  +
  +      public void run()
  +      {
  +         try
  +         {
  +            cache.getTransactionManager().begin();
  +            cache.removeNode(f);
  +            cache.getTransactionManager().commit();
  +         }
  +         catch (Exception e)
  +         {
  +            exceptions.add(e);
  +         }
  +      }
  +   }
  +
   }
  
  
  



More information about the jboss-cvs-commits mailing list