Search in sources :

Example 46 with FixedPartitionAttributes

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

the class MemberCommandsDUnitTest method createPartitionedRegion.

private void createPartitionedRegion(String regionName) {
    final Cache cache = getCache();
    // Create the data region
    RegionFactory<String, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
    dataRegionFactory.setConcurrencyLevel(4);
    EvictionAttributes ea = EvictionAttributes.createLIFOEntryAttributes(100, EvictionAction.LOCAL_DESTROY);
    dataRegionFactory.setEvictionAttributes(ea);
    dataRegionFactory.setEnableAsyncConflation(true);
    FixedPartitionAttributes fpa = FixedPartitionAttributes.createFixedPartition("Par1", true);
    PartitionAttributes pa = new PartitionAttributesFactory().setLocalMaxMemory(100).setRecoveryDelay(2).setTotalMaxMemory(200).setRedundantCopies(1).addFixedPartitionAttributes(fpa).create();
    dataRegionFactory.setPartitionAttributes(pa);
    dataRegionFactory.create(regionName);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) Cache(org.apache.geode.cache.Cache)

Example 47 with FixedPartitionAttributes

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

the class LuceneTestUtilities method createFixedPartitionedRegion.

public static Region createFixedPartitionedRegion(final Cache cache, String regionName, List<FixedPartitionAttributes> fpaList, int localMaxMemory) {
    List<String> allPartitions = new ArrayList();
    if (fpaList != null) {
        for (FixedPartitionAttributes fpa : fpaList) {
            allPartitions.add(fpa.getPartitionName());
        }
    } else {
        allPartitions.add("Q1");
        allPartitions.add("Q2");
    }
    AttributesFactory fact = new AttributesFactory();
    PartitionAttributesFactory pfact = new PartitionAttributesFactory();
    pfact.setTotalNumBuckets(16);
    pfact.setRedundantCopies(1);
    pfact.setLocalMaxMemory(localMaxMemory);
    if (fpaList != null) {
        for (FixedPartitionAttributes fpa : fpaList) {
            pfact.addFixedPartitionAttributes(fpa);
        }
    }
    pfact.setPartitionResolver(new MyFixedPartitionResolver(allPartitions));
    fact.setPartitionAttributes(pfact.create());
    Region r = cache.createRegionFactory(fact.create()).create(regionName);
    assertNotNull(r);
    return r;
}
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) ArrayList(java.util.ArrayList) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) LuceneIndexForPartitionedRegion(org.apache.geode.cache.lucene.internal.LuceneIndexForPartitionedRegion)

Example 48 with FixedPartitionAttributes

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

the class LuceneTestUtilities method initDataStoreForFixedPR.

public static Region initDataStoreForFixedPR(final Cache cache) throws Exception {
    List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
    int vmNum = VM.getCurrentVMNum();
    if (vmNum % 2 == 0) {
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, true);
        FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter2, false);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
    } else {
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, false);
        FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter2, true);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
    }
    return createFixedPartitionedRegion(cache, REGION_NAME, fpaList, 40);
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) IntPoint(org.apache.lucene.document.IntPoint) FloatPoint(org.apache.lucene.document.FloatPoint)

Example 49 with FixedPartitionAttributes

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

the class RegionManagementDUnitTest method createFixedPartitionRegion.

/**
   * Invoked in member VMs
   */
private void createFixedPartitionRegion(final List<FixedPartitionAttributes> fixedPartitionAttributesList) {
    SystemManagementService service = getSystemManagementService_tmp();
    PartitionAttributesFactory partitionAttributesFactory = new PartitionAttributesFactory();
    partitionAttributesFactory.setRedundantCopies(2).setTotalNumBuckets(12);
    for (FixedPartitionAttributes fixedPartitionAttributes : fixedPartitionAttributesList) {
        partitionAttributesFactory.addFixedPartitionAttributes(fixedPartitionAttributes);
    }
    partitionAttributesFactory.setPartitionResolver(new SingleHopQuarterPartitionResolver());
    AttributesFactory attributesFactory = new AttributesFactory();
    attributesFactory.setPartitionAttributes(partitionAttributesFactory.create());
    fixedPartitionedRegion = getCache_tmp().createRegion(FIXED_PR_NAME, attributesFactory.create());
    assertThat(fixedPartitionedRegion).isNotNull();
    RegionMXBean regionMXBean = service.getLocalRegionMBean(FIXED_PR_PATH);
    RegionAttributes regionAttributes = fixedPartitionedRegion.getAttributes();
    PartitionAttributesData partitionAttributesData = regionMXBean.listPartitionAttributes();
    verifyPartitionData(regionAttributes, partitionAttributesData);
    FixedPartitionAttributesData[] fixedPartitionAttributesData = regionMXBean.listFixedPartitionAttributes();
    assertThat(fixedPartitionAttributesData).isNotNull();
    assertThat(fixedPartitionAttributesData).hasSize(3);
    for (int i = 0; i < fixedPartitionAttributesData.length; i++) {
    // TODO: add real assertions
    // LogWriterUtils.getLogWriter().info("<ExpectedString> Fixed PR Data is " +
    // fixedPartitionAttributesData[i] + "</ExpectedString> ");
    }
}
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) RegionAttributes(org.apache.geode.cache.RegionAttributes) SingleHopQuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver) SystemManagementService(org.apache.geode.management.internal.SystemManagementService)

Example 50 with FixedPartitionAttributes

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

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