Search in sources :

Example 81 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class StaleReadDetectorTest method createConfigWithNearCache.

private Config createConfigWithNearCache(boolean invalidateOnChange) {
    Config config = getConfig();
    config.setProperty(PARTITION_COUNT.getName(), "1");
    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setCacheLocalEntries(true);
    nearCacheConfig.setInvalidateOnChange(invalidateOnChange);
    MapConfig mapConfig = config.getMapConfig(MAP_NAME);
    mapConfig.setNearCacheConfig(nearCacheConfig);
    return config;
}
Also used : Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 82 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class NearCacheRecordStoreTest method doEvictionWithEntryCountMaxSizePolicy.

private void doEvictionWithEntryCountMaxSizePolicy(InMemoryFormat inMemoryFormat, EvictionPolicy evictionPolicy) {
    int maxSize = DEFAULT_RECORD_COUNT / 2;
    EvictionConfig evictionConfig = new EvictionConfig().setMaxSizePolicy(MaxSizePolicy.ENTRY_COUNT).setSize(maxSize).setEvictionPolicy(evictionPolicy == null ? EvictionConfig.DEFAULT_EVICTION_POLICY : evictionPolicy);
    NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat).setEvictionConfig(evictionConfig);
    NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        nearCacheRecordStore.put(i, null, "Record-" + i, null);
        nearCacheRecordStore.doEviction(false);
        assertTrue(maxSize >= nearCacheRecordStore.size());
    }
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 83 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class NearCacheRecordStoreTestSupport method clearRecordsOrDestroyStore.

void clearRecordsOrDestroyStore(InMemoryFormat inMemoryFormat, boolean destroy) {
    NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat);
    NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        nearCacheRecordStore.put(i, null, "Record-" + i, null);
        // ensure that they are stored
        assertNotNull(nearCacheRecordStore.get(i));
    }
    if (destroy) {
        nearCacheRecordStore.destroy();
    } else {
        nearCacheRecordStore.clear();
    }
    assertEquals(0, nearCacheRecordStore.size());
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 84 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class NearCacheRecordStoreTestSupport method statsCalculated.

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, null, "Record-" + i, null);
        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();
    // Note that System.currentTimeMillis() is not monotonically increasing.
    // Below assertions can fail anytime but for testing purposes we can use `assertTrueEventually`.
    long nearCacheStatsCreationTime = nearCacheStats.getCreationTime();
    assertTrue("nearCacheStatsCreationTime=" + nearCacheStatsCreationTime + ", and creationStartTime=" + creationStartTime, nearCacheStatsCreationTime >= creationStartTime);
    assertTrue("nearCacheStatsCreationTime=" + nearCacheStatsCreationTime + ", and creationEndTime=" + creationEndTime, nearCacheStatsCreationTime <= creationEndTime);
    assertEquals(expectedHits, nearCacheStats.getHits());
    assertEquals(expectedMisses, nearCacheStats.getMisses());
    assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
    switch(inMemoryFormat) {
        case NATIVE:
        case BINARY:
            assertTrue(memoryCostWhenFull > 0);
            break;
        case OBJECT:
            assertEquals(0, memoryCostWhenFull);
            break;
        default:
    }
    int sizeBefore = nearCacheRecordStore.size();
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        nearCacheRecordStore.invalidate(i * 3);
    }
    int sizeAfter = nearCacheRecordStore.size();
    int invalidatedSize = sizeBefore - sizeAfter;
    expectedEntryCount -= invalidatedSize;
    assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
    switch(inMemoryFormat) {
        case NATIVE:
        case BINARY:
            assertTrue(nearCacheStats.getOwnedEntryMemoryCost() > 0);
            assertTrue(nearCacheStats.getOwnedEntryMemoryCost() < memoryCostWhenFull);
            break;
        case OBJECT:
            assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
            break;
        default:
    }
    nearCacheRecordStore.clear();
    assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
}
Also used : NearCacheStats(com.hazelcast.nearcache.NearCacheStats) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 85 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class NearCacheRecordStoreTestSupport method ttlEvaluated.

void ttlEvaluated(InMemoryFormat inMemoryFormat) {
    int ttlSeconds = 3;
    NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat).setTimeToLiveSeconds(ttlSeconds);
    NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        nearCacheRecordStore.put(i, null, "Record-" + i, null);
    }
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        assertNotNull(nearCacheRecordStore.get(i));
    }
    sleepSeconds(ttlSeconds + 1);
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        assertNull(nearCacheRecordStore.get(i));
    }
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Aggregations

NearCacheConfig (com.hazelcast.config.NearCacheConfig)212 Test (org.junit.Test)89 QuickTest (com.hazelcast.test.annotation.QuickTest)82 Config (com.hazelcast.config.Config)66 HazelcastInstance (com.hazelcast.core.HazelcastInstance)65 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)62 ClientConfig (com.hazelcast.client.config.ClientConfig)51 MapConfig (com.hazelcast.config.MapConfig)37 EvictionConfig (com.hazelcast.config.EvictionConfig)24 Before (org.junit.Before)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)16 CacheConfig (com.hazelcast.config.CacheConfig)15 ParallelTest (com.hazelcast.test.annotation.ParallelTest)15 NearCacheTestUtils.getBaseConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig)14 AssertTask (com.hazelcast.test.AssertTask)14 NightlyTest (com.hazelcast.test.annotation.NightlyTest)12 MapStoreConfig (com.hazelcast.config.MapStoreConfig)11 Data (com.hazelcast.nio.serialization.Data)11 MatchingPointConfigPatternMatcher (com.hazelcast.config.matcher.MatchingPointConfigPatternMatcher)10 CachingProvider (javax.cache.spi.CachingProvider)10