Search in sources :

Example 31 with PartitionAttributesFactory

use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.

the class PartitionedRegionCacheCloseDUnitTest method createRegionAttributesForPR.

// protected static Region getBucket2Node(Region root, int prid)
// {
// Region ret = null;
// AttributesFactory factory = new AttributesFactory(root.getAttributes());
// factory.setDataPolicy(DataPolicy.REPLICATE);
// factory.setScope(Scope.DISTRIBUTED_ACK);
// RegionAttributes regionAttr = factory.create();
// try {
// ret = ((LocalRegion)root)
// .createSubregion(PartitionedRegionHelper.BUCKET_2_NODE_TABLE_PREFIX
// + prid, regionAttr, new InternalRegionArguments().setIsUsedForPartitionedRegionAdmin(true));
// }
// catch (RegionExistsException ree) {
// ret = root
// .getSubregion(PartitionedRegionHelper.BUCKET_2_NODE_TABLE_PREFIX
// + prid);
// }
// catch (IOException ieo) {
// fail("IOException creating bucket2node",ieo);
// } catch (ClassNotFoundException cne) {
// fail("ClassNotFoundExcpetion creating bucket2node ", cne);
// }
// return ret;
// }
/**
   * This private methods sets the passed attributes and returns RegionAttribute object, which is
   * used in create region
   * 
   * @param redundancy
   * @param localMaxMem
   * 
   * @return
   */
protected RegionAttributes createRegionAttributesForPR(int redundancy, int localMaxMem) {
    AttributesFactory attr = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    PartitionAttributes prAttr = paf.setRedundantCopies(redundancy).setLocalMaxMemory(localMaxMem).setTotalNumBuckets(totalNumBuckets).create();
    attr.setPartitionAttributes(prAttr);
    return attr.create();
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes)

Example 32 with PartitionAttributesFactory

use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.

the class PartitionedRegionCreationDUnitTest method getCacheSerializableRunnableForPRPersistence.

/**
   * this function creates partition region with the specified persistence and throws appropriate
   * exception
   */
public CacheSerializableRunnable getCacheSerializableRunnableForPRPersistence(final String regionName, final int localMaxMemory, final boolean isPersistent, final boolean expectException) {
    SerializableRunnable createPrRegion1;
    createPrRegion1 = new CacheSerializableRunnable(regionName) {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region partitionedregion = null;
            try {
                AttributesFactory attr = new AttributesFactory();
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                // 0: accessor
                paf.setLocalMaxMemory(localMaxMemory);
                PartitionAttributes prAttr = paf.create();
                attr.setPartitionAttributes(prAttr);
                if (isPersistent) {
                    attr.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
                } else {
                    attr.setDataPolicy(DataPolicy.PARTITION);
                }
                partitionedregion = cache.createRegion(regionName, attr.create());
                if (expectException) {
                    fail("Expect exception but it did not");
                }
                assertNotNull("Partitioned Region " + regionName + " not in cache", cache.getRegion(regionName));
                assertNotNull("Partitioned Region ref null", partitionedregion);
                assertTrue("Partitioned Region ref claims to be destroyed", !partitionedregion.isDestroyed());
            } catch (IllegalStateException ex) {
                if (localMaxMemory > 0) {
                    // datastore
                    assertTrue(ex.getMessage().contains("DataPolicy for Datastore members should all be persistent or not."));
                } else {
                    assertTrue(ex.getMessage().contains("Persistence is not allowed when local-max-memory is zero."));
                }
            }
        }
    };
    return (CacheSerializableRunnable) createPrRegion1;
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Example 33 with PartitionAttributesFactory

use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.

the class PartitionedRegionDelayedRecoveryDUnitTest method testStartupDelay.

