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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations