Search in sources :

Example 36 with RegionFactory

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");
    });
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) SingleHopQuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionFactory(org.apache.geode.cache.RegionFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 37 with RegionFactory

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);
    });
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) RegionFactory(org.apache.geode.cache.RegionFactory) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Cache(org.apache.geode.cache.Cache)

Example 38 with RegionFactory

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);
    });
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) SystemManagementService(org.apache.geode.management.internal.SystemManagementService)

Example 39 with RegionFactory

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));
            }
        }
    });
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 40 with RegionFactory

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);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) RegionFactory(org.apache.geode.cache.RegionFactory) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Cache(org.apache.geode.cache.Cache)

Aggregations

RegionFactory (org.apache.geode.cache.RegionFactory)124 Region (org.apache.geode.cache.Region)63 Cache (org.apache.geode.cache.Cache)57 Test (org.junit.Test)54 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)51 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)44 VM (org.apache.geode.test.dunit.VM)44 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)31 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)31 CacheException (org.apache.geode.cache.CacheException)30 Host (org.apache.geode.test.dunit.Host)28 Properties (java.util.Properties)25 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)22 File (java.io.File)21 DiskStore (org.apache.geode.cache.DiskStore)20 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)20 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)18 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)17 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)17