Search in sources :

Example 11 with NearCacheStats

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

Example 12 with NearCacheStats

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheStats(com.hazelcast.monitor.NearCacheStats) MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 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 14 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)

Example 15 with NearCacheStats

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

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