Search in sources :

Example 1 with LocalMapStats

use of com.hazelcast.monitor.LocalMapStats in project spring-boot by spring-projects.

the class HazelcastCacheStatisticsProvider method getCacheStatistics.

@Override
public CacheStatistics getCacheStatistics(CacheManager cacheManager, HazelcastCache cache) {
    DefaultCacheStatistics statistics = new DefaultCacheStatistics();
    LocalMapStats mapStatistics = ((IMap<?, ?>) cache.getNativeCache()).getLocalMapStats();
    statistics.setSize(mapStatistics.getOwnedEntryCount());
    statistics.setGetCacheCounts(mapStatistics.getHits(), mapStatistics.getGetOperationCount() - mapStatistics.getHits());
    return statistics;
}
Also used : LocalMapStats(com.hazelcast.monitor.LocalMapStats) IMap(com.hazelcast.core.IMap)

Example 2 with LocalMapStats

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

the class LocalMapStatsTest method testLastAccessTime_updatedConcurrently.

@Test
public void testLastAccessTime_updatedConcurrently() throws InterruptedException {
    final long startTime = Clock.currentTimeMillis();
    final IMap<String, String> map = getMap();
    final String key = "key";
    map.put(key, "value");
    map.put(key, "value");
    final LocalMapStats localMapStats = map.getLocalMapStats();
    final long lastUpdateTime = localMapStats.getLastUpdateTime();
    new Thread(new Runnable() {

        @Override
        public void run() {
            sleepAtLeastMillis(1);
            map.put(key, "value2");
            // causes the local stats object to update
            map.getLocalMapStats();
        }
    }).start();
    assertTrue(lastUpdateTime >= startTime);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(localMapStats.getLastUpdateTime() > lastUpdateTime);
        }
    });
}
Also used : LocalMapStats(com.hazelcast.monitor.LocalMapStats) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with LocalMapStats

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

the class LocalMapStatsTest method testPutAllGenerated.

@Test
public void testPutAllGenerated() throws Exception {
    IMap<Integer, Integer> map = getMap();
    for (int i = 0; i < 100; i++) {
        Map<Integer, Integer> putMap = new HashMap<Integer, Integer>(2);
        putMap.put(i, i);
        putMap.put(100 + i, 100 + i);
        map.putAll(putMap);
    }
    LocalMapStats localMapStats = map.getLocalMapStats();
    assertEquals(200, localMapStats.getPutOperationCount());
}
Also used : LocalMapStats(com.hazelcast.monitor.LocalMapStats) HashMap(java.util.HashMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with LocalMapStats

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

the class LocalMapStatsTest method testPutAndHitsGenerated.

@Test
public void testPutAndHitsGenerated() throws Exception {
    IMap<Integer, Integer> map = getMap();
    for (int i = 0; i < 100; i++) {
        map.put(i, i);
        map.get(i);
    }
    LocalMapStats localMapStats = map.getLocalMapStats();
    assertEquals(100, localMapStats.getPutOperationCount());
    assertEquals(100, localMapStats.getHits());
}
Also used : LocalMapStats(com.hazelcast.monitor.LocalMapStats) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with LocalMapStats

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

the class LocalMapStatsTest method testPutAsync.

@Test
public void testPutAsync() throws Exception {
    IMap<Integer, Integer> map = getMap();
    for (int i = 0; i < 100; i++) {
        map.putAsync(i, i);
    }
    final LocalMapStats localMapStats = map.getLocalMapStats();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(100, localMapStats.getPutOperationCount());
        }
    });
}
Also used : LocalMapStats(com.hazelcast.monitor.LocalMapStats) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

LocalMapStats (com.hazelcast.monitor.LocalMapStats)15 ParallelTest (com.hazelcast.test.annotation.ParallelTest)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 AssertTask (com.hazelcast.test.AssertTask)6 IMap (com.hazelcast.core.IMap)2 HashMap (java.util.HashMap)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 NearCacheStats (com.hazelcast.monitor.NearCacheStats)1 LocalMapStatsImpl (com.hazelcast.monitor.impl.LocalMapStatsImpl)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 HashSet (java.util.HashSet)1