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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations