use of org.apache.geode.internal.cache.xmlcache.CacheCreation 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.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testPartitionedRegionAttributesForMemLruWithMaxMem.
@Test
public void testPartitionedRegionAttributesForMemLruWithMaxMem() throws Exception {
final int redundantCopies = 1;
final int maxMem = 25;
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setStatisticsEnabled(true);
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(redundantCopies);
paf.setTotalMaxMemory(500);
paf.setLocalMaxMemory(100);
AttributesFactory fac = new AttributesFactory(attrs);
fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(maxMem, null, EvictionAction.LOCAL_DESTROY));
fac.setPartitionAttributes(paf.create());
cache.createRegion("parRoot", fac.create());
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);
assertEquals(ea.getAlgorithm(), EvictionAlgorithm.LRU_MEMORY);
assertEquals(ea.getAction(), EvictionAction.LOCAL_DESTROY);
assertNotSame(ea.getMaximum(), maxMem);
assertEquals(ea.getMaximum(), pa.getLocalMaxMemory());
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testDataPolicy.
@Test
public void testDataPolicy() throws Exception {
CacheCreation cache = new CacheCreation();
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.NORMAL);
cache.createRegion("rootNORMAL", attrs);
}
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.NORMAL);
attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
cache.createRegion("rootNORMAL_ALL", attrs);
}
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setMirrorType(MirrorType.KEYS_VALUES);
cache.createRegion("rootREPLICATE", attrs);
}
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
cache.createRegion("rootPERSISTENT_REPLICATE", attrs);
}
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.EMPTY);
cache.createRegion("rootEMPTY", attrs);
}
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.EMPTY);
attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
cache.createRegion("rootEMPTY_ALL", attrs);
}
testXml(cache);
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testTwoCacheServerGroups.
@Test
public void testTwoCacheServerGroups() throws Exception {
CacheCreation cache = new CacheCreation();
CacheServer bs = cache.addCacheServer();
bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
String[] groups = new String[] { "group1", "group2" };
bs.setGroups(groups);
testXml(cache);
Cache c = getCache();
assertNotNull(c);
CacheServer server = (CacheServer) cache.getCacheServers().iterator().next();
assertNotNull(server);
assertEquals(Arrays.asList(groups), Arrays.asList(server.getGroups()));
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testCustomEntryXml.
/**
* Test both customEntryIdleTime and customEntryTimeToLife
*/
@Test
public void testCustomEntryXml() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
RegionCreation root = (RegionCreation) cache.createRegion("root", attrs);
{
attrs = new RegionAttributesCreation(cache);
attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
attrs.setInitialCapacity(142);
attrs.setLoadFactor(42.42f);
attrs.setStatisticsEnabled(true);
attrs.setCustomEntryIdleTimeout(new Expiry1());
attrs.setCustomEntryTimeToLive(new Expiry5());
root.createSubregion("one", attrs);
}
{
attrs = new RegionAttributesCreation(cache);
attrs.setScope(Scope.DISTRIBUTED_ACK);
attrs.setInitialCapacity(242);
attrs.setStatisticsEnabled(true);
attrs.setCustomEntryIdleTimeout(new Expiry2());
Region region = root.createSubregion("two", attrs);
{
attrs = new RegionAttributesCreation(cache);
attrs.setScope(Scope.DISTRIBUTED_ACK);
attrs.setLoadFactor(43.43f);
attrs.setStatisticsEnabled(true);
attrs.setCustomEntryIdleTimeout(new Expiry3());
attrs.setCustomEntryTimeToLive(new Expiry4());
region.createSubregion("three", attrs);
}
}
testXml(cache);
}
Aggregations