Search in sources :

Example 16 with FixedPartitionAttributes

use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.

the class RegionManagementDUnitTest method testFixedPRRegionMBean.

/**
   * Tests all Region MBean related Management APIs
   * <p>
   * a) Notification propagated to member MBean while a region is created
   * <p>
   * b) Creates and check a Fixed Partitioned Region
   */
@Test
public void testFixedPRRegionMBean() throws Exception {
    createMembersAndThenManagers_tmp();
    // Adding notification listener for remote cache memberVMs
    // TODO: why?
    addMemberNotificationListener(this.managerVM, 3);
    int primaryIndex = 0;
    for (VM memberVM : this.memberVMs) {
        List<FixedPartitionAttributes> fixedPartitionAttributesList = createFixedPartitionList(primaryIndex + 1);
        memberVM.invoke(() -> createFixedPartitionRegion(fixedPartitionAttributesList));
        primaryIndex++;
    }
    verifyRemoteFixedPartitionRegion(this.managerVM);
    for (VM memberVM : this.memberVMs) {
        closeRegion(memberVM, FIXED_PR_PATH);
    }
    verifyMemberNotifications(this.managerVM, FIXED_PR_PATH, 3);
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) Invoke.invokeInEveryVM(org.apache.geode.test.dunit.Invoke.invokeInEveryVM) VM(org.apache.geode.test.dunit.VM) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 17 with FixedPartitionAttributes

use of org.apache.geode.cache.FixedPartitionAttributes 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 18 with FixedPartitionAttributes

use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.

the class FixedPartitioningWithColocationAndPersistenceDUnitTest method testColocation_FPRs_ChildUsingAttributesOfParent_HA.

/**
   * This tests validates that Customer-Order-shipment colocation with failover scenario,
   */
