Search in sources :

Example 1 with NearCachedMapProxyImpl

use of com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl in project hazelcast by hazelcast.

the class MapRemoteService method createDistributedObject.

@Override
public DistributedObject createDistributedObject(String name) {
    MapConfig mapConfig = nodeEngine.getConfig().findMapConfig(name);
    checkMapConfig(mapConfig);
    if (mapConfig.isNearCacheEnabled()) {
        checkNearCacheConfig(name, mapConfig.getNearCacheConfig(), false);
        return new NearCachedMapProxyImpl(name, mapServiceContext.getService(), nodeEngine, mapConfig);
    } else {
        return new MapProxyImpl(name, mapServiceContext.getService(), nodeEngine, mapConfig);
    }
}
Also used : MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) MapConfig(com.hazelcast.config.MapConfig) ConfigValidator.checkMapConfig(com.hazelcast.internal.config.ConfigValidator.checkMapConfig)

Example 2 with NearCachedMapProxyImpl

use of com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl in project hazelcast by hazelcast.

the class NearCacheLiteMemberTest method testPutAll.

public static void testPutAll(HazelcastInstance instance, HazelcastInstance lite, String mapName) {
    IMap<Object, Object> map = instance.getMap(mapName);
    IMap<Object, Object> liteMap = lite.getMap(mapName);
    NearCachedMapProxyImpl proxy = (NearCachedMapProxyImpl) liteMap;
    NearCache liteNearCache = proxy.getNearCache();
    SerializationService serializationService = ((SerializationServiceSupport) instance).getSerializationService();
    int count = 100;
    // fill the near cache with the same data as below so we can detect when it is emptied
    for (int i = 0; i < count; i++) {
        liteNearCache.put(serializationService.toData(i), i);
    }
    final NearCacheStats stats = liteNearCache.getNearCacheStats();
    assertEquals(100, stats.getOwnedEntryCount());
    Map<Object, Object> localMap = new HashMap<Object, Object>();
    for (int i = 0; i < count; i++) {
        localMap.put(i, i);
    }
    map.putAll(localMap);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(0, stats.getOwnedEntryCount());
        }
    });
    for (int i = 0; i < count; i++) {
        liteMap.get(i);
    }
    assertLiteMemberNearCacheNonEmpty(lite, mapName);
}
Also used : HashMap(java.util.HashMap) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) NearCache(com.hazelcast.internal.nearcache.NearCache) SerializationService(com.hazelcast.spi.serialization.SerializationService) NearCacheStats(com.hazelcast.monitor.NearCacheStats) SerializationServiceSupport(com.hazelcast.spi.impl.SerializationServiceSupport) AssertTask(com.hazelcast.test.AssertTask)

Example 3 with NearCachedMapProxyImpl

use of com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl in project hazelcast by hazelcast.

the class GetAllTest method ensure_supplied_number_of_keys_are_in_near_cache.

@Test
public void ensure_supplied_number_of_keys_are_in_near_cache() throws Exception {
    final int entryCount = 100000;
    final String mapName = "test";
    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setCacheLocalEntries(true);
    nearCacheConfig.setInvalidateOnChange(true);
    Config config = new Config();
    config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap map = node.getMap(mapName);
    for (int i = 0; i < entryCount; i++) {
        map.put(i, i);
    }
    HashSet keys = new HashSet();
    for (int i = 0; i < entryCount; i++) {
        keys.add(i);
    }
    map.getAll(keys);
    assertEquals(entryCount, ((NearCachedMapProxyImpl) map).getNearCache().size());
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with NearCachedMapProxyImpl

use of com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl in project hazelcast by hazelcast.

the class NearCacheBatchInvalidationTest method testHigherBatchSize_shouldNotCauseAnyInvalidation_onRemoteNode.

@Test
public void testHigherBatchSize_shouldNotCauseAnyInvalidation_onRemoteNode() throws Exception {
    String mapName = randomMapName();
    Config config = newConfig(mapName);
    configureBatching(config, true, Integer.MAX_VALUE, Integer.MAX_VALUE);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance node1 = factory.newHazelcastInstance(config);
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    IMap<String, Integer> map1 = node1.getMap(mapName);
    IMap<String, Integer> map2 = node2.getMap(mapName);
    int size = 1000;
    List<String> keys = new ArrayList<String>();
    for (int i = 0; i < size; i++) {
        keys.add(generateKeyOwnedBy(node1));
    }
    // fill map-1
    for (int i = 0; i < size; i++) {
        map1.put(keys.get(i), i);
    }
    // fill Near Cache on node-1
    for (int i = 0; i < size; i++) {
        map1.get(keys.get(i));
    }
    // fill Near Cache on node-2
    for (int i = 0; i < size; i++) {
        map2.get(keys.get(i));
    }
    // generate invalidation data
    for (int i = 0; i < size; i++) {
        map1.put(keys.get(i), i);
    }
    NearCache nearCache1 = ((NearCachedMapProxyImpl) map1).getNearCache();
    NearCache nearCache2 = ((NearCachedMapProxyImpl) map2).getNearCache();
    // Near Cache on one node should be invalidated wholly, other node should not receive any event.
    // Due to the higher batch-size to sent invalidation.
    assertEquals(size, nearCache1.size() + nearCache2.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ArrayList(java.util.ArrayList) NearCache(com.hazelcast.internal.nearcache.NearCache) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

NearCachedMapProxyImpl (com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl)4 Config (com.hazelcast.config.Config)2 MapConfig (com.hazelcast.config.MapConfig)2 NearCacheConfig (com.hazelcast.config.NearCacheConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 NearCache (com.hazelcast.internal.nearcache.NearCache)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 IMap (com.hazelcast.core.IMap)1 ConfigValidator.checkMapConfig (com.hazelcast.internal.config.ConfigValidator.checkMapConfig)1 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)1 NearCacheStats (com.hazelcast.monitor.NearCacheStats)1 SerializationServiceSupport (com.hazelcast.spi.impl.SerializationServiceSupport)1 SerializationService (com.hazelcast.spi.serialization.SerializationService)1 AssertTask (com.hazelcast.test.AssertTask)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1