Search in sources :

Example 66 with NearCacheConfig

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

the class MemberMapReconciliationTest method setUp.

@Before
public void setUp() {
    NearCacheConfig nearCacheConfig = new NearCacheConfig(MAP_NAME).setInMemoryFormat(nearCacheInMemoryFormat).setInvalidateOnChange(true).setCacheLocalEntries(true);
    MapConfig mapConfig = new MapConfig(MAP_NAME).setInMemoryFormat(mapInMemoryFormat).setNearCacheConfig(nearCacheConfig);
    // we want to test that reconciliation doesn't cause any premature
    // removal of entries by falsely assuming some entries as stale
    config = getConfig().setProperty(MAX_TOLERATED_MISS_COUNT.getName(), "0").setProperty(RECONCILIATION_INTERVAL_SECONDS.getName(), valueOf(RECONCILIATION_INTERVAL_SECS)).setProperty(MIN_RECONCILIATION_INTERVAL_SECONDS.getName(), valueOf(RECONCILIATION_INTERVAL_SECS)).setProperty(MAP_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS.getName(), valueOf(Integer.MAX_VALUE)).setProperty(MAP_INVALIDATION_MESSAGE_BATCH_SIZE.getName(), valueOf(Integer.MAX_VALUE)).addMapConfig(mapConfig);
    server = factory.newHazelcastInstance(config);
    serverMap = server.getMap(MAP_NAME);
    nearCachedServerMap = nearCachedMapFromNewServer();
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig) Before(org.junit.Before)

Example 67 with NearCacheConfig

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

the class NearCacheTest method testGetAll.

@Test
public void testGetAll() {
    int mapSize = 1000;
    String mapName = "testGetAllWithNearCache";
    Config config = getConfig();
    NearCacheConfig nearCacheConfig = newNearCacheConfig();
    nearCacheConfig.setInvalidateOnChange(false);
    config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
    TestHazelcastInstanceFactory hazelcastInstanceFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance[] instances = hazelcastInstanceFactory.newInstances(config);
    warmUpPartitions(instances);
    HazelcastInstance hazelcastInstance = instances[0];
    InternalPartitionService partitionService = getPartitionService(hazelcastInstance);
    // populate map
    IMap<Integer, Integer> map = hazelcastInstance.getMap(mapName);
    populateMap(map, mapSize);
    Set<Integer> keys = map.keySet();
    // populate Near Cache
    int expectedHits = 0;
    for (int i = 0; i < mapSize; i++) {
        map.get(i);
        int partitionId = partitionService.getPartitionId(i);
        if (!partitionService.isPartitionOwner(partitionId)) {
            // map proxy stores non-owned entries (belong to partition which its not owner) inside its Near Cache
            expectedHits++;
        }
    }
    // generate Near Cache hits
    Map<Integer, Integer> allEntries = map.getAll(keys);
    for (int i = 0; i < mapSize; i++) {
        assertEquals(i, (int) allEntries.get(i));
    }
    // check Near Cache hits
    long hits = getNearCacheStats(map).getHits();
    assertEquals(format("Near Cache hits should be %d but were %d", expectedHits, hits), expectedHits, hits);
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 68 with NearCacheConfig

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

the class NearCacheTest method testNearCacheEviction.

@Test
public void testNearCacheEviction() {
    String mapName = "testNearCacheEviction";
    NearCacheConfig nearCacheConfig = newNearCacheConfigWithEntryCountEviction(EvictionPolicy.LRU, MAX_CACHE_SIZE);
    Config config = getConfig();
    config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance(config);
    IMap<Integer, Integer> map = hazelcastInstance.getMap(mapName);
    testNearCacheEviction(map, MAX_CACHE_SIZE);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 69 with NearCacheConfig

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

the class NearCacheTest method multiple_get_on_non_existing_key_generates_one_miss.

@Test
public void multiple_get_on_non_existing_key_generates_one_miss() {
    String mapName = "test";
    Config config = getConfig();
    NearCacheConfig nearCacheConfig = newNearCacheConfig();
    nearCacheConfig.setCacheLocalEntries(true);
    config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap map = node.getMap(mapName);
    map.get(1);
    map.get(1);
    map.get(1);
    NearCacheStats nearCacheStats = map.getLocalMapStats().getNearCacheStats();
    assertEquals(1, nearCacheStats.getMisses());
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheStats(com.hazelcast.nearcache.NearCacheStats) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 70 with NearCacheConfig

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

the class EventListenerCounterTest method near_cache_invalidation_listener_does_not_cause_map_container_creation_on_join.

@Test
public void near_cache_invalidation_listener_does_not_cause_map_container_creation_on_join() {
    Config config = smallInstanceConfig();
    MapConfig mapConfig = config.getMapConfig("default");
    mapConfig.setNearCacheConfig(new NearCacheConfig());
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance node1 = factory.newHazelcastInstance(config);
    // here a near-cache enabled map adds an
    // invalidation listener behind the scenes.
    node1.getMap("test");
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    node1.shutdown();
    assertNull("during join process, there shouldn't be any map-container created", getExistingMapContainer(node2, "test"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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