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();
}
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;
}
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;
}
});
}
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);
}
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();
}
Aggregations