use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class RegionTestCase method testEntryIdleInvalidate.
/**
* Tests that an entry in a local region that remains idle for a given amount of time is
* invalidated.
*/
@Test
public void testEntryIdleInvalidate() 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.INVALIDATE);
factory.setEntryIdleTimeout(expire);
factory.setStatisticsEnabled(true);
TestCacheListener list = new TestCacheListener() {
public void afterCreate2(EntryEvent e) {
}
public void afterUpdate2(EntryEvent e) {
}
public void afterInvalidate2(EntryEvent e) {
}
};
factory.setCacheListener(list);
RegionAttributes attrs = factory.create();
Region region = null;
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
region = createRegion(name, attrs);
// DebuggerSupport.waitForJavaDebugger(getLogWriter(), "Set breakpoint in
// invalidate");
ExpiryTask.suspendExpiration();
Region.Entry entry = null;
long tilt;
try {
region.create(key, value);
tilt = System.currentTimeMillis() + timeout;
assertTrue(list.waitForInvocation(333));
entry = region.getEntry(key);
assertNotNull(entry.getValue());
} finally {
ExpiryTask.permitExpiration();
}
waitForInvalidate(entry, tilt);
ExpiryTask.suspendExpiration();
try {
region.put(key, value);
tilt = System.currentTimeMillis() + timeout;
entry = region.getEntry(key);
assertNotNull(entry.getValue());
} finally {
ExpiryTask.permitExpiration();
}
waitForInvalidate(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 testEntryIdleDestroy.
/**
* Tests that an entry in a region that remains idle for a given amount of time is destroyed.
*/
@Test
public void testEntryIdleDestroy() throws Exception {
EntryExpiryTask.expiryTaskListener = new ExpiryCallbacks();
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.setEntryIdleTimeout(expire);
factory.setStatisticsEnabled(true);
TestCacheListener list = new TestCacheListener() {
public void afterCreate2(EntryEvent e) {
}
public void afterDestroy2(EntryEvent e) {
}
};
factory.setCacheListener(list);
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.create(key, null);
tilt = System.currentTimeMillis() + timeout;
assertTrue(list.wasInvoked());
entry = region.getEntry(key);
} finally {
ExpiryTask.permitExpiration();
}
waitForDestroy(entry, tilt);
assertNull(region.getEntry(key));
ExpiryTask.suspendExpiration();
try {
region.put(key, value);
tilt = System.currentTimeMillis() + timeout;
entry = region.getEntry(key);
assertNotNull(entry.getValue());
} finally {
ExpiryTask.permitExpiration();
}
waitForDestroy(entry, tilt);
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
EntryExpiryTask.expiryTaskListener = null;
}
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class RegionTestCase method testRegionTtlInvalidate.
/**
* Tests that a region expires with an invalidation after a given time to live.
*/
@Test
public void testRegionTtlInvalidate() throws CacheException, InterruptedException {
if (getRegionAttributes().getPartitionAttributes() != null)
return;
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
final String name = this.getUniqueName();
vm0.invoke(new CacheSerializableRunnable("testRegionTtlInvalidate") {
public void run2() throws CacheException {
// ms
final int timeout = 22;
final Object key = "KEY";
final Object value = "VALUE";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.INVALIDATE);
factory.setRegionTimeToLive(expire);
factory.setStatisticsEnabled(true);
RegionAttributes attrs = factory.create();
Region region = null;
Region.Entry entry = null;
long tilt;
ExpiryTask.suspendExpiration();
try {
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
region = createRegion(name, attrs);
region.put(key, value);
region.put("k2", "v2");
tilt = System.currentTimeMillis() + timeout;
entry = region.getEntry(key);
assertNotNull(entry.getValue());
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
}
} finally {
ExpiryTask.permitExpiration();
}
waitForInvalidate(entry, tilt, 10);
waitForInvalidate(region.getEntry("k2"), tilt, 10);
}
});
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class RegionTestCase method testRegionIdleDestroy.
/**
* Tests that a region expires with a destruction after a given idle time.
*/
@Test
public void testRegionIdleDestroy() throws CacheException, InterruptedException {
if (getRegionAttributes().getPartitionAttributes() != null)
return;
final String name = this.getUniqueName();
// ms
final int timeout = 22;
final Object key = "KEY";
final Object value = "VALUE";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
factory.setRegionIdleTimeout(expire);
factory.setStatisticsEnabled(true);
RegionAttributes attrs = factory.create();
Region region = null;
long tilt;
ExpiryTask.suspendExpiration();
try {
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
region = createRegion(name, attrs);
region.put(key, value);
tilt = System.currentTimeMillis() + timeout;
assertFalse(region.isDestroyed());
} finally {
ExpiryTask.permitExpiration();
}
waitForRegionDestroy(region, 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 testRegionTtlDestroy.
/**
* Tests that a region expires with a destruction after a given time to live.
*/
@Test
public void testRegionTtlDestroy() throws CacheException, InterruptedException {
if (getRegionAttributes().getPartitionAttributes() != null)
return;
final String name = this.getUniqueName();
// ms
final int timeout = 22;
final Object key = "KEY";
final Object value = "VALUE";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
factory.setRegionTimeToLive(expire);
factory.setStatisticsEnabled(true);
RegionAttributes attrs = factory.create();
Region region = null;
long tilt;
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
ExpiryTask.suspendExpiration();
try {
try {
region = createRegion(name, attrs);
assertFalse(region.isDestroyed());
tilt = System.currentTimeMillis() + timeout;
region.put(key, value);
Region.Entry entry = region.getEntry(key);
assertNotNull(entry.getValue());
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
}
} finally {
ExpiryTask.permitExpiration();
}
waitForRegionDestroy(region, tilt);
}
Aggregations