Search in sources :

Example 51 with RegionAttributesCreation

use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.

the class CacheXml66DUnitTest method testEvictionLRUEntryAttributes.

@Test
public void testEvictionLRUEntryAttributes() throws Exception {
    final String rName = getUniqueName();
    CacheCreation cache = new CacheCreation();
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(80, EvictionAction.LOCAL_DESTROY));
    cache.createRegion(rName, attrs);
    testXml(cache);
}
Also used : RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Test(org.junit.Test)

Example 52 with RegionAttributesCreation

use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.

the class CacheXml66DUnitTest method testDefaultRecoveryDelayAttributes.

/**
   * Tests that a region created with a named attributes set programmatically for recovery-delay has
   * the correct attributes.
   */
@Test
public void testDefaultRecoveryDelayAttributes() throws Exception {
    CacheCreation cache = new CacheCreation();
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(1);
    paf.setTotalMaxMemory(500);
    paf.setLocalMaxMemory(100);
    attrs.setPartitionAttributes(paf.create());
    cache.createRegion("parRoot", attrs);
    Region r = cache.getRegion("parRoot");
    assertEquals(r.getAttributes().getPartitionAttributes().getRedundantCopies(), 1);
    assertEquals(r.getAttributes().getPartitionAttributes().getLocalMaxMemory(), 100);
    assertEquals(r.getAttributes().getPartitionAttributes().getTotalMaxMemory(), 500);
    assertEquals(-1, r.getAttributes().getPartitionAttributes().getRecoveryDelay());
    assertEquals(0, r.getAttributes().getPartitionAttributes().getStartupRecoveryDelay());
    testXml(cache);
    Cache c = getCache();
    assertNotNull(c);
    Region region = c.getRegion("parRoot");
    assertNotNull(region);
    RegionAttributes regionAttrs = region.getAttributes();
    PartitionAttributes pa = regionAttrs.getPartitionAttributes();
    assertEquals(pa.getRedundantCopies(), 1);
    assertEquals(pa.getLocalMaxMemory(), 100);
    assertEquals(pa.getTotalMaxMemory(), 500);
    assertEquals(-1, r.getAttributes().getPartitionAttributes().getRecoveryDelay());
    assertEquals(0, r.getAttributes().getPartitionAttributes().getStartupRecoveryDelay());
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) 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 53 with RegionAttributesCreation

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

Example 54 with RegionAttributesCreation

use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.

the class CacheXml66DUnitTest method testRegisteringNamedRegionAttributes.

/**
   * Tests that named region attributes are registered when the cache is created.
   */
@Test
public void testRegisteringNamedRegionAttributes() throws Exception {
    CacheCreation cache = new CacheCreation();
    RegionAttributesCreation attrs;
    String id1 = "id1";
    attrs = new RegionAttributesCreation(cache);
    attrs.setScope(Scope.DISTRIBUTED_ACK);
    attrs.setMirrorType(MirrorType.KEYS);
    cache.setRegionAttributes(id1, attrs);
    String id2 = "id2";
    attrs = new RegionAttributesCreation(cache);
    attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
    attrs.setMirrorType(MirrorType.KEYS_VALUES);
    attrs.setConcurrencyLevel(15);
    cache.setRegionAttributes(id2, attrs);
    String id3 = "id3";
    attrs = new RegionAttributesCreation(cache);
    attrs.setScope(Scope.LOCAL);
    attrs.setValueConstraint(Integer.class);
    cache.setRegionAttributes(id3, attrs);
    testXml(cache);
}
Also used : RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Test(org.junit.Test)

Example 55 with RegionAttributesCreation

use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.

the class CacheXml66DUnitTest method testDiskStoreFactory.

@Test
public void testDiskStoreFactory() throws Exception {
    CacheCreation cache = new CacheCreation();
    DiskStoreFactory dsf = cache.createDiskStoreFactory();
    dsf.setDiskDirs(new File[] { new File("non_exist_dir") });
    DiskStore ds1 = dsf.create(getUniqueName());
    dsf.setDiskDirs(new File[] { new File(".") });
    ds1 = dsf.create(getUniqueName());
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setScope(Scope.DISTRIBUTED_ACK);
    attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    attrs.setDiskStoreName(getUniqueName());
    AttributesFactory factory = new AttributesFactory(attrs);
    RegionAttributes ra = factory.create();
    RegionCreation root = (RegionCreation) cache.createRegion("root", ra);
    factory = new AttributesFactory();
    factory.setDiskStoreName(getUniqueName());
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    ra = factory.create();
    RegionCreation root2 = (RegionCreation) cache.createRegion("root2", ra);
    factory = new AttributesFactory();
    factory.setDiskStoreName(null);
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    ra = factory.create();
    RegionCreation root3 = (RegionCreation) cache.createRegion("root3", ra);
    testXml(cache);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskWriteAttributesFactory(org.apache.geode.cache.DiskWriteAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) File(java.io.File) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Test(org.junit.Test)

Aggregations

RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)87 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)86 Test (org.junit.Test)85 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)64 Region (org.apache.geode.cache.Region)37 Cache (org.apache.geode.cache.Cache)35 LocalRegion (org.apache.geode.internal.cache.LocalRegion)32 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)28 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)28 ClientCache (org.apache.geode.cache.client.ClientCache)27 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)17 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)14 File (java.io.File)13 RegionAttributes (org.apache.geode.cache.RegionAttributes)11 RegionCreation (org.apache.geode.internal.cache.xmlcache.RegionCreation)11 DiskWriteAttributesFactory (org.apache.geode.cache.DiskWriteAttributesFactory)10 FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)9 CacheServer (org.apache.geode.cache.server.CacheServer)8 AttributesFactory (org.apache.geode.cache.AttributesFactory)7 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)7