Search in sources :

Example 1 with ResourceManagerCreation

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

the class CacheXml66DUnitTest method testPartitionedRegionAttributesForEviction.

/**
   * Tests that a Partitioned Region can be created with a named attributes set programmatically for
   * ExpirationAttributes
   */
@Test
public void testPartitionedRegionAttributesForEviction() throws Exception {
    final int redundantCopies = 1;
    CacheCreation cache = new CacheCreation();
    if (getGemFireVersion().equals(CacheXml.VERSION_6_0)) {
        ResourceManagerCreation rm = new ResourceManagerCreation();
        rm.setCriticalHeapPercentage(95);
        cache.setResourceManagerCreation(rm);
    }
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setStatisticsEnabled(true);
    RegionAttributes rootAttrs = null;
    ExpirationAttributes expiration = new ExpirationAttributes(60, ExpirationAction.DESTROY);
    CacheXMLPartitionResolver partitionResolver = new CacheXMLPartitionResolver();
    Properties params = new Properties();
    params.setProperty("initial-index-value", "1000");
    params.setProperty("secondary-index-value", "5000");
    partitionResolver.init(params);
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(redundantCopies);
    paf.setTotalMaxMemory(500);
    paf.setLocalMaxMemory(100);
    paf.setPartitionResolver(partitionResolver);
    AttributesFactory fac = new AttributesFactory(attrs);
    // TODO: Move test back to using LRUHeap when config issues have settled
    // if (getGemFireVersion().equals(CacheXml.GEMFIRE_6_0)) {
    // fac.setEvictionAttributes(EvictionAttributes.createLRUHeapAttributes(null,
    // EvictionAction.OVERFLOW_TO_DISK));
    // } else {
    fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(100, null, EvictionAction.OVERFLOW_TO_DISK));
    // }
    fac.setEntryTimeToLive(expiration);
    fac.setEntryIdleTimeout(expiration);
    DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
    dwaf.setSynchronous(true);
    fac.setPartitionAttributes(paf.create());
    rootAttrs = fac.create();
    cache.createRegion("parRoot", rootAttrs);
    Region r = cache.getRegion("parRoot");
    assertNotNull(r);
    assertEquals(r.getAttributes().getPartitionAttributes().getRedundantCopies(), redundantCopies);
    assertEquals(r.getAttributes().getPartitionAttributes().getLocalMaxMemory(), 100);
    assertEquals(r.getAttributes().getPartitionAttributes().getTotalMaxMemory(), 500);
    assertEquals(r.getAttributes().getPartitionAttributes().getPartitionResolver(), partitionResolver);
    assertEquals(r.getAttributes().getEntryIdleTimeout().getTimeout(), expiration.getTimeout());
    assertEquals(r.getAttributes().getEntryTimeToLive().getTimeout(), expiration.getTimeout());
    testXml(cache);
    Cache c = getCache();
    assertNotNull(c);
    Region region = c.getRegion("parRoot");
    assertNotNull(region);
    RegionAttributes regionAttrs = region.getAttributes();
    PartitionAttributes pa = regionAttrs.getPartitionAttributes();
    EvictionAttributes ea = regionAttrs.getEvictionAttributes();
    assertEquals(pa.getRedundantCopies(), 1);
    assertEquals(pa.getLocalMaxMemory(), 100);
    assertEquals(pa.getTotalMaxMemory(), 500);
    assertNotNull(pa.getPartitionResolver().getClass());
    assertEquals(pa.getPartitionResolver(), partitionResolver);
    assertEquals(regionAttrs.getEntryIdleTimeout().getTimeout(), expiration.getTimeout());
    assertEquals(regionAttrs.getEntryTimeToLive().getTimeout(), expiration.getTimeout());
    // TODO: Move test back to using LRUHeap when config issues have settled
    // if (getGemFireVersion().equals(CacheXml.GEMFIRE_6_0)) {
    // assertIndexDetailsEquals(ea.getAlgorithm(),EvictionAlgorithm.LRU_HEAP);
    // } else {
    assertEquals(ea.getAlgorithm(), EvictionAlgorithm.LRU_MEMORY);
    // }
    assertEquals(ea.getAction(), EvictionAction.OVERFLOW_TO_DISK);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ResourceManagerCreation(org.apache.geode.internal.cache.xmlcache.ResourceManagerCreation) Properties(java.util.Properties) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskWriteAttributesFactory(org.apache.geode.cache.DiskWriteAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) 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) DiskWriteAttributesFactory(org.apache.geode.cache.DiskWriteAttributesFactory) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 2 with ResourceManagerCreation

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

