Fqn fqn = Fqn.fromString("/test");
Fqn backupFqn = fqnTransformer.getBackupFqn(caches.get(2).getLocalAddress(), fqn);
TestingUtil.dumpCacheContents(caches);
ReplicationListener replListener0 = ReplicationListener.getReplicationListener(caches.get(0));
replListener0.expect(PutKeyValueCommand.class);
caches.get(2).put(fqn, key, value);
replListener0.waitForReplicationToOccur();
TestingUtil.dumpCacheContents(caches);
assertEquals("Value should exist", value, caches.get(2).get(fqn, key));
TestingUtil.dumpCacheContents(caches);
// use exists instead of get() to prevent going up the interceptor stack
assertTrue("Should be false", !caches.get(0).exists(fqn));
assertTrue("Should be false", !caches.get(1).exists(fqn));
assertTrue("Value be true", caches.get(0).exists(backupFqn));
assertFalse("Should be false", caches.get(1).exists(backupFqn));
assertFalse("Should be false", caches.get(2).exists(backupFqn));
Address cache2Addr = caches.get(2).getLocalAddress();
// forcefully kill data owner.
caches.get(2).stop();
caches.get(2).destroy();
TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
waitForSingleBuddy(caches.get(0), caches.get(1));
// TestingUtil.dumpCacheContents(cachePool);
// assert that the remaining cachePool have picked new buddies. Cache 1 should have cache 2's backup data.
assert caches.get(0).peek(fqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
assert caches.get(1).peek(fqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have self as a backup root.";
assert caches.get(0).peek(fqnTransformer.getBackupRoot(cache2Addr), false) == null : "Should not have dead node as a backup root.";
assert caches.get(0).peek(Fqn.fromRelativeElements(fqnTransformer.getDeadBackupRoot(cache2Addr), 1), false) != null : "Should have dead node as a defunct backup root.";
assert caches.get(1).peek(fqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have self as a backup root.";
assert caches.get(1).peek(fqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
assert caches.get(1).peek(fqnTransformer.getBackupRoot(cache2Addr), false) == null : "Should not have dead node as a backup root.";
assert caches.get(1).peek(Fqn.fromRelativeElements(fqnTransformer.getDeadBackupRoot(cache2Addr), 1), false) == null : "Should not have dead node as a defunct backup root.";
replListener0.expect(DataGravitationCleanupCommand.class);
// 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(1).get(fqn, key));
replListener0.waitForReplicationToOccur();
// use exists instead of get() to prevent going up the interceptor stack
assert caches.get(0).peek(fqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
assert caches.get(0).peek(fqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have self as a backup root.";
assert caches.get(0).peek(fqnTransformer.getBackupRoot(cache2Addr), false) == null : "Should not have dead node as a backup root.";