Search in sources :

Example 6 with NearCacheStats

use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.

the class NearCacheLiteMemberTest method testPutAll.

public static void testPutAll(HazelcastInstance instance, HazelcastInstance lite, String mapName) {
    IMap<Object, Object> map = instance.getMap(mapName);
    IMap<Object, Object> liteMap = lite.getMap(mapName);
    NearCachedMapProxyImpl proxy = (NearCachedMapProxyImpl) liteMap;
    NearCache liteNearCache = proxy.getNearCache();
    SerializationService serializationService = ((SerializationServiceSupport) instance).getSerializationService();
    int count = 100;
    // fill the near cache with the same data as below so we can detect when it is emptied
    for (int i = 0; i < count; i++) {
        liteNearCache.put(serializationService.toData(i), i);
    }
    final NearCacheStats stats = liteNearCache.getNearCacheStats();
    assertEquals(100, stats.getOwnedEntryCount());
    Map<Object, Object> localMap = new HashMap<Object, Object>();
    for (int i = 0; i < count; i++) {
        localMap.put(i, i);
    }
    map.putAll(localMap);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(0, stats.getOwnedEntryCount());
        }
    });
    for (int i = 0; i < count; i++) {
        liteMap.get(i);
    }
    assertLiteMemberNearCacheNonEmpty(lite, mapName);
}
Also used : HashMap(java.util.HashMap) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) NearCache(com.hazelcast.internal.nearcache.NearCache) SerializationService(com.hazelcast.spi.serialization.SerializationService) NearCacheStats(com.hazelcast.monitor.NearCacheStats) SerializationServiceSupport(com.hazelcast.spi.impl.SerializationServiceSupport) AssertTask(com.hazelcast.test.AssertTask)

Example 7 with NearCacheStats

use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.

the class NearCacheTest method testNearCacheStats.

@Test
public void testNearCacheStats() {
    int mapSize = 1000;
    String mapName = randomMapName();
    Config config = getConfig();
    config.getMapConfig(mapName).setNearCacheConfig(newNearCacheConfig().setInvalidateOnChange(false));
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance[] instances = factory.newInstances(config);
    // populate map
    IMap<Integer, Integer> map = instances[0].getMap(mapName);
    populateMap(map, mapSize);
    // populate Near Cache
    populateNearCache(map, mapSize);
    NearCacheStats stats = getNearCacheStats(map);
    long ownedEntryCount = stats.getOwnedEntryCount();
    long misses = stats.getMisses();
    assertTrue(format("Near Cache entry count should be > %d but were %d", 400, ownedEntryCount), ownedEntryCount > 400);
    assertEquals(format("Near Cache misses should be %d but were %d", mapSize, misses), mapSize, misses);
    // make some hits
    populateNearCache(map, mapSize);
    stats = getNearCacheStats(map);
    long hits = stats.getHits();
    misses = stats.getMisses();
    long hitsAndMisses = hits + misses;
    assertTrue(format("Near Cache hits should be > %d but were %d", 400, hits), hits > 400);
    assertTrue(format("Near Cache misses should be > %d but were %d", 400, misses), misses > 400);
    assertEquals(format("Near Cache hits + misses should be %s but were %d", mapSize * 2, hitsAndMisses), mapSize * 2, hitsAndMisses);
}
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) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with NearCacheStats

use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.

the class NearCacheRecordStoreTestSupport method statsCalculated.

