Search in sources :

Example 16 with CacheStatistics

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

the class CacheStatsTest method testPutStat.

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

Example 17 with CacheStatistics

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

the class CacheStatsTest method doTestForOwnedEntryCount.

private void doTestForOwnedEntryCount(boolean useBackups, boolean triggerMigration) {
    final String cacheName = randomName();
    ICache<Integer, String> cache;
    CacheStatistics[] allStats;
    HazelcastInstance instance2 = null;
    if (useBackups) {
        // Create the second instance to store data as backup.
        instance2 = getHazelcastInstance();
        CachingProvider cp = getCachingProvider(instance2);
        CacheManager cm = cp.getCacheManager();
        cache = createCache(cacheName);
        ICache<Integer, String> c = cm.getCache(cacheName).unwrap(ICache.class);
        allStats = new CacheStatistics[] { cache.getLocalCacheStatistics(), c.getLocalCacheStatistics() };
    } else {
        cache = createCache(cacheName);
        allStats = new CacheStatistics[] { cache.getLocalCacheStatistics() };
    }
    final int ENTRY_COUNT = 100;
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.put(i, "Value-" + i);
    }
    assertOwnedEntryCount(ENTRY_COUNT, allStats);
    if (triggerMigration && instance2 != null) {
        // Shutdown the second instance to trigger migration so first instance will be owner of all partitions.
        instance2.shutdown();
        allStats = new CacheStatistics[] { cache.getLocalCacheStatistics() };
        assertOwnedEntryCount(ENTRY_COUNT, allStats);
    }
    for (int i = 0; i < 10; i++) {
        cache.remove(i);
    }
    assertOwnedEntryCount(ENTRY_COUNT - 10, allStats);
    for (int i = 10; i < ENTRY_COUNT; i++) {
        cache.remove(i);
    }
    assertOwnedEntryCount(0, allStats);
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.put(i, "Value-" + i);
    }
    assertOwnedEntryCount(ENTRY_COUNT, allStats);
    if (triggerMigration) {
        // Create the second instance to trigger migration
        // so the second instance will be owner of some partitions
        // and the first instance will lose ownership of some instances.
        instance2 = getHazelcastInstance();
        CachingProvider cp = getCachingProvider(instance2);
        CacheManager cm = cp.getCacheManager();
        ICache<Integer, String> c = cm.getCache(cacheName).unwrap(ICache.class);
        allStats = new CacheStatistics[] { cache.getLocalCacheStatistics(), c.getLocalCacheStatistics() };
        assertOwnedEntryCount(ENTRY_COUNT, allStats);
    }
    cache.clear();
    assertOwnedEntryCount(0, allStats);
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.put(i, "Value-" + i);
    }
    assertOwnedEntryCount(ENTRY_COUNT, allStats);
    cache.destroy();
    assertOwnedEntryCount(0, allStats);
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) CachingProvider(javax.cache.spi.CachingProvider)

Example 18 with CacheStatistics

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

the class CacheStatsTest method testAverageGetTimeStat.

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

Example 19 with CacheStatistics

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

the class CacheStatsTest method testMissStat.

@Test
public void testMissStat() {
    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(GET_COUNT - ENTRY_COUNT, stats.getCacheMisses());
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with CacheStatistics

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

the class CacheStatsTest method testEvictions.

@Test
public void testEvictions() {
    ICache<Integer, String> cache = createCache();
    CacheStatistics stats = cache.getLocalCacheStatistics();
    // TODO Produce a case that triggers evictions and verify the eviction count
    // At the moment, we are just verifying that this stats is supported
    stats.getCacheEvictions();
}
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