use of com.hazelcast.nearcache.NearCacheStats in project hazelcast by hazelcast.
the class ClientTxnMapNearCacheTest method replaceIfSame_invalidates_server_side_near_cache.
@Test
public void replaceIfSame_invalidates_server_side_near_cache() {
TransactionContext context = client.newTransactionContext();
context.beginTransaction();
TransactionalMap<Object, Object> txnMap = context.getMap(MAP_NAME);
for (int i = 0; i < KEY_COUNT; i++) {
txnMap.replace(i, i, i);
}
context.commitTransaction();
NearCacheStats nearCacheStats = serverMap.getLocalMapStats().getNearCacheStats();
long ownedEntryCount = nearCacheStats.getOwnedEntryCount();
long invalidations = nearCacheStats.getInvalidations();
assertEquals(0, ownedEntryCount);
assertEquals(KEY_COUNT, invalidations);
}
use of com.hazelcast.nearcache.NearCacheStats in project hazelcast by hazelcast.
the class NearCacheRecordStoreTestSupport method expiredRecordsCleanedUpSuccessfully.
void expiredRecordsCleanedUpSuccessfully(InMemoryFormat inMemoryFormat, boolean useIdleTime) {
int cleanUpThresholdSeconds = 3;
NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat);
if (useIdleTime) {
nearCacheConfig.setMaxIdleSeconds(cleanUpThresholdSeconds);
} else {
nearCacheConfig.setTimeToLiveSeconds(cleanUpThresholdSeconds);
}
NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
nearCacheRecordStore.put(i, null, "Record-" + i, null);
}
sleepSeconds(cleanUpThresholdSeconds + 1);
nearCacheRecordStore.doExpiration();
assertEquals(0, nearCacheRecordStore.size());
NearCacheStats nearCacheStats = nearCacheRecordStore.getNearCacheStats();
assertEquals(0, nearCacheStats.getOwnedEntryCount());
assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
}
use of com.hazelcast.nearcache.NearCacheStats in project hazelcast by hazelcast.
the class NearCacheTestSupport method testNearCacheEviction.
protected void testNearCacheEviction(IMap<Integer, Integer> map, int size) {
// all Near Cache implementations use the same eviction algorithm, which evicts a single entry
int expectedEvictions = 1;
// populate map with an extra entry
populateMap(map, size + 1);
// populate Near Caches
populateNearCache(map, size);
NearCacheStats statsBeforeEviction = getNearCacheStatsCopy(map);
// trigger eviction via fetching the extra entry
map.get(size);
waitForNearCacheEvictions(map, expectedEvictions);
// we expect (size + the extra entry - the expectedEvictions) entries in the Near Cache
int expectedOwnedEntryCount = size + 1 - expectedEvictions;
NearCacheStats stats = getNearCacheStats(map);
assertEquals("got the wrong ownedEntryCount", expectedOwnedEntryCount, stats.getOwnedEntryCount());
assertEquals("got the wrong eviction count", expectedEvictions, stats.getEvictions());
assertEquals("got the wrong expiration count", 0, stats.getExpirations());
assertEquals("we expect the same hits", statsBeforeEviction.getHits(), stats.getHits());
assertEquals("we expect one miss more", statsBeforeEviction.getMisses() + 1, stats.getMisses());
}
use of com.hazelcast.nearcache.NearCacheStats in project hazelcast by hazelcast.
the class NearCacheTestSupport method assertNearCacheExpiration.
protected void assertNearCacheExpiration(final IMap<Integer, Integer> map, final int size) {
assertTrueEventually(() -> {
NearCache nearCache = getBackingNearCache(map);
NearCacheStats stats = getNearCacheStats(map);
// make assertions over near cache's backing map size.
long nearCacheSize = nearCache.size();
assertEquals(format("Expected zero near cache size but found: %d, [%s] ", nearCacheSize, stats), 0, nearCacheSize);
// make assertions over near cache stats.
long ownedEntryCount = stats.getOwnedEntryCount();
assertEquals(format("Expected no owned entry but found: %d, [%s]", ownedEntryCount, stats), 0, ownedEntryCount);
long ownedEntryMemoryCost = stats.getOwnedEntryMemoryCost();
assertEquals(format("Expected zero memory cost but found: %d, [%s]", ownedEntryMemoryCost, stats), 0, ownedEntryMemoryCost);
long expiredCount = stats.getExpirations();
assertEquals(format("Expected to see all entries as expired but found: %d, [%s]", expiredCount, stats), size, expiredCount);
long evictedCount = stats.getEvictions();
assertEquals(format("Expiration should not trigger eviction stat but found: %d, [%s]", evictedCount, stats), 0, evictedCount);
});
}
use of com.hazelcast.nearcache.NearCacheStats in project hazelcast by hazelcast.
the class MemberMapReconciliationTest method test_reconciliation_does_not_cause_premature_removal.
@Test
public void test_reconciliation_does_not_cause_premature_removal() {
int total = 100;
for (int i = 0; i < total; i++) {
serverMap.put(i, i);
}
for (int i = 0; i < total; i++) {
nearCachedServerMap.get(i);
}
final IMap<Integer, Integer> nearCachedMapFromNewServer = nearCachedMapFromNewServer();
warmUpPartitions(factory.getAllHazelcastInstances());
waitAllForSafeState(factory.getAllHazelcastInstances());
waitForNearCacheInvalidationMetadata(nearCachedMapFromNewServer, server);
for (int i = 0; i < total; i++) {
nearCachedMapFromNewServer.get(i);
}
NearCacheStats nearCacheStats = nearCachedMapFromNewServer.getLocalMapStats().getNearCacheStats();
assertStats(MAP_NAME, nearCacheStats, total, 0, total);
sleepSeconds(2 * RECONCILIATION_INTERVAL_SECS);
for (int i = 0; i < total; i++) {
nearCachedMapFromNewServer.get(i);
}
assertStats(MAP_NAME, nearCacheStats, total, total, total);
}
Aggregations