use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.
the class CacheStatisticsDUnitTest method testHitMissCount.
//////// Test methods
/**
* Tests that the {@link CacheStatistics#getHitCount hit count} and
* {@link CacheStatistics#getMissCount miss count} are updated properly for a local region and its
* entries.
*/
@Test
public void testHitMissCount() throws CacheException {
String name = this.getUniqueName();
// value exists
Object key = "KEY";
// no entry
Object key2 = "KEY2";
// entry, invalid
Object key3 = "KEY3";
Object value = "VALUE";
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setStatisticsEnabled(true);
Region region = createRegion(name, factory.create());
CacheStatistics rStats = region.getStatistics();
assertEquals(0, rStats.getHitCount());
assertEquals(0, rStats.getMissCount());
assertEquals(0.0f, rStats.getHitRatio(), 0.0f);
assertNull(region.get(key));
assertEquals(0, rStats.getHitCount());
assertEquals(1, rStats.getMissCount());
assertEquals(0.0f, rStats.getHitRatio(), 0.0f);
assertNull(region.get(key));
assertEquals(0, rStats.getHitCount());
assertEquals(2, rStats.getMissCount());
assertEquals(0.0f, rStats.getHitRatio(), 0.0f);
rStats.resetCounts();
assertEquals(0, rStats.getHitCount());
assertEquals(0, rStats.getMissCount());
assertEquals(0.0f, rStats.getHitRatio(), 0.0f);
region.put(key, value);
assertEquals(0, rStats.getHitCount());
assertEquals(0, rStats.getMissCount());
CacheStatistics eStats = region.getEntry(key).getStatistics();
assertEquals(0, eStats.getHitCount());
assertEquals(0, eStats.getMissCount());
assertEquals(0.0f, eStats.getHitRatio(), 0.0f);
region.get(key);
assertEquals(1, eStats.getHitCount());
assertEquals(0, eStats.getMissCount());
assertEquals(1.0f, eStats.getHitRatio(), 0.0f);
assertEquals(1, rStats.getHitCount());
assertEquals(0, rStats.getMissCount());
assertEquals(1.0f, rStats.getHitRatio(), 0.0f);
region.get(key2);
// assert independent from eStats
assertEquals(1, eStats.getHitCount());
assertEquals(0, eStats.getMissCount());
assertEquals(1.0f, eStats.getHitRatio(), 0.0f);
assertEquals(1, rStats.getHitCount());
assertEquals(1, rStats.getMissCount());
assertEquals(0.5f, rStats.getHitRatio(), 0.0f);
region.create(key3, null);
CacheStatistics e3Stats = region.getEntry(key3).getStatistics();
assertEquals(0, e3Stats.getHitCount());
assertEquals(0, e3Stats.getMissCount());
assertEquals(0.0f, e3Stats.getHitRatio(), 0.0f);
// miss on existing entry
region.get(key3);
assertEquals(0, e3Stats.getHitCount());
assertEquals(1, e3Stats.getMissCount());
assertEquals(0.0f, e3Stats.getHitRatio(), 0.0f);
assertEquals(1, rStats.getHitCount());
assertEquals(2, rStats.getMissCount());
assertEquals(0.33f, rStats.getHitRatio(), 0.01f);
eStats.resetCounts();
assertEquals(0, eStats.getHitCount());
assertEquals(0, eStats.getMissCount());
assertEquals(0.0f, eStats.getHitRatio(), 0.0f);
rStats.resetCounts();
region.invalidate(key);
assertEquals(0, eStats.getHitCount());
assertEquals(0, eStats.getMissCount());
assertEquals(0.0f, eStats.getHitRatio(), 0.0f);
region.get(key);
assertEquals(0, eStats.getHitCount());
assertEquals(1, eStats.getMissCount());
assertEquals(0, rStats.getHitCount());
assertEquals(1, rStats.getMissCount());
region.destroy(key);
try {
eStats.getMissCount();
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 clearViaFilterClass.
/**
* do a localDestroy on all matching keys
*
* @param key the regular expression to match on
*/
private void clearViaFilterClass(String key) {
InterestFilter filter;
try {
Class filterClass = ClassLoadUtil.classFromName(key);
filter = (InterestFilter) filterClass.newInstance();
} catch (ClassNotFoundException cnfe) {
throw new RuntimeException(LocalizedStrings.LocalRegion_CLASS_0_NOT_FOUND_IN_CLASSPATH.toLocalizedString(key), cnfe);
} catch (Exception e) {
throw new RuntimeException(LocalizedStrings.LocalRegion_CLASS_0_COULD_NOT_BE_INSTANTIATED.toLocalizedString(key), e);
}
for (Object entryObject : entrySet(false)) {
Entry entry = (Entry) entryObject;
try {
Object entryKey = entry.getKey();
if (!(entryKey instanceof String)) {
continue;
}
InterestEvent e = new InterestEvent(entryKey, entry.getValue(), true);
if (!filter.notifyOnRegister(e)) {
// the filter does not want to know about this entry, so skip it.
continue;
}
localDestroyNoCallbacks(entryKey);
} catch (EntryDestroyedException ignore) {
// ignore to fix bug 35534
}
}
}
use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.
the class LocalRegion method clearViaRegEx.
/**
* do a localDestroy on all matching keys
*
* @param key the regular expression to match on
* @see #registerInterestRegex(String)
*/
private void clearViaRegEx(String key) {
// TODO: if (key.equals(".*)) then cmnClearRegionNoCallbacks
Pattern keyPattern = Pattern.compile(key);
for (Iterator it = this.entrySet(false).iterator(); it.hasNext(); ) {
Region.Entry entry = (Region.Entry) it.next();
try {
Object entryKey = entry.getKey();
if (!(entryKey instanceof String)) {
continue;
}
if (!keyPattern.matcher((String) entryKey).matches()) {
// key does not match the regex, this entry should not be returned.
continue;
}
localDestroyNoCallbacks(entryKey);
} catch (EntryDestroyedException ignore) {
// ignore to fix bug 35534
}
}
}
use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.
the class HAInterestPart2DUnitTest method testBug35945.
/**
* Bug Test for Bug # 35945 A java level Deadlock between acquireConnection and RegionEntry during
* processRecoveredEndpoint by Dead Server Monitor Thread.
*
* @throws Exception
*/
@Test
public void testBug35945() throws Exception {
PORT1 = ((Integer) server1.invoke(() -> HAInterestTestCase.createServerCache())).intValue();
server1.invoke(() -> HAInterestTestCase.createEntriesK1andK2());
createClientPoolCacheConnectionToSingleServer(this.getName(), NetworkUtils.getServerHostName(server1.getHost()));
registerK1AndK2();
verifyRefreshedEntriesFromServer();
server1.invoke(() -> HAInterestTestCase.stopServer());
verifyDeadAndLiveServers(1, 0);
// put on stopped server
server1.invoke(() -> HAInterestTestCase.putK1andK2());
// spawn a thread to put on server , which will acquire a lock on entry
setClientServerObserverForBeforeInterestRecovery();
server1.invoke(() -> HAInterestTestCase.startServer());
verifyDeadAndLiveServers(0, 1);
waitForBeforeInterestRecoveryCallBack();
// verify updated value of k1 as a refreshEntriesFromServer
final Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
assertNotNull(r1);
WaitCriterion wc = new WaitCriterion() {
private String excuse;
@Override
public boolean done() {
Region.Entry e1 = r1.getEntry(k1);
Region.Entry e2 = r1.getEntry(k2);
Object v1 = null;
if (e1 != null) {
try {
v1 = e1.getValue();
} catch (EntryDestroyedException ignore) {
// handled to fix GEODE-296
}
}
if (e1 == null || !server_k1_updated.equals(v1)) {
excuse = "v1=" + v1;
return false;
}
Object v2 = null;
if (e2 != null) {
try {
v2 = e2.getValue();
} catch (EntryDestroyedException ignore) {
// handled to fix GEODE-296
}
}
if (e2 == null || !server_k2.equals(v2)) {
excuse = "v2=" + v2;
return false;
}
return true;
}
@Override
public String description() {
return excuse;
}
};
Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, true);
}
use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.
the class HAInterestPart2DUnitTest method testRefreshEntriesFromPrimaryWhenDSMDetectsServerLive.
/**
* Tests a Scenario: Only one server, register interest on the server stop server , and update the
* registered entries on the server start the server , DSM will recover interest list on this live
* server and verify that as a part of recovery it refreshes registered entries from the server,
* because it is primary
*/
@Test
public void testRefreshEntriesFromPrimaryWhenDSMDetectsServerLive() throws Exception {
IgnoredException.addIgnoredException(ServerConnectivityException.class.getName());
PORT1 = ((Integer) server1.invoke(() -> HAInterestTestCase.createServerCache())).intValue();
server1.invoke(() -> HAInterestTestCase.createEntriesK1andK2());
createClientPoolCacheConnectionToSingleServer(this.getName(), NetworkUtils.getServerHostName(server1.getHost()));
registerK1AndK2();
verifyRefreshedEntriesFromServer();
server1.invoke(() -> HAInterestTestCase.stopServer());
verifyDeadAndLiveServers(1, 0);
server1.invoke(() -> HAInterestTestCase.putK1andK2());
server1.invoke(() -> HAInterestTestCase.startServer());
verifyDeadAndLiveServers(0, 1);
final Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
assertNotNull(r1);
// Verify for interest registration after cache-server is started.
server1.invoke(() -> HAInterestTestCase.verifyInterestRegistration());
WaitCriterion wc = new WaitCriterion() {
private String excuse;
@Override
public boolean done() {
Region.Entry e1;
Region.Entry e2;
try {
e1 = r1.getEntry(k1);
if (e1 == null) {
excuse = "Entry for k1 is null";
return false;
}
} catch (EntryDestroyedException e) {
excuse = "Entry destroyed";
return false;
}
if (!server_k1.equals(e1.getValue())) {
excuse = "e1 value is not server_k1";
return false;
}
try {
e2 = r1.getEntry(k2);
if (e2 == null) {
excuse = "Entry for k2 is null";
return false;
}
} catch (EntryDestroyedException e) {
excuse = "Entry destroyed";
return false;
}
if (!server_k2.equals(e2.getValue())) {
excuse = "e2 value is not server_k2";
return false;
}
return true;
}
@Override
public String description() {
return excuse;
}
};
Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, true);
}
Aggregations