Search in sources :

Example 81 with PartitionAttributes

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

the class PartitionedRegionDestroyDUnitTest method createRegionAttrsForPR.

protected RegionAttributes createRegionAttrsForPR(int red, int localMaxMem) {
    AttributesFactory attr = new AttributesFactory();
    attr.setDataPolicy(DataPolicy.PARTITION);
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    PartitionAttributes prAttr = paf.setRedundantCopies(red).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 82 with PartitionAttributes

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

the class Bug39356DUnitTest method testMoveBucketToHostThatHasTheBucketAlready.

/**
   * A test to make sure that we cannot move a bucket to a member which already hosts the bucket,
   * thereby reducing our redundancy.
   */
@Test
public void testMoveBucketToHostThatHasTheBucketAlready() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {

        public void run() {
            Cache cache = getCache();
            AttributesFactory attr = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            paf.setRecoveryDelay(-1);
            paf.setStartupRecoveryDelay(-1);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            cache.createRegion("region1", attr.create());
        }
    };
    vm0.invoke(createPrRegion);
    vm1.invoke(createPrRegion);
    // Create a bucket
    vm0.invoke(new SerializableRunnable("createSomeBuckets") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            region.put(Integer.valueOf(0), "A");
        }
    });
    final InternalDistributedMember vm1MemberId = (InternalDistributedMember) vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            return InternalDistributedSystem.getAnyInstance().getDistributedMember();
        }
    });
    // Move the bucket
    vm0.invoke(new SerializableRunnable("moveBucket") {

        public void run() {
            Cache cache = getCache();
            PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
            Set<InternalDistributedMember> owners = region.getRegionAdvisor().getBucketOwners(0);
            assertEquals(2, owners.size());
            PartitionedRegionDataStore ds = region.getDataStore();
            assertTrue(ds.isManagingBucket(0));
            // try to move the bucket from the other member to this one. This should
            // fail because we already have the bucket
            assertFalse(ds.moveBucket(0, vm1MemberId, true));
            assertEquals(owners, region.getRegionAdvisor().getBucketOwners(0));
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Host(org.apache.geode.test.dunit.Host) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 83 with PartitionAttributes

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

the class Bug42055DUnitTest method testPROverflow.

@Test
public void testPROverflow() throws Exception {
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    SerializableCallable createDataRegion = new SerializableCallable("createDataRegion") {

        public Object call() throws Exception {
            Cache cache = getCache();
            AttributesFactory attr = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
            Region region = cache.createRegion("region1", attr.create());
            return null;
        }
    };
    vm0.invoke(createDataRegion);
    SerializableRunnable createEmptyRegion = new SerializableRunnable("createEmptyRegion") {

        public void run() {
            Cache cache = getCache();
            AttributesFactory<Integer, TestDelta> attr = new AttributesFactory<Integer, TestDelta>();
            PartitionAttributesFactory<Integer, TestDelta> paf = new PartitionAttributesFactory<Integer, TestDelta>();
            paf.setLocalMaxMemory(0);
            PartitionAttributes<Integer, TestDelta> prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            attr.setDataPolicy(DataPolicy.PARTITION);
            attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
            Region<Integer, TestDelta> region = cache.createRegion("region1", attr.create());
        }
    };
    vm1.invoke(createEmptyRegion);
}
Also used : PartitionAttributes(org.apache.geode.cache.PartitionAttributes) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) 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) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 84 with PartitionAttributes

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

the class Bug40632DUnitTest method testLocalInvalidateTimeToLive.

@Test
public void testLocalInvalidateTimeToLive() throws Exception {
    Cache cache = getCache();
    AttributesFactory attr = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(1);
    paf.setRecoveryDelay(-1);
    paf.setStartupRecoveryDelay(-1);
    PartitionAttributes prAttr = paf.create();
    attr.setStatisticsEnabled(true);
    attr.setEntryTimeToLive(new ExpirationAttributes(1000, ExpirationAction.LOCAL_INVALIDATE));
    attr.setPartitionAttributes(prAttr);
    try {
        cache.createRegion("region1", attr.create());
        fail("We should not have been able to create the region");
    } catch (IllegalStateException expected) {
    }
}
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) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 85 with PartitionAttributes

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

the class Bug40632DUnitTest method testLocalDestroyIdleTimeout.

@Test
public void testLocalDestroyIdleTimeout() throws Exception {
    Cache cache = getCache();
    AttributesFactory attr = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(1);
    paf.setRecoveryDelay(-1);
    paf.setStartupRecoveryDelay(-1);
    PartitionAttributes prAttr = paf.create();
    attr.setStatisticsEnabled(true);
    attr.setEntryIdleTimeout(new ExpirationAttributes(1000, ExpirationAction.LOCAL_DESTROY));
    attr.setPartitionAttributes(prAttr);
    try {
        cache.createRegion("region1", attr.create());
        fail("We should not have been able to create the region");
    } catch (IllegalStateException expected) {
    }
}
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) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

PartitionAttributes (org.apache.geode.cache.PartitionAttributes)129 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)117 AttributesFactory (org.apache.geode.cache.AttributesFactory)107 Region (org.apache.geode.cache.Region)82 Test (org.junit.Test)67 Cache (org.apache.geode.cache.Cache)66 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)61 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)49 Host (org.apache.geode.test.dunit.Host)48 VM (org.apache.geode.test.dunit.VM)48 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)47 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)38 RegionAttributes (org.apache.geode.cache.RegionAttributes)28 CacheException (org.apache.geode.cache.CacheException)26 LocalRegion (org.apache.geode.internal.cache.LocalRegion)26 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)21 BucketRegion (org.apache.geode.internal.cache.BucketRegion)19 FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)18 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)16 HashSet (java.util.HashSet)15