[jbosscache-commits] JBoss Cache SVN: r5619 - in core/trunk/src: main/java/org/jboss/cache/commands/remote and 3 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Apr 22 08:57:24 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-04-22 08:57:24 -0400 (Tue, 22 Apr 2008)
New Revision: 5619

Modified:
   core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java
   core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
   core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/remote/GravitateDataCommand.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java
   core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyGroupAssignmentTest.java
   core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java
   core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java
   core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithTransactionsTest.java
   core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java
Log:
fixed stuff


Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java	2008-04-22 11:14:28 UTC (rev 5618)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java	2008-04-22 12:57:24 UTC (rev 5619)
@@ -243,7 +243,7 @@
     */
    public static Fqn getBackupFqn(Address dataOwnerAddress, Fqn origFqn)
    {
-      return getBackupFqn(BuddyManager.getGroupNameFromAddress(dataOwnerAddress), origFqn);
+      return getBackupFqn(getGroupNameFromAddress(dataOwnerAddress), origFqn);
    }
 
    /**
@@ -295,7 +295,61 @@
    public static Fqn getActualFqn(Fqn fqn)
    {
       if (!isBackupFqn(fqn)) return fqn;
-      // remove the first 2 elements
-      return fqn.getSubFqn(2, fqn.size());
+      // remove the first 2 (or 3 in the case of a dead backup region) elements
+      return fqn.getSubFqn(isDeadBackupFqn(fqn) ? 3 : 2, fqn.size());
    }
+
+   /**
+    * Tests whether a given Fqn belongs to a dead backup region.
+    *
+    * @param name fqn to test
+    * @return true if the fqn is a part of a dead backup region; false otherwise.
+    */
+   @SuppressWarnings("unchecked")
+   public static boolean isDeadBackupFqn(Fqn name)
+   {
+      if (name == null) return false;
+      Object elem1 = name.get(1);
+      if (elem1 instanceof String)
+      {
+         String strElem1 = (String) elem1;
+         return name.hasElement(BuddyManager.BUDDY_BACKUP_SUBTREE) && strElem1.endsWith(":DEAD");
+      }
+      else
+      {
+         return false;
+      }
+   }
+
+   /**
+    * @param dataOwner owner of a data set
+    * @return a backup root for a given data owner
+    */
+   @SuppressWarnings("unchecked")
+   public static Fqn<String> getBackupRoot(Address dataOwner)
+   {
+      return (Fqn) Fqn.fromRelativeElements(BUDDY_BACKUP_SUBTREE_FQN, getGroupNameFromAddress(dataOwner));
+   }
+
+   /**
+    * Returns the backup root of a dead data owner
+    *
+    * @param dataOwner owner of data
+    * @return Fqn of dead data owner's root
+    */
+   @SuppressWarnings("unchecked")
+   public static Fqn<String> getDeadBackupRoot(Address dataOwner)
+   {
+      return (Fqn) Fqn.fromRelativeElements(BUDDY_BACKUP_SUBTREE_FQN, getGroupNameFromAddress(dataOwner) + ":DEAD");
+   }
+
+   public static boolean isDeadBackupRoot(Fqn f)
+   {
+      return f.getParent().equals(BUDDY_BACKUP_SUBTREE_FQN) && f.getLastElementAsString().endsWith(":DEAD");
+   }
+
+   public static String getGroupNameFromAddress(Address address)
+   {
+      return address.toString().replace(':', '_');
+   }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java	2008-04-22 11:14:28 UTC (rev 5618)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java	2008-04-22 12:57:24 UTC (rev 5619)
@@ -217,11 +217,6 @@
       return config.getBuddyPoolName();
    }
 
-   public static String getGroupNameFromAddress(Address address)
-   {
-      return address.toString().replace(':', '_');
-   }
-
    /**
     * Stops the buddy manager and the related async thread.
     */
@@ -266,7 +261,7 @@
             throw new CacheException("Unable to initialize BuddyManager - the RPCManager has not connected to the cluster and local Address is null!");
          }
       }
