Search in sources :

Example 31 with NearCacheConfig

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

the class AbstractNearCachePreloaderTest method getNearCacheConfig.

protected NearCacheConfig getNearCacheConfig(boolean invalidationOnChange, int maxSize, String preloaderDir) {
    EvictionConfig evictionConfig = new EvictionConfig().setMaximumSizePolicy(MaxSizePolicy.ENTRY_COUNT).setSize(maxSize).setEvictionPolicy(EvictionPolicy.LRU);
    NearCacheConfig nearCacheConfig = createNearCacheConfig(InMemoryFormat.BINARY).setName(defaultNearCache).setInvalidateOnChange(invalidationOnChange).setEvictionConfig(evictionConfig);
    nearCacheConfig.getPreloaderConfig().setEnabled(true).setDirectory(preloaderDir);
    return nearCacheConfig;
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheTestUtils.createNearCacheConfig(com.hazelcast.internal.nearcache.NearCacheTestUtils.createNearCacheConfig)

Example 32 with NearCacheConfig

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

the class NearCacheRecordStoreTestSupport method createNearCacheWithMaxSizePolicy.

protected void createNearCacheWithMaxSizePolicy(InMemoryFormat inMemoryFormat, EvictionConfig.MaxSizePolicy maxSizePolicy, int size) {
    NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat);
    EvictionConfig evictionConfig = new EvictionConfig();
    evictionConfig.setMaximumSizePolicy(maxSizePolicy);
    evictionConfig.setSize(size);
    nearCacheConfig.setEvictionConfig(evictionConfig);
    createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 33 with NearCacheConfig

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

the class NearCacheRecordStoreTestSupport method maxIdleTimeEvaluatedSuccessfully.

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

Example 34 with NearCacheConfig

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

Example 35 with NearCacheConfig

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

the class NearCacheRecordStoreTestSupport method putAndRemoveRecord.

protected void putAndRemoveRecord(InMemoryFormat inMemoryFormat) {
    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, "Record-" + i);
        // ensure that they are stored
        assertNotNull(nearCacheRecordStore.get(i));
    }
    assertEquals(DEFAULT_RECORD_COUNT, nearCacheRecordStore.size());
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        nearCacheRecordStore.remove(i);
        assertNull(nearCacheRecordStore.get(i));
    }
    assertEquals(0, nearCacheRecordStore.size());
}
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