Search in sources :

Example 6 with NearCacheStats

use of com.hazelcast.nearcache.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);
    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.nearcache.NearCacheStats) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with NearCacheStats

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

the class NearCacheTest method multiple_get_on_non_existing_key_generates_one_miss.

@Test
public void multiple_get_on_non_existing_key_generates_one_miss() {
    String mapName = "test";
    Config config = getConfig();
    NearCacheConfig nearCacheConfig = newNearCacheConfig();
    nearCacheConfig.setCacheLocalEntries(true);
    config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap map = node.getMap(mapName);
    map.get(1);
    map.get(1);
    map.get(1);
    NearCacheStats nearCacheStats = map.getLocalMapStats().getNearCacheStats();
    assertEquals(1, nearCacheStats.getMisses());
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheStats(com.hazelcast.nearcache.NearCacheStats) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with NearCacheStats

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

the class AbstractNearCachePreloaderTest method assertNearCachePreloadDoneEventually.

private static void assertNearCachePreloadDoneEventually(final NearCacheTestContext clientContext, long timeoutSeconds) {
    assertTrueEventually(() -> {
        NearCache nearCache = clientContext.nearCache;
        NearCacheStats stats = nearCache.getNearCacheStats();
        int size = nearCache.size();
        assertTrue(format("Preloading has not finished yet. [size: %d, %s]", size, stats), nearCache.isPreloadDone());
    });
}
Also used : NearCacheStats(com.hazelcast.nearcache.NearCacheStats) NearCacheTestUtils.getValueFromNearCache(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getValueFromNearCache) NearCacheTestUtils.getRecordFromNearCache(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getRecordFromNearCache) NearCache(com.hazelcast.internal.nearcache.NearCache)

Example 9 with NearCacheStats

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

the class NearCacheRecordStoreTestSupport method statsCalculated.

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, null, "Record-" + i, null);
        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();
    // Note that System.currentTimeMillis() is not monotonically increasing.
    // Below assertions can fail anytime but for testing purposes we can use `assertTrueEventually`.
    long nearCacheStatsCreationTime = nearCacheStats.getCreationTime();
    assertTrue("nearCacheStatsCreationTime=" + nearCacheStatsCreationTime + ", and creationStartTime=" + creationStartTime, nearCacheStatsCreationTime >= creationStartTime);
    assertTrue("nearCacheStatsCreationTime=" + nearCacheStatsCreationTime + ", and creationEndTime=" + creationEndTime, nearCacheStatsCreationTime <= creationEndTime);
    assertEquals(expectedHits, nearCacheStats.getHits());
    assertEquals(expectedMisses, nearCacheStats.getMisses());
    assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
    switch(inMemoryFormat) {
        case NATIVE:
        case BINARY:
            assertTrue(memoryCostWhenFull > 0);
            break;
        case OBJECT:
            assertEquals(0, memoryCostWhenFull);
            break;
        default:
    }
    int sizeBefore = nearCacheRecordStore.size();
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        nearCacheRecordStore.invalidate(i * 3);
    }
    int sizeAfter = nearCacheRecordStore.size();
    int invalidatedSize = sizeBefore - sizeAfter;
    expectedEntryCount -= invalidatedSize;
    assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
    switch(inMemoryFormat) {
        case NATIVE:
        case BINARY:
            assertTrue(nearCacheStats.getOwnedEntryMemoryCost() > 0);
            assertTrue(nearCacheStats.getOwnedEntryMemoryCost() < memoryCostWhenFull);
            break;
        case OBJECT:
            assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
            break;
        default:
    }
    nearCacheRecordStore.clear();
    assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
}
Also used : NearCacheStats(com.hazelcast.nearcache.NearCacheStats) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 10 with NearCacheStats

use of com.hazelcast.nearcache.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 = new NearCacheStatsImpl(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 : NearCacheStatsImpl(com.hazelcast.internal.monitor.impl.NearCacheStatsImpl) NearCacheStats(com.hazelcast.nearcache.NearCacheStats)

Aggregations

NearCacheStats (com.hazelcast.nearcache.NearCacheStats)31 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)22 QuickTest (com.hazelcast.test.annotation.QuickTest)22 Test (org.junit.Test)22 NightlyTest (com.hazelcast.test.annotation.NightlyTest)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 NearCacheConfig (com.hazelcast.config.NearCacheConfig)5 NearCache (com.hazelcast.internal.nearcache.NearCache)5 TransactionContext (com.hazelcast.transaction.TransactionContext)5 Config (com.hazelcast.config.Config)3 MapConfig (com.hazelcast.config.MapConfig)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 IMap (com.hazelcast.map.IMap)2 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)1 NearCacheStatsImpl (com.hazelcast.internal.monitor.impl.NearCacheStatsImpl)1 DefaultNearCache (com.hazelcast.internal.nearcache.impl.DefaultNearCache)1 NearCacheTestUtils.getRecordFromNearCache (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getRecordFromNearCache)1 NearCacheTestUtils.getValueFromNearCache (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getValueFromNearCache)1 LocalMapStats (com.hazelcast.map.LocalMapStats)1 LocalIndexStats (com.hazelcast.query.LocalIndexStats)1