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

Manik Surtani msurtani at jboss.com
Wed Dec 20 08:56:49 EST 2006


  User: msurtani
  Date: 06/12/20 08:56:49

  Modified:    tests/stress/org/jboss/cache  LocalStressTest.java
  Log:
  refactored
  
  Revision  Changes    Path
  1.8       +34 -35    JBossCache/tests/stress/org/jboss/cache/LocalStressTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: LocalStressTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/stress/org/jboss/cache/LocalStressTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- LocalStressTest.java	6 Sep 2006 15:31:02 -0000	1.7
  +++ LocalStressTest.java	20 Dec 2006 13:56:49 -0000	1.8
  @@ -15,6 +15,7 @@
   import org.jboss.cache.factories.XmlConfigurationParser;
   import org.jboss.cache.lock.IsolationLevel;
   import org.jboss.cache.lock.LockStrategyFactory;
  +import org.jboss.cache.misc.TestingUtil;
   import org.jboss.cache.transaction.DummyTransactionManager;
   
   import javax.naming.Context;
  @@ -26,6 +27,7 @@
   import javax.transaction.SystemException;
   import javax.transaction.UserTransaction;
   import java.util.ArrayList;
  +import java.util.List;
   import java.util.Properties;
   import java.util.Random;
   
  @@ -36,7 +38,7 @@
    * Local mode stress test for TreeCache.
    *
    * @author <a href="mailto:bwang at jboss.org">Ben Wang</a> May 20 2003
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   public class LocalStressTest extends TestCase
   {
  @@ -46,7 +48,7 @@
      //   final static Log log_=LogFactory.getLog(LocalStressTestCase.class);
      String oldFactory_ = null;
      final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
  -   static ArrayList nodeList_;
  +   static List<String> nodeList_;
      static final int depth_ = 4;
      static final int children_ = 4;
      DummyTransactionManager tm_;
  @@ -141,6 +143,13 @@
         UserTransaction tx = null;
         tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
   
  +      // create "root" nodes to remove WL contention on /
  +      cache_.put("/", null);
  +      cache_.put("/0", null);
  +      cache_.put("/1", null);
  +      cache_.put("/2", null);
  +      cache_.put("/3", null);
  +
         RunThread t1 = new RunThread(tx, 1);
         RunThread t2 = new RunThread(tx, 2);
   
  @@ -184,13 +193,13 @@
         {
            for (int loop = 0; loop < MAX_LOOP; loop++)
            {
  -            sleep_(random_.nextInt(50));
  +            TestingUtil.sleepRandom(50);
               log("Executing op1. Loop-" + loop);
               op1();
  -            sleep_(random_.nextInt(50));
  +            TestingUtil.sleepRandom(50);
               log("Executing op2...");
               op2();
  -            sleep_(random_.nextInt(50));
  +            TestingUtil.sleepRandom(50);
               log("Executing op3...");
               op3();
            }
  @@ -202,15 +211,17 @@
         {
            int i = random_.nextInt(nodeList_.size() - 1);
            String key = Integer.toString(i);
  -         String value = Integer.toString(i);
   
            tx_.begin();
  -         String node = (String) nodeList_.get(i);
  +         String node = nodeList_.get(i);
            cache_.get(node, key);
  -         sleep_(random_.nextInt(SLEEP_TIME)); // sleep for max 200 millis
  -         cache_.put(node, key, value);
  -         sleep_(random_.nextInt(SLEEP_TIME)); // sleep for max 200 millis
  -         cache_.remove(node, key);
  +         TestingUtil.sleepRandom(SLEEP_TIME);
  +
  +         // uncommenting these leads to a classic deadlock.
  +
  +//         cache_.put(node, key, value);
  +//         sleep_(random_.nextInt(SLEEP_TIME)); // sleep for max 200 millis
  +//         cache_.remove(node, key);
            tx_.commit();
         }
   
  @@ -222,11 +233,11 @@
            String key = Integer.toString(i);
   
            tx_.begin();
  -         String node = (String) nodeList_.get(i);
  +         String node = nodeList_.get(i);
            cache_.get(node, key);
  -         sleep_(random_.nextInt(SLEEP_TIME)); // sleep for max 200 millis
  +         TestingUtil.sleepRandom(SLEEP_TIME);
            cache_.get(node, key);
  -         sleep_(random_.nextInt(SLEEP_TIME)); // sleep for max 200 millis
  +         TestingUtil.sleepRandom(SLEEP_TIME);
            tx_.commit();
         }
   
  @@ -239,23 +250,12 @@
            String value = Integer.toString(i);
   
            tx_.begin();
  -         String node = (String) nodeList_.get(i);
  +         String node = nodeList_.get(i);
            cache_.put(node, key, value);
  -         sleep_(random_.nextInt(SLEEP_TIME)); // sleep for max 200 millis
  +         TestingUtil.sleepRandom(SLEEP_TIME);
            cache_.remove(node, key);
            tx_.commit();
         }
  -
  -      private void sleep_(long msecs)
  -      {
  -         try
  -         {
  -            Thread.sleep(msecs);
  -         }
  -         catch (Exception ex)
  -         {
  -         }
  -      }
      }
   
      /**
  @@ -263,11 +263,11 @@
       * of the hierarchy and children is the number of children under each node.
       * This strucutre is used to add, get, and remove for each node.
       */
  -   private ArrayList nodeGen(int depth, int children)
  +   private List<String> nodeGen(int depth, int children)
      {
  -      ArrayList strList = new ArrayList();
  -      ArrayList oldList = new ArrayList();
  -      ArrayList newList = new ArrayList();
  +      List<String> strList = new ArrayList<String>();
  +      List<String> oldList = new ArrayList<String>();
  +      List<String> newList = new ArrayList<String>();
   
         oldList.add("/");
         newList.add("/");
  @@ -276,12 +276,12 @@
         while (depth > 0)
         {
            // Trying to produce node name at this depth.
  -         newList = new ArrayList();
  -         for (int i = 0; i < oldList.size(); i++)
  +         newList = new ArrayList<String>();
  +         for (String anOldList : oldList)
            {
               for (int j = 0; j < children; j++)
               {
  -               String tmp = (String) oldList.get(i);
  +               String tmp = anOldList;
                  tmp += Integer.toString(j);
                  if (depth != 1)
                     tmp += "/";
  @@ -305,7 +305,6 @@
      private static void log(String str)
      {
         System.out.println("Thread: " + Thread.currentThread() + ": " + str);
  -//        System.out.println(str);
      }
   
   }
  
  
  



More information about the jboss-cvs-commits mailing list