use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class RegionAttributesCreation method setRegionIdleTimeout.
public ExpirationAttributes setRegionIdleTimeout(ExpirationAttributes idleTimeout) {
ExpirationAttributes old = this.regionIdleTimeout;
this.regionIdleTimeout = idleTimeout;
setHasRegionIdleTimeout(true);
return old;
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class CacheXmlParser method endEntryIdleTime.
/**
* When a <code>entry-idle-time</code> element is finished, an optional Declarable (the
* custom-expiry) is followed by the {@link ExpirationAttributes} are on top of the stack followed
* by the {@link RegionAttributesCreation} to which the expiration attributes are assigned.
*/
private void endEntryIdleTime() {
Declarable custom = null;
if (stack.peek() instanceof Declarable) {
custom = (Declarable) stack.pop();
}
ExpirationAttributes expire = (ExpirationAttributes) stack.pop();
Object a = stack.peek();
// } else
if (a instanceof RegionAttributesCreation) {
((RegionAttributesCreation) a).setEntryIdleTimeout(expire);
if (custom != null) {
((RegionAttributesCreation) a).setCustomEntryIdleTimeout((CustomExpiry) custom);
}
} else {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_REGIONATTRIBUTES_OR_PARTITIONATTRIBUTES.toLocalizedString(ENTRY_IDLE_TIME));
}
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class RegionReliabilityTestCase method testNoAccessWithLocalEntryExpiration.
/**
* Tests affect of NO_ACCESS on local entry expiration actions.
*/
@Test
public void testNoAccessWithLocalEntryExpiration() throws Exception {
final String name = this.getUniqueName();
final String roleA = name + "-A";
// assign names to 4 vms...
final String[] requiredRoles = { roleA };
Set requiredRolesSet = new HashSet();
for (int i = 0; i < requiredRoles.length; i++) {
requiredRolesSet.add(InternalRole.getRole(requiredRoles[i]));
}
assertEquals(requiredRoles.length, requiredRolesSet.size());
// connect controller to system...
Properties config = new Properties();
config.setProperty(ROLES, "");
getSystem(config);
getCache();
// create region in controller...
MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.NO_ACCESS, ResumptionAction.NONE);
AttributesFactory fac = new AttributesFactory();
fac.setMembershipAttributes(ra);
fac.setScope(getRegionScope());
fac.setStatisticsEnabled(true);
RegionAttributes attr = fac.create();
final Region region = createExpiryRootRegion(name, attr);
// wait for memberTimeout to expire
waitForMemberTimeout();
// use vm1 to create role
Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Create Region") {
public void run2() throws CacheException {
createConnection(new String[] { roleA });
AttributesFactory fac = new AttributesFactory();
fac.setScope(getRegionScope());
RegionAttributes attr = fac.create();
createRootRegion(name, attr);
}
});
// test to make sure expiration is not suspended
region.put("expireMe", "expireMe");
assertTrue(region.size() == 1);
Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Close Region") {
public void run2() throws CacheException {
Region region = getRootRegion(name);
region.close();
}
});
// TODO: waitForMemberTimeout(); ?
// set expiration and sleep
AttributesMutator mutator = region.getAttributesMutator();
mutator.setEntryTimeToLive(new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
sleep(200);
// make sure no values were expired
Set entries = ((LocalRegion) region).basicEntries(false);
assertTrue(entries.size() == 1);
// create region again in vm1
Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Create Region") {
public void run2() throws CacheException {
AttributesFactory fac = new AttributesFactory();
fac.setScope(getRegionScope());
RegionAttributes attr = fac.create();
createRootRegion(name, attr);
}
});
waitForEntryDestroy(region, "expireMe");
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class RegionTestCase method testEntryExpirationAfterMutate.
@Test
public void testEntryExpirationAfterMutate() throws CacheException, InterruptedException {
final String name = this.getUniqueName();
// ms
final int timeout = 20;
final int hugeTimeout = Integer.MAX_VALUE;
final ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.INVALIDATE);
final ExpirationAttributes hugeExpire = new ExpirationAttributes(hugeTimeout, ExpirationAction.INVALIDATE);
final String key = "KEY";
final String value = "VALUE";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
factory.setStatisticsEnabled(true);
RegionAttributes attrs = factory.create();
Region region = null;
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
region = createRegion(name, attrs);
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
}
long tilt;
region.create(key, value);
tilt = System.currentTimeMillis() + timeout;
// Now go from huge timeout to a timeout
ExpiryTask.suspendExpiration();
Region.Entry entry = null;
try {
region.getAttributesMutator().setEntryIdleTimeout(expire);
entry = region.getEntry(key);
assertEquals(value, entry.getValue());
} finally {
ExpiryTask.permitExpiration();
}
waitForInvalidate(entry, tilt);
// Now go from a big timeout to a short one
region.getAttributesMutator().setEntryIdleTimeout(hugeExpire);
region.put(key, value);
tilt = System.currentTimeMillis() + timeout;
entry = region.getEntry(key);
Wait.pause(timeout * 2);
assertEquals(value, entry.getValue());
region.getAttributesMutator().setEntryIdleTimeout(expire);
waitForInvalidate(entry, tilt);
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class RegionExpirationDUnitTest method testRegionTTLAfterMutating.
@Test
public void testRegionTTLAfterMutating() throws InterruptedException, CacheException {
String regionName = getUniqueName();
int firstTimeout = 2;
int secondTimeout = 6;
createWithExpiration(regionName, new ExpirationAttributes(firstTimeout, ExpirationAction.DESTROY), null);
long startTime = System.currentTimeMillis();
final Region region = getOrCreateRootRegion().getSubregion(regionName);
region.getAttributesMutator().setRegionTimeToLive(new ExpirationAttributes(secondTimeout, ExpirationAction.DESTROY));
Thread.sleep(firstTimeout * 1000 + 100);
if (region.isDestroyed()) {
assertTrue(System.currentTimeMillis() >= startTime + secondTimeout * 1000);
}
Thread.sleep((secondTimeout - firstTimeout) * 1000 + 100);
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
return region.isDestroyed();
}
public String description() {
return "region never destroyed";
}
};
Wait.waitForCriterion(wc, 30 * 1000, 1000, true);
}
Aggregations