use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class RegionTestCase method testLocalInvalidateRegion.
/**
* Tests locally invalidating an entire region
*/
@Test
public void testLocalInvalidateRegion() throws CacheException {
String name = this.getUniqueName();
Region region = createRegion(name);
region.put("A", "a");
region.put("B", "b");
region.put("C", "c");
boolean isKV = getRegionAttributes().getMirrorType().isKeysValues();
try {
region.localInvalidateRegion();
if (isKV)
fail("Should have thrown an IllegalStateException");
} catch (IllegalStateException e) {
if (!isKV)
throw e;
else
// abort test
return;
}
Region.Entry entry;
entry = region.getEntry("A");
assertNotNull(entry);
assertNull(entry.getValue());
entry = region.getEntry("B");
assertNotNull(entry);
assertNull(entry.getValue());
entry = region.getEntry("C");
assertNotNull(entry);
assertNull(entry.getValue());
}
use of org.apache.geode.cache.Region.Entry 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.Region.Entry in project geode by apache.
the class RegionTestCase method testLocalInvalidateEntry.
/**
* Tests locally invalidating a region entry
*/
@Test
public void testLocalInvalidateEntry() throws CacheException {
if (!supportsLocalDestroyAndLocalInvalidate()) {
return;
}
String name = this.getUniqueName();
Object key = "KEY";
Object value = "VALUE";
Region region = createRegion(name);
region.put(key, value);
Region.Entry entry = region.getEntry(key);
boolean isMirrorKeysValues = getRegionAttributes().getMirrorType().isKeysValues();
try {
region.localInvalidate(key);
if (isMirrorKeysValues)
fail("Should have thrown an IllegalStateException");
} catch (IllegalStateException e) {
if (!isMirrorKeysValues)
throw e;
else
// abort test
return;
}
assertNull(entry.getValue());
assertNull(region.get(key));
}
use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class RegionTestCase method testDestroyEntry.
/**
* Tests {@link Region#destroy destroying} an entry and attempting to access it afterwards.
*/
@Test
public void testDestroyEntry() throws CacheException {
String name = this.getUniqueName();
Object key = name;
Object value = new Integer(42);
Region region = createRegion(name);
try {
region.destroy(key);
fail("Should have thrown an EntryNotFoundException");
} catch (EntryNotFoundException ex) {
// pass...
}
region.put(key, value);
Region.Entry entry = region.getEntry(key);
assertNotNull(entry);
region.destroy(key);
Region.Entry entry2 = region.getEntry(key);
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Found entry for destroyed key: " + entry2);
assertNull(entry2);
if (entry.isLocal()) {
assertTrue(entry.isDestroyed());
} else {
assertFalse(entry.isDestroyed());
}
assertEquals(0, region.keySet().size());
if (entry.isLocal()) {
try {
entry.getKey();
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
try {
entry.getRegion();
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
try {
entry.getStatistics();
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
try {
entry.getUserAttribute();
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
try {
entry.setUserAttribute("blah");
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
try {
entry.getValue();
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
}
}
use of org.apache.geode.cache.Region.Entry 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;
}
}
Aggregations