use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testRebalanceWithOfflineChildRegionTwoDiskStores.
// GEODE-1380: time sensitive, async actions with 30 sec max
@Category(FlakyTest.class)
@Test
public void testRebalanceWithOfflineChildRegionTwoDiskStores() throws Throwable {
SerializableRunnable createParentPR = 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();
paf.setRedundantCopies(0);
paf.setRecoveryDelay(0);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_REGION_NAME, af.create());
}
};
SerializableRunnable createChildPR = new SerializableRunnable() {
public void run() {
Cache cache = getCache();
DiskStore ds2 = cache.findDiskStore("disk2");
if (ds2 == null) {
ds2 = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk2");
}
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(0);
paf.setRecoveryDelay(0);
paf.setColocatedWith(PR_REGION_NAME);
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk2");
af.setPartitionAttributes(paf.create());
cache.createRegion("region2", af.create());
}
};
rebalanceWithOfflineChildRegion(createParentPR, createChildPR);
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testColocatedPRsRecoveryOneMemberLater.
@Test
public void testColocatedPRsRecoveryOneMemberLater() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
SerializableRunnable createParentPR = new SerializableRunnable("createParentPR") {
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(1);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_REGION_NAME, af.create());
}
};
SerializableRunnable createChildPR = getCreateChildPRRunnable();
vm0.invoke(createParentPR);
vm1.invoke(createParentPR);
vm2.invoke(createParentPR);
vm0.invoke(createChildPR);
vm1.invoke(createChildPR);
vm2.invoke(createChildPR);
createData(vm0, 0, NUM_BUCKETS, "a");
createData(vm0, 0, NUM_BUCKETS, "b", "region2");
Set<Integer> vm0Buckets = getBucketList(vm0, PR_REGION_NAME);
assertEquals(vm0Buckets, getBucketList(vm0, "region2"));
Set<Integer> vm1Buckets = getBucketList(vm1, PR_REGION_NAME);
assertEquals(vm1Buckets, getBucketList(vm1, "region2"));
Set<Integer> vm2Buckets = getBucketList(vm2, PR_REGION_NAME);
assertEquals(vm2Buckets, getBucketList(vm2, "region2"));
Set<Integer> vm0PrimaryBuckets = getPrimaryBucketList(vm0, PR_REGION_NAME);
assertEquals(vm0PrimaryBuckets, getPrimaryBucketList(vm0, "region2"));
Set<Integer> vm1PrimaryBuckets = getPrimaryBucketList(vm1, PR_REGION_NAME);
assertEquals(vm1PrimaryBuckets, getPrimaryBucketList(vm1, "region2"));
Set<Integer> vm2PrimaryBuckets = getPrimaryBucketList(vm2, PR_REGION_NAME);
assertEquals(vm2PrimaryBuckets, getPrimaryBucketList(vm2, "region2"));
closeCache(vm2);
// Make sure the other members notice that vm2 has gone
// TODO use a callback for this.
Thread.sleep(4000);
closeCache(vm0);
closeCache(vm1);
// Create the members, but don't initialize
// VM2 yet
AsyncInvocation async0 = vm0.invokeAsync(createParentPR);
AsyncInvocation async1 = vm1.invokeAsync(createParentPR);
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
vm0.invoke(createChildPR);
vm1.invoke(createChildPR);
waitForBucketRecovery(vm0, vm0Buckets);
waitForBucketRecovery(vm1, vm1Buckets);
checkData(vm0, 0, NUM_BUCKETS, "a");
// region 2 didn't have persistent data, so it nothing should be recovered
checkData(vm0, 0, NUM_BUCKETS, null, "region2");
// Make sure can do a put in all of the buckets in vm2
createData(vm0, 0, NUM_BUCKETS, "c", "region2");
// Now all of those buckets should exist
checkData(vm0, 0, NUM_BUCKETS, "c", "region2");
// Now we initialize vm2.
vm2.invoke(createParentPR);
// Make sure vm2 hasn't created any buckets in the parent PR yet
// We don't want any buckets until the child PR is created
assertEquals(Collections.emptySet(), getBucketList(vm2, PR_REGION_NAME));
vm2.invoke(createChildPR);
// Now vm2 should have created all of the appropriate buckets.
assertEquals(vm2Buckets, getBucketList(vm2, PR_REGION_NAME));
assertEquals(vm2Buckets, getBucketList(vm2, "region2"));
vm0PrimaryBuckets = getPrimaryBucketList(vm0, PR_REGION_NAME);
assertEquals(vm0PrimaryBuckets, getPrimaryBucketList(vm0, "region2"));
vm1PrimaryBuckets = getPrimaryBucketList(vm1, PR_REGION_NAME);
assertEquals(vm1PrimaryBuckets, getPrimaryBucketList(vm1, "region2"));
vm2PrimaryBuckets = getPrimaryBucketList(vm2, PR_REGION_NAME);
assertEquals(vm2PrimaryBuckets, getPrimaryBucketList(vm2, "region2"));
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testReplaceOfflineMemberAndRestartCreateColocatedPRLate.
@Test
public void testReplaceOfflineMemberAndRestartCreateColocatedPRLate() throws Throwable {
SerializableRunnable createParentPR = 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();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(0);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_REGION_NAME, af.create());
}
};
SerializableRunnable createChildPR = new SerializableRunnable() {
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().contains("region2")) {
recoveryDone.countDown();
}
}
};
InternalResourceManager.setResourceObserver(observer);
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(0);
paf.setColocatedWith(PR_REGION_NAME);
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
af.setPartitionAttributes(paf.create());
cache.createRegion("region2", af.create());
try {
if (!recoveryDone.await(MAX_WAIT, TimeUnit.MILLISECONDS)) {
fail("timed out");
}
} catch (InterruptedException e) {
Assert.fail("interrupted", e);
}
}
};
replaceOfflineMemberAndRestartCreateColocatedPRLate(createParentPR, createChildPR);
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class UpdatePropagationPRDUnitTest method createCacheServerAttributes.
@Override
protected RegionAttributes createCacheServerAttributes() {
AttributesFactory factory = new AttributesFactory();
factory.setPartitionAttributes((new PartitionAttributesFactory()).create());
return factory.create();
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class QueryDataDUnitTest method testRegionsLocalDataSet.
@Test
public void testRegionsLocalDataSet() throws Exception {
String partitionedRegionName = this.testName.getMethodName() + "_PARTITIONED_REGION";
String[] values1 = new String[] { "val1", "val2", "val3" };
String[] values2 = new String[] { "val4", "val5", "val6" };
this.memberVMs[0].invoke(this.testName.getMethodName() + " Create Region", () -> {
PartitionAttributesFactory partitionAttributesFactory = new PartitionAttributesFactory();
partitionAttributesFactory.setRedundantCopies(2).setTotalNumBuckets(12);
List<FixedPartitionAttributes> fixedPartitionAttributesList = createFixedPartitionList(1);
for (FixedPartitionAttributes fixedPartitionAttributes : fixedPartitionAttributesList) {
partitionAttributesFactory.addFixedPartitionAttributes(fixedPartitionAttributes);
}
partitionAttributesFactory.setPartitionResolver(new SingleHopQuarterPartitionResolver());
RegionFactory regionFactory = this.managementTestRule.getCache().createRegionFactory(RegionShortcut.PARTITION).setPartitionAttributes(partitionAttributesFactory.create());
Region region = regionFactory.create(partitionedRegionName);
for (int i = 0; i < values1.length; i++) {
region.put(getDate(2013, 1, i + 5), values1[i]);
}
});
this.memberVMs[1].invoke(this.testName.getMethodName() + " Create Region", () -> {
PartitionAttributesFactory partitionAttributesFactory = new PartitionAttributesFactory();
partitionAttributesFactory.setRedundantCopies(2).setTotalNumBuckets(12);
List<FixedPartitionAttributes> fixedPartitionAttributesList = createFixedPartitionList(2);
for (FixedPartitionAttributes fixedPartitionAttributes : fixedPartitionAttributesList) {
partitionAttributesFactory.addFixedPartitionAttributes(fixedPartitionAttributes);
}
partitionAttributesFactory.setPartitionResolver(new SingleHopQuarterPartitionResolver());
RegionFactory regionFactory = this.managementTestRule.getCache().createRegionFactory(RegionShortcut.PARTITION).setPartitionAttributes(partitionAttributesFactory.create());
Region region = regionFactory.create(partitionedRegionName);
for (int i = 0; i < values2.length; i++) {
region.put(getDate(2013, 5, i + 5), values2[i]);
}
});
this.memberVMs[2].invoke(this.testName.getMethodName() + " Create Region", () -> {
PartitionAttributesFactory partitionAttributesFactory = new PartitionAttributesFactory();
partitionAttributesFactory.setRedundantCopies(2).setTotalNumBuckets(12);
List<FixedPartitionAttributes> fixedPartitionAttributesList = createFixedPartitionList(3);
fixedPartitionAttributesList.forEach(partitionAttributesFactory::addFixedPartitionAttributes);
partitionAttributesFactory.setPartitionResolver(new SingleHopQuarterPartitionResolver());
RegionFactory regionFactory = this.managementTestRule.getCache().createRegionFactory(RegionShortcut.PARTITION).setPartitionAttributes(partitionAttributesFactory.create());
regionFactory.create(partitionedRegionName);
});
List<String> member1RealData = this.memberVMs[0].invoke(() -> getLocalDataSet(partitionedRegionName));
List<String> member2RealData = this.memberVMs[1].invoke(() -> getLocalDataSet(partitionedRegionName));
List<String> member3RealData = this.memberVMs[2].invoke(() -> getLocalDataSet(partitionedRegionName));
this.managerVM.invoke(this.testName.getMethodName(), () -> {
DistributedSystemMXBean distributedSystemMXBean = this.managementTestRule.getSystemManagementService().getDistributedSystemMXBean();
DistributedRegionMXBean distributedRegionMXBean = awaitDistributedRegionMXBean("/" + partitionedRegionName, 3);
String alias = "Waiting for all entries to get reflected at managing node";
int expectedEntryCount = values1.length + values2.length;
await(alias).until(() -> assertThat(distributedRegionMXBean.getSystemRegionEntryCount()).isEqualTo(expectedEntryCount));
String query = "Select * from /" + partitionedRegionName;
String member1Result = distributedSystemMXBean.queryData(query, member1.getId(), 0);
verifyJsonIsValid(member1Result);
String member2Result = distributedSystemMXBean.queryData(query, member2.getId(), 0);
verifyJsonIsValid(member2Result);
String member3Result = distributedSystemMXBean.queryData(query, member3.getId(), 0);
verifyJsonIsValid(member3Result);
for (String val : member1RealData) {
assertThat(member1Result).contains(val);
}
for (String val : member2RealData) {
assertThat(member2Result).contains(val);
}
assertThat(member3Result).contains("No Data Found");
});
}
Aggregations