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

Manik Surtani manik at jboss.org
Mon Apr 23 11:56:29 EDT 2007


  User: msurtani
  Date: 07/04/23 11:56:29

  Modified:    tests/functional/org/jboss/cache/buddyreplication 
                        BuddyBackupActivationInactivationTest.java
  Log:
  Better comments and javadocs in Region and RegionManager, plus enabled tests in test class
  
  Revision  Changes    Path
  1.17      +44 -67    JBossCache/tests/functional/org/jboss/cache/buddyreplication/BuddyBackupActivationInactivationTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BuddyBackupActivationInactivationTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/buddyreplication/BuddyBackupActivationInactivationTest.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -b -r1.16 -r1.17
  --- BuddyBackupActivationInactivationTest.java	16 Apr 2007 17:37:10 -0000	1.16
  +++ BuddyBackupActivationInactivationTest.java	23 Apr 2007 15:56:29 -0000	1.17
  @@ -6,14 +6,18 @@
    */
   package org.jboss.cache.buddyreplication;
   
  +import org.jboss.cache.Cache;
   import org.jboss.cache.CacheImpl;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.DefaultCacheFactory;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.Region;
   import org.jboss.cache.config.BuddyReplicationConfig;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.config.Configuration.CacheMode;
   import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
   import org.jboss.cache.factories.XmlConfigurationParser;
  +import org.jboss.cache.misc.TestingUtil;
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   
  @@ -21,7 +25,6 @@
   import javax.xml.parsers.DocumentBuilderFactory;
   import java.util.HashMap;
   import java.util.Map;
  -import java.util.Set;
   
   /**
    * Tests handling of the buddy backup region during region
  @@ -35,94 +38,71 @@
      public static final Fqn A_B = Fqn.fromString("/a/b");
      public static final String JOE = "JOE";
   
  -   protected Map caches;
  +   protected Map<String, Cache> caches;
      private ClassLoader orig_TCL;
   
      public void testBuddyBackupActivation() throws Exception
      {
  -      /** TODO: Uncomment once we have FLUSH in place
  -       *
  -
  -       CacheImpl[] caches = new CacheImpl[2];
  -       caches[0] = createCache("cache1", true, true, true);
  -       caches[1] = createCache("cache2", true, true, true);
  +      CacheSPI cache1 = createCache("cache1", true, true, true);
  +      CacheSPI cache2 = createCache("cache2", true, true, true);
   
  -       TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
  +      TestingUtil.blockUntilViewsReceived(VIEW_BLOCK_TIMEOUT, cache1, cache2);
   
  -       caches[0].activateRegion("/a");
  -
  -       caches[0].put(A_B, "name", JOE);
  +      cache1.getRegionManager().activate(Fqn.fromString("/a"));
  +      cache1.put(A_B, "name", JOE);
   
          TestingUtil.sleepThread(getSleepTimeout());
   
  -       caches[1].activateRegion("/a");
  +      cache2.getRegionManager().activate(Fqn.fromString("/a"));
  +      Fqn fqn = BuddyManager.getBackupFqn(cache1.getLocalAddress(), A_B);
   
  -       Fqn fqn = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN,
  -       BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress()));
  -       fqn = new Fqn(fqn, A_B);
  -
  -       assertEquals("State transferred with activation", JOE, caches[1].get(fqn, "name"));
  -       */
  +      assertEquals("State transferred with activation", JOE, cache2.get(fqn, "name"));
      }
   
      public void testReplToInactiveRegion() throws Exception
      {
  -      // TODO: Reinstate once we have proper FLUSH working.
  -      // This test relies on calls to inactive regions being queued and re-run
  -      // when the region is activated.  After discussions with Brian, the queueing
  -      // was removed, presuming FLUSH will fix this.  Need to test with FLUSH.
  -      // - Manik Surtani (16 Oct 2006)
  -      /*
  -      CacheImpl[] caches = new CacheImpl[2];
  -      caches[0] = createCache("cache1", true, true, true);
  -      caches[1] = createCache("cache2", true, true, true);
  -
  -      TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
  +      CacheSPI cache1 = createCache("cache1", true, true, true);
  +      CacheSPI cache2 = createCache("cache2", true, true, true);
   
  -      caches[0].activateRegion("/a");
  +      TestingUtil.blockUntilViewsReceived(VIEW_BLOCK_TIMEOUT, cache1, cache2);
  +      Fqn backupFqn = BuddyManager.getBackupFqn(cache1.getLocalAddress(), A_B);
  +      Fqn A = Fqn.fromString("/a");
  +
  +      Region regionA = cache1.getRegion(A, true);
  +      regionA.registerContextClassLoader(getClass().getClassLoader());
  +      regionA.activate();
   
         // Activate the buddy backup subtree in the recipient so any
         // repl message doesn't get rejected due to that tree being inactive
  -      caches[1].activateRegion(BuddyManager.BUDDY_BACKUP_SUBTREE);
  +      cache2.getRegionManager().activate(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
  +      cache2.getRegionManager().deactivate(A);
   
  -      caches[0].put(A_B, "name", JOE);
  +      cache1.put(A_B, "name", JOE);
   
         TestingUtil.sleepThread(getSleepTimeout());
  +      assertNull("Should be no replication to inactive region", cache2.get(A_B, "name"));
   
  -      assertNull("No replication to inactive region", caches[1].get(A_B, "name"));
  -
  -      Fqn fqn = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN,
  -              BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress()));
  -      fqn = new Fqn(fqn, A_B);
  -
  -      assertNull("No replication to inactive backup region", caches[1].get(fqn, "name"));
  -      */
  +      assertNull("Should be no replication to inactive backup region", cache2.get(backupFqn, "name"));
      }
   
      public void testBuddyBackupInactivation() throws Exception
      {
  -      // TODO: Reinstate once we have proper FLUSH working.
  -      // This test relies on calls to inactive regions being queued and re-run
  -      // when the region is activated.  After discussions with Brian, the queueing
  -      // was removed, presuming FLUSH will fix this.  Need to test with FLUSH.
  -      // - Manik Surtani (16 Oct 2006)
  -      /*
               CacheImpl cache1 = createCache("cache1", true, true, true);
  -
  -            cache1.activateRegion("/a");
  +      Fqn A = Fqn.fromString("/a");
  +      Region regionA = cache1.getRegion(A, true);
  +      regionA.registerContextClassLoader(getClass().getClassLoader());
  +      regionA.activate();
   
               Fqn fqn = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, "test");
               fqn = new Fqn(fqn, A_B);
               cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
               cache1.put(fqn, "name", JOE);
   
  -            assertEquals("Put OK", JOE, cache1.get(fqn, "name"));
  -
  -            cache1.inactivateRegion("/a");
  +      assertEquals("Put should have been OK", JOE, cache1.get(fqn, "name"));
   
  -            assertNull("Inactivation cleared region", cache1.get(fqn, "name"));
  -      */
  +      regionA.deactivate();
   
  +      assertNull("Inactivation should have cleared region", cache1.get(fqn, "name"));
      }
   
      protected CacheImpl createCache(String cacheID,
  @@ -166,7 +146,7 @@
      {
         super.setUp();
   
  -      caches = new HashMap();
  +      caches = new HashMap<String, Cache>();
   
         // Save the TCL in case a test changes it
         orig_TCL = Thread.currentThread().getContextClassLoader();
  @@ -179,16 +159,13 @@
         // Restore the TCL in case a test changed it
         Thread.currentThread().setContextClassLoader(orig_TCL);
   
  -      Set keys = caches.keySet();
  -      String[] cacheIDs = new String[keys.size()];
  -      cacheIDs = (String[]) keys.toArray(cacheIDs);
  -      for (int i = 0; i < cacheIDs.length; i++)
  +      for (String cacheID : caches.keySet())
         {
  -         stopCache((CacheImpl) caches.get(cacheIDs[i]));
  +         stopCache(caches.get(cacheID));
         }
      }
   
  -   protected void stopCache(CacheImpl cache)
  +   protected void stopCache(Cache cache)
      {
         if (cache != null)
         {
  
  
  



More information about the jboss-cvs-commits mailing list