public void testPartialStateTransferWithLoader() throws Exception
{
log.info("Enter testPartialStateTransferWithLoader");
PojoCache cache1 = createCache("cache1", false, true, true);
cache1.activateRegion("/a");
cache1.putObject(A_B_1, joe);
cache1.putObject(A_B_2, jane);
PojoCache cache2 = createCache("cache2", false, true, true);
// Pause to give caches time to see each other
TestingUtil.blockUntilViewsReceived(new PojoCache[]
{cache1, cache2}, 60000);
CacheLoader loader = cache2.getCacheLoader();
Map map = loader.get(A_B_1);
if (map != null)
{
assertNull("/a/b/1 name not transferred per policy", map.get("name"));
assertNull("/a/b/1 age not transferred per policy", map.get("age"));
}
map = loader.get(A_B_2);
if (map != null)
{
assertNull("/a/b/1 name not transferred per policy", map.get("name"));
assertNull("/a/b/1 age not transferred per policy", map.get("age"));
}
assertNull("/a/b/1 not transferred per policy", cache2.getObject(A_B_1));
assertNull("/a/b/2 not transferred per policy", cache2.getObject(A_B_2));
cache2.activateRegion("/a/b");
assertEquals("Correct name from loader for /a/b/1", joe.getName(), loader.get(A_B_1).get("name"));
assertEquals("Correct age from loader for /a/b/1", TWENTY, loader.get(A_B_1).get("age"));
assertEquals("Correct name from loader for /a/b/2", jane.getName(), loader.get(A_B_2).get("name"));
assertEquals("Correct age from loader for /a/b/2", TWENTYFIVE, loader.get(A_B_2).get("age"));
Person ab1 = (Person) cache2.getObject(A_B_1);
Person ab2 = (Person) cache2.getObject(A_B_2);
assertEquals("Name for /a/b/1 is Joe", joe.getName(), ab1.getName());
assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab1.getAddress().getCity());
assertEquals("Name for /a/b/1 is Jane", jane.getName(), ab2.getName());
assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab2.getAddress().getCity());
assertTrue("Address for Joe and Jane is the same object", ab1.getAddress() == ab2.getAddress());
cache1.putObject(A_C_1, bob);
cache1.putObject(A_C_2, jill);
assertNull("/a/c/1 not transferred per policy", cache2.getObject(A_C_1));
cache2.activateRegion("/a/c");
assertEquals("Correct name from loader for /a/b/1", joe.getName(), loader.get(A_B_1).get("name"));
assertEquals("Correct age from loader for /a/b/1", TWENTY, loader.get(A_B_1).get("age"));
assertEquals("Correct name from loader for /a/b/2", jane.getName(), loader.get(A_B_2).get("name"));
assertEquals("Correct age from loader for /a/b/2", TWENTYFIVE, loader.get(A_B_2).get("age"));
assertEquals("Correct name from loader for /a/c/1", bob.getName(), loader.get(A_C_1).get("name"));
assertEquals("Correct age from loader for /a/c/1", FORTY, loader.get(A_C_1).get("age"));
assertEquals("Correct name from loader for /a/c/2", jill.getName(), loader.get(A_C_2).get("name"));
assertEquals("Correct age from loader for /a/c/2", TWENTYFIVE, loader.get(A_C_2).get("age"));
Person ac1 = (Person) cache2.getObject(A_C_1);
Person ac2 = (Person) cache2.getObject(A_C_2);
assertEquals("Name for /a/c/1 is Bob", bob.getName(), ac1.getName());
assertEquals("City for /a/c/1 is Fremont", addr2.getCity(), ac1.getAddress().getCity());
assertEquals("Name for /a/c/2 is Jill", jill.getName(), ac2.getName());
assertEquals("City for /a/c/2 is Fremont", addr2.getCity(), ac2.getAddress().getCity());
assertTrue("Bob and Jill have same Address", ac1.getAddress() == ac2.getAddress());