Search in sources :

Example 1 with QuarterPartitionResolver

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);
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) QuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver) ArrayList(java.util.ArrayList) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 2 with QuarterPartitionResolver

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);
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) QuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver) ArrayList(java.util.ArrayList) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CacheException(org.apache.geode.cache.CacheException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CacheXmlException(org.apache.geode.cache.CacheXmlException) SAXException(org.xml.sax.SAXException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 3 with QuarterPartitionResolver

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);
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Date(java.util.Date) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) QuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver) VM(org.apache.geode.test.dunit.VM) Months_Accessor(org.apache.geode.internal.cache.partitioned.fixed.FixedPartitioningTestBase.Months_Accessor) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with QuarterPartitionResolver

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;
}
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)

Aggregations

FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)4 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)4 QuarterPartitionResolver (org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver)4 Cache (org.apache.geode.cache.Cache)3 Region (org.apache.geode.cache.Region)3 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2 ClientCache (org.apache.geode.cache.client.ClientCache)2 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)2 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)2 RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)2 UnknownHostException (java.net.UnknownHostException)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1