the class CacheXml66DUnitTest method testResourceManagerThresholds.

/**
   * Test the ResourceManager element's critical-heap-percentage and eviction-heap-percentage
   * attributes
   */
@Test
public void testResourceManagerThresholds() throws Exception {
    CacheCreation cache = new CacheCreation();
    final float low = 90.0f;
    final float high = 95.0f;
    Cache c;
    ResourceManagerCreation rmc = new ResourceManagerCreation();
    rmc.setEvictionHeapPercentage(low);
    rmc.setCriticalHeapPercentage(high);
    cache.setResourceManagerCreation(rmc);
    testXml(cache);
    {
        c = getCache();
        assertEquals(low, c.getResourceManager().getEvictionHeapPercentage(), 0);
        assertEquals(high, c.getResourceManager().getCriticalHeapPercentage(), 0);
    }
    closeCache();
    rmc = new ResourceManagerCreation();
    // Set them to similar values
    rmc.setEvictionHeapPercentage(low);
    rmc.setCriticalHeapPercentage(low + 1);
    cache.setResourceManagerCreation(rmc);
    testXml(cache);
    {
        c = getCache();
        assertEquals(low, c.getResourceManager().getEvictionHeapPercentage(), 0);
        assertEquals(low + 1, c.getResourceManager().getCriticalHeapPercentage(), 0);
    }
    closeCache();
    rmc = new ResourceManagerCreation();
    rmc.setEvictionHeapPercentage(high);
    rmc.setCriticalHeapPercentage(low);
    cache.setResourceManagerCreation(rmc);
    IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.MemoryMonitor_EVICTION_PERCENTAGE_LTE_CRITICAL_PERCENTAGE.toLocalizedString());
    try {
        testXml(cache);
        assertTrue(false);
    } catch (IllegalArgumentException expected) {
    } finally {
        expectedException.remove();
        closeCache();
    }
    // Disable eviction
    rmc = new ResourceManagerCreation();
    rmc.setEvictionHeapPercentage(0);
    rmc.setCriticalHeapPercentage(low);
    cache.setResourceManagerCreation(rmc);
    testXml(cache);
    {
        c = getCache();
        assertEquals(0f, c.getResourceManager().getEvictionHeapPercentage(), 0);
        assertEquals(low, c.getResourceManager().getCriticalHeapPercentage(), 0);
    }
    closeCache();
    // Disable refusing ops in "red zone"
    rmc = new ResourceManagerCreation();
    rmc.setEvictionHeapPercentage(low);
    rmc.setCriticalHeapPercentage(0);
    cache.setResourceManagerCreation(rmc);
    testXml(cache);
    {
        c = getCache();
        assertEquals(low, c.getResourceManager().getEvictionHeapPercentage(), 0);
        assertEquals(0f, c.getResourceManager().getCriticalHeapPercentage(), 0);
    }
    closeCache();
    // Disable both
    rmc = new ResourceManagerCreation();
    rmc.setEvictionHeapPercentage(0);
    rmc.setCriticalHeapPercentage(0);
    cache.setResourceManagerCreation(rmc);
    testXml(cache);
    c = getCache();
    assertEquals(0f, c.getResourceManager().getEvictionHeapPercentage(), 0);
    assertEquals(0f, c.getResourceManager().getCriticalHeapPercentage(), 0);
}
Also used : IgnoredException(org.apache.geode.test.dunit.IgnoredException) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) ResourceManagerCreation(org.apache.geode.internal.cache.xmlcache.ResourceManagerCreation) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 3 with ResourceManagerCreation

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

