use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class PRDeltaPropagationDUnitTest method createPR.
public static void createPR(String partitionedRegionName, Integer redundancy, Integer localMaxMemory, Integer totalNumBuckets, Boolean setExpiry, Boolean withCloning, Compressor compressor) {
PartitionAttributesFactory paf = new PartitionAttributesFactory();
PartitionAttributes prAttr = paf.setRedundantCopies(redundancy.intValue()).setLocalMaxMemory(localMaxMemory.intValue()).setTotalNumBuckets(totalNumBuckets.intValue()).create();
AttributesFactory attr = new AttributesFactory();
attr.setPartitionAttributes(prAttr);
attr.setDataPolicy(DataPolicy.PARTITION);
attr.setConcurrencyChecksEnabled(true);
attr.setCloningEnabled(withCloning);
if (setExpiry) {
attr.setStatisticsEnabled(true);
attr.setEntryIdleTimeout(new ExpirationAttributes(1, ExpirationAction.INVALIDATE));
}
if (compressor != null) {
attr.setCompressor(compressor);
}
// attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(5));
assertNotNull(cache);
deltaPR = cache.createRegion(partitionedRegionName, attr.create());
assertNotNull(deltaPR);
LogWriterUtils.getLogWriter().info("Partitioned Region " + partitionedRegionName + " created Successfully :" + deltaPR);
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class JUnit4CacheTestCase method createRegion.
public final Region createRegion(final String name, final String rootName, final RegionAttributes attributes) throws CacheException {
Region root = getRootRegion(rootName);
if (root == null) {
// don't put listeners on root region
RegionAttributes rootAttrs = attributes;
AttributesFactory fac = new AttributesFactory(attributes);
ExpirationAttributes expiration = ExpirationAttributes.DEFAULT;
// fac.setCacheListener(null);
fac.setCacheLoader(null);
fac.setCacheWriter(null);
fac.setPoolName(null);
fac.setPartitionAttributes(null);
fac.setRegionTimeToLive(expiration);
fac.setEntryTimeToLive(expiration);
fac.setRegionIdleTimeout(expiration);
fac.setEntryIdleTimeout(expiration);
rootAttrs = fac.create();
root = createRootRegion(rootName, rootAttrs);
}
InternalRegionArguments internalArgs = getInternalRegionArguments();
if (internalArgs == null) {
return root.createSubregion(name, attributes);
} else {
try {
LocalRegion lr = (LocalRegion) root;
return lr.createSubregion(name, attributes, internalArgs);
} catch (IOException ioe) {
AssertionError assErr = new AssertionError("unexpected exception");
assErr.initCause(ioe);
throw assErr;
} catch (ClassNotFoundException cnfe) {
AssertionError assErr = new AssertionError("unexpected exception");
assErr.initCause(cnfe);
throw assErr;
}
}
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class RegionTestCase method testEntryIdleReset.
/**
* Verify that accessing an entry resets its idle time
*
* @throws Exception
*/
@Test
public void testEntryIdleReset() throws Exception {
final String name = this.getUniqueName();
// Test no longer waits for this timeout to expire
// seconds
final int timeout = 90;
final String key = "KEY";
final String value = "VALUE";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
factory.setEntryIdleTimeout(expire);
factory.setStatisticsEnabled(true);
RegionAttributes attrs = factory.create();
LocalRegion region = (LocalRegion) createRegion(name, attrs);
region.create(key, null);
EntryExpiryTask eet = region.getEntryExpiryTask(key);
long createExpiryTime = eet.getExpirationTime();
Wait.waitForExpiryClockToChange(region);
// touch
region.get(key);
assertSame(eet, region.getEntryExpiryTask(key));
long getExpiryTime = eet.getExpirationTime();
if (getExpiryTime - createExpiryTime <= 0L) {
fail("get did not reset the expiration time. createExpiryTime=" + createExpiryTime + " getExpiryTime=" + getExpiryTime);
}
Wait.waitForExpiryClockToChange(region);
// touch
region.put(key, value);
assertSame(eet, region.getEntryExpiryTask(key));
long putExpiryTime = eet.getExpirationTime();
if (putExpiryTime - getExpiryTime <= 0L) {
fail("put did not reset the expiration time. getExpiryTime=" + getExpiryTime + " putExpiryTime=" + putExpiryTime);
}
// TODO other ops that should be validated?
// Now verify operations that do not modify the expiry time
Wait.waitForExpiryClockToChange(region);
// touch
region.invalidate(key);
assertSame(eet, region.getEntryExpiryTask(key));
long invalidateExpiryTime = eet.getExpirationTime();
if (region.getConcurrencyChecksEnabled()) {
if (putExpiryTime - getExpiryTime <= 0L) {
fail("invalidate did not reset the expiration time. putExpiryTime=" + putExpiryTime + " invalidateExpiryTime=" + invalidateExpiryTime);
}
} else {
if (invalidateExpiryTime != putExpiryTime) {
fail("invalidate did reset the expiration time. putExpiryTime=" + putExpiryTime + " invalidateExpiryTime=" + invalidateExpiryTime);
}
}
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class RegionTestCase method testEntryTtlDestroy.
/**
* Tests that an entry in a region expires with a destroy after a given time to live.
*/
@Test
public void testEntryTtlDestroy() throws CacheException, InterruptedException {
final String name = this.getUniqueName();
// ms
final int timeout = 20;
final String key = "KEY";
final String value = "VALUE";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
factory.setEntryTimeToLive(expire);
factory.setStatisticsEnabled(true);
RegionAttributes attrs = factory.create();
Region region = null;
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
region = createRegion(name, attrs);
ExpiryTask.suspendExpiration();
Region.Entry entry = null;
long tilt;
try {
region.put(key, value);
tilt = System.currentTimeMillis();
entry = region.getEntry(key);
assertNotNull(entry.getValue());
} finally {
ExpiryTask.permitExpiration();
}
waitForDestroy(entry, tilt);
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
}
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class RegionTestCase method testEntryTtlInvalidate.
/**
* Tests that an entry in a region expires with an invalidation after a given time to live.
*/
@Test
public void testEntryTtlInvalidate() throws CacheException {
final String name = this.getUniqueName();
// ms!
final int timeout = 20;
final String key = "KEY";
final String value = "VALUE";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.INVALIDATE);
factory.setEntryTimeToLive(expire);
factory.setStatisticsEnabled(true);
RegionAttributes attrs = factory.create();
Region region = null;
/**
* Crank up the expiration so test runs faster. This property only needs to be set while the
* region is created
*/
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
region = createRegion(name, attrs);
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
}
ExpiryTask.suspendExpiration();
Region.Entry entry = null;
long tilt;
try {
region.put(key, value);
tilt = System.currentTimeMillis() + timeout;
entry = region.getEntry(key);
assertNotNull(entry.getValue());
} finally {
ExpiryTask.permitExpiration();
}
waitForInvalidate(entry, tilt);
}
Aggregations