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