use of org.apache.geode.cache.RegionFactory 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.cache.RegionFactory in project geode by apache.
the class DiskManagementDUnitTest method createPersistentRegionAsync.
private AsyncInvocation createPersistentRegionAsync(final VM memberVM) {
return memberVM.invokeAsync("createPersistentRegionAsync", () -> {
File dir = new File(diskDir, String.valueOf(ProcessUtils.identifyPid()));
Cache cache = this.managementTestRule.getCache();
DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
diskStoreFactory.setDiskDirs(new File[] { dir });
diskStoreFactory.setMaxOplogSize(1);
diskStoreFactory.setAllowForceCompaction(true);
diskStoreFactory.setAutoCompact(false);
DiskStore diskStore = diskStoreFactory.create(REGION_NAME);
RegionFactory regionFactory = cache.createRegionFactory();
regionFactory.setDiskStoreName(diskStore.getName());
regionFactory.setDiskSynchronous(true);
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
regionFactory.setScope(Scope.DISTRIBUTED_ACK);
regionFactory.create(REGION_NAME);
});
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class ManagementTestBase method createDistributedRegionAsync.
/**
* Creates a Distributed Region
*/
private AsyncInvocation createDistributedRegionAsync(final VM vm, final String regionName) {
return vm.invokeAsync("Create Distributed region", () -> {
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
SystemManagementService service = (SystemManagementService) getManagementService();
RegionFactory rf = cache.createRegionFactory(RegionShortcut.REPLICATE);
LogWriterUtils.getLogWriter().info("Creating Dist Region");
rf.create(regionName);
});
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class GemfireDataCommandsDUnitTest method setupWith2Regions.
void setupWith2Regions() {
final VM vm1 = Host.getHost(0).getVM(1);
final VM vm2 = Host.getHost(0).getVM(2);
setUpJmxManagerOnVm0ThenConnect(null);
vm1.invoke(new SerializableRunnable() {
public void run() {
// no need to close cache as it will be closed as part of teardown2
Cache cache = getCache();
RegionFactory<Integer, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
Region region = dataRegionFactory.create(REBALANCE_REGION_NAME);
for (int i = 0; i < 10; i++) {
region.put("key" + (i + 200), "value" + (i + 200));
}
region = dataRegionFactory.create(REBALANCE_REGION2_NAME);
for (int i = 0; i < 50; i++) {
region.put("key" + (i + 200), "value" + (i + 200));
}
}
});
vm2.invoke(new SerializableRunnable() {
public void run() {
// no need to close cache as it will be closed as part of teardown2
Cache cache = getCache();
RegionFactory<Integer, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
Region region = dataRegionFactory.create(REBALANCE_REGION_NAME);
for (int i = 0; i < 150; i++) {
region.put("key" + (i + 400), "value" + (i + 400));
}
region = dataRegionFactory.create(REBALANCE_REGION2_NAME);
for (int i = 0; i < 100; i++) {
region.put("key" + (i + 200), "value" + (i + 200));
}
}
});
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class IndexCommandsDUnitTest method createRepRegWithPersistence.
private Region<?, ?> createRepRegWithPersistence(String regionName, String diskStoreName, String diskDirName) {
Cache cache = getCache();
File diskStoreDirFile = new File(diskDirName);
diskStoreDirFile.deleteOnExit();
if (!diskStoreDirFile.exists()) {
diskStoreDirFile.mkdirs();
}
DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
diskStoreFactory.setDiskDirs(new File[] { diskStoreDirFile });
diskStoreFactory.setMaxOplogSize(1);
diskStoreFactory.setAllowForceCompaction(true);
diskStoreFactory.setAutoCompact(false);
diskStoreFactory.create(diskStoreName);
/****
* Eviction Attributes
*/
EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK);
RegionFactory regionFactory = cache.createRegionFactory();
regionFactory.setDiskStoreName(diskStoreName);
regionFactory.setDiskSynchronous(true);
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
regionFactory.setEvictionAttributes(ea);
return regionFactory.create(regionName);
}
Aggregations