Search in sources :

Example 6 with CacheStatistics

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

the class CacheStatsTest method testExpirations.

@Test
public void testExpirations() {
    ICache<Integer, String> cache = createCache();
    CacheStatistics stats = cache.getLocalCacheStatistics();
    // TODO Produce a case that triggers expirations and verify the expiration 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)

Example 7 with CacheStatistics

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

the class CacheStatsTest method testNearCacheStatsWhenNearCacheDisabled.

@Test(expected = UnsupportedOperationException.class)
public void testNearCacheStatsWhenNearCacheDisabled() {
    ICache<Integer, String> cache = createCache();
    CacheStatistics stats = cache.getLocalCacheStatistics();
    stats.getNearCacheStatistics();
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with CacheStatistics

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

the class CacheStatsTest method testStatisticsDisabled.

@Test
public void testStatisticsDisabled() {
    long now = System.currentTimeMillis();
    CacheConfig cacheConfig = createCacheConfig();
    cacheConfig.setStatisticsEnabled(false);
    ICache<Integer, String> cache = createCache(cacheConfig);
    CacheStatistics stats = cache.getLocalCacheStatistics();
    assertTrue(stats.getCreationTime() >= now);
    final int ENTRY_COUNT = 100;
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.put(i, "Value-" + i);
    }
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.get(i);
    }
    for (int i = 0; i < 10; i++) {
        cache.remove(i);
    }
    assertEquals(0, stats.getCacheHits());
    assertEquals(0, stats.getCacheHitPercentage(), 0.0f);
    assertEquals(0, stats.getCacheMisses());
    assertEquals(0, stats.getCacheMissPercentage(), 0.0f);
    assertEquals(0, stats.getCacheGets());
    assertEquals(0, stats.getAverageGetTime(), 0.0f);
    assertEquals(0, stats.getCachePuts());
    assertEquals(0, stats.getAveragePutTime(), 0.0f);
    assertEquals(0, stats.getCacheRemovals());
    assertEquals(0, stats.getAverageRemoveTime(), 0.0f);
    assertEquals(0, stats.getLastAccessTime());
    assertEquals(0, stats.getLastUpdateTime());
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics) CacheConfig(com.hazelcast.config.CacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with CacheStatistics

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

the class CacheStatsTest method testAverageRemoveTimeStat.

@Test
public void testAverageRemoveTimeStat() {
    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 < ENTRY_COUNT; i++) {
        cache.remove(i);
    }
    long end = System.nanoTime();
    float avgRemoveTime = (end - start) / 1000;
    assertTrue(stats.getAverageRemoveTime() > 0);
    assertTrue(stats.getAverageRemoveTime() < avgRemoveTime);
    float currentAverageRemoveTime = stats.getAverageRemoveTime();
    sleepAtLeastMillis(1);
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.remove(i);
    }
    // Latest removes has no effect since keys are already removed at previous loop
    assertEquals(currentAverageRemoveTime, stats.getAverageRemoveTime(), 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 10 with CacheStatistics

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

the class LocalCacheStatsImplTest method testSerialization.

@Test
public void testSerialization() {
    CacheStatistics cacheStatistics = new CacheStatistics() {

        @Override
        public long getCreationTime() {
            return 1986;
        }

        @Override
        public long getLastUpdateTime() {
            return 2014;
        }

        @Override
        public long getLastAccessTime() {
            return 2015;
        }

        @Override
        public long getOwnedEntryCount() {
            return 1000;
        }

        @Override
        public long getCacheHits() {
            return 127;
        }

        @Override
        public float getCacheHitPercentage() {
            return 12.5f;
        }

        @Override
        public long getCacheMisses() {
            return 5;
        }

        @Override
        public float getCacheMissPercentage() {
            return 11.4f;
        }

        @Override
        public long getCacheGets() {
            return 6;
        }

        @Override
        public long getCachePuts() {
            return 7;
        }

        @Override
        public long getCacheRemovals() {
            return 8;
        }

        @Override
        public long getCacheEvictions() {
            return 9;
        }

        @Override
        public float getAverageGetTime() {
            return 23.42f;
        }

        @Override
        public float getAveragePutTime() {
            return 42.23f;
        }

        @Override
        public float getAverageRemoveTime() {
            return 127.45f;
        }

        @Override
        public NearCacheStats getNearCacheStatistics() {
            return null;
        }
    };
    LocalCacheStatsImpl localCacheStats = new LocalCacheStatsImpl(cacheStatistics);
    JsonObject serialized = localCacheStats.toJson();
    LocalCacheStatsImpl deserialized = new LocalCacheStatsImpl();
    deserialized.fromJson(serialized);
    assertEquals(1986, deserialized.getCreationTime());
    assertEquals(2014, deserialized.getLastUpdateTime());
    assertEquals(2015, deserialized.getLastAccessTime());
    assertEquals(1000, deserialized.getOwnedEntryCount());
    assertEquals(127, deserialized.getCacheHits());
    assertEquals(12.5f, deserialized.getCacheHitPercentage(), 0.0001);
    assertEquals(5, deserialized.getCacheMisses());
    assertEquals(11.4f, deserialized.getCacheMissPercentage(), 0.0001);
    assertEquals(6, deserialized.getCacheGets());
    assertEquals(7, deserialized.getCachePuts());
    assertEquals(8, deserialized.getCacheRemovals());
    assertEquals(9, deserialized.getCacheEvictions());
    assertEquals(23.42f, deserialized.getAverageGetTime(), 0.0001);
    assertEquals(42.23f, deserialized.getAveragePutTime(), 0.0001);
    assertEquals(127.45f, deserialized.getAverageRemoveTime(), 0.0001);
    assertTrue(deserialized.getCreationTime() > 0);
    assertNotNull(deserialized.toString());
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics) JsonObject(com.eclipsesource.json.JsonObject) 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