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

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


  User: msurtani
  Date: 07/07/19 08:28:08

  Modified:    tests/functional/org/jboss/cache/optimistic  Tag:
                        Branch_JBossCache_1_4_0
                        ConcurrentTransactionTest.java
  Log:
  JBCACHE-1067
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.5   +37 -18    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.4
  retrieving revision 1.1.2.5
  diff -u -b -r1.1.2.4 -r1.1.2.5
  --- ConcurrentTransactionTest.java	19 Jul 2007 11:54:44 -0000	1.1.2.4
  +++ ConcurrentTransactionTest.java	19 Jul 2007 12:28:08 -0000	1.1.2.5
  @@ -12,6 +12,9 @@
   import org.jboss.cache.TreeCache;
   import org.jboss.cache.interceptors.Interceptor;
   import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
  +import org.jboss.cache.interceptors.TxInterceptor;
  +import org.jboss.cache.marshall.JBCMethodCall;
  +import org.jboss.cache.marshall.MethodDeclarations;
   import org.jboss.cache.misc.TestingUtil;
   import org.jgroups.blocks.MethodCall;
   
  @@ -205,8 +208,18 @@
      
      public void testConcurrentCreationWithoutTx() throws Exception
        {
  -        SlowdownInterceptor slowdownInterceptor = new SlowdownInterceptor();
  -        slowdownInterceptor.slowThreadName = "SLOW";
  +        final String slowThreadName = "SLOW";
  +        Interceptor slowdownInterceptor = new Interceptor()
  +        {
  +           public Object invoke(MethodCall c) throws Throwable
  +           {
  +              if (Thread.currentThread().getName().equals(slowThreadName))
  +              {
  +                 Thread.sleep(1000);
  +              }
  +              return super.invoke(c);
  +           }
  +        };
   
           List interceptors = cache.getInterceptors();
           int i=0;
  @@ -226,7 +239,7 @@
           System.out.println(cache.getInterceptorChain());
   
           // now create 2 threads to do concurrent puts.
  -        Putter slow = new Putter(slowdownInterceptor.slowThreadName);
  +        Putter slow = new Putter(slowThreadName);
           Putter fast = new Putter("FAST");
   
           // start the slow putter first
  @@ -243,14 +256,25 @@
   
        public void testConcurrentDeletionWithoutTx() throws Exception
        {
  -        SlowdownInterceptor slowdownInterceptor = new SlowdownInterceptor();
  -        slowdownInterceptor.slowThreadName = "SLOW";
  +        final String slowThreadName = "SLOW";
  +        Interceptor slowdownInterceptor = new Interceptor()
  +        {
  +           public Object invoke(MethodCall c) throws Throwable
  +           {
  +              if (Thread.currentThread().getName().equals(slowThreadName) &&
  +                      ((JBCMethodCall) c).getMethodId() == MethodDeclarations.optimisticPrepareMethod_id)
  +              {
  +                 Thread.sleep(1000);
  +              }
  +              return super.invoke(c);
  +           }
  +        };
   
           List interceptors = cache.getInterceptors();
           int i=0;
           for (i=0; i<interceptors.size(); i++)
           {
  -           if (interceptors.get(i) instanceof OptimisticCreateIfNotExistsInterceptor) break;
  +           if (interceptors.get(i) instanceof TxInterceptor) break;
           }
   
           Interceptor prev = (Interceptor) interceptors.get(i);
  @@ -264,10 +288,10 @@
           System.out.println(cache.getInterceptorChain());
   
           // now create 2 threads to do concurrent puts.
  -        Remover slow = new Remover(slowdownInterceptor.slowThreadName);
  +        Remover slow = new Remover(slowThreadName);
           Remover fast = new Remover("FAST");
   
  -        cache.put(fqn, "hello", "world");
  +        cache.put(f, "hello", "world");
   
           // start the slow putter first
           slow.start();
  @@ -281,16 +305,6 @@
           assertEquals(0, exceptions.size());
        }
   
  -   public class SlowdownInterceptor extends Interceptor
  -   {
  -      private String slowThreadName;
  -      public Object invoke(MethodCall c) throws Throwable
  -      {
  -         if (Thread.currentThread().getName().equals(slowThreadName)) Thread.sleep(1000);
  -         return super.invoke(c);
  -      }
  -   }
  -
      public class Putter extends Thread
        {
           public Putter(String name)
  @@ -302,7 +316,9 @@
           {
              try
              {
  +              assertFalse(cache.exists(f));
                 cache.put(new Fqn(f, getName()), "a", "b");
  +              assertTrue(cache.exists(f));
              }
              catch (Exception e)
              {
  @@ -322,7 +338,10 @@
         {
            try
            {
  +            cache.getTransactionManager().begin();
               cache.remove(f);
  +            cache.getTransactionManager().commit();
  +            assertFalse(cache.exists(f));
            }
            catch (Exception e)
            {
  
  
  



More information about the jboss-cvs-commits mailing list