use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.
the class NearCacheRecordStoreTestSupport method expiredRecordsCleanedUpSuccessfully.
protected void expiredRecordsCleanedUpSuccessfully(InMemoryFormat inMemoryFormat, boolean useIdleTime) {
int cleanUpThresholdSeconds = 3;
NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat);
if (useIdleTime) {
nearCacheConfig.setMaxIdleSeconds(cleanUpThresholdSeconds);
} else {
nearCacheConfig.setTimeToLiveSeconds(cleanUpThresholdSeconds);
}
NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
nearCacheRecordStore.put(i, "Record-" + i);
}
sleepSeconds(cleanUpThresholdSeconds + 1);
nearCacheRecordStore.doExpiration();
assertEquals(0, nearCacheRecordStore.size());
NearCacheStats nearCacheStats = nearCacheRecordStore.getNearCacheStats();
assertEquals(0, nearCacheStats.getOwnedEntryCount());
assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
}
use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.
the class NearCacheTest method testNearCacheEntriesNotExpired_afterIMapExpiration.
/**
* Near Cache has its own eviction/expiration mechanism, so eviction/expiration on an IMap
* should not force any Near Cache eviction/expiration. Exceptions from this rule are direct calls to
* <ul>
* <li>{@link IMap#evict(Object)}</li>
* <li>{@link IMap#evictAll()}</li>
* </ul>
*/
@Test
public void testNearCacheEntriesNotExpired_afterIMapExpiration() {
int mapSize = 3;
String mapName = randomMapName();
Config config = createNearCachedMapConfig(mapName);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Integer, Integer> map = instance.getMap(mapName);
CountDownLatch latch = new CountDownLatch(mapSize);
addEntryEvictedListener(map, latch);
populateMapWithExpirableEntries(map, mapSize, 3, TimeUnit.SECONDS);
populateNearCache(map, mapSize);
int nearCacheSizeBeforeExpiration = getNearCacheSize(map);
waitUntilEvictionEventsReceived(latch);
// wait some extra time for possible events
sleepSeconds(2);
int nearCacheSizeAfterExpiration = getNearCacheSize(map);
NearCacheStats stats = getNearCacheStats(map);
assertEquals(0, stats.getExpirations());
assertEquals(0, stats.getEvictions());
assertEquals(nearCacheSizeBeforeExpiration, nearCacheSizeAfterExpiration);
}
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);
}
});
}
use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.
the class LocalMapStatsProvider method addNearCacheStats.
private void addNearCacheStats(String mapName, LocalMapStatsImpl localMapStats, LocalMapOnDemandCalculatedStats onDemandStats) {
NearCache nearCache = mapNearCacheManager.getNearCache(mapName);
if (nearCache == null) {
return;
}
NearCacheStats nearCacheStats = nearCache.getNearCacheStats();
localMapStats.setNearCacheStats(nearCacheStats);
if (NATIVE != nearCache.getInMemoryFormat()) {
onDemandStats.incrementHeapCost(nearCacheStats.getOwnedEntryMemoryCost());
}
}
Aggregations