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

Manik Surtani manik at jboss.org
Thu Jul 19 07:54:44 EDT 2007


  User: msurtani
  Date: 07/07/19 07:54:44

  Modified:    tests/functional/org/jboss/cache/optimistic  Tag:
                        Branch_JBossCache_1_4_0
                        ConcurrentTransactionTest.java
  Log:
  Preparing for release of 1.4.1.SP4
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.4   +75 -21    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.3
  retrieving revision 1.1.2.4
  diff -u -b -r1.1.2.3 -r1.1.2.4
  --- ConcurrentTransactionTest.java	18 Jul 2007 15:40:38 -0000	1.1.2.3
  +++ ConcurrentTransactionTest.java	19 Jul 2007 11:54:44 -0000	1.1.2.4
  @@ -205,24 +205,46 @@
      
      public void testConcurrentCreationWithoutTx() throws Exception
        {
  -        Interceptor in = new Interceptor()
  -        {
  -           public Object invoke(MethodCall c) throws Throwable
  +        SlowdownInterceptor slowdownInterceptor = new SlowdownInterceptor();
  +        slowdownInterceptor.slowThreadName = "SLOW";
  +
  +        List interceptors = cache.getInterceptors();
  +        int i=0;
  +        for (i=0; i<interceptors.size(); i++)
              {
  -              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;
  +           if (interceptors.get(i) instanceof OptimisticCreateIfNotExistsInterceptor) break;
              }
  -        };
  +
  +        Interceptor prev = (Interceptor) interceptors.get(i);
  +        Interceptor next = (Interceptor) interceptors.get(i+1);
  +
  +        slowdownInterceptor.setNext(next);
  +        prev.setNext(slowdownInterceptor);
  +
  +        cache.setInterceptorChain((Interceptor) interceptors.get(0));
  +
  +        System.out.println(cache.getInterceptorChain());
  +
  +        // now create 2 threads to do concurrent puts.
  +        Putter slow = new Putter(slowdownInterceptor.slowThreadName);
  +        Putter fast = new Putter("FAST");
  +
  +        // 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 void testConcurrentDeletionWithoutTx() throws Exception
  +     {
  +        SlowdownInterceptor slowdownInterceptor = new SlowdownInterceptor();
  +        slowdownInterceptor.slowThreadName = "SLOW";
   
           List interceptors = cache.getInterceptors();
           int i=0;
  @@ -234,16 +256,18 @@
           Interceptor prev = (Interceptor) interceptors.get(i);
           Interceptor next = (Interceptor) interceptors.get(i+1);
   
  -        in.setNext(next);
  -        prev.setNext(in);
  +        slowdownInterceptor.setNext(next);
  +        prev.setNext(slowdownInterceptor);
   
           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");
  +        Remover slow = new Remover(slowdownInterceptor.slowThreadName);
  +        Remover fast = new Remover("FAST");
  +
  +        cache.put(fqn, "hello", "world");
   
           // start the slow putter first
           slow.start();
  @@ -257,6 +281,16 @@
           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)
  @@ -277,4 +311,24 @@
           }
        }
   
  +   public class Remover extends Thread
  +   {
  +      public Remover(String name)
  +      {
  +         super(name);
  +      }
  +
  +      public void run()
  +      {
  +         try
  +         {
  +            cache.remove(f);
  +         }
  +         catch (Exception e)
  +         {
  +            exceptions.add(e);
  +         }
  +      }
  +   }
  +
   }
  
  
  



More information about the jboss-cvs-commits mailing list