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

Vladmir Blagojevic vladimir.blagojevic at jboss.com
Thu Dec 21 16:41:36 EST 2006


  User: vblagojevic
  Date: 06/12/21 16:41:36

  Modified:    tests/functional/org/jboss/cache/statetransfer    
                        FailedStateTransferTest.java VersionedTestBase.java
                        StateTransferTestBase.java
                        StateTransfer200Test.java
  Log:
  test update
  
  Revision  Changes    Path
  1.7       +46 -15    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.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- FailedStateTransferTest.java	11 Sep 2006 17:42:41 -0000	1.6
  +++ FailedStateTransferTest.java	21 Dec 2006 21:41:36 -0000	1.7
  @@ -22,9 +22,9 @@
   
   package org.jboss.cache.statetransfer;
   
  +import java.io.InputStream;
  +
   import org.jboss.cache.CacheException;
  -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;
  @@ -55,9 +55,21 @@
         tree.create();
         tree.start();
   
  -      CacheSPI recipient = createCache("recipient", false, false, false, false, false);
  +      
  +      TreeCache recipient = new SecretiveStateCache();
  +      recipient.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replAsync-service.xml"));
  +      recipient.getConfiguration().setClusterName("VersionedTestBase");
  +      recipient.getConfiguration().setReplVersionString(getReplicationVersion());
  +      // Use a long timeout to facilitate setting debugger breakpoints
  +      recipient.getConfiguration().setInitialStateRetrievalTimeout(60000);
  +      
  +      //Put the cache in the map before starting, so if it fails in
  +      // start it can still be destroyed later
  +      caches.put("secretive2", recipient.getCacheSPI());
  +      
         try
         {
  +         recipient.create();
            recipient.start();
            fail("start() should throw an exception");
         }
  @@ -72,20 +84,39 @@
         return Version.version;
      }
   
  -   /**
  -    * Overrides the superclass to always throw an exception in _getState
  -    */
      private static class SecretiveStateCache extends TreeCache
      {
         SecretiveStateCache() throws Exception
         {
            super();
  +         ml = new Adaptor();
         }
  +      class Adaptor extends MessageListenerAdaptor
  +      {
   
  -      public byte[] _getState(Fqn fqn, long timeout, boolean force, boolean suppressErrors) throws Throwable
  +         @Override
  +         public void setState(byte[] new_state)
         {
  -         throw new TimeoutException("Planned Timeout");
  +            setStateException = new TimeoutException("Planned Timeout");
         }
   
  +         @Override
  +         public void setState(InputStream istream)
  +         {
  +            setStateException = new TimeoutException("Planned Timeout");
  +         }
  +
  +         @Override
  +         public void setState(String state_id, byte[] state)
  +         {
  +            setStateException = new TimeoutException("Planned Timeout");
  +         }
  +
  +         @Override
  +         public void setState(String state_id, InputStream istream)
  +         {
  +            setStateException = new TimeoutException("Planned Timeout");
  +         }         
  +      }
      }
   }
  
  
  
  1.20      +10 -85    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.19
  retrieving revision 1.20
  diff -u -b -r1.19 -r1.20
  --- VersionedTestBase.java	14 Nov 2006 19:56:09 -0000	1.19
  +++ VersionedTestBase.java	21 Dec 2006 21:41:36 -0000	1.20
  @@ -7,7 +7,6 @@
   
   package org.jboss.cache.statetransfer;
   
  -import EDU.oswego.cs.dl.util.concurrent.Semaphore;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
  @@ -18,6 +17,8 @@
   
   import java.lang.reflect.Method;
   import java.util.Random;
  +import java.util.concurrent.Semaphore;
  +import java.util.concurrent.TimeUnit;
   
   /**
    * Abstract superclass of "StateTransferVersion"-specific tests
  @@ -454,7 +455,7 @@
      {
         // TODO: Needs revisiting after concurrent FLUSH is supported
         //http://jira.jboss.com/jira/browse/JGRP-332
  -      //concurrentActivationTest(true);
  +      concurrentActivationTest(true);
      }
   
      /**
  @@ -468,7 +469,7 @@
      {
         // TODO: Needs revisiting after concurrent FLUSH is supported
         //http://jira.jboss.com/jira/browse/JGRP-332
  -      //concurrentActivationTest(false);
  +      concurrentActivationTest(false);
      }
   
      /**
  @@ -522,7 +523,7 @@
            // we know the threads are done         
            for (int i = 0; i < count; i++)
            {
  -            boolean acquired = semaphore.attempt(60000);
  +            boolean acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
               if (!acquired)
                  fail("failed to acquire semaphore " + i);
            }
  @@ -623,7 +624,7 @@
            // we know the threads are done         
            for (int i = 0; i < count; i++)
            {
  -            boolean acquired = semaphore.attempt(60000);
  +            boolean acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
               if (!acquired)
                  fail("failed to acquire semaphore " + i);
            }
  @@ -718,7 +719,7 @@
      {
         // TODO: Needs revisiting after concurrent FLUSH is supported
         //http://jira.jboss.com/jira/browse/JGRP-332
  -      //concurrentUseTest(true);
  +      concurrentUseTest(true);
      }
   
      /**
  @@ -731,7 +732,7 @@
      {
         // TODO: Needs revisiting after concurrent FLUSH is supported
         //http://jira.jboss.com/jira/browse/JGRP-332
  -      //concurrentUseTest(false);
  +      concurrentUseTest(false);
      }
   
      /**
  @@ -812,7 +813,7 @@
                  stressors[i].stopPuts();
                  System.out.println("Run " + x + "-- /" + names[i] + " activated on A");
                  // Reacquire one semaphore ticket
  -               boolean acquired = semaphore.attempt(60000);
  +               boolean acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
                  if (!acquired)
                     fail("failed to acquire semaphore " + i);
   
  @@ -973,7 +974,7 @@
            {
               if (i > 0)
               {
  -               acquired = semaphore.attempt(60000);
  +               acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
                  if (!acquired)
                     throw new Exception(name + " cannot acquire semaphore");
               }
  @@ -1020,80 +1021,4 @@
   
   
      }
  -
  -   private abstract class CacheUser implements Runnable
  -   {
  -      protected Semaphore semaphore;
  -      protected CacheSPI cache;
  -      protected String name;
  -      protected Exception exception;
  -      protected Thread thread;
  -
  -      CacheUser(Semaphore semaphore,
  -                String name,
  -                boolean sync,
  -                boolean activateRoot)
  -              throws Exception
  -      {
  -         this.cache = createCache(name, sync, true, false);
  -         this.semaphore = semaphore;
  -         this.name = name;
  -
  -         if (activateRoot)
  -            cache.getRegion(Fqn.ROOT, true).activate();
  -      }
  -
  -      public void run()
  -      {
  -         boolean acquired = false;
  -         try
  -         {
  -            acquired = semaphore.attempt(60000);
  -            if (!acquired)
  -               throw new Exception(name + " cannot acquire semaphore");
  -            //System.out.println(name + " acquired semaphore");
  -
  -            useCache();
  -
  -         }
  -         catch (Exception e)
  -         {
  -            System.out.println(name + ": " + e.getLocalizedMessage());
  -            e.printStackTrace(System.out);
  -
  -            // Save it for the test to check
  -            exception = e;
  -         }
  -         finally
  -         {
  -            if (acquired)
  -               semaphore.release();
  -         }
  -
  -      }
  -
  -      abstract void useCache() throws Exception;
  -
  -      public Exception getException()
  -      {
  -         return exception;
  -      }
  -
  -      public CacheSPI getCacheSPI()
  -      {
  -         return cache;
  -      }
  -
  -      public void start()
  -      {
  -         thread = new Thread(this);
  -         thread.start();
  -      }
  -
  -      public void cleanup()
  -      {
  -         if (thread != null && thread.isAlive())
  -            thread.interrupt();
  -      }
  -   }
   }
  
  
  
  1.25      +85 -1     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.24
  retrieving revision 1.25
  diff -u -b -r1.24 -r1.25
  --- StateTransferTestBase.java	31 Oct 2006 06:57:29 -0000	1.24
  +++ StateTransferTestBase.java	21 Dec 2006 21:41:36 -0000	1.25
  @@ -26,17 +26,19 @@
   import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.config.Configuration;
  -import org.jboss.cache.factories.CacheFactory;
   import org.jboss.cache.factories.DefaultCacheFactory;
   import org.jboss.cache.factories.XmlConfigurationParser;
   import org.jboss.cache.loader.AbstractCacheLoaderTestBase;
   import org.jboss.cache.marshall.SelectedClassnameClassLoader;
   
  +
   import java.io.File;
   import java.util.HashMap;
   import java.util.Map;
   import java.util.Properties;
   import java.util.Set;
  +import java.util.concurrent.Semaphore;
  +import java.util.concurrent.TimeUnit;
   
   /**
    * Abstract superclass of the StateTransfer tests.
  @@ -293,4 +295,86 @@
         return new SelectedClassnameClassLoader(null, null, notFoundClasses, cl);
      }
   
  +   protected abstract class CacheUser implements Runnable
  +   {
  +      protected Semaphore semaphore;
  +      protected CacheSPI cache;
  +      protected String name;
  +      protected Exception exception;
  +      protected Thread thread;
  +
  +      CacheUser(){}
  +      
  +      CacheUser(Semaphore semaphore,
  +                String name,
  +                boolean sync,
  +                boolean activateRoot)
  +              throws Exception
  +      {
  +         this.cache = createCache(name, sync, true, false);
  +         this.semaphore = semaphore;
  +         this.name = name;
  +
  +         if (activateRoot)
  +            cache.getRegion(Fqn.ROOT, true).activate();
  +      }
  +
  +      public void run()
  +      {
  +         boolean acquired = false;
  +         try
  +         {
  +            acquired = semaphore.tryAcquire(60, TimeUnit.SECONDS);
  +            if (!acquired)
  +               throw new Exception(name + " cannot acquire semaphore");
  +            //System.out.println(name + " acquired semaphore");
  +
  +            useCache();
  +
  +         }
  +         catch (Exception e)
  +         {
  +            System.out.println(name + ": " + e.getLocalizedMessage());
  +            e.printStackTrace(System.out);
  +
  +            // Save it for the test to check
  +            exception = e;
  +         }
  +         finally
  +         {
  +            if (acquired)
  +               semaphore.release();
  +         }
  +
  +      }
  +
  +      abstract void useCache() throws Exception;
  +
  +      public Exception getException()
  +      {
  +         return exception;
  +      }
  +
  +      public CacheSPI getCacheSPI()
  +      {
  +         return cache;
  +      }
  +      
  +      public String getName()
  +      {
  +         return name;
  +      }
  +
  +      public void start()
  +      {
  +         thread = new Thread(this);
  +         thread.start();
  +      }
  +
  +      public void cleanup()
  +      {
  +         if (thread != null && thread.isAlive())
  +            thread.interrupt();
  +      }
  +   }
   }
  
  
  
  1.11      +14 -5     JBossCache/tests/functional/org/jboss/cache/statetransfer/StateTransfer200Test.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: StateTransfer200Test.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/statetransfer/StateTransfer200Test.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- StateTransfer200Test.java	20 Nov 2006 03:53:57 -0000	1.10
  +++ StateTransfer200Test.java	21 Dec 2006 21:41:36 -0000	1.11
  @@ -26,7 +26,7 @@
    * Tests that state transfer works properly if the version is 2.0.0.GA.
    *
    * @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
  - * @version $Revision: 1.10 $
  + * @version $Revision: 1.11 $
    */
   public class StateTransfer200Test extends VersionedTestBase
   {
  @@ -107,9 +107,18 @@
         cache1.put(A_C, "name", BOB);
         cache1.put(A_C, "age", FORTY);
   
  -      CacheSPI cache2 = createCache("cache2", false, false, true, false, true);
  -      // Pause to give caches time to see each other
  -      TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
  +      CacheSPI cache2 = null;
  +      try
  +      {
  +         cache2 = createCache("cache2", false, false, true, false, false);
  +         cache2.create();
  +         cache2.start();
  +         fail("Should have caused an exception");
  +      }
  +      catch(Exception e)
  +      {
  +         assertNotNull(e);
  +      }      
   
         //when persistent transfer fails as in this case state recipient cacheloader should be wiped clean
         assertFalse("/a/b is not in cache loader ", cache2.getCacheLoader().exists(A_B));
  
  
  



More information about the jboss-cvs-commits mailing list