use of org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver 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");
});
}
use of org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver 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;
}
use of org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver in project geode by apache.
the class FixedPRSinglehopDUnitTest method createServer.
public static int createServer(boolean isAccessor, List<FixedPartitionAttributes> fpaList) {
FixedPRSinglehopDUnitTest test = new FixedPRSinglehopDUnitTest();
cache = test.getCache();
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());
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;
}
use of org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver in project geode by apache.
the class FixedPRSinglehopDUnitTest method createPeer.
public static void createPeer(boolean isAccessor, List<FixedPartitionAttributes> fpaList) {
FixedPRSinglehopDUnitTest test = new FixedPRSinglehopDUnitTest();
cache = test.getCache();
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());
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());
}
use of org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver in project geode by apache.
the class RegionManagementDUnitTest method createFixedPartitionRegion.
/**
* Invoked in member VMs
*/
private void createFixedPartitionRegion(final List<FixedPartitionAttributes> fixedPartitionAttributesList) {
SystemManagementService service = getSystemManagementService_tmp();
PartitionAttributesFactory partitionAttributesFactory = new PartitionAttributesFactory();
partitionAttributesFactory.setRedundantCopies(2).setTotalNumBuckets(12);
for (FixedPartitionAttributes fixedPartitionAttributes : fixedPartitionAttributesList) {
partitionAttributesFactory.addFixedPartitionAttributes(fixedPartitionAttributes);
}
partitionAttributesFactory.setPartitionResolver(new SingleHopQuarterPartitionResolver());
AttributesFactory attributesFactory = new AttributesFactory();
attributesFactory.setPartitionAttributes(partitionAttributesFactory.create());
fixedPartitionedRegion = getCache_tmp().createRegion(FIXED_PR_NAME, attributesFactory.create());
assertThat(fixedPartitionedRegion).isNotNull();
RegionMXBean regionMXBean = service.getLocalRegionMBean(FIXED_PR_PATH);
RegionAttributes regionAttributes = fixedPartitionedRegion.getAttributes();
PartitionAttributesData partitionAttributesData = regionMXBean.listPartitionAttributes();
verifyPartitionData(regionAttributes, partitionAttributesData);
FixedPartitionAttributesData[] fixedPartitionAttributesData = regionMXBean.listFixedPartitionAttributes();
assertThat(fixedPartitionAttributesData).isNotNull();
assertThat(fixedPartitionAttributesData).hasSize(3);
for (int i = 0; i < fixedPartitionAttributesData.length; i++) {
// TODO: add real assertions
// LogWriterUtils.getLogWriter().info("<ExpectedString> Fixed PR Data is " +
// fixedPartitionAttributesData[i] + "</ExpectedString> ");
}
}
Aggregations