use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.
the class NearCacheLiteMemberTest method testPutAll.
public static void testPutAll(HazelcastInstance instance, HazelcastInstance lite, String mapName) {
IMap<Object, Object> map = instance.getMap(mapName);
IMap<Object, Object> liteMap = lite.getMap(mapName);
NearCachedMapProxyImpl proxy = (NearCachedMapProxyImpl) liteMap;
NearCache liteNearCache = proxy.getNearCache();
SerializationService serializationService = ((SerializationServiceSupport) instance).getSerializationService();
int count = 100;
// fill the near cache with the same data as below so we can detect when it is emptied
for (int i = 0; i < count; i++) {
liteNearCache.put(serializationService.toData(i), i);
}
final NearCacheStats stats = liteNearCache.getNearCacheStats();
assertEquals(100, stats.getOwnedEntryCount());
Map<Object, Object> localMap = new HashMap<Object, Object>();
for (int i = 0; i < count; i++) {
localMap.put(i, i);
}
map.putAll(localMap);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, stats.getOwnedEntryCount());
}
});
for (int i = 0; i < count; i++) {
liteMap.get(i);
}
assertLiteMemberNearCacheNonEmpty(lite, mapName);
}
use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.
the class NearCacheTest method testNearCacheStats.
@Test
public void testNearCacheStats() {
int mapSize = 1000;
String mapName = randomMapName();
Config config = getConfig();
config.getMapConfig(mapName).setNearCacheConfig(newNearCacheConfig().setInvalidateOnChange(false));
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance[] instances = factory.newInstances(config);
// populate map
IMap<Integer, Integer> map = instances[0].getMap(mapName);
populateMap(map, mapSize);
// populate Near Cache
populateNearCache(map, mapSize);
NearCacheStats stats = getNearCacheStats(map);
long ownedEntryCount = stats.getOwnedEntryCount();
long misses = stats.getMisses();
assertTrue(format("Near Cache entry count should be > %d but were %d", 400, ownedEntryCount), ownedEntryCount > 400);
assertEquals(format("Near Cache misses should be %d but were %d", mapSize, misses), mapSize, misses);
// make some hits
populateNearCache(map, mapSize);
stats = getNearCacheStats(map);
long hits = stats.getHits();
misses = stats.getMisses();
long hitsAndMisses = hits + misses;
assertTrue(format("Near Cache hits should be > %d but were %d", 400, hits), hits > 400);
assertTrue(format("Near Cache misses should be > %d but were %d", 400, misses), misses > 400);
assertEquals(format("Near Cache hits + misses should be %s but were %d", mapSize * 2, hitsAndMisses), mapSize * 2, hitsAndMisses);
}
use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.
the class NearCacheRecordStoreTestSupport method statsCalculated.
protected void statsCalculated(InMemoryFormat inMemoryFormat) {
long creationStartTime = System.currentTimeMillis();
NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat);
NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
long creationEndTime = System.currentTimeMillis();
int expectedEntryCount = 0;
int expectedHits = 0;
int expectedMisses = 0;
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
nearCacheRecordStore.put(i, "Record-" + i);
expectedEntryCount++;
}
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
if (nearCacheRecordStore.get(i * 3) != null) {
expectedHits++;
} else {
expectedMisses++;
}
}
NearCacheStats nearCacheStats = nearCacheRecordStore.getNearCacheStats();
long memoryCostWhenFull = nearCacheStats.getOwnedEntryMemoryCost();
assertTrue(nearCacheStats.getCreationTime() >= creationStartTime);
assertTrue(nearCacheStats.getCreationTime() <= creationEndTime);
assertEquals(expectedHits, nearCacheStats.getHits());
assertEquals(expectedMisses, nearCacheStats.getMisses());
assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
switch(inMemoryFormat) {
case BINARY:
assertTrue(memoryCostWhenFull > 0);
break;
case OBJECT:
assertEquals(0, memoryCostWhenFull);
}
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
if (nearCacheRecordStore.remove(i * 3)) {
expectedEntryCount--;
}
}
assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
switch(inMemoryFormat) {
case BINARY:
assertTrue(nearCacheStats.getOwnedEntryMemoryCost() > 0);
assertTrue(nearCacheStats.getOwnedEntryMemoryCost() < memoryCostWhenFull);
break;
case OBJECT:
assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
break;
}
nearCacheRecordStore.clear();
switch(inMemoryFormat) {
case BINARY:
case OBJECT:
assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
break;
}
}
use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.
the class NearCacheTestUtils method assertNearCacheStats.
/**
* Asserts the {@link NearCacheStats} for expected values.
*
* @param context the {@link NearCacheTestContext} to retrieve the stats from
* @param expectedOwnedEntryCount the expected owned entry count
* @param expectedHits the expected Near Cache hits
* @param expectedMisses the expected Near Cache misses
* @param expectedEvictions the expected Near Cache evictions
* @param expectedExpirations the expected Near Cache expirations
*/
public static void assertNearCacheStats(NearCacheTestContext<?, ?, ?, ?> context, long expectedOwnedEntryCount, long expectedHits, long expectedMisses, long expectedEvictions, long expectedExpirations) {
NearCacheStats stats = context.stats;
assertEqualsFormat("Near Cache entry count should be %d, but was %d (%s)", expectedOwnedEntryCount, stats.getOwnedEntryCount(), stats);
assertEqualsFormat("Near Cache hits should be %d, but were %d (%s)", expectedHits, stats.getHits(), stats);
assertEqualsFormat("Near Cache misses should be %d, but were %d (%s)", expectedMisses, stats.getMisses(), stats);
assertEqualsFormat("Near Cache evictions should be %d, but were %d (%s)", expectedEvictions, stats.getEvictions(), stats);
assertEqualsFormat("Near Cache expirations should be %d, but were %d (%s)", expectedExpirations, stats.getExpirations(), stats);
}
use of com.hazelcast.monitor.NearCacheStats in project hazelcast by hazelcast.
the class AbstractNearCachePreloaderTest method assertLastNearCachePersistence.
private static void assertLastNearCachePersistence(NearCacheTestContext context, File defaultStoreFile, int keyCount) {
NearCacheStats nearCacheStats = context.nearCache.getNearCacheStats();
assertEquals(keyCount, nearCacheStats.getLastPersistenceKeyCount());
if (keyCount > 0) {
assertTrue(nearCacheStats.getLastPersistenceWrittenBytes() > 0);
assertTrue(defaultStoreFile.exists());
} else {
assertEquals(0, nearCacheStats.getLastPersistenceWrittenBytes());
assertFalse(defaultStoreFile.exists());
}
assertTrue(nearCacheStats.getLastPersistenceFailure().isEmpty());
}
Aggregations