Search in sources :

Example 1 with SingleHopQuarterPartitionResolver

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");
    });
}
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 2 with SingleHopQuarterPartitionResolver

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;
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SingleHopQuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver) QuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) DistributedSystem(org.apache.geode.distributed.DistributedSystem)

Example 3 with SingleHopQuarterPartitionResolver

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;
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SingleHopQuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException)

Example 4 with SingleHopQuarterPartitionResolver

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());
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SingleHopQuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver)

Example 5 with SingleHopQuarterPartitionResolver

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> ");
    }
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) SingleHopQuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver) SystemManagementService(org.apache.geode.management.internal.SystemManagementService)

Aggregations

FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)5 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)5 SingleHopQuarterPartitionResolver (org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)4 IOException (java.io.IOException)2 CacheServer (org.apache.geode.cache.server.CacheServer)2 Properties (java.util.Properties)1 CacheFactory (org.apache.geode.cache.CacheFactory)1 Region (org.apache.geode.cache.Region)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 RegionFactory (org.apache.geode.cache.RegionFactory)1 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)1 DistributedSystem (org.apache.geode.distributed.DistributedSystem)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 QuarterPartitionResolver (org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver)1 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 Test (org.junit.Test)1