Search in sources :

Example 21 with NearCache

use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.

the class NearCacheBatchInvalidationTest method testMapClear_shouldClearNearCaches_onOwnerAndBackupNodes.

@Test
public void testMapClear_shouldClearNearCaches_onOwnerAndBackupNodes() throws Exception {
    String mapName = randomMapName();
    Config config = newConfig(mapName);
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    configureBatching(config, true, 5, 5);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance node1 = factory.newHazelcastInstance(config);
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    final IMap<Integer, Integer> map1 = node1.getMap(mapName);
    final IMap<Integer, Integer> map2 = node2.getMap(mapName);
    int size = 1000;
    // fill map-1
    for (int i = 0; i < size; i++) {
        map1.put(i, i);
    }
    // fill Near Cache on node-1
    for (int i = 0; i < size; i++) {
        map1.get(i);
    }
    // fill Near Cache on node-2
    for (int i = 0; i < size; i++) {
        map2.get(i);
    }
    map1.clear();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            NearCache nearCache1 = ((NearCachedMapProxyImpl) map1).getNearCache();
            NearCache nearCache2 = ((NearCachedMapProxyImpl) map2).getNearCache();
            assertEquals(0, 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) AssertTask(com.hazelcast.test.AssertTask) NearCache(com.hazelcast.internal.nearcache.NearCache) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with NearCache

use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.

the class LocalMapStatsProvider method addNearCacheStats.

private void addNearCacheStats(String mapName, LocalMapStatsImpl localMapStats, LocalMapOnDemandCalculatedStats onDemandStats) {
    NearCache nearCache = mapNearCacheManager.getNearCache(mapName);
    if (nearCache == null) {
        return;
    }
    NearCacheStats nearCacheStats = nearCache.getNearCacheStats();
    localMapStats.setNearCacheStats(nearCacheStats);
    onDemandStats.incrementHeapCost(nearCacheStats.getOwnedEntryMemoryCost());
}
Also used : NearCacheStats(com.hazelcast.nearcache.NearCacheStats) NearCache(com.hazelcast.internal.nearcache.NearCache)

Example 23 with NearCache

use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.

the class ClientCacheNearCacheCacheOnUpdateTest method checkNearCacheInstance.

protected void checkNearCacheInstance(ICache iCacheOnClient) {
    NearCache nearCache = ((NearCachedClientCacheProxy<Object, Object>) iCacheOnClient).getNearCache();
    assertInstanceOf(DefaultNearCache.class, nearCache);
}
Also used : DefaultNearCache(com.hazelcast.internal.nearcache.impl.DefaultNearCache) NearCache(com.hazelcast.internal.nearcache.NearCache)

Example 24 with NearCache

use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.

the class MapNearCacheInvalidationFromClientTest method testClear.

@Test
public void testClear() {
    IMap<Object, Object> map = client.getMap(mapName);
    final int count = 100;
    for (int i = 0; i < count; i++) {
        map.put(i, i);
    }
    final IMap<Object, Object> liteMap = lite.getMap(mapName);
    final NearCache nearCache = getNearCache(lite, mapName);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            for (int i = 0; i < count; i++) {
                liteMap.get(i);
            }
            assertEquals(count, nearCache.size());
        }
    });
    map.clear();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals(0, nearCache.size());
        }
    });
}
Also used : NearCache(com.hazelcast.internal.nearcache.NearCache) AssertTask(com.hazelcast.test.AssertTask) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with NearCache

use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.

the class ClientMapNearCacheTest method receives_one_clearEvent_after_mapLoadAll_call_from_client.

@Test
public void receives_one_clearEvent_after_mapLoadAll_call_from_client() {
    // configure map-store
    Config config = newConfig();
    config.getMapConfig("default").getMapStoreConfig().setEnabled(true).setImplementation(new SimpleMapStore());
    // populate Near Cache
    NearCacheConfig nearCacheConfig = newNearCacheConfig();
    final IMap<Integer, Integer> clientMap = getNearCachedMapFromClient(config, nearCacheConfig, 2);
    populateMap(clientMap, 1000);
    populateNearCache(clientMap, 1000);
    // create a new client to send events
    HazelcastInstance anotherClient = hazelcastFactory.newHazelcastClient(newClientConfig());
    IMap<Object, Object> anotherClientMap = anotherClient.getMap(clientMap.getName());
    anotherClientMap.loadAll(true);
    InternalSerializationService serializationService = getSerializationService(hazelcastFactory.getAllHazelcastInstances().iterator().next());
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            NearCache<Object, Object> nearCache = ((NearCachedClientMapProxy<Integer, Integer>) clientMap).getNearCache();
            for (int i = 0; i < 1000; i++) {
                Object key = i;
                if (nearCacheConfig.isSerializeKeys()) {
                    key = serializationService.toData(i);
                }
                assertNull("Near Cache should be empty", nearCache.get(key));
            }
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheTestUtils.getBaseConfig(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) AssertTask(com.hazelcast.test.AssertTask) NearCache(com.hazelcast.internal.nearcache.NearCache) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

NearCache (com.hazelcast.internal.nearcache.NearCache)33 Test (org.junit.Test)17 QuickTest (com.hazelcast.test.annotation.QuickTest)16 AssertTask (com.hazelcast.test.AssertTask)14 Config (com.hazelcast.config.Config)12 NearCacheConfig (com.hazelcast.config.NearCacheConfig)12 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)12 MapConfig (com.hazelcast.config.MapConfig)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)9 NearCacheTestUtils.getBaseConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig)6 DefaultNearCache (com.hazelcast.internal.nearcache.impl.DefaultNearCache)5 NearCacheStats (com.hazelcast.nearcache.NearCacheStats)5 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 NearCacheRecord (com.hazelcast.internal.nearcache.NearCacheRecord)3 AbstractNearCacheRecordStore (com.hazelcast.internal.nearcache.impl.store.AbstractNearCacheRecordStore)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 NearCachedMapProxyImpl (com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl)3 NightlyTest (com.hazelcast.test.annotation.NightlyTest)3