Search in sources :

Example 21 with NearCacheStats

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());
}
Also used : NearCacheStats(com.hazelcast.monitor.NearCacheStats)

Example 22 with NearCacheStats

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);
        }
    });
}
Also used : NearCacheStats(com.hazelcast.monitor.NearCacheStats) AssertTask(com.hazelcast.test.AssertTask)

Aggregations

NearCacheStats (com.hazelcast.monitor.NearCacheStats)22 ParallelTest (com.hazelcast.test.annotation.ParallelTest)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 NearCacheConfig (com.hazelcast.config.NearCacheConfig)4 NearCache (com.hazelcast.internal.nearcache.NearCache)3 AssertTask (com.hazelcast.test.AssertTask)3 Config (com.hazelcast.config.Config)2 EvictionConfig (com.hazelcast.config.EvictionConfig)2 MapConfig (com.hazelcast.config.MapConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 MapContainer (com.hazelcast.map.impl.MapContainer)1 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)1 MapNearCacheManager (com.hazelcast.map.impl.nearcache.MapNearCacheManager)1 NearCachedMapProxyImpl (com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl)1 LocalMapStats (com.hazelcast.monitor.LocalMapStats)1 LocalMapStatsImpl (com.hazelcast.monitor.impl.LocalMapStatsImpl)1 SerializationServiceSupport (com.hazelcast.spi.impl.SerializationServiceSupport)1 SerializationService (com.hazelcast.spi.serialization.SerializationService)1