Search in sources :

Example 1 with Months_Accessor

use of org.apache.geode.internal.cache.partitioned.fixed.FixedPartitioningTestBase.Months_Accessor 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)

Aggregations

ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 Cache (org.apache.geode.cache.Cache)1 FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)1 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)1 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)1 Region (org.apache.geode.cache.Region)1 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 Months_Accessor (org.apache.geode.internal.cache.partitioned.fixed.FixedPartitioningTestBase.Months_Accessor)1 QuarterPartitionResolver (org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver)1 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)1 Host (org.apache.geode.test.dunit.Host)1 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)1 VM (org.apache.geode.test.dunit.VM)1