use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.
the class NearCacheTestSupport method testNearCacheEviction.
protected void testNearCacheEviction(IMap<Integer, Integer> map, int size) {
// all Near Cache implementations use the same eviction algorithm, which evicts a single entry
int expectedEvictions = 1;
// populate map with an extra entry
populateMap(map, size + 1);
// populate Near Caches
populateNearCache(map, size);
NearCacheStats statsBeforeEviction = getNearCacheStats(map);
// trigger eviction via fetching the extra entry
map.get(size);
waitForNearCacheEvictions(map, expectedEvictions);
// we expect (size + the extra entry - the expectedEvictions) entries in the Near Cache
int expectedOwnedEntryCount = size + 1 - expectedEvictions;
NearCacheStats stats = getNearCacheStats(map);
assertEquals("got the wrong ownedEntryCount", expectedOwnedEntryCount, stats.getOwnedEntryCount());
assertEquals("got the wrong eviction count", expectedEvictions, stats.getEvictions());
assertEquals("got the wrong expiration count", 0, stats.getExpirations());
assertEquals("we expect the same hits", statsBeforeEviction.getHits(), stats.getHits());
assertEquals("we expect the same misses", statsBeforeEviction.getMisses(), stats.getMisses());
}
use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.
the class NearCacheTestSupport method testNearCacheExpiration.
protected void testNearCacheExpiration(final IMap<Integer, Integer> map, final int size, int expireSeconds) {
populateMap(map, size);
populateNearCache(map, size);
final NearCacheStats statsBeforeExpiration = getNearCacheStats(map);
assertTrue(format("we expected to have all map entries in the Near Cache or already expired (%s)", statsBeforeExpiration), statsBeforeExpiration.getOwnedEntryCount() + statsBeforeExpiration.getExpirations() >= size);
sleepSeconds(expireSeconds + 1);
assertTrueEventually(new AssertTask() {
public void run() {
// map.get() triggers Near Cache eviction/expiration process,
// but we need to call this on every assert since the Near Cache has a cooldown for expiration cleanups
map.get(0);
NearCacheStats stats = getNearCacheStats(map);
assertEquals("we expect the same hits", statsBeforeExpiration.getHits(), stats.getHits());
assertEquals("we expect the same misses", statsBeforeExpiration.getMisses(), stats.getMisses());
assertEquals("we expect all entries beside the 'trigger entry' to be deleted from the Near Cache", 1, stats.getOwnedEntryCount());
assertEquals("we did not expect any entries to be evicted from the Near Cache", 0, stats.getEvictions());
assertTrue(format("we expect at least %d entries to be expired from the Near Cache", size), stats.getExpirations() >= size);
}
});
}
Aggregations