Search in sources :

Example 26 with NearCacheStats

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);
}
Also used : NearCacheStats(com.hazelcast.nearcache.NearCacheStats) TransactionContext(com.hazelcast.transaction.TransactionContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with NearCacheStats

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());
}
Also used : NearCacheStats(com.hazelcast.nearcache.NearCacheStats) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 28 with NearCacheStats

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());
}
Also used : NearCacheStats(com.hazelcast.nearcache.NearCacheStats)

Example 29 with NearCacheStats

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);
    });
}
Also used : NearCacheStats(com.hazelcast.nearcache.NearCacheStats) NearCache(com.hazelcast.internal.nearcache.NearCache)

Example 30 with NearCacheStats

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);
}
Also used : NearCacheStats(com.hazelcast.nearcache.NearCacheStats) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

NearCacheStats (com.hazelcast.nearcache.NearCacheStats)31 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)22 QuickTest (com.hazelcast.test.annotation.QuickTest)22 Test (org.junit.Test)22 NightlyTest (com.hazelcast.test.annotation.NightlyTest)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 NearCacheConfig (com.hazelcast.config.NearCacheConfig)5 NearCache (com.hazelcast.internal.nearcache.NearCache)5 TransactionContext (com.hazelcast.transaction.TransactionContext)5 Config (com.hazelcast.config.Config)3 MapConfig (com.hazelcast.config.MapConfig)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 IMap (com.hazelcast.map.IMap)2 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)1 NearCacheStatsImpl (com.hazelcast.internal.monitor.impl.NearCacheStatsImpl)1 DefaultNearCache (com.hazelcast.internal.nearcache.impl.DefaultNearCache)1 NearCacheTestUtils.getRecordFromNearCache (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getRecordFromNearCache)1 NearCacheTestUtils.getValueFromNearCache (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getValueFromNearCache)1 LocalMapStats (com.hazelcast.map.LocalMapStats)1 LocalIndexStats (com.hazelcast.query.LocalIndexStats)1