use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class PartitionedRegionLoaderWriterDUnitTest method createRegionWithPossibleFail.
public static void createRegionWithPossibleFail(CacheLoader cacheLoader, CacheWriter cacheWriter, Integer localMaxMemory) {
final PartitionedRegionLoaderWriterDUnitTest test = new PartitionedRegionLoaderWriterDUnitTest();
test.createCache(new Properties());
// add expected exception
test.cache.getLogger().info("<ExpectedException action=add>" + IllegalStateException.class.getName() + "</ExpectedException>");
try {
AttributesFactory factory = new AttributesFactory();
factory.setCacheLoader(cacheLoader);
factory.setCacheWriter(cacheWriter);
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setLocalMaxMemory(localMaxMemory.intValue());
factory.setDataPolicy(DataPolicy.PARTITION);
factory.setPartitionAttributes(paf.create());
RegionAttributes attrs = factory.create();
cache.createRegion(PartitionedRegionName, attrs);
fail("Expected Exception ");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().startsWith("Incompatible"));
}
test.cache.getLogger().info("<ExpectedException action=remove>" + IllegalStateException.class.getName() + "</ExpectedException>");
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method createColocatedPRs.
/**
* Create three PRs on a VM, named region1, region2, and region3. The colocated with attribute
* describes which region region3 should be colocated with.
*
* @param colocatedWith
*/
private void createColocatedPRs(final String colocatedWith) {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(0);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion("region1", af.create());
cache.createRegion("region2", af.create());
if (colocatedWith != null) {
paf.setColocatedWith(colocatedWith);
}
af.setPartitionAttributes(paf.create());
cache.createRegion("region3", af.create());
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method getCreateChildPRRunnable.
private SerializableRunnable getCreateChildPRRunnable() {
return new SerializableRunnable("createChildPR") {
public void run() {
Cache cache = getCache();
final CountDownLatch recoveryDone = new CountDownLatch(1);
ResourceObserver observer = new InternalResourceManager.ResourceObserverAdapter() {
@Override
public void recoveryFinished(Region region) {
if (region.getName().equals("region2")) {
recoveryDone.countDown();
}
}
};
InternalResourceManager.setResourceObserver(observer);
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setColocatedWith(PR_REGION_NAME);
af.setPartitionAttributes(paf.create());
cache.createRegion("region2", af.create());
try {
recoveryDone.await(MAX_WAIT, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Assert.fail("interrupted", e);
}
}
};
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testColocatedPRs.
/**
* Testing that we can colocate persistent PRs
*/
@Test
public void testColocatedPRs() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
SerializableRunnable createPRs = new SerializableRunnable("region1") {
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(0);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_REGION_NAME, af.create());
paf.setColocatedWith(PR_REGION_NAME);
af.setPartitionAttributes(paf.create());
cache.createRegion("region2", af.create());
paf.setColocatedWith("region2");
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PARTITION);
af.setDiskStoreName(null);
cache.createRegion("region3", af.create());
}
};
vm0.invoke(createPRs);
vm1.invoke(createPRs);
vm2.invoke(createPRs);
createData(vm0, 0, NUM_BUCKETS, "a");
createData(vm0, 0, NUM_BUCKETS, "b", "region2");
createData(vm0, 0, NUM_BUCKETS, "c", "region3");
Set<Integer> vm0Buckets = getBucketList(vm0, PR_REGION_NAME);
assertEquals(vm0Buckets, getBucketList(vm0, "region2"));
assertEquals(vm0Buckets, getBucketList(vm0, "region3"));
Set<Integer> vm1Buckets = getBucketList(vm1, PR_REGION_NAME);
assertEquals(vm1Buckets, getBucketList(vm1, "region2"));
assertEquals(vm1Buckets, getBucketList(vm1, "region3"));
Set<Integer> vm2Buckets = getBucketList(vm2, PR_REGION_NAME);
assertEquals(vm2Buckets, getBucketList(vm2, "region2"));
assertEquals(vm2Buckets, getBucketList(vm2, "region3"));
closeCache(vm0);
closeCache(vm1);
closeCache(vm2);
AsyncInvocation async0 = vm0.invokeAsync(createPRs);
AsyncInvocation async1 = vm1.invokeAsync(createPRs);
AsyncInvocation async2 = vm2.invokeAsync(createPRs);
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
async2.getResult(MAX_WAIT);
// The secondary buckets can be recovered asynchronously,
// so wait for them to come back.
waitForBuckets(vm0, vm0Buckets, PR_REGION_NAME);
waitForBuckets(vm0, vm0Buckets, "region2");
waitForBuckets(vm1, vm1Buckets, PR_REGION_NAME);
waitForBuckets(vm1, vm1Buckets, "region2");
checkData(vm0, 0, NUM_BUCKETS, "a");
checkData(vm0, 0, NUM_BUCKETS, "b", "region2");
// region 3 didn't have persistent data, so it nothing should be recovered
checkData(vm0, 0, NUM_BUCKETS, null, "region3");
// Make sure can do a put in all of the buckets in region 3
createData(vm0, 0, NUM_BUCKETS, "c", "region3");
// Now all of those buckets should exist.
checkData(vm0, 0, NUM_BUCKETS, "c", "region3");
// The region 3 buckets should be restored in the appropriate places.
assertEquals(vm0Buckets, getBucketList(vm0, "region3"));
assertEquals(vm1Buckets, getBucketList(vm1, "region3"));
assertEquals(vm2Buckets, getBucketList(vm2, "region3"));
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testSinglePRWithCustomExpiry.
/**
* Test for bug 44184
*/
@Test
public void testSinglePRWithCustomExpiry() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(1);
SerializableRunnable createPR = new SerializableRunnable() {
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
af.setPartitionAttributes(paf.create());
af.setCustomEntryIdleTimeout(new TestCustomExpiration());
af.setEntryIdleTimeout(new ExpirationAttributes(60, ExpirationAction.INVALIDATE));
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
RegionAttributes attr = af.create();
cache.createRegion(PR_REGION_NAME, attr);
}
};
vm0.invoke(createPR);
createData(vm0, 0, 1, "a");
Set<Integer> vm0Buckets = getBucketList(vm0);
// closePR(vm0);
closeCache(vm0);
vm0.invoke(createPR);
assertEquals(vm0Buckets, getBucketList(vm0));
checkData(vm0, 0, 1, "a");
}
Aggregations