the class CacheXml66DUnitTest method testPARTITION_PERSISTENT_OVERFLOW.

@Test
public void testPARTITION_PERSISTENT_OVERFLOW() throws Exception {
    CacheCreation cache = new CacheCreation();
    ResourceManagerCreation rmc = new ResourceManagerCreation();
    rmc.setCriticalHeapPercentage(80.0f);
    cache.setResourceManagerCreation(rmc);
    RegionCreation root = (RegionCreation) cache.createRegion("ppartitionoverflow", "PARTITION_PERSISTENT_OVERFLOW");
    testXml(cache);
    GemFireCacheImpl c = (GemFireCacheImpl) getCache();
    Region r = c.getRegion("ppartitionoverflow");
    assertNotNull(r);
    RegionAttributes ra = r.getAttributes();
    assertEquals(DataPolicy.PERSISTENT_PARTITION, ra.getDataPolicy());
    assertNotNull(ra.getPartitionAttributes());
    assertEquals(0, ra.getPartitionAttributes().getRedundantCopies());
    assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes());
    assertEquals(80.0f, c.getResourceManager().getCriticalHeapPercentage(), 0);
    assertEquals(75.0f, c.getResourceManager().getEvictionHeapPercentage(), 0);
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) 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) ResourceManagerCreation(org.apache.geode.internal.cache.xmlcache.ResourceManagerCreation) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) Test(org.junit.Test)

Example 4 with ResourceManagerCreation

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

the class CacheXmlGeode10DUnitTest method testResourceManagerThresholds.

/**
   * Test the ResourceManager element's critical-off-heap-percentage and
   * eviction-off-heap-percentage attributes
   */
@Test
public void testResourceManagerThresholds() throws Exception {
    CacheCreation cache = new CacheCreation();
    final float low = 90.0f;
    final float high = 95.0f;
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + OFF_HEAP_MEMORY_SIZE, "1m");
    Cache c;
    ResourceManagerCreation rmc = new ResourceManagerCreation();
    rmc.setEvictionOffHeapPercentage(low);
    rmc.setCriticalOffHeapPercentage(high);
    cache.setResourceManagerCreation(rmc);
    testXml(cache);
    {
        c = getCache();
        assertEquals(low, c.getResourceManager().getEvictionOffHeapPercentage(), 0);
        assertEquals(high, c.getResourceManager().getCriticalOffHeapPercentage(), 0);
    }
    closeCache();
    rmc = new ResourceManagerCreation();
    // Set them to similar values
    rmc.setEvictionOffHeapPercentage(low);
    rmc.setCriticalOffHeapPercentage(low + 1);
    cache.setResourceManagerCreation(rmc);
    testXml(cache);
    {
        c = getCache();
        assertEquals(low, c.getResourceManager().getEvictionOffHeapPercentage(), 0);
        assertEquals(low + 1, c.getResourceManager().getCriticalOffHeapPercentage(), 0);
    }
    closeCache();
    rmc = new ResourceManagerCreation();
    rmc.setEvictionOffHeapPercentage(high);
    rmc.setCriticalOffHeapPercentage(low);
    cache.setResourceManagerCreation(rmc);
    IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.MemoryMonitor_EVICTION_PERCENTAGE_LTE_CRITICAL_PERCENTAGE.toLocalizedString());
    try {
        testXml(cache);
        fail("Expected IllegalArgumentException to be thrown");
    } catch (IllegalArgumentException expected) {
    } finally {
        expectedException.remove();
        closeCache();
    }
    // Disable eviction
    rmc = new ResourceManagerCreation();
    rmc.setEvictionOffHeapPercentage(0);
    rmc.setCriticalOffHeapPercentage(low);
    cache.setResourceManagerCreation(rmc);
    testXml(cache);
    {
        c = getCache();
        assertEquals(0f, c.getResourceManager().getEvictionOffHeapPercentage(), 0);
        assertEquals(low, c.getResourceManager().getCriticalOffHeapPercentage(), 0);
    }
    closeCache();
    // Disable refusing ops in "red zone"
    rmc = new ResourceManagerCreation();
    rmc.setEvictionOffHeapPercentage(low);
    rmc.setCriticalOffHeapPercentage(0);
    cache.setResourceManagerCreation(rmc);
    testXml(cache);
    {
        c = getCache();
        assertEquals(low, c.getResourceManager().getEvictionOffHeapPercentage(), 0);
        assertEquals(0f, c.getResourceManager().getCriticalOffHeapPercentage(), 0);
    }
    closeCache();
    // Disable both
    rmc = new ResourceManagerCreation();
    rmc.setEvictionOffHeapPercentage(0);
    rmc.setCriticalOffHeapPercentage(0);
    cache.setResourceManagerCreation(rmc);
    testXml(cache);
    c = getCache();
    assertEquals(0f, c.getResourceManager().getEvictionOffHeapPercentage(), 0);
    assertEquals(0f, c.getResourceManager().getCriticalOffHeapPercentage(), 0);
}
Also used : IgnoredException(org.apache.geode.test.dunit.IgnoredException) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ResourceManagerCreation(org.apache.geode.internal.cache.xmlcache.ResourceManagerCreation) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 5 with ResourceManagerCreation

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

