[jboss-cvs] JBossCache/tests/stress/org/jboss/cache ...

Manik Surtani manik at jboss.org
Wed May 23 06:28:57 EDT 2007


  User: msurtani
  Date: 07/05/23 06:28:57

  Modified:    tests/stress/org/jboss/cache 
                        ReadWriteLockWithUpgradeStressTest.java
  Log:
  Initiated a bunch of performance fixes, including replacing CopyOnWriteArraySets with org.jboss.cache.util.concurrent.ConcurrentHashSet.
  Also ran an imports optimiser on the code base - there were a lot of unused imports floating about.
  
  Revision  Changes    Path
  1.3       +61 -34    JBossCache/tests/stress/org/jboss/cache/ReadWriteLockWithUpgradeStressTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ReadWriteLockWithUpgradeStressTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/stress/org/jboss/cache/ReadWriteLockWithUpgradeStressTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- ReadWriteLockWithUpgradeStressTest.java	8 Dec 2006 19:00:38 -0000	1.2
  +++ ReadWriteLockWithUpgradeStressTest.java	23 May 2007 10:28:57 -0000	1.3
  @@ -1,8 +1,5 @@
   package org.jboss.cache;
   
  -import java.util.concurrent.TimeUnit;
  -import java.util.concurrent.locks.Lock;
  -
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -10,6 +7,9 @@
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.lock.ReadWriteLockWithUpgrade;
   
  +import java.util.concurrent.TimeUnit;
  +import java.util.concurrent.locks.Lock;
  +
   /**
    * Stress test for RWLock with upgrade.
    */
  @@ -19,7 +19,7 @@
      static final long SLEEP_MSECS = 50;
      static final int LOOPS = 200;
      static int SEED = 1;
  -   static Log log_=LogFactory.getLog("ReadWriteLockWithUpgrade");
  +   static Log log_ = LogFactory.getLog("ReadWriteLockWithUpgrade");
      int counter;
   
      public ReadWriteLockWithUpgradeStressTest(String name)
  @@ -44,26 +44,30 @@
         return suite;
      }
   
  -   public void setUp() throws Exception {
  +   public void setUp() throws Exception
  +   {
         super.setUp();
         log("Setting up stress test case ...");
         counter = 0;
      }
   
  -   public void tearDown() throws Exception {
  +   public void tearDown() throws Exception
  +   {
         super.tearDown();
         log("Tearing down stress test case ...");
      }
   
   
  -   public void testTimedWriteLocks() throws InterruptedException {
  +   public void testTimedWriteLocks() throws InterruptedException
  +   {
         ReadWriteLockWithUpgrade l = new ReadWriteLockWithUpgrade();
  -      final int NUM=1000000;
  +      final int NUM = 1000000;
   
  -      for(int i=0; i < NUM; i++) {
  +      for (int i = 0; i < NUM; i++)
  +      {
            l.writeLock().tryLock(2000, TimeUnit.MILLISECONDS);
            l.writeLock().unlock();
  -         if(i % 10000 == 0)
  +         if (i % 10000 == 0)
               System.out.println(i);
         }
      }
  @@ -76,13 +80,16 @@
            public void run()
            {
               java.util.Random rand = new java.util.Random(++SEED);
  -            for (int i = 0; i < LOOPS; i++) {
  +            for (int i = 0; i < LOOPS; i++)
  +            {
                  int duration = rand.nextInt((int) SLEEP_MSECS);
                  _sleep(SLEEP_MSECS);
                  Lock rlock = null;
  -               try {
  +               try
  +               {
                     rlock = lock_.readLock();
  -                  if (!rlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
  +                  if (!rlock.tryLock(msecs, TimeUnit.MILLISECONDS))
  +                  {
                        log("Read lock attempt failed.");
   //                     fail("Read lock attempt failed.");
                        counter++;
  @@ -91,9 +98,12 @@
                     log("acquired read lock");
                     _sleep(duration);
                     log("released read lock");
  -               } catch (Exception ex) {
                  }
  -               finally {
  +               catch (Exception ex)
  +               {
  +               }
  +               finally
  +               {
                     rlock.unlock();
                  }
               }
  @@ -108,13 +118,16 @@
            public void run()
            {
               java.util.Random rand = new java.util.Random(++SEED);
  -            for (int i = 0; i < LOOPS; i++) {
  +            for (int i = 0; i < LOOPS; i++)
  +            {
                  int duration = rand.nextInt((int) SLEEP_MSECS);
                  _sleep(SLEEP_MSECS + duration);
                  Lock wlock = null;
  -               try {
  +               try
  +               {
                     wlock = lock_.writeLock();
  -                  if (!wlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
  +                  if (!wlock.tryLock(msecs, TimeUnit.MILLISECONDS))
  +                  {
                        log("Write lock attempt failed.");
   //                     fail("Write lock attempt failed.");
                        counter++;
  @@ -123,9 +136,12 @@
                     log("acquired write lock");
                     _sleep(duration);
                     log("released write lock");
  -               } catch (Exception ex) {
                  }
  -               finally {
  +               catch (Exception ex)
  +               {
  +               }
  +               finally
  +               {
                     wlock.unlock();
                  }
               }
  @@ -140,14 +156,17 @@
            public void run()
            {
               java.util.Random rand = new java.util.Random(++SEED);
  -            for (int i = 0; i < LOOPS; i++) {
  +            for (int i = 0; i < LOOPS; i++)
  +            {
                  int duration = rand.nextInt((int) SLEEP_MSECS);
                  _sleep(SLEEP_MSECS);
                  Lock rlock = null;
                  Lock wlock = null;
  -               try {
  +               try
  +               {
                     rlock = lock_.readLock();
  -                  if (!wlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
  +                  if (!wlock.tryLock(msecs, TimeUnit.MILLISECONDS))
  +                  {
                        log("Read lock attempt failed.");
   //                   fail("Read lock attempt failed.");
                        counter++;
  @@ -158,7 +177,8 @@
                     // upgrade lock. Note that read lock will be released
                     // and write lock be acquired automatically.
                     wlock = lock_.upgradeLockAttempt(msecs);
  -                  if (wlock == null) {
  +                  if (wlock == null)
  +                  {
                        log("upgrade lock attempt failed");
   //                     fail("upgrade lock attempt failed");
                        rlock.unlock();
  @@ -168,10 +188,13 @@
                     log("Upgraded write lock");
                     _sleep(duration);
                     log("released write lock");
  -               } catch (Exception ex) {
                  }
  -               finally {
  -                  if(wlock != null)
  +               catch (Exception ex)
  +               {
  +               }
  +               finally
  +               {
  +                  if (wlock != null)
                        wlock.unlock();
                  }
               }
  @@ -179,11 +202,14 @@
         };
      }
   
  -   private void _sleep(long l) {
  -      try {
  +   private void _sleep(long l)
  +   {
  +      try
  +      {
            Thread.sleep(l);
         }
  -      catch(InterruptedException e) {
  +      catch (InterruptedException e)
  +      {
            e.printStackTrace();
         }
      }
  @@ -296,9 +322,10 @@
         checkCounter();
      }
   
  -   private void checkCounter() {
  -      if(counter > (LOOPS) ) 
  -          fail("Failed lock attempt or upgrade exceeded warning. Counter: "+counter);
  +   private void checkCounter()
  +   {
  +      if (counter > (LOOPS))
  +         fail("Failed lock attempt or upgrade exceeded warning. Counter: " + counter);
      }
   
      public static void log(String str)
  
  
  



More information about the jboss-cvs-commits mailing list