Search in sources :

Example 1 with TestCacheLoader

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));
}
Also used : LoaderHelper(org.apache.geode.cache.LoaderHelper) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) RegionFactory(org.apache.geode.cache.RegionFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Host(org.apache.geode.test.dunit.Host) TestCacheLoader(org.apache.geode.cache30.TestCacheLoader) CacheLoader(org.apache.geode.cache.CacheLoader) TestCacheLoader(org.apache.geode.cache30.TestCacheLoader) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

CacheLoader (org.apache.geode.cache.CacheLoader)1 LoaderHelper (org.apache.geode.cache.LoaderHelper)1 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)1 Region (org.apache.geode.cache.Region)1 RegionFactory (org.apache.geode.cache.RegionFactory)1 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)1 TestCacheLoader (org.apache.geode.cache30.TestCacheLoader)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 Host (org.apache.geode.test.dunit.Host)1 VM (org.apache.geode.test.dunit.VM)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 Test (org.junit.Test)1