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

Manik Surtani msurtani at jboss.com
Thu Jan 11 08:49:07 EST 2007


  User: msurtani
  Date: 07/01/11 08:49:07

  Modified:    tests/functional/org/jboss/cache/statetransfer   
                        StateTransferUnderLoadTest.java
                        StateTransferTestBase.java VersionedTestBase.java
  Log:
  Changed CacheImpl ctor to be protected, and changed cache factories accordingly
  
  Revision  Changes    Path
  1.8       +4 -2      JBossCache/tests/functional/org/jboss/cache/statetransfer/StateTransferUnderLoadTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: StateTransferUnderLoadTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/statetransfer/StateTransferUnderLoadTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- StateTransferUnderLoadTest.java	2 Jan 2007 18:26:07 -0000	1.7
  +++ StateTransferUnderLoadTest.java	11 Jan 2007 13:49:07 -0000	1.8
  @@ -5,9 +5,9 @@
   import junit.framework.TestSuite;
   import org.jboss.cache.Cache;
   import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.DefaultCacheFactory;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.config.Configuration;
  -import org.jboss.cache.factories.DefaultCacheFactory;
   import org.jboss.cache.misc.TestingUtil;
   import org.jboss.cache.transaction.DummyTransactionManager;
   
  @@ -21,7 +21,7 @@
    * Tests state transfer while the other node keeps sending transactional, synchronous method calls
    *
    * @author Bela Ban
  - * @version $Id: StateTransferUnderLoadTest.java,v 1.7 2007/01/02 18:26:07 msurtani Exp $
  + * @version $Id: StateTransferUnderLoadTest.java,v 1.8 2007/01/11 13:49:07 msurtani Exp $
    */
   public class StateTransferUnderLoadTest extends TestCase
   {
  @@ -131,9 +131,11 @@
         finally
         {
            if (writer != null)
  +         {
               writer.stop();
         }
      }
  +   }
   
   
      static class Writer implements Runnable
  
  
  
  1.33      +30 -11    JBossCache/tests/functional/org/jboss/cache/statetransfer/StateTransferTestBase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: StateTransferTestBase.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/statetransfer/StateTransferTestBase.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -b -r1.32 -r1.33
  --- StateTransferTestBase.java	4 Jan 2007 03:36:42 -0000	1.32
  +++ StateTransferTestBase.java	11 Jan 2007 13:49:07 -0000	1.33
  @@ -24,12 +24,11 @@
   
   import org.jboss.cache.Cache;
   import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.DefaultCacheFactory;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.config.Configuration.CacheMode;
  -import org.jboss.cache.factories.DefaultCacheFactory;
   import org.jboss.cache.factories.UnitTestCacheFactory;
  -import org.jboss.cache.factories.XmlConfigurationParser;
   import org.jboss.cache.loader.AbstractCacheLoaderTestBase;
   import org.jboss.cache.loader.CacheLoader;
   import org.jboss.cache.marshall.SelectedClassnameClassLoader;
  @@ -97,9 +96,11 @@
                                     boolean cacheLoaderAsync, boolean startCache) throws Exception
      {
         if (caches.get(cacheID) != null)
  +      {
            throw new IllegalStateException(cacheID + " already created");
  +      }
   
  -      CacheMode mode = sync ? CacheMode.REPL_SYNC:CacheMode.REPL_ASYNC;
  +      CacheMode mode = sync ? CacheMode.REPL_SYNC : CacheMode.REPL_ASYNC;
         Configuration c = UnitTestCacheFactory.createConfiguration(mode);
         c.setClusterName("VersionedTestBase");
         c.setReplVersionString(getReplicationVersion());
  @@ -114,7 +115,7 @@
         {
            configureCacheLoader(c, cacheLoaderClass, cacheID, useMarshalling, cacheLoaderAsync);
         }
  -//      tree.setConfiguration(c);
  +      //      tree.setConfiguration(c);
         CacheSPI tree = (CacheSPI) DefaultCacheFactory.getInstance().createCache(c, false);
         
         configureMultiplexer(tree);
  @@ -136,7 +137,7 @@
       * Provides a hook for multiplexer integration. This default implementation
       * is a no-op; subclasses that test mux integration would override
       * to integrate the given cache with a multiplexer.
  -    *
  +    * <p/>
       * param cache a cache that has been configured but not yet created.
       */
      protected void configureMultiplexer(Cache cache) throws Exception
  @@ -233,7 +234,9 @@
         TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
   
         if (asyncLoader)
  +      {
            TestingUtil.sleepThread((long) 100);
  +      }
   
         CacheLoader loader = cache2.getCacheLoaderManager().getCacheLoader();
   
  @@ -259,14 +262,18 @@
      protected String escapeWindowsPath(String path)
      {
         if ('/' == File.separatorChar)
  +      {
            return path;
  +      }
   
         char[] chars = path.toCharArray();
         StringBuffer sb = new StringBuffer();
         for (int i = 0; i < chars.length; i++)
         {
            if (chars[i] == '\\')
  +         {
               sb.append('\\');
  +         }
            sb.append(chars[i]);
         }
         return sb.toString();
  @@ -333,10 +340,14 @@
         }
   
         if (file.exists())
  +      {
            file.delete();
  +      }
         if (file.exists())
  +      {
            file.deleteOnExit();
      }
  +   }
   
      protected ClassLoader getClassLoader() throws Exception
      {
  @@ -378,8 +389,10 @@
            this.name = name;
   
            if (activateRoot)
  +         {
               cache.getRegion(Fqn.ROOT, true).activate();
         }
  +      }
   
         public void run()
         {
  @@ -388,7 +401,9 @@
            {
               acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
               if (!acquired)
  +            {
                  throw new Exception(name + " cannot acquire semaphore");
  +            }
               //System.out.println(name + " acquired semaphore");
   
               useCache();
  @@ -405,8 +420,10 @@
            finally
            {
               if (acquired)
  +            {
                  semaphore.release();
            }
  +         }
   
         }
   
  @@ -436,7 +453,9 @@
         public void cleanup()
         {
            if (thread != null && thread.isAlive())
  +         {
               thread.interrupt();
         }
      }
  +   }
   }
  
  
  
  1.28      +109 -81   JBossCache/tests/functional/org/jboss/cache/statetransfer/VersionedTestBase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: VersionedTestBase.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/statetransfer/VersionedTestBase.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -b -r1.27 -r1.28
  --- VersionedTestBase.java	9 Jan 2007 15:31:39 -0000	1.27
  +++ VersionedTestBase.java	11 Jan 2007 13:49:07 -0000	1.28
  @@ -10,14 +10,13 @@
   import org.jboss.cache.Cache;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.DefaultCacheFactory;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
   import org.jboss.cache.Region;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.config.Configuration.CacheMode;
  -import org.jboss.cache.factories.DefaultCacheFactory;
   import org.jboss.cache.factories.UnitTestCacheFactory;
  -import org.jboss.cache.factories.XmlConfigurationParser;
   import org.jboss.cache.loader.CacheLoader;
   import org.jboss.cache.marshall.InactiveRegionException;
   import org.jboss.cache.misc.TestingUtil;
  @@ -254,7 +253,7 @@
                 false,  // async
                 true,   // use marshaller
                 true,   // use cacheloader
  -              false, false); // don't start
  +              false, false);// don't start
         ClassLoader cl1 = getClassLoader();
         cache1.getRegion(A, true).registerContextClassLoader(cl1);
         startCache(cache1);
  @@ -270,7 +269,7 @@
                 false,  // async
                 true,   // use marshalling
                 true,   // use cacheloader
  -              false, true);  // start
  +              false, true);// start
   
         // Pause to give caches time to see each other
         TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
  @@ -283,7 +282,7 @@
   
         ClassLoader cl2 = getClassLoader();
   
  -//      cache2.registerClassLoader(A, cl2);
  +      //      cache2.registerClassLoader(A, cl2);
         Region r = cache2.getRegion(A, true);
         r.registerContextClassLoader(cl2);
   
  @@ -410,12 +409,16 @@
            {
               boolean acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
               if (!acquired)
  +            {
                  fail("failed to acquire semaphore " + i);
            }
  +         }
   
            // Sleep to allow any async calls to clear
            if (!sync)
  +         {
               TestingUtil.sleepThread((long) 500);
  +         }
   
            // Ensure the caches held by the activators see all the values
            for (int i = 0; i < count; i++)
  @@ -434,7 +437,7 @@
                  Fqn fqn = new Fqn(A_B, names[j]);
                  assertEquals("Incorrect value for " + fqn + " on activator " + names[i],
                          "VALUE", activators[i].getCacheValue(fqn));
  -//               System.out.println(names[i] + ":" + fqn + " = " + activators[i].getCacheValue(fqn));
  +               //               System.out.println(names[i] + ":" + fqn + " = " + activators[i].getCacheValue(fqn));
               }
   
            }
  @@ -446,8 +449,10 @@
         finally
         {
            for (int i = 0; i < count; i++)
  +         {
               activators[i].cleanup();
         }
  +      }
   
      }
   
  @@ -511,12 +516,16 @@
            {
               boolean acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
               if (!acquired)
  +            {
                  fail("failed to acquire semaphore " + i);
            }
  +         }
   
            // Sleep to allow any async calls to clear
            if (!sync)
  +         {
               TestingUtil.sleepThread(1000);
  +         }
   
            // Ensure the caches held by the activators see all the values
            for (int i = 0; i < count; i++)
  @@ -545,8 +554,10 @@
         finally
         {
            for (int i = 0; i < count; i++)
  +         {
               activators[i].cleanup();
         }
  +      }
   
      }
   
  @@ -682,7 +693,7 @@
               // Activate cacheA
               for (int i = 0; i < count; i++)
               {
  -//              System.out.println("Activating /" + names[i] + " on A");
  +               //              System.out.println("Activating /" + names[i] + " on A");
                  cacheA.getRegion(Fqn.fromString("/" + names[i]), true).activate();
                  // Stop the stressor so we don't pollute cacheA's state
                  // with too many messages sent after activation -- we want
  @@ -692,14 +703,16 @@
                  // Reacquire one semaphore ticket
                  boolean acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
                  if (!acquired)
  +               {
                     fail("failed to acquire semaphore " + i);
  +               }
   
                  // Pause to allow other work to proceed
                  TestingUtil.sleepThread((long) 100);
               }
   
               // Sleep to allow any in transit msgs to clear
  -//            if (!sync)
  +            //            if (!sync)
               TestingUtil.sleepThread((long) 1000);
   
               // Ensure the stressors saw no exceptions
  @@ -726,7 +739,9 @@
            }
   
            for (int i = 0; i < count; i++)
  +         {
               stressors[i].stopThread();
  +         }
   
         }
         finally
  @@ -734,9 +749,11 @@
            for (int i = 0; i < count; i++)
            {
               if (stressors[i] != null)
  +            {
                  stressors[i].cleanup();
            }
         }
  +      }
   
      }
   
  @@ -748,14 +765,14 @@
      public void testEvictionSeesStateTransfer() throws Exception
      {
         
  -      Configuration c = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC,true);
  +      Configuration c = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC, true);
         Cache cache1 = DefaultCacheFactory.getInstance().createCache(c, false);  
         cache1.start();
         caches.put("evict1", cache1);
         
         cache1.put(Fqn.fromString("/a/b/c"), "key", "value");
         
  -      c = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC,true);
  +      c = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC, true);
         Cache cache2 = DefaultCacheFactory.getInstance().createCache(c, false);
         cache2.start();
         caches.put("evict2", cache2);
  @@ -772,7 +789,7 @@
       */
      public void testEvictionAfterStateTransfer() throws Exception
      {      
  -      Configuration c = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC,true);
  +      Configuration c = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC, true);
         Cache cache1 = DefaultCacheFactory.getInstance().createCache(c, false);  
         cache1.start();
         caches.put("evict1", cache1);
  @@ -781,10 +798,12 @@
         {
            cache1.put(Fqn.fromString("/base/" + i), "key", "base" + i);
            if (i < 5)
  +         {
                cache1.put(Fqn.fromString("/org/jboss/test/data/" + i), "key", "data" + i);
         }
  +      }
         
  -      c = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC,true);
  +      c = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC, true);
         final Cache cache2 = DefaultCacheFactory.getInstance().createCache(c, false);
         cache2.start();
         caches.put("evict2", cache2);
  @@ -805,6 +824,7 @@
             Cache cache = null;
             boolean stopped = false;
             Exception ex = null;
  +
             public void run()
             {
                 int i = 25000;
  @@ -813,7 +833,7 @@
                     try
                     {
                         cache.put(Fqn.fromString("/base/" + i), "key", "base" + i);
  -                      cache.put(Fqn.fromString("/org/jboss/test/data/" + i), "key", "data"+i);
  +                  cache.put(Fqn.fromString("/org/jboss/test/data/" + i), "key", "data" + i);
                         i++;
                     }
                     catch (Exception e)
  @@ -823,10 +843,10 @@
                 }
             }
         }
  -      Putter p1= new Putter();
  +      Putter p1 = new Putter();
         p1.cache = cache1;
         p1.start();
  -      Putter p2= new Putter();
  +      Putter p2 = new Putter();
         p2.cache = cache2;
         p2.start();
         
  @@ -863,7 +883,7 @@
               int baseCount = children.size();
               if (baseCount < maxCountBase)
               {
  -                System.out.println("base " + baseCount + " < " + maxCountBase+ " elapsed = " + (System.currentTimeMillis() - start));
  +               System.out.println("base " + baseCount + " < " + maxCountBase + " elapsed = " + (System.currentTimeMillis() - start));
                   sawBaseDecrease = true;
               }
               else
  @@ -915,8 +935,10 @@
         parent = cache2.getRoot().getChild(Fqn.fromString("/org/jboss/test/data"));
         children = parent.getChildren();
         if (children != null)
  +      {
            assertEquals("All data children evicted", 0, children.size());
      }
  +   }
   
      private Object createBen(ClassLoader loader) throws Exception
      {
  @@ -954,11 +976,11 @@
         {
            TestingUtil.sleepRandom(5000);
            cache.getRegion(A_B, true).activate();
  -//         System.out.println(name + " activated region" + " " + System.currentTimeMillis());
  +         //         System.out.println(name + " activated region" + " " + System.currentTimeMillis());
            Fqn childFqn = Fqn.fromString("/a/b/" + name);
   
            cache.put(childFqn, "KEY", "VALUE");
  -//         System.out.println(name + " put fqn " + childFqn + " " + System.currentTimeMillis());
  +         //         System.out.println(name + " put fqn " + childFqn + " " + System.currentTimeMillis());
   
         }
   
  @@ -1032,8 +1054,10 @@
               {
                  acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
                  if (!acquired)
  +               {
                     throw new Exception(name + " cannot acquire semaphore");
               }
  +            }
   
               while (!putsStopped)
               {
  @@ -1054,9 +1078,11 @@
   
               // Go to sleep until directed otherwise
               while (!stopped && putsStopped)
  +            {
                  TestingUtil.sleepThread((long) 100);
            }
         }
  +      }
   
         public void stopPuts()
         {
  @@ -1072,8 +1098,10 @@
         {
            stopped = true;
            if (thread.isAlive())
  +         {
               thread.interrupt();
         }
  +      }
   
   
      }
  
  
  



More information about the jboss-cvs-commits mailing list