use of org.apache.geode.internal.cache.partitioned.fixed.FixedPartitioningTestBase.Months_Accessor in project geode by apache.
the class PartitionRegionHelperDUnitTest method testAssignBucketsToPartitions_FPR.
@Test
public void testAssignBucketsToPartitions_FPR() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
SerializableRunnable createPrRegion1 = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Q1", true, 3);
FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("Q2", false, 3);
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.addFixedPartitionAttributes(fpa1);
paf.addFixedPartitionAttributes(fpa2);
paf.setPartitionResolver(new QuarterPartitionResolver());
paf.setRedundantCopies(1);
paf.setTotalNumBuckets(12);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion("region1", attr.create());
}
};
vm0.invoke(createPrRegion1);
SerializableRunnable createPrRegion2 = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Q2", true, 3);
FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("Q3", false, 3);
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.addFixedPartitionAttributes(fpa1);
paf.addFixedPartitionAttributes(fpa2);
paf.setPartitionResolver(new QuarterPartitionResolver());
paf.setRedundantCopies(1);
paf.setTotalNumBuckets(12);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion("region1", attr.create());
}
};
vm1.invoke(createPrRegion2);
SerializableRunnable createPrRegion3 = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Q3", true, 3);
FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("Q1", false, 3);
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.addFixedPartitionAttributes(fpa1);
paf.addFixedPartitionAttributes(fpa2);
paf.setPartitionResolver(new QuarterPartitionResolver());
paf.setRedundantCopies(1);
paf.setTotalNumBuckets(12);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion("region1", attr.create());
}
};
vm2.invoke(createPrRegion3);
SerializableRunnable assignBuckets = new SerializableRunnable("assign partitions") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
PartitionRegionHelper.assignBucketsToPartitions(region);
}
};
AsyncInvocation future1 = vm0.invokeAsync(assignBuckets);
AsyncInvocation future2 = vm1.invokeAsync(assignBuckets);
AsyncInvocation future3 = vm2.invokeAsync(assignBuckets);
future1.join();
future2.join();
future3.join();
if (future1.exceptionOccurred())
throw future1.getException();
if (future2.exceptionOccurred())
throw future2.getException();
if (future3.exceptionOccurred())
throw future3.getException();
SerializableRunnable checkAssignment = new SerializableRunnable("check assignment") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
PartitionRegionInfo info = PartitionRegionHelper.getPartitionRegionInfo(region);
assertEquals(9, info.getCreatedBucketCount());
assertEquals(0, info.getLowRedundancyBucketCount());
for (PartitionMemberInfo member : info.getPartitionMemberInfo()) {
assertEquals(6, member.getBucketCount());
}
}
};
vm0.invoke(checkAssignment);
SerializableRunnable createPrRegion4 = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setPartitionResolver(new QuarterPartitionResolver());
paf.setLocalMaxMemory(0);
paf.setRedundantCopies(1);
paf.setTotalNumBuckets(12);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
Region region = cache.createRegion("region1", attr.create());
for (Months_Accessor month : Months_Accessor.values()) {
String dateString = 10 + "-" + month + "-" + "2009";
String DATE_FORMAT = "dd-MMM-yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
Date date = null;
try {
date = sdf.parse(dateString);
} catch (ParseException e) {
Assert.fail("Exception Occurred while parseing date", e);
}
String value = month.toString() + 10;
region.put(date, value);
}
}
};
vm3.invoke(createPrRegion4);
SerializableRunnable checkMembers = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
for (Months_Accessor month : Months_Accessor.values()) {
String dateString = 10 + "-" + month + "-" + "2009";
String DATE_FORMAT = "dd-MMM-yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
Date date = null;
try {
date = sdf.parse(dateString);
} catch (ParseException e) {
Assert.fail("Exception Occurred while parseing date", e);
}
DistributedMember key1Pri = PartitionRegionHelper.getPrimaryMemberForKey(region, date);
assertNotNull(key1Pri);
Set<DistributedMember> buk0AllMems = PartitionRegionHelper.getAllMembersForKey(region, date);
assertEquals(2, buk0AllMems.size());
Set<DistributedMember> buk0RedundantMems = PartitionRegionHelper.getRedundantMembersForKey(region, date);
assertEquals(1, buk0RedundantMems.size());
}
}
};
vm3.invoke(checkMembers);
}
Aggregations