Search in sources :

Example 1 with CacheStatistics

use of com.hazelcast.cache.CacheStatistics in project hazelcast by hazelcast.

the class CacheStatsTest method testHitPercentageStat.

@Test
public void testHitPercentageStat() {
    ICache<Integer, String> cache = createCache();
    CacheStatistics stats = cache.getLocalCacheStatistics();
    final int ENTRY_COUNT = 100;
    final int GET_COUNT = 3 * ENTRY_COUNT;
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.put(i, "Value-" + i);
    }
    for (int i = 0; i < GET_COUNT; i++) {
        cache.get(i);
    }
    float expectedHitPercentage = (float) ENTRY_COUNT / GET_COUNT * 100.0f;
    assertEquals(expectedHitPercentage, stats.getCacheHitPercentage(), 0.0f);
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with CacheStatistics

use of com.hazelcast.cache.CacheStatistics in project hazelcast by hazelcast.

the class CacheStatsTest method testMissPercentageStat.

public void testMissPercentageStat() {
    ICache<Integer, String> cache = createCache();
    CacheStatistics stats = cache.getLocalCacheStatistics();
    final int ENTRY_COUNT = 100;
    final int GET_COUNT = 3 * ENTRY_COUNT;
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.put(i, "Value-" + i);
    }
    for (int i = 0; i < GET_COUNT; i++) {
        cache.get(i);
    }
    float expectedMissPercentage = (float) (GET_COUNT - ENTRY_COUNT) / GET_COUNT * 100.0f;
    assertEquals(expectedMissPercentage, stats.getCacheMissPercentage(), 0.0f);
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics)

Example 3 with CacheStatistics

use of com.hazelcast.cache.CacheStatistics in project hazelcast by hazelcast.

the class CacheStatsTest method testAveragePutTimeStat.

@Test
public void testAveragePutTimeStat() {
    ICache<Integer, String> cache = createCache();
    CacheStatistics stats = cache.getLocalCacheStatistics();
    final int ENTRY_COUNT = 100;
    long start = System.nanoTime();
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.put(i, "Value-" + i);
    }
    long end = System.nanoTime();
    float avgPutTime = (end - start) / 1000;
    assertTrue(stats.getAveragePutTime() > 0);
    assertTrue(stats.getAveragePutTime() < avgPutTime);
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with CacheStatistics

use of com.hazelcast.cache.CacheStatistics in project hazelcast by hazelcast.

the class CacheStatsTest method testLastAccessTimeStat.

@Test
public void testLastAccessTimeStat() {
    ICache<Integer, String> cache = createCache();
    CacheStatistics stats = cache.getLocalCacheStatistics();
    final int ENTRY_COUNT = 100;
    long start, end;
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.put(i, "Value-" + i);
    }
    assertEquals(0, stats.getLastAccessTime());
    start = System.currentTimeMillis();
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.get(i);
    }
    end = System.currentTimeMillis();
    // Hits effect last access time
    assertTrue(stats.getLastAccessTime() >= start);
    assertTrue(stats.getLastAccessTime() <= end);
    long currentLastAccessTime = stats.getLastAccessTime();
    sleepAtLeastMillis(1);
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.remove(i);
    }
    // Removes has no effect on last access time
    assertEquals(currentLastAccessTime, stats.getLastAccessTime());
    sleepAtLeastMillis(1);
    start = System.currentTimeMillis();
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.get(i);
    }
    end = System.currentTimeMillis();
    // Misses also effect last access time
    assertTrue(stats.getLastAccessTime() >= start);
    assertTrue(stats.getLastAccessTime() <= end);
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with CacheStatistics

use of com.hazelcast.cache.CacheStatistics in project hazelcast by hazelcast.

the class CacheStatsTest method testHitStat.

@Test
public void testHitStat() {
    ICache<Integer, String> cache = createCache();
    CacheStatistics stats = cache.getLocalCacheStatistics();
    final int ENTRY_COUNT = 100;
    final int GET_COUNT = 3 * ENTRY_COUNT;
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.put(i, "Value-" + i);
    }
    for (int i = 0; i < GET_COUNT; i++) {
        cache.get(i);
    }
    assertEquals(ENTRY_COUNT, stats.getCacheHits());
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

CacheStatistics (com.hazelcast.cache.CacheStatistics)22 ParallelTest (com.hazelcast.test.annotation.ParallelTest)19 QuickTest (com.hazelcast.test.annotation.QuickTest)19 Test (org.junit.Test)19 CacheConfig (com.hazelcast.config.CacheConfig)3 JsonObject (com.eclipsesource.json.JsonObject)1 ICacheService (com.hazelcast.cache.impl.ICacheService)1 CacheStatsTest (com.hazelcast.cache.stats.CacheStatsTest)1 ClientConfig (com.hazelcast.client.config.ClientConfig)1 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)1 QueueService (com.hazelcast.collection.impl.queue.QueueService)1 Config (com.hazelcast.config.Config)1 GroupConfig (com.hazelcast.config.GroupConfig)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 DistributedExecutorService (com.hazelcast.executor.impl.DistributedExecutorService)1 MapService (com.hazelcast.map.impl.MapService)1 LocalWanStats (com.hazelcast.monitor.LocalWanStats)1 MultiMapService (com.hazelcast.multimap.impl.MultiMapService)1 ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)1