-      buddyGroup.setGroupName(getGroupNameFromAddress(localAddress));
+      buddyGroup.setGroupName(BuddyFqnTransformer.getGroupNameFromAddress(localAddress));
 
       if (config.getBuddyPoolName() != null)
       {
@@ -549,7 +544,7 @@
       buddyGroupsIParticipateIn.put(newGroup.getDataOwner(), newGroup);
 
       // Integrate state transfer from the data owner of the buddy group
-      Fqn integrationBase = getBackupRoot(newGroup.getDataOwner());
+      Fqn integrationBase = BuddyFqnTransformer.getBackupRoot(newGroup.getDataOwner());
 
       if (state.isEmpty())
       {
@@ -675,57 +670,6 @@
 
    // -------------- internal helpers methods --------------------
 
-   /**
-    * @param dataOwner owner of a data set
-    * @return a backup root for a given data owner
-    */
-   @SuppressWarnings("unchecked")
-   public static Fqn<String> getBackupRoot(Address dataOwner)
-   {
-      Fqn f = Fqn.fromRelativeElements(BUDDY_BACKUP_SUBTREE_FQN, getGroupNameFromAddress(dataOwner));
-      return f;
-   }
-
-   /**
-    * Returns the backup root of a dead data owner
-    *
-    * @param dataOwner owner of data
-    * @return Fqn of dead data owner's root
-    */
-   @SuppressWarnings("unchecked")
-   public static Fqn<String> getDeadBackupRoot(Address dataOwner)
-   {
-      Fqn f = Fqn.fromRelativeElements(BUDDY_BACKUP_SUBTREE_FQN, getGroupNameFromAddress(dataOwner) + ":DEAD");
-      return f;
-   }
-
-   public static boolean isDeadBackupRoot(Fqn f)
-   {
-      return f.getParent().equals(BUDDY_BACKUP_SUBTREE_FQN) && f.getLastElementAsString().endsWith(":DEAD");
-   }
-
-   /**
-    * Tests whether a given Fqn belongs to a dead backup region.
-    *
-    * @param name fqn to test
-    * @return true if the fqn is a part of a dead backup region; false otherwise.
-    */
-   @SuppressWarnings("unchecked")
-   public static boolean isDeadBackupFqn(Fqn name)
-   {
-      if (name == null) return false;
-      Object elem1 = name.get(1);
-      if (elem1 instanceof String)
-      {
-         String strElem1 = (String) elem1;
-         return name.hasElement(BuddyManager.BUDDY_BACKUP_SUBTREE) && strElem1.endsWith(":DEAD");
-      }
-      else
-      {
-         return false;
-      }
-   }
-
    private void removeFromGroup(List<Address> buddies)
    {
       if (log.isDebugEnabled())
@@ -1034,13 +978,6 @@
       return BuddyFqnTransformer.getBackupFqn(buddyGroup == null || buddyGroup.getGroupName() == null ? "null" : buddyGroup.getGroupName(), originalFqn);
    }
 
-   public static Fqn getActualFqn(Fqn fqn)
-   {
-      if (!BuddyFqnTransformer.isBackupFqn(fqn)) return fqn;
-      // remove the first 2 (or 3 in the case of a dead backup region) elements
-      return fqn.getSubFqn(isDeadBackupFqn(fqn) ? 3 : 2, fqn.size());
-   }
-
    private void migrateDefunctData(Node backupRoot, Address dataOwner)
    {
       Fqn defunctBackupRootFqn = getDefunctBackupRootFqn(dataOwner);
@@ -1060,7 +997,7 @@
    {
       // the defunct Fqn should be: /_BUDDY_BACKUP_/dataOwnerAddess:DEAD/N
       // where N is a number.
-      Fqn<String> defunctRoot = getDeadBackupRoot(dataOwner);
+      Fqn<String> defunctRoot = BuddyFqnTransformer.getDeadBackupRoot(dataOwner);
       cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
       Node defunctRootNode = cache.getRoot().addChild(defunctRoot);
       SortedSet childrenNames = new TreeSet(defunctRootNode.getChildrenNames()); // will be naturally sorted.
@@ -1186,7 +1123,7 @@
             for (Address a : toRemove)
             {
                BuddyGroup bg = buddyGroupsIParticipateIn.remove(a);
-               Node backupRoot = cache.getNode(getBackupRoot(bg.getDataOwner()));
+               Node backupRoot = cache.getNode(BuddyFqnTransformer.getBackupRoot(bg.getDataOwner()));
                migrateDefunctData(backupRoot, bg.getDataOwner());
             }
          }

Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java	2008-04-22 11:14:28 UTC (rev 5618)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java	2008-04-22 12:57:24 UTC (rev 5619)
@@ -5,6 +5,7 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.NodeSPI;
+import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
 import org.jboss.cache.buddyreplication.BuddyManager;
 import org.jboss.cache.commands.CommandsFactory;
 import org.jboss.cache.commands.CommandsVisitor;
@@ -83,11 +84,11 @@
          if (!executeRemove(gtx, fqn))
          {
             // only attempt to clean up the backup if the primary did not exist - a waste of a call otherwise.
-            Object result = executeRemove(gtx, fqn);
+            Object result = executeRemove(gtx, backup);
             if (wasNodeRemoved(result))
             {
                // if this is a DIRECT child of a DEAD buddy backup region, then remove the empty dead region structural node.
-               if (BuddyManager.isDeadBackupFqn(backup) && BuddyManager.isDeadBackupRoot(backup.getParent().getParent()))
+               if (BuddyFqnTransformer.isDeadBackupFqn(backup) && BuddyFqnTransformer.isDeadBackupRoot(backup.getParent().getParent()))
                {
                   NodeSPI deadBackupRoot = cacheData.peek(backup.getParent(), false);
                   if (deadBackupRoot.getChildrenMapDirect().isEmpty())
@@ -106,6 +107,10 @@
                }
             }
          }
+         else
+         {
+            if (trace) log.trace("Managed to remove primary (" + fqn + ").  Not bothering with backups.");
+         }
       }
       else
       {
@@ -217,11 +222,7 @@
    public String toString()
    {
       return "DataGravitationCleanupCommand{" +
-            "buddyManager=" + buddyManager +
-            ", transactionHelper=" + transactionHelper +
-            ", invoker=" + invoker +
-            ", commandsFactory=" + commandsFactory +
-            ", globalTransaction=" + globalTransaction +
+            "fqn=" + fqn +
             ", backup=" + backup +
             '}';
    }

Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/GravitateDataCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/GravitateDataCommand.java	2008-04-22 11:14:28 UTC (rev 5618)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/GravitateDataCommand.java	2008-04-22 12:57:24 UTC (rev 5619)
@@ -89,7 +89,7 @@
                      // childName is the name of a buddy group since all child names in this
                      // collection are direct children of BUDDY_BACKUP_SUBTREE_FQN
                      Fqn backupRoot = Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, childName);
-                     if (BuddyManager.isDeadBackupRoot(backupRoot))
+                     if (BuddyFqnTransformer.isDeadBackupRoot(backupRoot))
                      {
                         //actualNode = searchDeadRoot(backupRoot, fqn);
                         Set<Integer> deadChildNames = new TreeSet<Integer>(spi.getChildrenNames(backupRoot));
@@ -141,7 +141,7 @@
 
          if (backupNodeFqn == null && searchSubtrees)
          {
-            backupNodeFqn = BuddyFqnTransformer.getBackupFqn(BuddyManager.getGroupNameFromAddress(rpcManager.getLocalAddress()), fqn);
+            backupNodeFqn = BuddyFqnTransformer.getBackupFqn(BuddyFqnTransformer.getGroupNameFromAddress(rpcManager.getLocalAddress()), fqn);
          }
 
          List<NodeData> list = cacheData.getNodeData(new LinkedList<NodeData>(), (NodeSPI) actualNode);

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java	2008-04-22 11:14:28 UTC (rev 5618)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java	2008-04-22 12:57:24 UTC (rev 5619)
@@ -178,7 +178,7 @@
    protected boolean skipReplicationOfTransactionMethod(InvocationContext ctx)
    {
       GlobalTransaction gtx = ctx.getGlobalTransaction();
-      return gtx == null || gtx.isRemote();
+      return gtx == null || gtx.isRemote() || ctx.getOptionOverrides().isCacheModeLocal();
    }
 
    /**

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java	2008-04-22 11:14:28 UTC (rev 5618)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java	2008-04-22 12:57:24 UTC (rev 5619)
@@ -2,7 +2,10 @@
 
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.commands.CacheCommand;
+import org.jboss.cache.commands.remote.AnnounceBuddyPoolNameCommand;
+import org.jboss.cache.commands.remote.AssignToBuddyGroupCommand;
 import org.jboss.cache.commands.remote.DirectCommand;
+import org.jboss.cache.commands.remote.RemoveFromBuddyGroupCommand;
 import org.jboss.cache.invocation.CacheLifecycleManager;
 import org.jboss.cache.invocation.InterceptorChain;
 import org.jboss.cache.invocation.InvocationContextContainer;
@@ -85,6 +88,15 @@
       {
          if (trace) log.trace("This is a direct command - so performing directly and not via the invoker.");
          DirectCommand dCmd = (DirectCommand) cmd;
+
+         // need to check cache status for all except buddy replication commands.
+         if (!(dCmd instanceof AnnounceBuddyPoolNameCommand ||
+               dCmd instanceof AssignToBuddyGroupCommand ||
+               dCmd instanceof RemoveFromBuddyGroupCommand)
+               && !lifecycleManager.allowsInvocation(false))
+         {
+            return null;
+         }
          return dCmd.performDirectly();
       }
       InvocationContext ctx = invocationContextContainer.get();

Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyGroupAssignmentTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyGroupAssignmentTest.java	2008-04-22 11:14:28 UTC (rev 5618)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyGroupAssignmentTest.java	2008-04-22 12:57:24 UTC (rev 5619)
@@ -140,11 +140,11 @@
       System.out.println("*** Testing cache 1:");
       assertIsBuddy(caches.get(1), caches.get(0), true);
 
-      assert caches.get(0).peek(BuddyManager.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have backup region for self";
-      assert caches.get(0).peek(BuddyManager.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have backup region for buddy";
+      assert caches.get(0).peek(BuddyFqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have backup region for self";
+      assert caches.get(0).peek(BuddyFqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have backup region for buddy";
 
-      assert caches.get(1).peek(BuddyManager.getBackupRoot(caches.get(0).getLocalAddress()), false) != null : "Should have backup region for buddy";
-      assert caches.get(1).peek(BuddyManager.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have backup region for self";
+      assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) != null : "Should have backup region for buddy";
+      assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have backup region for self";
 
       caches.add(createCache(1, null));
 
@@ -162,17 +162,17 @@
       System.out.println("1 Lock info: " + CachePrinter.printCacheLockingInfo(caches.get(1)));
       System.out.println("2 Lock info: " + CachePrinter.printCacheLockingInfo(caches.get(2)));
 
-      assert caches.get(0).peek(BuddyManager.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have backup region for self";
-      assert caches.get(0).peek(BuddyManager.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should have backup region for non-buddy";
-      assert caches.get(0).peek(BuddyManager.getBackupRoot(caches.get(2).getLocalAddress()), false) != null : "Should have backup region for buddy";
+      assert caches.get(0).peek(BuddyFqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have backup region for self";
+      assert caches.get(0).peek(BuddyFqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should have backup region for non-buddy";
+      assert caches.get(0).peek(BuddyFqnTransformer.getBackupRoot(caches.get(2).getLocalAddress()), false) != null : "Should have backup region for buddy";
 
-      assert caches.get(1).peek(BuddyManager.getBackupRoot(caches.get(0).getLocalAddress()), false) != null : "Should have backup region for buddy";
-      assert caches.get(1).peek(BuddyManager.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have backup region for self";
-      assert caches.get(1).peek(BuddyManager.getBackupRoot(caches.get(2).getLocalAddress()), false) == null : "Should not have backup region for non-buddy";
+      assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) != null : "Should have backup region for buddy";
+      assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have backup region for self";
+      assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(2).getLocalAddress()), false) == null : "Should not have backup region for non-buddy";
 
-      assert caches.get(2).peek(BuddyManager.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have backup region for non-buddy";
-      assert caches.get(2).peek(BuddyManager.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have backup region for buddy";
-      assert caches.get(2).peek(BuddyManager.getBackupRoot(caches.get(2).getLocalAddress()), false) == null : "Should not have backup region for self";
+      assert caches.get(2).peek(BuddyFqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have backup region for non-buddy";
+      assert caches.get(2).peek(BuddyFqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have backup region for buddy";
+      assert caches.get(2).peek(BuddyFqnTransformer.getBackupRoot(caches.get(2).getLocalAddress()), false) == null : "Should not have backup region for self";
 
       // ensure no state transfer has happened!!
       assert caches.get(2).peek(Fqn.fromString("/cache0"), false) == null : "Unnecessary state should not have been transferred!";

Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java	2008-04-22 11:14:28 UTC (rev 5618)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java	2008-04-22 12:57:24 UTC (rev 5619)
@@ -51,7 +51,7 @@
       caches = createCaches(3, false);
 
       String fqn = "/test";
-      String backupFqn = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + fqn;
+      String backupFqn = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyFqnTransformer.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + fqn;
 
       assertNoStaleLocks(caches);
 
@@ -83,7 +83,7 @@
       caches = createCaches(3, false);
 
       String fqn = "/test";
-      String backupFqn = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + fqn;
+      String backupFqn = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyFqnTransformer.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + fqn;
 
       assertNoStaleLocks(caches);
 
@@ -127,7 +127,7 @@
       caches = createCaches(2, 4, false);
 
       String fqn = "/test";
-      String backupFqn = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + fqn;
+      String backupFqn = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyFqnTransformer.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + fqn;
 
       // put something in cache 1
       assertNoStaleLocks(caches);

Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java	2008-04-22 11:14:28 UTC (rev 5618)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java	2008-04-22 12:57:24 UTC (rev 5619)
@@ -70,15 +70,15 @@
          System.out.println("Killed.  Testing backup roots.");
          dumpCacheContents(caches);
          // assert that the remaining caches have picked new buddies.  Cache 1 should have cache 2's backup data.
-         assert caches.get(1).peek(BuddyManager.getBackupRoot(caches.get(2).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
-         assert caches.get(1).peek(BuddyManager.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have self as a backup root.";
-         assert caches.get(1).peek(BuddyManager.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have dead node as a backup root.";
-         assert caches.get(1).peek(Fqn.fromRelativeElements(BuddyManager.getDeadBackupRoot(caches.get(0).getLocalAddress()), 1), false) != null : "Should have dead node as a defunct backup root.";
+         assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(2).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
+         assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have self as a backup root.";
+         assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have dead node as a backup root.";
+         assert caches.get(1).peek(Fqn.fromRelativeElements(BuddyFqnTransformer.getDeadBackupRoot(caches.get(0).getLocalAddress()), 1), false) != null : "Should have dead node as a defunct backup root.";
 
-         assert caches.get(2).peek(BuddyManager.getBackupRoot(caches.get(2).getLocalAddress()), false) == null : "Should not have self as a backup root.";
-         assert caches.get(2).peek(BuddyManager.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
-         assert caches.get(2).peek(BuddyManager.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have dead node as a backup root.";
-         assert caches.get(2).peek(Fqn.fromRelativeElements(BuddyManager.getDeadBackupRoot(caches.get(0).getLocalAddress()), 1), false) == null : "Should not have dead node as a defunct backup root.";
+         assert caches.get(2).peek(BuddyFqnTransformer.getBackupRoot(caches.get(2).getLocalAddress()), false) == null : "Should not have self as a backup root.";
+         assert caches.get(2).peek(BuddyFqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
+         assert caches.get(2).peek(BuddyFqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have dead node as a backup root.";
+         assert caches.get(2).peek(Fqn.fromRelativeElements(BuddyFqnTransformer.getDeadBackupRoot(caches.get(0).getLocalAddress()), 1), false) == null : "Should not have dead node as a defunct backup root.";
       }
 
       System.out.println("***** Killed original data owner, about to call a get on a different cache instance.  *****");
@@ -86,7 +86,7 @@
       // according to data gravitation, a call to *any* cache should retrieve the data, and move the data to the new cache.
       assertEquals("Value should have gravitated", value, caches.get(2).get(fqn, key));
 
-      TestingUtil.sleepThread(500);
+      delay(); // cleanup commands are async
 
       dumpCacheContents(caches);
 
@@ -100,16 +100,16 @@
       }
       else
       {
-         assert caches.get(1).peek(BuddyManager.getBackupRoot(caches.get(2).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
-         assert caches.get(1).peek(BuddyManager.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have self as a backup root.";
-         assert caches.get(1).peek(BuddyManager.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have dead node as a backup root.";
-         assert caches.get(1).peek(Fqn.fromRelativeElements(BuddyManager.getDeadBackupRoot(caches.get(0).getLocalAddress()), 1), false) == null : "Should not have dead node as a defunct backup root.";
-         assert caches.get(1).peek(BuddyManager.getDeadBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have dead node as a defunct backup root.";
+         assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(2).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
+         assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have self as a backup root.";
+         assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have dead node as a backup root.";
+         assert caches.get(1).peek(Fqn.fromRelativeElements(BuddyFqnTransformer.getDeadBackupRoot(caches.get(0).getLocalAddress()), 1), false) == null : "Should not have dead node as a defunct backup root.";
+         assert caches.get(1).peek(BuddyFqnTransformer.getDeadBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have dead node as a defunct backup root.";
 
-         assert caches.get(2).peek(BuddyManager.getBackupRoot(caches.get(2).getLocalAddress()), false) == null : "Should not have self as a backup root.";
-         assert caches.get(2).peek(BuddyManager.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
-         assert caches.get(2).peek(BuddyManager.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have dead node as a backup root.";
-         assert caches.get(2).peek(Fqn.fromRelativeElements(BuddyManager.getDeadBackupRoot(caches.get(0).getLocalAddress()), 1), false) == null : "Should not have dead node as a defunct backup root.";
+         assert caches.get(2).peek(BuddyFqnTransformer.getBackupRoot(caches.get(2).getLocalAddress()), false) == null : "Should not have self as a backup root.";
+         assert caches.get(2).peek(BuddyFqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
+         assert caches.get(2).peek(BuddyFqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have dead node as a backup root.";
+         assert caches.get(2).peek(Fqn.fromRelativeElements(BuddyFqnTransformer.getDeadBackupRoot(caches.get(0).getLocalAddress()), 1), false) == null : "Should not have dead node as a defunct backup root.";
       }
       assertTrue("Should be false", !caches.get(1).exists(fqn));
 
@@ -169,6 +169,7 @@
 
       caches.get(1).getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
       assertEquals("value", caches.get(1).get(fqn, key));
+      delay(); // cleanup commands are async
 
       dumpCacheContents(caches);
 
@@ -186,8 +187,8 @@
       Fqn<String> fqn = Fqn.fromString("/test");
       Fqn<String> fqn2 = Fqn.fromString("/test/subtree");
 
-      Fqn<String> backupFqn = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + "/test");
-      Fqn<String> backupFqn2 = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + "/test/subtree");
+      Fqn<String> backupFqn = BuddyFqnTransformer.getBackupFqn(caches.get(0).getLocalAddress(), fqn);
+      Fqn<String> backupFqn2 = BuddyFqnTransformer.getBackupFqn(caches.get(0).getLocalAddress(), fqn2);
 
       caches.get(0).put(fqn, key, value);
       caches.get(0).put(fqn2, key, value);
@@ -211,9 +212,10 @@
 
       // gravitate to 2:
       caches.get(2).getNode(fqn);  // expect entire subtree to gravitate.
+      delay(); // cleanup commands are async
 
-      Fqn<String> newBackupFqn = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(2).getLocalAddress()) + "/test");
-      Fqn<String> newBackupFqn2 = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(2).getLocalAddress()) + "/test/subtree");
+      Fqn<String> newBackupFqn = BuddyFqnTransformer.getBackupFqn(caches.get(2).getLocalAddress(), fqn);
+      Fqn<String> newBackupFqn2 = BuddyFqnTransformer.getBackupFqn(caches.get(2).getLocalAddress(), fqn2);
 
       assertEquals(value, caches.get(2).get(fqn, key));
       assertTrue(caches.get(2).exists(fqn2));
@@ -229,6 +231,8 @@
       assertTrue(!caches.get(1).exists(newBackupFqn));
       assertTrue(!caches.get(1).exists(newBackupFqn2));
 
+      dumpCacheContents(caches);
+
       for (CacheSPI<Object, Object> cache : caches)
       {
          assertTrue(!cache.exists(backupFqn));
@@ -237,4 +241,9 @@
 
       assertNoLocks(caches);
    }
+
+   protected void delay()
+   {
+      TestingUtil.sleepThread(250);
+   }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithTransactionsTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithTransactionsTest.java	2008-04-22 11:14:28 UTC (rev 5618)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithTransactionsTest.java	2008-04-22 12:57:24 UTC (rev 5619)
@@ -27,8 +27,8 @@
       caches = createCaches(3, false, true, false);
 
       caches.get(0).put(fqn, key, value);
-      Fqn oldBackupFqn = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + "/test");
-      Fqn newBackupFqn = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(2).getLocalAddress()) + "/test");
+      Fqn oldBackupFqn = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyFqnTransformer.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + "/test");
+      Fqn newBackupFqn = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyFqnTransformer.getGroupNameFromAddress(caches.get(2).getLocalAddress()) + "/test");
 
       dumpCacheContents(caches);
 
@@ -86,8 +86,8 @@
       caches = createCaches(3, false, true, false);
 
       caches.get(0).put(fqn, key, value);
-      Fqn oldBackupFqn = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + "/test");
-      Fqn newBackupFqn = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(2).getLocalAddress()) + "/test");
+      Fqn oldBackupFqn = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyFqnTransformer.getGroupNameFromAddress(caches.get(0).getLocalAddress()) + "/test");
+      Fqn newBackupFqn = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyFqnTransformer.getGroupNameFromAddress(caches.get(2).getLocalAddress()) + "/test");
 
       dumpCacheContents(caches);
 

Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java	2008-04-22 11:14:28 UTC (rev 5618)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java	2008-04-22 12:57:24 UTC (rev 5619)
@@ -49,12 +49,12 @@
       System.out.println("buddy: " + CachePrinter.printCacheLockingInfo(buddy));
 
       assert dataOwner.peek(fqn, false) != null : "Should have data";
-      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) != null : "Should have backup node for buddy";
-      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
+      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(buddy.getLocalAddress())), false) != null : "Should have backup node for buddy";
+      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
 
       assert buddy.peek(fqn, false) == null : "Should not have data";
-      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
-      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) != null : "Should have backup node for buddy";
+      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
+      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) != null : "Should have backup node for buddy";
       assert buddy.peek(BuddyFqnTransformer.getBackupFqn(dataOwner.getLocalAddress(), fqn), false) != null : "Should have backup data";
 
       // now do a gravitate call.
@@ -64,12 +64,12 @@
       System.out.println("buddy: " + CachePrinter.printCacheLockingInfo(buddy));
 
       assert buddy.peek(fqn, false) != null : "Should have data";
-      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) != null : "Should have backup node for buddy";
-      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
+      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) != null : "Should have backup node for buddy";
+      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
 
       assert dataOwner.peek(fqn, false) == null : "Should not have data";
-      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
-      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) != null : "Should have backup node for buddy";
+      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
+      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(buddy.getLocalAddress())), false) != null : "Should have backup node for buddy";
       assert dataOwner.peek(BuddyFqnTransformer.getBackupFqn(buddy.getLocalAddress(), fqn), false) != null : "Should have backup data";
    }
 
@@ -93,13 +93,13 @@
       System.out.println("thirdInstance: " + CachePrinter.printCacheLockingInfo(thirdInstance));
 
       assert dataOwner.peek(fqn, false) != null : "Should have data";
-      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(thirdInstance.getLocalAddress())), false) != null : "Should have backup node for buddy";
-      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
-      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for 2nd instance!";
+      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(thirdInstance.getLocalAddress())), false) != null : "Should have backup node for buddy";
+      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
+      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for 2nd instance!";
 
       assert buddy.peek(fqn, false) == null : "Should not have data";
-      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
-      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) != null : "Should have backup node for buddy";
+      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
+      assert buddy.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) != null : "Should have backup node for buddy";
       assert buddy.peek(BuddyFqnTransformer.getBackupFqn(dataOwner.getLocalAddress(), fqn), false) != null : "Should have backup data";
 
       // now do a gravitate call.
@@ -110,12 +110,12 @@
       System.out.println("thirdInstance: " + CachePrinter.printCacheLockingInfo(thirdInstance));
 
       assert thirdInstance.peek(fqn, false) != null : "Should have data";
-      assert thirdInstance.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) != null : "Should have backup node for buddy";
-      assert thirdInstance.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(thirdInstance.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
+      assert thirdInstance.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(buddy.getLocalAddress())), false) != null : "Should have backup node for buddy";
+      assert thirdInstance.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(thirdInstance.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
 
       assert dataOwner.peek(fqn, false) == null : "Should not have data";
-      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
-      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(thirdInstance.getLocalAddress())), false) != null : "Should have backup node for buddy";
+      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
+      assert dataOwner.peek(Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyFqnTransformer.getGroupNameFromAddress(thirdInstance.getLocalAddress())), false) != null : "Should have backup node for buddy";
       assert dataOwner.peek(BuddyFqnTransformer.getBackupFqn(thirdInstance.getLocalAddress(), fqn), false) != null : "Should have backup data";
       assert buddy.peek(fqn, false) == null : "Should not have data";
       assert buddy.peek(fqn.getParent(), false) == null : "Should not have any part of the data";




More information about the jbosscache-commits mailing list