use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class RegionTestCase method testCustomEntryIdleTimeout3.
/**
* Configure custome entry expiration with an idle time. Create an entry and records its scheduled
* expiration time. Then mutate the region expiration configuration and confirm that the entry's
* expiration time is rescheduled.
*/
@Test
public void testCustomEntryIdleTimeout3() {
final String name = this.getUniqueName();
// test no longer waits for this expiration to happen
// ms
final int timeout1 = 500 * 1000;
// ms
final int timeout2 = 2000 * 1000;
final String key1 = "KEY1";
final String value1 = "VALUE1";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
ExpirationAttributes expire1 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
factory.setCustomEntryIdleTimeout(new TestExpiry(key1, expire1));
factory.setStatisticsEnabled(true);
TestCacheListener list = new TestCacheListener() {
public void afterCreate2(EntryEvent e) {
}
public void afterUpdate2(EntryEvent e) {
}
public void afterInvalidate2(EntryEvent e) {
eventCount++;
}
};
eventCount = 0;
factory.addCacheListener(list);
RegionAttributes attrs = factory.create();
LocalRegion region;
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
region = (LocalRegion) createRegion(name, attrs);
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
}
region.create(key1, value1);
EntryExpiryTask eet = region.getEntryExpiryTask(key1);
final long firstExpiryTime = eet.getExpirationTime();
AttributesMutator mutt = region.getAttributesMutator();
ExpirationAttributes expire2 = new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE);
mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire2));
eet = region.getEntryExpiryTask(key1);
final long secondExpiryTime = eet.getExpirationTime();
if ((secondExpiryTime - firstExpiryTime) <= 0) {
fail("expiration time should have been greater after changing region config from 500 to 2000. firstExpiryTime=" + firstExpiryTime + " secondExpiryTime=" + secondExpiryTime);
}
// now set back to be more recent
mutt = region.getAttributesMutator();
ExpirationAttributes expire3 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire3));
eet = region.getEntryExpiryTask(key1);
final long thirdExpiryTime = eet.getExpirationTime();
assertEquals(firstExpiryTime, thirdExpiryTime);
// confirm that it still has not expired
assertEquals(0, eventCount);
// now set it to a really short time and make sure it expires immediately
Wait.waitForExpiryClockToChange(region);
final Region.Entry entry = region.getEntry(key1);
mutt = region.getAttributesMutator();
ExpirationAttributes expire4 = new ExpirationAttributes(1, ExpirationAction.INVALIDATE);
mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire4));
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
return fetchEntryValue(entry) == null;
}
public String description() {
return "entry never became invalid";
}
};
Wait.waitForCriterion(wc, 10 * 1000, 10, true);
WaitCriterion waitForEventCountToBeOne = new WaitCriterion() {
public boolean done() {
return eventCount == 1;
}
public String description() {
return "eventCount never became 1";
}
};
Wait.waitForCriterion(waitForEventCountToBeOne, 10 * 1000, 10, true);
eventCount = 0;
}
use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class RegionTestCase method testEntryUserAttribute.
/**
* Tests a region entry's user attribute
*/
@Test
public void testEntryUserAttribute() throws CacheException {
String name = this.getUniqueName();
String key = "KEY";
String attr = "USER_ATTRIBUTE";
Region region = createRegion(name);
region.create(key, null);
Region.Entry entry = region.getEntry(key);
entry.setUserAttribute(attr);
assertEquals(attr, entry.getUserAttribute());
entry = region.getEntry(key);
assertEquals(attr, entry.getUserAttribute());
}
use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class RegionTestCase method testCustomEntryTtl2.
/**
* Verify that special entries don't expire but other entries in the region do
*/
@Test
public void testCustomEntryTtl2() {
final String name = this.getUniqueName();
// ms
final int timeout = 20;
final String key1 = "KEY1";
final String key2 = "KEY2";
final String value = "VALUE";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
// factory.setEntryIdleTimeout(expire);
ExpirationAttributes expire2 = new ExpirationAttributes(timeout, ExpirationAction.INVALIDATE);
factory.setCustomEntryTimeToLive(new TestExpiry(key2, expire2));
factory.setStatisticsEnabled(true);
TestCacheListener list = new TestCacheListener() {
public void afterCreate2(EntryEvent e) {
}
public void afterUpdate2(EntryEvent e) {
}
public void afterInvalidate2(EntryEvent e) {
}
};
factory.addCacheListener(list);
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);
}
region.create(key1, value);
// This value should NOT expire.
Wait.pause(timeout * 2);
assertTrue(region.get(key1).equals(value));
// This value SHOULD expire
// DebuggerSupport.waitForJavaDebugger(getLogWriter(), "Set breakpoint in invalidate");
ExpiryTask.suspendExpiration();
Region.Entry entry = null;
long tilt;
try {
region.create(key2, value);
tilt = System.currentTimeMillis() + timeout;
entry = region.getEntry(key2);
assertTrue(list.waitForInvocation(5000));
assertNotNull(entry.getValue());
} finally {
ExpiryTask.permitExpiration();
}
waitForInvalidate(entry, tilt);
// First value should still be in there
assertTrue(region.get(key1).equals(value));
// Do it again with a put (I guess)
ExpiryTask.suspendExpiration();
try {
region.put(key2, value);
tilt = System.currentTimeMillis() + timeout;
entry = region.getEntry(key2);
assertNotNull(entry.getValue());
} finally {
ExpiryTask.permitExpiration();
}
waitForInvalidate(entry, tilt);
// First value should still be in there
assertTrue(region.get(key1).equals(value));
}
use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class TXState method getEntryOnRemote.
/*
* (non-Javadoc)
*
* @see org.apache.geode.internal.cache.InternalDataView#getEntryOnRemote(java.lang.Object,
* org.apache.geode.internal.cache.LocalRegion)
*/
public Entry getEntryOnRemote(KeyInfo key, LocalRegion localRegion, boolean allowTombstones) throws DataLocationException {
PartitionedRegion pr = (PartitionedRegion) localRegion;
Region.Entry txval = getEntry(key, pr, allowTombstones);
if (txval == null) {
throw new EntryNotFoundException(LocalizedStrings.PartitionedRegionDataStore_ENTRY_NOT_FOUND.toLocalizedString());
} else {
NonLocalRegionEntry nlre = new NonLocalRegionEntry(txval, localRegion);
LocalRegion dataReg = localRegion.getDataRegionForRead(key);
return new EntrySnapshot(nlre, dataReg, (LocalRegion) txval.getRegion(), allowTombstones);
}
}
use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class TXStateProxyImpl method getEntry.
public Entry getEntry(KeyInfo keyInfo, LocalRegion region, boolean allowTombstones) {
try {
this.operationCount++;
Entry retVal = getRealDeal(keyInfo, region).getEntry(keyInfo, region, allowTombstones);
trackBucketForTx(keyInfo);
return retVal;
} catch (TransactionDataRebalancedException | PrimaryBucketException re) {
throw getTransactionException(keyInfo, re);
}
}
Aggregations