use of org.apache.geode.cache.EntryDestroyedException 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.EntryDestroyedException in project geode by apache.
the class LocalRegion method createExpiryTask.
/**
* If custom expiration returns non-null expiration attributes then create a CustomEntryExpiryTask
* for this region and the given entry and return it. Otherwise if the region is configured for
* expiration then create an EntryExpiryTask for this region and the given entry and return it.
* Null is returned if the expiration attributes indicate that expiration is disabled.
*/
private EntryExpiryTask createExpiryTask(RegionEntry regionEntry) {
if (regionEntry == null || regionEntry.isDestroyedOrRemoved()) {
return null;
}
if (this.customEntryIdleTimeout != null || this.customEntryTimeToLive != null) {
ExpiryRegionEntry expiryRegionEntry = new ExpiryRegionEntry(this, regionEntry);
ExpirationAttributes ttlAttributes = null;
ExpirationAttributes idleAttributes = null;
final RegionAttributes<?, ?> regionAttributes = this.getAttributes();
final CustomExpiry<?, ?> customTTL = regionAttributes.getCustomEntryTimeToLive();
if (customTTL != null) {
try {
ttlAttributes = customTTL.getExpiry(expiryRegionEntry);
if (ttlAttributes != null) {
this.checkEntryTimeoutAction("timeToLive", ttlAttributes.getAction());
}
} catch (RegionDestroyedException ignore) {
// Ignore - #42273
} catch (EntryNotFoundException ignore) {
// Ignore - #51933
} catch (EntryDestroyedException ignore) {
// Ignore - #51933
} catch (Exception e) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.EntryExpiryTask_ERROR_CALCULATING_EXPIRATION_0, e.getMessage()), e);
}
}
if (ttlAttributes == null) {
ttlAttributes = regionAttributes.getEntryTimeToLive();
}
CustomExpiry<?, ?> customIdle = regionAttributes.getCustomEntryIdleTimeout();
if (customIdle != null) {
try {
idleAttributes = customIdle.getExpiry(expiryRegionEntry);
if (idleAttributes != null) {
this.checkEntryTimeoutAction("idleTimeout", idleAttributes.getAction());
}
} catch (RegionDestroyedException ignore) {
// Ignore - #42273
} catch (EntryNotFoundException ignore) {
// Ignore - #51933
} catch (EntryDestroyedException ignore) {
// Ignore - #51933
} catch (Exception e) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.EntryExpiryTask_ERROR_CALCULATING_EXPIRATION_0, e.getMessage()), e);
}
}
if (idleAttributes == null) {
idleAttributes = regionAttributes.getEntryIdleTimeout();
}
final boolean ttlDisabled = ttlAttributes == null || ttlAttributes.getTimeout() == 0;
final boolean idleDisabled = idleAttributes == null || idleAttributes.getTimeout() == 0;
if (ttlDisabled && idleDisabled) {
return null;
} else if ((ttlDisabled || ttlAttributes.equals(regionAttributes.getEntryTimeToLive())) && (idleDisabled || idleAttributes.equals(regionAttributes.getEntryIdleTimeout()))) {
// no need for custom since we can just use the region's expiration attributes.
return new EntryExpiryTask(this, regionEntry);
} else {
return new CustomEntryExpiryTask(this, regionEntry, ttlAttributes, idleAttributes);
}
} else if (isEntryExpiryPossible()) {
return new EntryExpiryTask(this, regionEntry);
} else {
return null;
}
}
use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.
the class LocalExporter method export.
@Override
public long export(Region<K, V> region, ExportSink sink, SnapshotOptions<K, V> options) throws IOException {
LocalRegion local = RegionSnapshotServiceImpl.getLocalRegion(region);
long count = 0;
for (Entry<K, V> entry : region.entrySet()) {
try {
if (options.getFilter() == null || options.getFilter().accept(entry)) {
sink.write(new SnapshotRecord(local, entry));
count++;
}
} catch (EntryDestroyedException e) {
// continue to next entry
}
}
return count;
}
Aggregations