Search in sources :

Example 11 with FixedPartitionAttributes

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

the class FixedPartitioningDUnitTest method testDelete_WithoutPut.

/**
   * This test validate that a delete operation on empty region will throw EntryNotFoundException
   */
@Test
public void testDelete_WithoutPut() {
    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, 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, 12, new QuarterPartitionResolver(), 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, new QuarterPartitionResolver(), 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, new QuarterPartitionResolver(), null, false));
    try {
        member1.invoke(() -> FixedPartitioningTestBase.deleteOperation("Quarter"));
        fail("EntryNotFoundException expected");
    } catch (Exception ex) {
        if (!((ex.getCause() instanceof EntryNotFoundException))) {
            Assert.fail("Expected EntryNotFoundException ", ex);
        }
    }
    member1.invoke(() -> FixedPartitioningTestBase.putThroughDataStore("Quarter"));
    member1.invoke(() -> FixedPartitioningTestBase.getThroughDataStore("Quarter"));
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) 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 12 with FixedPartitionAttributes

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

the class FixedPartitioningDUnitTest method test_DataStoreWithoutPartition_DataStoreWithPartition.

/**
   * This test validates that if one datastore has the fixed partition attributes defined then other
   * datastore should also have the fixed partition attributes defined
   */
@Test
public void test_DataStoreWithoutPartition_DataStoreWithPartition() {
    IgnoredException expected = IgnoredException.addIgnoredException("IllegalStateException");
    try {
        member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", null, 1, 40, 12, new QuarterPartitionResolver(), null, false));
        member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, true, 3);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa1);
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false));
    } catch (Exception ex) {
        if (!((ex.getCause() instanceof IllegalStateException))) {
            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)

Example 13 with FixedPartitionAttributes

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

the class FixedPartitioningDUnitTest method testPut_ValidateDataOnMember_PrimarySecondary_Datastore.

/**
   * This tests validate that datastore member does the put on itself as well as other datastores as
   * per primary and secondary FixedPartitionAttributes defined on datastores.
   */
// GEODE-1704
@Category(FlakyTest.class)
@Test
public void testPut_ValidateDataOnMember_PrimarySecondary_Datastore() {
    member1.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);
    member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false));
    member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
    fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter3, false, 3);
    fpaList.clear();
    fpaList.add(fpa1);
    fpaList.add(fpa2);
    member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false));
    member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter3, true, 3);
    fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter4, false, 3);
    fpaList.clear();
    fpaList.add(fpa1);
    fpaList.add(fpa2);
    member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false));
    member4.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter4, true, 3);
    fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter1, false, 3);
    fpaList.clear();
    fpaList.add(fpa1);
    fpaList.add(fpa2);
    member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false));
    member1.invoke(() -> FixedPartitioningTestBase.putThroughDataStore("Quarter"));
    member1.invoke(() -> FixedPartitioningTestBase.checkPrimarySecondaryData(Quarter1, false));
    member2.invoke(() -> FixedPartitioningTestBase.checkPrimarySecondaryData(Quarter2, false));
    member3.invoke(() -> FixedPartitioningTestBase.checkPrimarySecondaryData(Quarter3, false));
    member4.invoke(() -> FixedPartitioningTestBase.checkPrimarySecondaryData(Quarter4, false));
    member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
    member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
    member3.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
    member4.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) 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 14 with FixedPartitionAttributes

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

the class FixedPartitioningDUnitTest method testPut_PartitionNotAvailableException.

/**
   * This test validates that if the required partition is not available at the time of entry
   * operation then PartitionNotAvailabelException is thrown
   */
@Test
public void testPut_PartitionNotAvailableException() {
    try {
        member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", null, 1, 0, 12, new QuarterPartitionResolver(), null, false));
        member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, true, 3);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa1);
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, 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, 1, 40, 12, new QuarterPartitionResolver(), null, false));
        member1.invoke(() -> FixedPartitioningTestBase.putThorughAccessor("Quarter"));
        fail("PartitionNotAvailableException Expected");
    } catch (Exception ex) {
        if (!((ex.getCause() instanceof PartitionNotAvailableException))) {
            Assert.fail("Expected PartitionNotAvailableException ", ex);
        }
    }
}
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) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 15 with FixedPartitionAttributes

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

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