Search in sources :

Example 41 with FixedPartitionAttributes

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

the class FixedPartitioningDUnitTest method testSamePartitionName_Primary_OnTwoMembers.

/**
   * Test validation : only one node should return primary for a particular partition name for a
   * specific FPR at any given point of time. DuplicatePrimaryPartitionException is thrown during
   * FPR creation if this condition is not met.
   */
@Test
public void testSamePartitionName_Primary_OnTwoMembers() {
    IgnoredException ex = IgnoredException.addIgnoredException("DuplicatePrimaryPartitionException");
    try {
        member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, true, 3);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa1);
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 9, new QuarterPartitionResolver(), null, false));
        member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
        fpaList.clear();
        fpaList.add(fpa1);
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 9, new QuarterPartitionResolver(), null, false));
        member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
        fpaList.clear();
        fpaList.add(fpa1);
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 9, new QuarterPartitionResolver(), null, false));
        fail("DuplicatePrimaryPartitionException Expected");
    } catch (Exception duplicate) {
        if (!((duplicate.getCause() instanceof DuplicatePrimaryPartitionException) && (duplicate.getCause().getMessage().contains("can not be defined as primary on more than one node")))) {
            Assert.fail("Expected DuplicatePrimaryPartitionException ", duplicate);
        }
    } finally {
        ex.remove();
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) IgnoredException(org.apache.geode.test.dunit.IgnoredException) DuplicatePrimaryPartitionException(org.apache.geode.cache.DuplicatePrimaryPartitionException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) DuplicatePrimaryPartitionException(org.apache.geode.cache.DuplicatePrimaryPartitionException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 42 with FixedPartitionAttributes

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

the class FixedPartitioningDUnitTest method testPut_CallBackWithResolver.

/**
   * This tests validate that datastore member tries the put with callback on itself as well as
   * other datastores as per primary FixedPartitionAttributes defined on datastores. here CallBack
   * implements FixedPartitionResolver.
   */
@Test
public void testPut_CallBackWithResolver() {
    member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, true, 3);
    List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
    fpaList.add(fpa1);
    member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 12, null, null, false));
    member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
    fpaList.clear();
    fpaList.add(fpa1);
    member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 12, null, null, false));
    member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter3, true, 3);
    fpaList.clear();
    fpaList.add(fpa1);
    member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 12, null, null, false));
    member4.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter4, true, 3);
    fpaList.clear();
    fpaList.add(fpa1);
    member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 12, null, null, false));
    member1.invoke(() -> FixedPartitioningTestBase.putThroughDataStore_CallBackWithResolver("Quarter"));
    member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryData(Quarter1));
    member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryData(Quarter2));
    member3.invoke(() -> FixedPartitioningTestBase.checkPrimaryData(Quarter3));
    member4.invoke(() -> FixedPartitioningTestBase.checkPrimaryData(Quarter4));
    member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(3, 3));
    member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(3, 3));
    member3.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(3, 3));
    member4.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(3, 3));
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 43 with FixedPartitionAttributes

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

the class FixedPartitioningDUnitTest method testNullPartitionName.

/**
   * This test validates that null partition name cannot be added in FixedPartitionAttributes
   */
@Test
public void testNullPartitionName() {
    try {
        member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        FixedPartitionAttributes fpa = FixedPartitionAttributes.createFixedPartition(null, true, 3);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa);
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 3, new QuarterPartitionResolver(), null, false));
        fail("IllegalStateException Expected");
    } catch (Exception illegal) {
        if (!((illegal.getCause() instanceof IllegalStateException) && (illegal.getCause().getMessage().contains("Fixed partition name cannot be null")))) {
            Assert.fail("Expected IllegalStateException ", illegal);
        }
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) DuplicatePrimaryPartitionException(org.apache.geode.cache.DuplicatePrimaryPartitionException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 44 with FixedPartitionAttributes

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

the class FixedPartitioningDUnitTest method testBug43283.

// GEODE-567: async actions, waitForCriterion, time sensitive,
@Category(FlakyTest.class)
// non-thread-safe test hook, eats exceptions (partially fixed)
@Test
public void testBug43283() {
    member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    member4.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    member1.invoke(() -> FixedPartitioningTestBase.setPRObserverBeforeCalculateStartingBucketId());
    member2.invoke(() -> FixedPartitioningTestBase.setPRObserverBeforeCalculateStartingBucketId());
    member3.invoke(() -> FixedPartitioningTestBase.setPRObserverBeforeCalculateStartingBucketId());
    member4.invoke(() -> FixedPartitioningTestBase.setPRObserverBeforeCalculateStartingBucketId());
    try {
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, true, 3);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa1);
        AsyncInvocation inv1 = member1.invokeAsync(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 12, new QuarterPartitionResolver(), null, false));
        FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
        fpaList.clear();
        fpaList.add(fpa2);
        AsyncInvocation inv2 = member2.invokeAsync(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 12, new QuarterPartitionResolver(), null, false));
        FixedPartitionAttributes fpa3 = FixedPartitionAttributes.createFixedPartition(Quarter3, true, 3);
        fpaList.clear();
        fpaList.add(fpa3);
        AsyncInvocation inv3 = member3.invokeAsync(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 12, new QuarterPartitionResolver(), null, false));
        member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", null, 0, 0, 12, new QuarterPartitionResolver(), null, false));
        try {
            member4.invoke(() -> FixedPartitioningTestBase.putThorughAccessor_Immediate("Quarter"));
        } catch (Exception e) {
            e.printStackTrace();
            if (!(e.getCause() instanceof PartitionNotAvailableException)) {
                Assert.fail("exception thrown is not PartitionNotAvailableException", e);
            }
        }
        try {
            inv1.join();
            inv2.join();
            inv3.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
            Assert.fail("Unexpected Exception", e);
        }
    } finally {
        member1.invoke(() -> FixedPartitioningTestBase.resetPRObserverBeforeCalculateStartingBucketId());
        member2.invoke(() -> FixedPartitioningTestBase.resetPRObserverBeforeCalculateStartingBucketId());
        member3.invoke(() -> FixedPartitioningTestBase.resetPRObserverBeforeCalculateStartingBucketId());
        member4.invoke(() -> FixedPartitioningTestBase.resetPRObserverBeforeCalculateStartingBucketId());
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) DuplicatePrimaryPartitionException(org.apache.geode.cache.DuplicatePrimaryPartitionException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 45 with FixedPartitionAttributes

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

the class FixedPartitioningDUnitTest method testNumBuckets_totalNumBuckets.

/**
   * Sum of num-buckets for different primary partitions should not be greater than totalNumBuckets.
   */
@Test
public void testNumBuckets_totalNumBuckets() {
    IgnoredException expected = IgnoredException.addIgnoredException("IllegalStateException");
    try {
        member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", null, 1, 0, 5, new QuarterPartitionResolver(), null, false));
        member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, true, 3);
        FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter2, false, 3);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 5, new QuarterPartitionResolver(), null, false));
        member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
        fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter3, false, 3);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 5, new QuarterPartitionResolver(), null, false));
        fail("IllegalStateException expected");
    } catch (Exception ex) {
        if (!((ex.getCause() instanceof IllegalStateException) && (ex.getCause().getMessage().contains("for different primary partitions should not be greater than total-num-buckets ")))) {
            Assert.fail("Expected IllegalStateException ", ex);
        }
    } finally {
        expected.remove();
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) IgnoredException(org.apache.geode.test.dunit.IgnoredException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) DuplicatePrimaryPartitionException(org.apache.geode.cache.DuplicatePrimaryPartitionException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

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