use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class Bug40632DUnitTest method testLocalDestroyTimeToLive.
@Test
public void testLocalDestroyTimeToLive() 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_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 Bug40632DUnitTest method testLocalInvalidateIdleTimeout.
@Test
public void testLocalInvalidateIdleTimeout() 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_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 PersistentPartitionedRegionJUnitTest method createRegion.
private Region createRegion(int ttl, boolean isHeapEviction, boolean isEntryEviction) {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOG_LEVEL, "info");
// props.setProperty("log-file", "junit.log");
cache = new CacheFactory(props).create();
cache.createDiskStoreFactory().setMaxOplogSize(1).setDiskDirs(new File[] { dir }).create("disk");
RegionFactory<Object, Object> rf = cache.createRegionFactory().setDataPolicy(DataPolicy.PERSISTENT_PARTITION).setDiskStoreName("disk");
rf.setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(1).create());
if (ttl > 0) {
rf.setEntryTimeToLive(new ExpirationAttributes(ttl, ExpirationAction.DESTROY));
}
if (isEntryEviction) {
rf.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(10, EvictionAction.OVERFLOW_TO_DISK));
} else if (isHeapEviction) {
rf.setEvictionAttributes(EvictionAttributes.createLRUHeapAttributes(ObjectSizer.DEFAULT, EvictionAction.OVERFLOW_TO_DISK));
}
Region region = rf.create("region");
return region;
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testSinglePRWithCustomExpiry.
/**
* Test for bug 44184
*/
@Test
public void testSinglePRWithCustomExpiry() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(1);
SerializableRunnable createPR = new SerializableRunnable() {
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
af.setPartitionAttributes(paf.create());
af.setCustomEntryIdleTimeout(new TestCustomExpiration());
af.setEntryIdleTimeout(new ExpirationAttributes(60, ExpirationAction.INVALIDATE));
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
RegionAttributes attr = af.create();
cache.createRegion(PR_REGION_NAME, attr);
}
};
vm0.invoke(createPR);
createData(vm0, 0, 1, "a");
Set<Integer> vm0Buckets = getBucketList(vm0);
// closePR(vm0);
closeCache(vm0);
vm0.invoke(createPR);
assertEquals(vm0Buckets, getBucketList(vm0));
checkData(vm0, 0, 1, "a");
}
use of org.apache.geode.cache.ExpirationAttributes 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);
}
Aggregations