protected void statsCalculated(InMemoryFormat inMemoryFormat) {
    long creationStartTime = System.currentTimeMillis();
    NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat);
    NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
    long creationEndTime = System.currentTimeMillis();
    int expectedEntryCount = 0;
    int expectedHits = 0;
    int expectedMisses = 0;
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        nearCacheRecordStore.put(i, "Record-" + i);
        expectedEntryCount++;
    }
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        if (nearCacheRecordStore.get(i * 3) != null) {
            expectedHits++;
        } else {
            expectedMisses++;
        }
    }
    NearCacheStats nearCacheStats = nearCacheRecordStore.getNearCacheStats();
    long memoryCostWhenFull = nearCacheStats.getOwnedEntryMemoryCost();
    assertTrue(nearCacheStats.getCreationTime() >= creationStartTime);
    assertTrue(nearCacheStats.getCreationTime() <= creationEndTime);
    assertEquals(expectedHits, nearCacheStats.getHits());
    assertEquals(expectedMisses, nearCacheStats.getMisses());
    assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
    switch(inMemoryFormat) {
        case BINARY:
            assertTrue(memoryCostWhenFull > 0);
            break;
        case OBJECT:
            assertEquals(0, memoryCostWhenFull);
    }
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        if (nearCacheRecordStore.remove(i * 3)) {
            expectedEntryCount--;
        }
    }
    assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
    switch(inMemoryFormat) {
        case BINARY:
            assertTrue(nearCacheStats.getOwnedEntryMemoryCost() > 0);
            assertTrue(nearCacheStats.getOwnedEntryMemoryCost() < memoryCostWhenFull);
            break;
        case OBJECT:
            assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
            break;
    }
    nearCacheRecordStore.clear();
    switch(inMemoryFormat) {
        case BINARY:
        case OBJECT:
            assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
            break;
    }
}
Also used : NearCacheStats(com.hazelcast.monitor.NearCacheStats) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 9 with NearCacheStats

use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.

the class NearCacheTestUtils method assertNearCacheStats.

/**
     * Asserts the {@link NearCacheStats} for expected values.
     *
     * @param context                 the {@link NearCacheTestContext} to retrieve the stats from
     * @param expectedOwnedEntryCount the expected owned entry count
     * @param expectedHits            the expected Near Cache hits
     * @param expectedMisses          the expected Near Cache misses
     * @param expectedEvictions       the expected Near Cache evictions
     * @param expectedExpirations     the expected Near Cache expirations
     */
public static void assertNearCacheStats(NearCacheTestContext<?, ?, ?, ?> context, long expectedOwnedEntryCount, long expectedHits, long expectedMisses, long expectedEvictions, long expectedExpirations) {
    NearCacheStats stats = context.stats;
    assertEqualsFormat("Near Cache entry count should be %d, but was %d (%s)", expectedOwnedEntryCount, stats.getOwnedEntryCount(), stats);
    assertEqualsFormat("Near Cache hits should be %d, but were %d (%s)", expectedHits, stats.getHits(), stats);
    assertEqualsFormat("Near Cache misses should be %d, but were %d (%s)", expectedMisses, stats.getMisses(), stats);
    assertEqualsFormat("Near Cache evictions should be %d, but were %d (%s)", expectedEvictions, stats.getEvictions(), stats);
    assertEqualsFormat("Near Cache expirations should be %d, but were %d (%s)", expectedExpirations, stats.getExpirations(), stats);
}
Also used : NearCacheStats(com.hazelcast.monitor.NearCacheStats)

Example 10 with NearCacheStats

use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.

the class AbstractNearCachePreloaderTest method assertLastNearCachePersistence.

private static void assertLastNearCachePersistence(NearCacheTestContext context, File defaultStoreFile, int keyCount) {
    NearCacheStats nearCacheStats = context.nearCache.getNearCacheStats();
    assertEquals(keyCount, nearCacheStats.getLastPersistenceKeyCount());
    if (keyCount > 0) {
        assertTrue(nearCacheStats.getLastPersistenceWrittenBytes() > 0);
        assertTrue(defaultStoreFile.exists());
    } else {
        assertEquals(0, nearCacheStats.getLastPersistenceWrittenBytes());
        assertFalse(defaultStoreFile.exists());
    }
    assertTrue(nearCacheStats.getLastPersistenceFailure().isEmpty());
}
Also used : NearCacheStats(com.hazelcast.monitor.NearCacheStats)

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