Search in sources :

Example 46 with PartitionAttributes

use of org.apache.geode.cache.PartitionAttributes 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 47 with PartitionAttributes

use of org.apache.geode.cache.PartitionAttributes 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 48 with PartitionAttributes

use of org.apache.geode.cache.PartitionAttributes 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 49 with PartitionAttributes

use of org.apache.geode.cache.PartitionAttributes 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 50 with PartitionAttributes

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

the class PartitionedRegionHADUnitTest method createRegionAttributesForPR.

/**
   * 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)

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