use of org.apache.geode.cache30.TestCacheLoader in project geode by apache.
the class PartitionedRegionAPIDUnitTest method testCacherLoaderHelper.
@Test
public void testCacherLoaderHelper() throws Exception {
final String rName = getUniqueName();
Host host = Host.getHost(0);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
final int localMaxMemory = 10;
final String key1 = "key1";
final String arg = "loaderArg";
CacheSerializableRunnable createLoaderPR = new CacheSerializableRunnable("createLoaderPR") {
public void run2() throws CacheException {
getCache();
CacheLoader cl = new TestCacheLoader() {
public Object load2(LoaderHelper helper) throws CacheLoaderException {
assertNotNull(helper);
assertEquals(key1, helper.getKey());
assertEquals(rName, helper.getRegion().getName());
assertEquals(arg, helper.getArgument());
return helper.getArgument();
}
};
PartitionedRegion pr = (PartitionedRegion) new RegionFactory().setCacheLoader(cl).setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(1).setLocalMaxMemory(localMaxMemory).create()).create(rName);
assertSame(cl, pr.getDataStore().getCacheLoader());
}
};
vm2.invoke(createLoaderPR);
vm3.invoke(createLoaderPR);
// create a "pure" accessor, no data storage
getCache();
Region pr = new RegionFactory().setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(1).setLocalMaxMemory(0).create()).create(rName);
assertEquals(arg, pr.get(key1, arg));
}
Aggregations