use of org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver in project geode by apache.
the class CacheXml66DUnitTest method testFixedPartitioning.
/**
* Tests that a partitioned region is created with FixedPartitionAttributes set programatically
* and correct cache.xml is generated with the same FixedPartitionAttributes
*/
@Test
public void testFixedPartitioning() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation();
FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Q1");
FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("Q2", true);
FixedPartitionAttributes fpa3 = FixedPartitionAttributes.createFixedPartition("Q3", 3);
FixedPartitionAttributes fpa4 = FixedPartitionAttributes.createFixedPartition("Q4", false, 3);
List<FixedPartitionAttributes> fpattrsList = new ArrayList<FixedPartitionAttributes>();
fpattrsList.add(fpa1);
fpattrsList.add(fpa2);
fpattrsList.add(fpa3);
fpattrsList.add(fpa4);
QuarterPartitionResolver resolver = new QuarterPartitionResolver();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1).setPartitionResolver(resolver).addFixedPartitionAttributes(fpa1).addFixedPartitionAttributes(fpa2).addFixedPartitionAttributes(fpa3).addFixedPartitionAttributes(fpa4);
attrs.setPartitionAttributes(paf.create());
cache.createRegion("Quarter", attrs);
Region r = cache.getRegion("Quarter");
validateAttributes(r, fpattrsList, resolver, false);
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region region = c.getRegion("Quarter");
assertNotNull(region);
validateAttributes(region, fpattrsList, resolver, false);
}
use of org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver in project geode by apache.
the class CacheXml66DUnitTest method testFixedPartitioning_colocation_WithAttributes.
@Test
public void testFixedPartitioning_colocation_WithAttributes() throws Exception {
CacheCreation cache = new CacheCreation();
FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Q1");
FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("Q2", true);
FixedPartitionAttributes fpa3 = FixedPartitionAttributes.createFixedPartition("Q3", 3);
FixedPartitionAttributes fpa4 = FixedPartitionAttributes.createFixedPartition("Q4", false, 3);
List<FixedPartitionAttributes> fpattrsList = new ArrayList<FixedPartitionAttributes>();
fpattrsList.add(fpa1);
fpattrsList.add(fpa2);
fpattrsList.add(fpa3);
fpattrsList.add(fpa4);
QuarterPartitionResolver resolver = new QuarterPartitionResolver();
Region customerRegion = null;
Region orderRegion = null;
{
RegionAttributesCreation attrs = new RegionAttributesCreation();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1).setPartitionResolver(resolver).addFixedPartitionAttributes(fpa1).addFixedPartitionAttributes(fpa2).addFixedPartitionAttributes(fpa3).addFixedPartitionAttributes(fpa4);
attrs.setPartitionAttributes(paf.create());
cache.createRegion("Customer", attrs);
}
customerRegion = cache.getRegion("Customer");
validateAttributes(customerRegion, fpattrsList, resolver, false);
try {
RegionAttributesCreation attrs = new RegionAttributesCreation();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1).setPartitionResolver(resolver).addFixedPartitionAttributes(fpa1).addFixedPartitionAttributes(fpa2).addFixedPartitionAttributes(fpa3).addFixedPartitionAttributes(fpa4).setColocatedWith("Customer");
attrs.setPartitionAttributes(paf.create());
cache.createRegion("Order", attrs);
orderRegion = cache.getRegion("Order");
validateAttributes(orderRegion, fpattrsList, resolver, true);
} catch (Exception illegal) {
// TODO: clean this expected exception up
if (!((illegal instanceof IllegalStateException) && (illegal.getMessage().contains("can not be specified in PartitionAttributesFactory")))) {
Assert.fail("Expected IllegalStateException ", illegal);
}
RegionAttributesCreation attrs = new RegionAttributesCreation();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1).setPartitionResolver(resolver).setColocatedWith("Customer");
attrs.setPartitionAttributes(paf.create());
cache.createRegion("Order", attrs);
orderRegion = cache.getRegion("Order");
validateAttributes(orderRegion, fpattrsList, resolver, true);
}
testXml(cache);
Cache c = getCache();
assertNotNull(c);
customerRegion = c.getRegion("Customer");
assertNotNull(customerRegion);
validateAttributes(customerRegion, fpattrsList, resolver, false);
orderRegion = c.getRegion("Order");
assertNotNull(orderRegion);
validateAttributes(orderRegion, fpattrsList, resolver, true);
}
use of org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver 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);
}
use of org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver in project geode by apache.
the class FixedPRSinglehopDUnitTest method createServerWithLocator.
public static int createServerWithLocator(String locator, boolean isAccessor, List<FixedPartitionAttributes> fpaList, boolean simpleFPR) {
FixedPRSinglehopDUnitTest test = new FixedPRSinglehopDUnitTest();
Properties props = new Properties();
props = new Properties();
props.setProperty(LOCATORS, locator);
DistributedSystem ds = test.getSystem(props);
cache = new CacheFactory(props).create(ds);
CacheServer server = cache.addCacheServer();
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
server.setPort(port);
server.setHostnameForClients("localhost");
try {
server.start();
} catch (IOException e) {
Assert.fail("Failed to start server ", e);
}
if (!fpaList.isEmpty() || isAccessor) {
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1).setTotalNumBuckets(12);
if (isAccessor) {
paf.setLocalMaxMemory(0);
}
for (FixedPartitionAttributes fpa : fpaList) {
paf.addFixedPartitionAttributes(fpa);
}
// paf.setPartitionResolver(new SingleHopQuarterPartitionResolver());
paf.setPartitionResolver(new QuarterPartitionResolver());
AttributesFactory attr = new AttributesFactory();
attr.setPartitionAttributes(paf.create());
region = cache.createRegion(PR_NAME, attr.create());
assertNotNull(region);
LogWriterUtils.getLogWriter().info("Partitioned Region " + PR_NAME + " created Successfully :" + region.toString());
}
return port;
}
Aggregations