the class CacheXml66DUnitTest method testPARTITION_REDUNDANT_PERSISTENT_OVERFLOW.

@Test
public void testPARTITION_REDUNDANT_PERSISTENT_OVERFLOW() throws Exception {
    CacheCreation cache = new CacheCreation();
    ResourceManagerCreation rmc = new ResourceManagerCreation();
    // test bug 42130
    rmc.setEvictionHeapPercentage(0.0f);
    cache.setResourceManagerCreation(rmc);
    RegionCreation root = (RegionCreation) cache.createRegion("prpartitionoverflow", "PARTITION_REDUNDANT_PERSISTENT_OVERFLOW");
    testXml(cache);
    GemFireCacheImpl c = (GemFireCacheImpl) getCache();
    Region r = c.getRegion("prpartitionoverflow");
    assertNotNull(r);
    RegionAttributes ra = r.getAttributes();
    assertEquals(DataPolicy.PERSISTENT_PARTITION, ra.getDataPolicy());
    assertNotNull(ra.getPartitionAttributes());
    assertEquals(1, ra.getPartitionAttributes().getRedundantCopies());
    assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes());
    assertEquals(0.0f, c.getResourceManager().getEvictionHeapPercentage(), 0);
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) 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) ResourceManagerCreation(org.apache.geode.internal.cache.xmlcache.ResourceManagerCreation) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) Test(org.junit.Test)

Aggregations

CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)6 ResourceManagerCreation (org.apache.geode.internal.cache.xmlcache.ResourceManagerCreation)6 Test (org.junit.Test)6 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)5 Region (org.apache.geode.cache.Region)4 RegionAttributes (org.apache.geode.cache.RegionAttributes)4 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)4 LocalRegion (org.apache.geode.internal.cache.LocalRegion)4 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)4 Cache (org.apache.geode.cache.Cache)3 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)3 RegionCreation (org.apache.geode.internal.cache.xmlcache.RegionCreation)3 ClientCache (org.apache.geode.cache.client.ClientCache)2 IgnoredException (org.apache.geode.test.dunit.IgnoredException)2 Properties (java.util.Properties)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 DiskWriteAttributesFactory (org.apache.geode.cache.DiskWriteAttributesFactory)1 EvictionAttributes (org.apache.geode.cache.EvictionAttributes)1 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)1 FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)1