use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class Bug40632DUnitTest method testLocalInvalidateTimeToLive.
@Test
public void testLocalInvalidateTimeToLive() throws Exception {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(-1);
paf.setStartupRecoveryDelay(-1);
PartitionAttributes prAttr = paf.create();
attr.setStatisticsEnabled(true);
attr.setEntryTimeToLive(new ExpirationAttributes(1000, ExpirationAction.LOCAL_INVALIDATE));
attr.setPartitionAttributes(prAttr);
try {
cache.createRegion("region1", attr.create());
fail("We should not have been able to create the region");
} catch (IllegalStateException expected) {
}
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class Bug40632DUnitTest method testLocalDestroyIdleTimeout.
@Test
public void testLocalDestroyIdleTimeout() throws Exception {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(-1);
paf.setStartupRecoveryDelay(-1);
PartitionAttributes prAttr = paf.create();
attr.setStatisticsEnabled(true);
attr.setEntryIdleTimeout(new ExpirationAttributes(1000, ExpirationAction.LOCAL_DESTROY));
attr.setPartitionAttributes(prAttr);
try {
cache.createRegion("region1", attr.create());
fail("We should not have been able to create the region");
} catch (IllegalStateException expected) {
}
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class CacheXml66DUnitTest method testExpirationAttriubutes.
/**
* Tests creating a cache with a various {@link ExpirationAttributes}.
*/
@Test
public void testExpirationAttriubutes() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setStatisticsEnabled(true);
{
ExpirationAttributes expire = new ExpirationAttributes(42, ExpirationAction.INVALIDATE);
attrs.setRegionTimeToLive(expire);
}
{
ExpirationAttributes expire = new ExpirationAttributes(43, ExpirationAction.DESTROY);
attrs.setRegionIdleTimeout(expire);
}
{
ExpirationAttributes expire = new ExpirationAttributes(44, ExpirationAction.LOCAL_INVALIDATE);
attrs.setEntryTimeToLive(expire);
}
{
ExpirationAttributes expire = new ExpirationAttributes(45, ExpirationAction.LOCAL_DESTROY);
attrs.setEntryIdleTimeout(expire);
}
cache.createRegion("root", attrs);
testXml(cache);
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class CacheXml66DUnitTest method testModifyRegionViaCacheXml.
/**
* Tests that loading cache XML can modify a region.
*/
@Test
public void testModifyRegionViaCacheXml() throws Exception {
CacheCreation creation = new CacheCreation();
int timeout1a = 123;
ExpirationAction action1a = ExpirationAction.LOCAL_DESTROY;
int timeout1b = 456;
ExpirationAction action1b = ExpirationAction.DESTROY;
RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout1a, action1a));
Region root = creation.createRegion("root", attrs);
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout1b, action1b));
Region subregion = root.createSubregion("subregion", attrs);
testXml(creation);
Cache cache = getCache();
root = cache.getRegion("root");
assertEquals(timeout1a, root.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action1a, root.getAttributes().getEntryIdleTimeout().getAction());
subregion = root.getSubregion("subregion");
assertEquals(timeout1b, subregion.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action1b, subregion.getAttributes().getEntryIdleTimeout().getAction());
creation = new CacheCreation();
int timeout2a = 234;
ExpirationAction action2a = ExpirationAction.LOCAL_INVALIDATE;
int timeout2b = 567;
ExpirationAction action2b = ExpirationAction.INVALIDATE;
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout2a, action2a));
attrs.setCacheListener(new MyTestCacheListener());
root = creation.createRegion("root", attrs);
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout2b, action2b));
subregion = root.createSubregion("subregion", attrs);
cache.loadCacheXml(generate(creation));
root = cache.getRegion("root");
subregion = root.getSubregion("subregion");
assertEquals(timeout2a, root.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action2a, root.getAttributes().getEntryIdleTimeout().getAction());
assertTrue(root.getAttributes().getCacheListener() instanceof MyTestCacheListener);
assertEquals(timeout2b, subregion.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action2b, subregion.getAttributes().getEntryIdleTimeout().getAction());
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class CacheXml66DUnitTest method testPartitionedRegionAttributesForExpiration.
/**
* Tests that a Partitioned Region can be created with a named attributes set programmatically for
* ExpirationAttributes
*/
@Test
public void testPartitionedRegionAttributesForExpiration() throws Exception {
CacheCreation cache = new CacheCreation();
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(1);
paf.setTotalMaxMemory(500);
paf.setLocalMaxMemory(100);
paf.setPartitionResolver(partitionResolver);
AttributesFactory fac = new AttributesFactory(attrs);
fac.setEntryTimeToLive(expiration);
fac.setEntryIdleTimeout(expiration);
fac.setPartitionAttributes(paf.create());
rootAttrs = fac.create();
cache.createRegion("parRoot", rootAttrs);
Region r = cache.getRegion("parRoot");
assertNotNull(r);
assertEquals(r.getAttributes().getPartitionAttributes().getRedundantCopies(), 1);
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();
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());
}
Aggregations