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

Manik Surtani msurtani at jboss.com
Wed Sep 6 11:31:00 EDT 2006


  User: msurtani
  Date: 06/09/06 11:31:00

  Modified:    tests/functional/org/jboss/cache/statetransfer  
                        FailedStateTransferTest.java VersionedTestBase.java
  Log:
  Removed TreeCache dependency on ServiceMBeanSupport
  
  Revision  Changes    Path
  1.5       +6 -6      JBossCache/tests/functional/org/jboss/cache/statetransfer/FailedStateTransferTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FailedStateTransferTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/statetransfer/FailedStateTransferTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- FailedStateTransferTest.java	20 Jul 2006 21:58:21 -0000	1.4
  +++ FailedStateTransferTest.java	6 Sep 2006 15:31:00 -0000	1.5
  @@ -23,8 +23,8 @@
   package org.jboss.cache.statetransfer;
   
   import org.jboss.cache.CacheException;
  -import org.jboss.cache.Fqn;
   import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.Fqn;
   import org.jboss.cache.TreeCache;
   import org.jboss.cache.Version;
   import org.jboss.cache.factories.XmlConfigurationParser;
  @@ -41,7 +41,7 @@
   
      public void testFailedStateTransfer() throws Exception
      {
  -      TreeCache tree =new SecretiveStateCache();
  +      TreeCache tree = new SecretiveStateCache();
         tree.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replAsync-service.xml"));
         tree.getConfiguration().setClusterName("VersionedTestBase");
         tree.getConfiguration().setReplVersionString(getReplicationVersion());
  @@ -52,14 +52,14 @@
         // start it can still be destroyed later
         caches.put("secretive", tree);
   
  -      tree.createService();
  -      tree.startService();
  +      tree.create();
  +      tree.start();
   
         CacheSPI recipient = createCache("recipient", false, false, false, false, false);
         try
         {
            recipient.start();
  -         fail("startService() should throw an exception");
  +         fail("start() should throw an exception");
         }
         catch (CacheException good)
         {
  
  
  
  1.9       +268 -260  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.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- VersionedTestBase.java	20 Jul 2006 21:58:21 -0000	1.8
  +++ VersionedTestBase.java	6 Sep 2006 15:31:00 -0000	1.9
  @@ -7,21 +7,20 @@
   
   package org.jboss.cache.statetransfer;
   
  -import java.lang.reflect.Method;
  -import java.util.Random;
  -
  +import EDU.oswego.cs.dl.util.concurrent.Semaphore;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.loader.CacheLoader;
   import org.jboss.cache.misc.TestingUtil;
   
  -import EDU.oswego.cs.dl.util.concurrent.Semaphore;
  +import java.lang.reflect.Method;
  +import java.util.Random;
   
   /**
    * Abstract superclass of "StateTransferVersion"-specific tests 
    * of CacheSPI's state transfer capability.
  - * 
  + * <p/>
    * TODO add tests with classloader regions
    * 
    * @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
  @@ -33,7 +32,8 @@
      
      public static final Fqn A = Fqn.fromString("/a");
      public static final Fqn B = Fqn.fromString("/b");
  -   public static final Fqn C = Fqn.fromString("/c");;
  +   public static final Fqn C = Fqn.fromString("/c");
  +   ;
      public static final Fqn A_B = Fqn.fromString("/a/b");
      public static final Fqn A_C = Fqn.fromString("/a/c");
      public static final Fqn A_D = Fqn.fromString("/a/d");
  @@ -50,7 +50,7 @@
         CacheSPI cache2 = createCache("cache2", false, false, false);
         
         // Pause to give caches time to see each other
  -      TestingUtil.blockUntilViewsReceived(new CacheSPI[] { cache1, cache2 }, 60000);
  +      TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
         
         assertEquals("Incorrect name for /a/b", JOE, cache2.get(A_B, "name"));
         assertEquals("Incorrect age for /a/b", TWENTY, cache2.get(A_B, "age"));
  @@ -82,10 +82,10 @@
         cache2.start();
         
         // Pause to give caches time to see each other
  -      TestingUtil.blockUntilViewsReceived(new CacheSPI[] { cache1, cache2 }, 60000);
  +      TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
         
         if (asyncLoader)
  -          TestingUtil.sleepThread((long)100);
  +         TestingUtil.sleepThread((long) 100);
         
         CacheLoader loader = cache2.getCacheLoader();
         
  @@ -114,7 +114,7 @@
         CacheSPI cache2 = createCache("cache2", false, true, false);
         
         // Pause to give caches time to see each other
  -      TestingUtil.blockUntilViewsReceived(new CacheSPI[] { cache1, cache2 }, 60000);
  +      TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
         
         assertNull("/a/b name transferred against policy", cache2.get(A_B, "name"));
         assertNull("/a/b age transferred against policy", cache2.get(A_B, "age"));
  @@ -175,7 +175,7 @@
         CacheSPI cache2 = createCache("cache2", false, true, true);
         
         // Pause to give caches time to see each other
  -      TestingUtil.blockUntilViewsReceived(new CacheSPI[] { cache1, cache2 }, 60000);
  +      TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
         
         CacheLoader loader = cache2.getCacheLoader();
         
  @@ -255,7 +255,7 @@
         // will find the classes w/ their own loader if TCL can't.  Need
         // to find a way to test!
         // But, at least it tests JBCACHE-305 by registering a classloader
  -      // both before and after startService()
  +      // both before and after start()
         
         // Set the TCL to a classloader that can't see Person/Address
         Thread.currentThread().setContextClassLoader(getNotFoundClassLoader());
  @@ -283,7 +283,7 @@
                                             false, true);  // start
         
         // Pause to give caches time to see each other
  -      TestingUtil.blockUntilViewsReceived(new CacheSPI[] { cache1, cache2 }, 60000);
  +      TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
         
         CacheLoader loader = cache2.getCacheLoader();
         
  @@ -316,7 +316,7 @@
         CacheSPI cache2 = createCache("cache2", false, true, true);
         
         // Pause to give caches time to see each other
  -      TestingUtil.blockUntilViewsReceived(new CacheSPI[] { cache1, cache2 }, 60000);
  +      TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
         
         CacheLoader loader = cache2.getCacheLoader();
         
  @@ -371,7 +371,7 @@
       * As soon as each cache has activated its region, it does a put to a node
       * in the region, thus complicating the lives of the other caches trying
       * to get partial state.
  -    * <p>
  +    * <p/>
       * Failure condition is if any node sees an exception or if the final state
       * of all caches is not consistent.
       * 
  @@ -380,21 +380,24 @@
       */
      private void concurrentActivationTest(boolean sync) throws Exception
      {
  -      String[] names = { "A", "B", "C", "D", "E" };
  +      String[] names = {"A", "B", "C", "D", "E"};
         int count = names.length;
         CacheActivator[] activators = new CacheActivator[count];
         
         
  -      try {
  +      try
  +      {
            // Create a semaphore and take all its tickets
            Semaphore semaphore = new Semaphore(count);         
  -         for (int i = 0; i < count; i++) {
  +         for (int i = 0; i < count; i++)
  +         {
               semaphore.acquire();
            }   
            
            // Create activation threads that will block on the semaphore
            CacheSPI[] caches = new CacheSPI[count];
  -         for (int i = 0; i < count; i++) {
  +         for (int i = 0; i < count; i++)
  +         {
               activators[i] = new CacheActivator(semaphore, names[i], sync);
               caches[i] = activators[i].getCacheSPI();
               activators[i].start();
  @@ -407,11 +410,12 @@
            semaphore.release(count);
            
            // Sleep to ensure the threads get all the semaphore tickets
  -          TestingUtil.sleepThread((long)1000);
  +         TestingUtil.sleepThread((long) 1000);
   
             // Reacquire the semaphore tickets; when we have them all
            // we know the threads are done         
  -         for (int i = 0; i < count; i++) {
  +         for (int i = 0; i < count; i++)
  +         {
               boolean acquired = semaphore.attempt(60000);
               if (!acquired)
                  fail("failed to acquire semaphore " + i);
  @@ -419,7 +423,7 @@
   
            // Sleep to allow any async calls to clear
            if (!sync)
  -             TestingUtil.sleepThread((long)500);
  +            TestingUtil.sleepThread((long) 500);
            
            // Ensure the caches held by the activators see all the values
            for (int i = 0; i < count; i++)
  @@ -437,10 +441,12 @@
               
            }
         }
  -      catch (Exception ex) {
  +      catch (Exception ex)
  +      {
            fail(ex.getLocalizedMessage());
         }
  -      finally {
  +      finally
  +      {
            for (int i = 0; i < count; i++)
               activators[i].cleanup();
         }
  @@ -477,16 +483,16 @@
       * that each node has consistent state.
       * 
       * @param sync whether to use REPL_SYNC or REPL_ASYNCE
  -    * 
       * @throws Exception
       */
      private void concurrentUseTest(boolean sync) throws Exception
      {
  -      String[] names = { "B", "C", "D", "E" };
  +      String[] names = {"B", "C", "D", "E"};
         int count = names.length;
         CacheStressor[] stressors = new CacheStressor[count];
         
  -      try {
  +      try
  +      {
            
            // The first cache we create is inactivated.
            CacheSPI cacheA = createCache("cacheA", sync, true, false);
  @@ -496,7 +502,8 @@
            
            // Create a semaphore and take all its tickets
            Semaphore semaphore = new Semaphore(count);         
  -         for (int i = 0; i < count; i++) {
  +         for (int i = 0; i < count; i++)
  +         {
               semaphore.acquire();
            }   
            
  @@ -533,7 +540,7 @@
               
               // Sleep to ensure the threads get all the semaphore tickets
               // and to ensure puts are actively in progress
  -             TestingUtil.sleepThread((long)300);
  +            TestingUtil.sleepThread((long) 300);
   
                // Activate cacheA
               for (int i = 0; i < count; i++)
  @@ -551,12 +558,12 @@
                     fail("failed to acquire semaphore " + i);
                  
                  // Pause to allow other work to proceed
  -                TestingUtil.sleepThread((long)100);
  +               TestingUtil.sleepThread((long) 100);
               }
               
               // Sleep to allow any in transit msgs to clear
   //            if (!sync)
  -             TestingUtil.sleepThread((long)1000);
  +            TestingUtil.sleepThread((long) 1000);
   
                // Ensure the stressors saw no exceptions
               for (int i = 0; i < count; i++)
  @@ -570,7 +577,7 @@
               {
                  for (int j = 0; j < SUBTREE_SIZE; j++)
                  {
  -                  Fqn fqn = Fqn.fromString("/" + names[i] +"/" + j);
  +                  Fqn fqn = Fqn.fromString("/" + names[i] + "/" + j);
                     assertEquals("/A/" + j + " matches " + fqn,
                                  cacheA.get(fqn, "KEY"),
                                  stressors[i].getCacheSPI().get(fqn, "KEY"));
  @@ -582,7 +589,8 @@
               stressors[i].stopThread();
            
         }
  -      finally {
  +      finally
  +      {
            for (int i = 0; i < count; i++)
            {
               if (stressors[i] != null)
  @@ -595,20 +603,20 @@
      private Object createBen(ClassLoader loader) throws Exception
      {
         Class addrClazz = loader.loadClass("org.jboss.cache.marshall.Address");
  -      Method setCity = addrClazz.getMethod("setCity", new Class[] { String.class});
  -      Method setStreet = addrClazz.getMethod("setStreet", new Class[] { String.class});
  -      Method setZip = addrClazz.getMethod("setZip", new Class[] { int.class});
  +      Method setCity = addrClazz.getMethod("setCity", new Class[]{String.class});
  +      Method setStreet = addrClazz.getMethod("setStreet", new Class[]{String.class});
  +      Method setZip = addrClazz.getMethod("setZip", new Class[]{int.class});
         Object addr = addrClazz.newInstance();
  -      setCity.invoke(addr, new Object[] { "San Jose" });
  -      setStreet.invoke(addr, new Object[] { "1007 Home" } );
  -      setZip.invoke(addr, new Object[] { new Integer(90210) } );
  +      setCity.invoke(addr, new Object[]{"San Jose"});
  +      setStreet.invoke(addr, new Object[]{"1007 Home"});
  +      setZip.invoke(addr, new Object[]{new Integer(90210)});
         
         Class benClazz = loader.loadClass("org.jboss.cache.marshall.Person");
  -      Method setName = benClazz.getMethod("setName", new Class[] { String.class});
  -      Method setAddress = benClazz.getMethod("setAddress", new Class[] { addrClazz });
  +      Method setName = benClazz.getMethod("setName", new Class[]{String.class});
  +      Method setAddress = benClazz.getMethod("setAddress", new Class[]{addrClazz});
         Object ben = benClazz.newInstance();
  -      setName.invoke(ben, new Object[] { "Ben" } );
  -      setAddress.invoke(ben, new Object[] { addr } );
  +      setName.invoke(ben, new Object[]{"Ben"});
  +      setAddress.invoke(ben, new Object[]{addr});
         
         return ben;
      }
  @@ -674,26 +682,26 @@
                     throw new Exception(name + " cannot acquire semaphore");
               }
               
  -            while(!putsStopped)
  +            while (!putsStopped)
               {
                  factor = random.nextInt(50);
                  
  -               fqn = Fqn.fromString("/" + name +"/" + String.valueOf(factor % SUBTREE_SIZE));
  +               fqn = Fqn.fromString("/" + name + "/" + String.valueOf(factor % SUBTREE_SIZE));
                  Integer value = new Integer(factor / SUBTREE_SIZE);
                  cache.put(fqn, "KEY", value);
   
  -                TestingUtil.sleepThread((long)factor);
  +               TestingUtil.sleepThread((long) factor);
   
                   i++;
               }
               
  -            System.out.println(name + ": last put [#"+ i + "] -- " + fqn + " = " + (factor / SUBTREE_SIZE));
  +            System.out.println(name + ": last put [#" + i + "] -- " + fqn + " = " + (factor / SUBTREE_SIZE));
               
               semaphore.release();
               
               // Go to sleep until directed otherwise
               while (!stopped && putsStopped)
  -                TestingUtil.sleepThread((long)100);
  +               TestingUtil.sleepThread((long) 100);
            }
         }
         
  
  
  



More information about the jboss-cvs-commits mailing list