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

Brian Stansberry brian.stansberry at jboss.com
Thu Jul 20 12:22:06 EDT 2006


  User: bstansberry
  Date: 06/07/20 12:22:06

  Modified:    tests/functional/org/jboss/cache/misc  TestingUtil.java
  Log:
  Work with CacheSPI as well
  
  Revision  Changes    Path
  1.7       +113 -4    JBossCache/tests/functional/org/jboss/cache/misc/TestingUtil.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TestingUtil.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/misc/TestingUtil.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- TestingUtil.java	20 Jul 2006 09:03:54 -0000	1.6
  +++ TestingUtil.java	20 Jul 2006 16:22:06 -0000	1.7
  @@ -7,10 +7,10 @@
   
   package org.jboss.cache.misc;
   
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.TreeCache;
   
  -import java.util.Vector;
  -
  +import java.util.List;
   /**
    * Utilities for unit testing JBossCache.
    * 
  @@ -21,6 +21,30 @@
   {
   
      /**
  +    * Loops, continually calling {@link #areCacheViewsComplete(CacheSPI[])}
  +    * until it either returns true or <code>timeout</code> ms have elapsed.
  +    * 
  +    * @param caches     caches which must all have consistent views
  +    * @param timeout    max number of ms to loop
  +    * 
  +    * @throws RuntimeException  if <code>timeout</code> ms have elapse without
  +    *                           all caches having the same number of members.
  +    */
  +   public static void blockUntilViewsReceived(CacheSPI[] caches, long timeout)
  +   {
  +      long failTime = System.currentTimeMillis() + timeout;
  +      
  +      while (System.currentTimeMillis() < failTime)
  +      {
  +         sleepThread(100);
  +         if (areCacheViewsComplete(caches))
  +            return;
  +      }
  +      
  +      throw new RuntimeException("timed out before caches had complete views");
  +   }
  +   
  +   /**
       * Loops, continually calling {@link #areCacheViewsComplete(TreeCache[])}
       * until it either returns true or <code>timeout</code> ms have elapsed.
       * 
  @@ -54,6 +78,30 @@
       * @throws RuntimeException  if <code>timeout</code> ms have elapse without
       *                           all caches having the same number of members.
       */
  +   public static void blockUntilViewReceived(CacheSPI cache, int groupSize, long timeout)
  +   {
  +      long failTime = System.currentTimeMillis() + timeout;
  +      
  +      while (System.currentTimeMillis() < failTime)
  +      {
  +         sleepThread(100);
  +         if (isCacheViewComplete(cache, groupSize))
  +            return;
  +      }
  +      
  +      throw new RuntimeException("timed out before caches had complete views");
  +   }
  +   
  +   /**
  +    * Loops, continually calling {@link #areCacheViewsComplete(TreeCache[])}
  +    * until it either returns true or <code>timeout</code> ms have elapsed.
  +    * 
  +    * @param groupSize  number of caches expected in the group
  +    * @param timeout    max number of ms to loop
  +    * 
  +    * @throws RuntimeException  if <code>timeout</code> ms have elapse without
  +    *                           all caches having the same number of members.
  +    */
      public static void blockUntilViewReceived(TreeCache cache, int groupSize, long timeout)
      {
         long failTime = System.currentTimeMillis() + timeout;
  @@ -70,6 +118,31 @@
      
      /**
       * Checks each cache to see if the number of elements in the array
  +    * returned by {@link CacheSPI#getMembers()} matches the size of 
  +    * the <code>caches</code> parameter.
  +    * 
  +    * @param caches caches that should form a View
  +    * @return   <code>true</code> if all caches have 
  +    *           <code>caches.length</code> members; false otherwise
  +    * 
  +    * @throws IllegalStateException if any of the caches have MORE view
  +    *                               members than caches.length
  +    */
  +   public static boolean areCacheViewsComplete(CacheSPI[] caches)
  +   {
  +      int memberCount = caches.length;
  +      
  +      for (int i = 0; i < memberCount; i++)
  +      {
  +         if (!isCacheViewComplete(caches[i], memberCount))
  +            return false;
  +      }
  +      
  +      return true;
  +   }
  +   
  +   /**
  +    * Checks each cache to see if the number of elements in the array
       * returned by {@link TreeCache#getMembers()} matches the size of 
       * the <code>caches</code> parameter.
       * 
  @@ -100,7 +173,43 @@
       */
      public static boolean isCacheViewComplete(TreeCache cache, int memberCount)
      {
  -      Vector members = cache.getMembers();
  +      List members = cache.getMembers();
  +      if (members == null || memberCount > members.size())
  +      {
  +         return false;
  +      }
  +      else if (memberCount < members.size())
  +      {
  +         // This is an exceptional condition
  +         StringBuffer sb = new StringBuffer("Cache at address ");
  +         sb.append(cache.getLocalAddress());
  +         sb.append(" had ");
  +         sb.append(members.size());
  +         sb.append(" members; expecting ");
  +         sb.append(memberCount);
  +         sb.append(". Members were (");
  +         for (int j = 0; j < members.size(); j++)
  +         {
  +            if (j > 0)
  +               sb.append(", ");
  +            sb.append(members.get(j));
  +         }
  +         sb.append(')');
  +         
  +         throw new IllegalStateException(sb.toString());
  +      }
  +      
  +      return true;
  +   }
  +
  +   /**
  +    *
  +    * @param cache
  +    * @param memberCount
  +    */
  +   public static boolean isCacheViewComplete(CacheSPI cache, int memberCount)
  +   {
  +      List members = cache.getMembers();
         if (members == null || memberCount > members.size())
         {
            return false;
  @@ -119,7 +228,7 @@
            {
               if (j > 0)
                  sb.append(", ");
  -            sb.append(members.elementAt(j));
  +            sb.append(members.get(j));
            }
            sb.append(')');
            
  
  
  



More information about the jboss-cvs-commits mailing list