Author: bstansberry(a)jboss.com
Date: 2009-10-12 18:30:16 -0400 (Mon, 12 Oct 2009)
New Revision: 8246
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy2NodesNoBuddyPoolTest.java
Log:
[JBCACHE-1549] Add test for failure condition
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy2NodesNoBuddyPoolTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy2NodesNoBuddyPoolTest.java 2009-10-01
11:21:31 UTC (rev 8245)
+++
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy2NodesNoBuddyPoolTest.java 2009-10-12
22:30:16 UTC (rev 8246)
@@ -29,7 +29,7 @@
@Override
public void tearDown() throws Exception
{
- if (caches.get(2) != null)
+ if (caches.size() > 2 && caches.get(2) != null)
{
Cache cache = caches.get(2);
caches.remove(2);
@@ -148,4 +148,49 @@
assertFalse("Should be null", caches.get(2).exists(backupFqn));
assertNoStaleLocks(caches);
}
+
+ /**
+ * Test for
https://jira.jboss.org/jira/browse/JBCACHE-1549
+ *
+ * @throws Exception
+ */
+ public void testStateTransferOnBuddyRestart() throws Exception
+ {
+ String key = "key";
+ String value = "value";
+
+ Fqn fqn = Fqn.fromString("/test");
+ Fqn backupFqn = fqnTransformer.getBackupFqn(caches.get(0).getLocalAddress(), fqn);
+
+ assertNoStaleLocks(caches);
+
+ // put something in cache 0
+ caches.get(0).put(fqn, key, value);
+
+ assertNoStaleLocks(caches);
+
+ // this should be in neither of the other cachePool' "main" trees
+ assertEquals(value, caches.get(0).get(fqn, key));
+ assertFalse("Should be false", caches.get(1).exists(fqn));
+
+ // check the backup trees
+ assertEquals("Buddy should have data in backup tree", value,
caches.get(1).get(backupFqn, key));
+
+ assertNoStaleLocks(caches);
+
+ // now re-start cache 1
+ caches.get(1).stop();
+ TestingUtil.blockUntilViewsReceived(3000, caches.get(0));
+ caches.get(1).start();
+
+ // allow this cache a few msecs to join
+ TestingUtil.blockUntilViewsReceived(3000, caches.get(0), caches.get(1));
+
+ TestingUtil.sleepThread(2000); // allow buddy group reorg
+
+ // check the backup tree to confirm that original key/value was transferred
+ // This is the test that fails with JBCACHE-1549
+ assertEquals("Buddy should have data in backup tree", value,
caches.get(1).get(backupFqn, key));
+
+ }
}