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