@Test
public void testColocation_FPRs_ChildUsingAttributesOfParent_HA() {
    try {
        member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("10", true, 5);
        FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("30", false, 5);
        FixedPartitionAttributes fpa3 = FixedPartitionAttributes.createFixedPartition("40", false, 5);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        fpaList.add(fpa3);
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, false));
        fpa1 = FixedPartitionAttributes.createFixedPartition("20", true, 5);
        fpa2 = FixedPartitionAttributes.createFixedPartition("30", false, 5);
        fpa3 = FixedPartitionAttributes.createFixedPartition("40", false, 5);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        fpaList.add(fpa3);
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, false));
        fpa1 = FixedPartitionAttributes.createFixedPartition("30", true, 5);
        fpa2 = FixedPartitionAttributes.createFixedPartition("40", true, 5);
        fpa3 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
        FixedPartitionAttributes fpa4 = FixedPartitionAttributes.createFixedPartition("20", false, 5);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        fpaList.add(fpa3);
        fpaList.add(fpa4);
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, false));
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        member1.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
        member1.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
        member2.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
        member3.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
        member3.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.putCustomerPartitionedRegion("Customer"));
        member1.invoke(() -> FixedPartitioningTestBase.putOrderPartitionedRegion("Order"));
        member1.invoke(() -> FixedPartitioningTestBase.putShipmentPartitionedRegion("Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
        member3.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(20, 10, "Customer", "Order", "Shipment"));
        member3.invoke(() -> FixedPartitioningTestBase.closeCache());
        Wait.pause(4000);
        member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocationAfterCacheClosed(15, 5, "Customer", "Order", "Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocationAfterCacheClosed(15, 5, "Customer", "Order", "Shipment"));
        member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        fpa1 = FixedPartitionAttributes.createFixedPartition("30", true, 5);
        fpa2 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
        fpa3 = FixedPartitionAttributes.createFixedPartition("20", false, 5);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        fpaList.add(fpa3);
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, false));
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        Wait.pause(4000);
        member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
        member3.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
        member4.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        fpa1 = FixedPartitionAttributes.createFixedPartition("40", true, 5);
        fpa2 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
        fpa3 = FixedPartitionAttributes.createFixedPartition("20", false, 5);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        fpaList.add(fpa3);
        member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, false));
        member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        Wait.pause(4000);
        member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
        member3.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
        member4.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
    } catch (Exception e) {
        Assert.fail("Unexpected Exception ", e);
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 19 with FixedPartitionAttributes

use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.

the class FixedPartitioningWithColocationAndPersistenceDUnitTest method testColocation_FPR_Persistence_Colocation_OneMemberAlive.

/**
   * Tests validate the behavior of FPR with persistence and with colocation when one member is kept
   * alive and other members goes down and come up
   */
@Test
public void testColocation_FPR_Persistence_Colocation_OneMemberAlive() {
    try {
        member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("10", true, 5);
        FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("20", false, 5);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 1, 50, 20, new CustomerFixedPartitionResolver(), null, true));
        fpa1 = FixedPartitionAttributes.createFixedPartition("20", true, 5);
        fpa2 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 1, 50, 20, new CustomerFixedPartitionResolver(), null, true));
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        member1.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
        member1.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
        member2.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.putCustomerPartitionedRegion_Persistence1("Customer"));
        member1.invoke(() -> FixedPartitioningTestBase.putOrderPartitionedRegion_Persistence1("Order"));
        member1.invoke(() -> FixedPartitioningTestBase.putShipmentPartitionedRegion_Persistence1("Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(10, 5, "Customer", "Order", "Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(10, 5, "Customer", "Order", "Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.closeCache());
        member1.invoke(() -> FixedPartitioningTestBase.putCustomerPartitionedRegion_Persistence2("Customer"));
        member1.invoke(() -> FixedPartitioningTestBase.putOrderPartitionedRegion_Persistence2("Order"));
        member1.invoke(() -> FixedPartitioningTestBase.putShipmentPartitionedRegion_Persistence2("Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(10, 10, "Customer", "Order", "Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        fpa1 = FixedPartitionAttributes.createFixedPartition("20", true, 5);
        fpa2 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        AsyncInvocation[] async = new AsyncInvocation[2];
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 1, 50, 20, new CustomerFixedPartitionResolver(), null, true));
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        Wait.pause(4000);
        member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(10, 5, "Customer", "Order", "Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(10, 5, "Customer", "Order", "Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
    } catch (Exception e) {
        Assert.fail("Unexpected Exception ", e);
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 20 with FixedPartitionAttributes

use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.

the class FixedPartitioningWithColocationAndPersistenceDUnitTest method testColocation_WithFPROnChildRegion.

/**
   * This tests validates that in colocation of FPRs child region cannot specify
   * FixedPartitionAttributes
   * 
   */
@Test
public void testColocation_WithFPROnChildRegion() {
    try {
        member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Customer100", true, 2);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa1);
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 0, 40, 8, null, null, false));
        fpa1 = FixedPartitionAttributes.createFixedPartition("Order100", true, 2);
        fpaList.clear();
        fpaList.add(fpa1);
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", fpaList, 0, 40, 8, null, "Customer", false));
        fail("IllegalStateException expected");
    } catch (Exception illegal) {
        if (!((illegal.getCause() instanceof IllegalStateException) && (illegal.getCause().getMessage().contains("not be specified in PartitionAttributesFactory if colocated-with is specified")))) {
            Assert.fail("Expected IllegalStateException ", illegal);
        }
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)63 Test (org.junit.Test)46 ArrayList (java.util.ArrayList)45 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)43 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)30 IgnoredException (org.apache.geode.test.dunit.IgnoredException)16 DuplicatePrimaryPartitionException (org.apache.geode.cache.DuplicatePrimaryPartitionException)15 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)15 PartitionNotAvailableException (org.apache.geode.cache.partition.PartitionNotAvailableException)15 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)12 AttributesFactory (org.apache.geode.cache.AttributesFactory)7 Region (org.apache.geode.cache.Region)6 VM (org.apache.geode.test.dunit.VM)6 Cache (org.apache.geode.cache.Cache)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 SingleHopQuarterPartitionResolver (org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver)5 Host (org.apache.geode.test.dunit.Host)5 IOException (java.io.IOException)4 QuarterPartitionResolver (org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver)4 HashSet (java.util.HashSet)3