String tmpLocation = System.getProperty("java.io.tmpdir", "/tmp");
tmpLocation = tmpLocation + File.separator + "JBossCacheBRWithCacheLoaderTest";
try
{
TreeCache cache0 = createCacheWithCacheLoader(tmpLocation + File.separator + "0", true, true, passivation, true, false);
configureEviction(cache0);
TreeCache cache1 = createCacheWithCacheLoader(tmpLocation + File.separator + "1", true, true, passivation, true, false);
configureEviction(cache1);
TreeCache cache2 = createCacheWithCacheLoader(tmpLocation + File.separator + "2", true, true, passivation, true, false);
configureEviction(cache2);
caches = new TreeCache[3];
caches[0] = cache0;
caches[1] = cache1;
caches[2] = cache2;
cache0.start();
cache1.start();
cache2.start();
TestingUtil.blockUntilViewsReceived(caches, 600000);
TestingUtil.sleepThread(getSleepTimeout());
assertTrue("Cache1 should be cache0's buddy!", cache0.getBuddyManager().getBuddyAddresses().contains(cache1.getLocalAddress()));
Fqn foo = Fqn.fromString("/foo");
Fqn backupFoo = BuddyManager.getBackupFqn(cache0.getLocalAddress(), foo);
cache0.put(foo, "key", "value");
// test that the data exists in both the data owner and the buddy
assertTrue("Data should exist in data owner", cache0.exists(foo));
assertTrue("Buddy should have data", cache1.exists(backupFoo));
// Sleep long enough for eviction to run twice plus a bit
TestingUtil.sleepThread(3050);
// test that the data we're looking for has been evicted in both the data owner and the buddy.
assertFalse("Data should have evicted in data owner", cache0.exists(foo));
assertFalse("Buddy should have data evicted", cache1.exists(backupFoo));
// now test that this exists in both loaders.
assertNotNull("Should exist in data owner's loader", cache0.getCacheLoader().get(foo));
assertNotNull("Should exist in buddy's loader", cache1.getCacheLoader().get(backupFoo));
// doing a get on cache2 will guarantee a remote data gravitation.
assertEquals("Passivated value available from buddy", "value", cache2.get(foo, "key"));
}
finally
{
cleanup(caches);
TestingUtil.recursiveRemove(new File(tmpLocation));