Author: manik.surtani(a)jboss.com
Date: 2008-04-07 07:27:27 -0400 (Mon, 07 Apr 2008)
New Revision: 5507
Modified:
core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyGroupAssignmentTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java
core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
Log:
JBCACHE-1258: Cleanup of backup regions
Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-04-07 09:51:48 UTC
(rev 5506)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-04-07 11:27:27 UTC
(rev 5507)
@@ -118,12 +118,14 @@
case LOCAL:
log.debug("cache mode is local, will not create the channel");
isInLocalMode = true;
+ isUsingBuddyReplication = false;
break;
case REPL_SYNC:
case REPL_ASYNC:
case INVALIDATION_ASYNC:
case INVALIDATION_SYNC:
isInLocalMode = false;
+ isUsingBuddyReplication = configuration.getBuddyReplicationConfig() != null
&& configuration.getBuddyReplicationConfig().isEnabled();
if (log.isDebugEnabled()) log.debug("Cache mode is " +
configuration.getCacheMode());
initialiseChannelAndRpcDispatcher();
@@ -171,8 +173,6 @@
}
if (log.isInfoEnabled()) log.info("Cache local address is " +
getLocalAddress());
}
-
- isUsingBuddyReplication = configuration.getBuddyReplicationConfig() != null
&& configuration.getBuddyReplicationConfig().isEnabled();
}
public void disconnect()
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-07
09:51:48 UTC (rev 5506)
+++
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyGroupAssignmentTest.java 2008-04-07
11:27:27 UTC (rev 5507)
@@ -9,7 +9,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.util.CachePrinter;
import org.testng.annotations.Test;
@@ -29,11 +29,6 @@
log.debug("Running testSingleBuddy");
caches = createCaches(3, false);
- for (CacheSPI cache : caches)
- {
- printBuddyGroup(cache);
- }
-
System.out.println("*** Testing cache 0:");
assertIsBuddy(caches.get(0), caches.get(1), true);
System.out.println("*** Testing cache 1:");
@@ -129,4 +124,61 @@
assertIsBuddy(caches.get(3), caches.get(2), false);
assertNoLocks(caches);
}
+
+ public void testAddingNewCaches() throws Exception
+ {
+ log.debug("Running testAddingNewCaches");
+ caches = createCaches(2, false);
+
+ // get some data in there.
+
+ caches.get(0).put("/cache0", "k", "v");
+ caches.get(1).put("/cache1", "k", "v");
+
+ System.out.println("*** Testing cache 0:");
+ assertIsBuddy(caches.get(0), caches.get(1), true);
+ System.out.println("*** Testing cache 1:");
+ assertIsBuddy(caches.get(1), caches.get(0), true);
+
+ assert caches.get(0).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress())), false) == null :
"Should not have backup region for self";
+ assert caches.get(0).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(1).getLocalAddress())), false) != null :
"Should have backup region for buddy";
+
+ assert caches.get(1).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress())), false) != null :
"Should have backup region for buddy";
+ assert caches.get(1).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(1).getLocalAddress())), false) == null :
"Should not have backup region for self";
+
+ caches.add(createCache(1, null));
+
+ TestingUtil.blockUntilViewsReceived(60000, caches);
+
+ System.out.println("*** Testing cache 0:");
+ assertIsBuddy(caches.get(0), caches.get(1), true);
+ System.out.println("*** Testing cache 1:");
+ assertIsBuddy(caches.get(1), caches.get(2), true);
+ System.out.println("*** Testing cache 2:");
+ assertIsBuddy(caches.get(2), caches.get(0), true);
+
+
+ System.out.println("0 Lock info: " +
CachePrinter.printCacheLockingInfo(caches.get(0)));
+ 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(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress())), false) == null :
"Should not have backup region for self";
+ assert caches.get(0).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(1).getLocalAddress())), false) == null :
"Should have backup region for non-buddy";
+ assert caches.get(0).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(2).getLocalAddress())), false) != null :
"Should have backup region for buddy";
+
+ assert caches.get(1).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress())), false) != null :
"Should have backup region for buddy";
+ assert caches.get(1).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(1).getLocalAddress())), false) == null :
"Should not have backup region for self";
+ assert caches.get(1).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(2).getLocalAddress())), false) == null :
"Should not have backup region for non-buddy";
+
+ assert caches.get(2).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress())), false) == null :
"Should not have backup region for non-buddy";
+ assert caches.get(2).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(caches.get(1).getLocalAddress())), false) != null :
"Should have backup region for buddy";
+ assert caches.get(2).peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE,
BuddyManager.getGroupNameFromAddress(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!";
+ assert caches.get(2).peek(Fqn.fromString("/cache1"), false) == null :
"Unnecessary state should not have been transferred!";
+
+ // ensure backup state has been transferred.
+ assert
caches.get(2).peek(BuddyManager.getBackupFqn(caches.get(1).getLocalAddress(),
Fqn.fromString("/cache1")), false) != null : "Backup state should have
transferred!";
+ }
}
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java 2008-04-07
09:51:48 UTC (rev 5506)
+++
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java 2008-04-07
11:27:27 UTC (rev 5507)
@@ -127,7 +127,7 @@
protected CacheSPI<Object, Object> createCache(boolean optimisticLocks, int
numBuddies, String buddyPoolName, boolean useDataGravitation, boolean removeOnFind,
boolean start) throws Exception
{
- CacheSPI<Object, Object> c = (CacheSPI<Object, Object>) new
DefaultCacheFactory().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
false);
+ CacheSPI<Object, Object> c = (CacheSPI<Object, Object>) new
DefaultCacheFactory<Object,
Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
false);
c.getConfiguration().setClusterName("BuddyReplicationTest");
// basic config
String xmlString =
"<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n"
+
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-07
09:51:48 UTC (rev 5506)
+++
core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java 2008-04-07
11:27:27 UTC (rev 5507)
@@ -120,6 +120,5 @@
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";
assert buddy.peek(BuddyManager.getBackupFqn(dataOwner.getLocalAddress(), fqn),
false) == null : "Should NOT have backup data";
-
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2008-04-07 09:51:48 UTC
(rev 5506)
+++ core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2008-04-07 11:27:27 UTC
(rev 5507)
@@ -552,4 +552,9 @@
}
throw new RuntimeException("Timed out waiting for condition");
}
+
+ public static void blockUntilViewsReceived(int timeout, List caches)
+ {
+ blockUntilViewsReceived((Cache[]) caches.toArray(new Cache[]{}), timeout);
+ }
}