use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class CQListGIIDUnitTest method createRegion.
public static Region createRegion(String name, String rootName, RegionAttributes attrs) throws CacheException {
Region root = cache.getRegion(rootName);
if (root == null) {
// don't put listeners on root region
RegionAttributes rootAttrs = attrs;
AttributesFactory fac = new AttributesFactory(attrs);
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 = cache.createRegion(rootName, rootAttrs);
}
return createSubregion(root, name, attrs, null);
}
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 RemoteTransactionDUnitTest method testExpirySuspend_bug45984.
@Test
public void testExpirySuspend_bug45984() {
Host host = Host.getHost(0);
VM vm1 = host.getVM(0);
VM vm2 = host.getVM(1);
final String regionName = getName();
// create region with expiration
vm1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
RegionFactory<String, String> rf = getCache().createRegionFactory();
rf.setEntryTimeToLive(new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
rf.setScope(Scope.DISTRIBUTED_ACK);
rf.create(regionName);
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
}
return null;
}
});
// create replicate region
vm2.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
return null;
}
});
vm1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
final Region<String, String> r = getCache().getRegion(regionName);
WaitCriterion wc2 = new WaitCriterion() {
@Override
public boolean done() {
return !r.containsKey("key") && !r.containsKey("nonTXKey");
}
@Override
public String description() {
return "did not expire containsKey(key)=" + r.containsKey("key") + " r.containsKey(nonTXKey)=" + r.containsKey("nonTXKey");
}
};
ExpiryTask.suspendExpiration();
Region.Entry entry = null;
long tilt;
try {
r.put("key", "value");
LocalRegion lr = (LocalRegion) r;
r.put("nonTXkey", "nonTXvalue");
getCache().getCacheTransactionManager().begin();
r.put("key", "newvalue");
TXExpiryJUnitTest.waitForEntryExpiration(lr, "key");
} finally {
ExpiryTask.permitExpiration();
}
TransactionId tx = getCache().getCacheTransactionManager().suspend();
// A remote tx will allow expiration to happen on the side that
// is not hosting the tx. But it will not allow an expiration
// initiated on the hosting jvm.
// tx is hosted in vm2 so expiration can happen in vm1.
Wait.waitForCriterion(wc2, 30000, 5, true);
getCache().getCacheTransactionManager().resume(tx);
assertTrue(r.containsKey("key"));
getCache().getCacheTransactionManager().commit();
Wait.waitForCriterion(wc2, 30000, 5, true);
return null;
}
});
}
Aggregations