// GEODE-757: time sensitive, fails because event occurs 2 millis too
@Category(FlakyTest.class)
// thread unsafe test hook
@Test
public void testStartupDelay() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    SerializableRunnable createPrRegions = new SerializableRunnable("createRegions") {

        public void run() {
            Cache cache = getCache();
            InternalResourceManager.setResourceObserver(new MyResourceObserver());
            AttributesFactory attr = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setStartupRecoveryDelay(5000);
            paf.setRedundantCopies(1);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            cache.createRegion("region1", attr.create());
        }
    };
    // create the region in 2 VMS
    vm0.invoke(createPrRegions);
    vm1.invoke(createPrRegions);
    // Do 1 put, which should create 1 bucket
    vm0.invoke(new SerializableRunnable("putData") {

        public void run() {
            Cache cache = getCache();
            PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
            region1.put(Integer.valueOf(1), "B");
            region1.put(Integer.valueOf(2), "B");
            region1.put(Integer.valueOf(3), "B");
            region1.put(Integer.valueOf(4), "B");
        }
    });
    // close 1 cache, which should make the bucket drop below
    // the expected redundancy level.
    vm1.invoke(new SerializableRunnable("close cache") {

        public void run() {
            Cache cache = getCache();
            cache.close();
        }
    });
    final long begin = System.currentTimeMillis();
    // create the region in a third VM, which won't have any buckets
    vm2.invoke(createPrRegions);
    long elapsed = System.currentTimeMillis() - begin;
    assertTrue("Create region should not have waited to recover redundancy. Elapsed=" + elapsed, elapsed < 5000);
    // wait for the bucket to be copied
    elapsed = waitForBucketRecovery(vm2, 4, begin);
    assertTrue("Did not wait at least 5 seconds to create the bucket. Elapsed=" + elapsed, elapsed >= 5000);
    vm2.invoke(new SerializableCallable("wait for primary move") {

        public Object call() throws Exception {
            Cache cache = getCache();
            MyResourceObserver observer = (MyResourceObserver) InternalResourceManager.getResourceObserver();
            observer.waitForRecovery(30, TimeUnit.SECONDS);
            PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
            assertEquals(2, region1.getDataStore().getNumberOfPrimaryBucketsManaged());
            return null;
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Host(org.apache.geode.test.dunit.Host) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 34 with PartitionAttributesFactory

use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.

the class PartitionedRegionDelayedRecoveryDUnitTest method testDelay.

// GEODE-860: time sensitive, thread unsafe test hook, CountDownLatch,
@Category(FlakyTest.class)
// InterruptedException
@Test
public void testDelay() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    SerializableRunnable createPrRegions = new SerializableRunnable("createRegions") {

        public void run() {
            final CountDownLatch rebalancingFinished = new CountDownLatch(1);
            InternalResourceManager.setResourceObserver(new ResourceObserverAdapter() {

                @Override
                public void rebalancingOrRecoveryFinished(Region region) {
                    rebalancingFinished.countDown();
                }
            });
            try {
                Cache cache = getCache();
                AttributesFactory attr = new AttributesFactory();
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                paf.setRecoveryDelay(5000);
                paf.setRedundantCopies(1);
                PartitionAttributes prAttr = paf.create();
                attr.setPartitionAttributes(prAttr);
                cache.createRegion("region1", attr.create());
                if (!rebalancingFinished.await(60000, TimeUnit.MILLISECONDS)) {
                    fail("Redundancy recovery did not happen within 60 seconds");
                }
            } catch (InterruptedException e) {
                Assert.fail("interrupted", e);
            } finally {
                InternalResourceManager.setResourceObserver(null);
            }
        }
    };
    // create the region in 2 VMS
    vm0.invoke(createPrRegions);
    vm1.invoke(createPrRegions);
    // Do 1 put, which should create 1 bucket
    vm0.invoke(new SerializableRunnable("putData") {

        public void run() {
            Cache cache = getCache();
            PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
            region1.put("A", "B");
        }
    });
    // create the region in a third VM, which won't have any buckets
    vm2.invoke(createPrRegions);
    final long begin = System.currentTimeMillis();
    // close 1 cache, which should make the bucket drop below
    // the expected redundancy level.
    vm1.invoke(new SerializableRunnable("close cache") {

        public void run() {
            Cache cache = getCache();
            cache.close();
        }
    });
    long elapsed = waitForBucketRecovery(vm2, 1, begin);
    assertTrue("Did not wait at least 5 seconds to create the bucket. Elapsed=" + elapsed, elapsed >= 5000);
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Host(org.apache.geode.test.dunit.Host) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceObserverAdapter(org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserverAdapter) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 35 with PartitionAttributesFactory

use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.

the class PartitionedRegionEvictionDUnitTest method testEvictionValidationForLRUMaximum.

// Test to validate the Eviction Attribute : LRU Maximum
@Test
public void testEvictionValidationForLRUMaximum() {
    final Host host = Host.getHost(0);
    final VM testDatastore = host.getVM(2);
    final VM firstDatastore = host.getVM(3);
    final String uniqName = getUniqueName();
    final int redundantCopies = 1;
    final int maxEntries = 226;
    final String name = uniqName + "-PR";
    final EvictionAttributes firstEvictionAttributes = EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.LOCAL_DESTROY);
    // Creating LRU Entry Count Eviction Attribute : maxentries : 2
    final SerializableRunnable create = new CacheSerializableRunnable("Create Entry LRU with local destroy on a partitioned Region") {

        public void run2() {
            final AttributesFactory factory = new AttributesFactory();
            factory.setOffHeap(isOffHeap());
            factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
            factory.setEvictionAttributes(firstEvictionAttributes);
            final Region pr = createRootRegion(name, factory.create());
            assertNotNull(pr);
            assertEquals(firstEvictionAttributes, pr.getAttributes().getEvictionAttributes());
        }
    };
    firstDatastore.invoke(create);
    final SerializableRunnable create2 = new SerializableRunnable("Create Entry LRU with Overflow to disk partitioned Region") {

        public void run() {
            final AttributesFactory factory = new AttributesFactory();
            factory.setOffHeap(isOffHeap());
            factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
            final EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(firstEvictionAttributes.getMaximum() + 10, firstEvictionAttributes.getAction());
            factory.setEvictionAttributes(ea);
            final Region pr = createRootRegion(name, factory.create());
            assertNotNull(pr);
        }
    };
    testDatastore.invoke(create2);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)340 AttributesFactory (org.apache.geode.cache.AttributesFactory)289 Region (org.apache.geode.cache.Region)173 Test (org.junit.Test)154 Cache (org.apache.geode.cache.Cache)136 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)116 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)112 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)110 VM (org.apache.geode.test.dunit.VM)101 Host (org.apache.geode.test.dunit.Host)99 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)95 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)75 CacheException (org.apache.geode.cache.CacheException)58 LocalRegion (org.apache.geode.internal.cache.LocalRegion)48 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)47 IOException (java.io.IOException)42 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)42 DiskStore (org.apache.geode.cache.DiskStore)41 RegionAttributes (org.apache.geode.cache.RegionAttributes)41 BucketRegion (org.apache.geode.internal.cache.BucketRegion)35