Search in sources :

Example 16 with NearCache

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

the class ClientMapRecordStateStressTest method assertFinalRecordStateIsReadPermitted.

private void assertFinalRecordStateIsReadPermitted(IMap clientMap, InternalSerializationService ss) {
    NearCachedClientMapProxy proxy = (NearCachedClientMapProxy) clientMap;
    NearCache nearCache = proxy.getNearCache();
    DefaultNearCache unwrap = (DefaultNearCache) nearCache.unwrap(DefaultNearCache.class);
    for (int i = 0; i < KEY_SPACE; i++) {
        Data key = ss.toData(i);
        AbstractNearCacheRecordStore nearCacheRecordStore = (AbstractNearCacheRecordStore) unwrap.getNearCacheRecordStore();
        NearCacheRecord record = nearCacheRecordStore.getRecord(key);
        if (record != null) {
            assertEquals(record.toString(), READ_PERMITTED, record.getRecordState());
        }
    }
}
Also used : DefaultNearCache(com.hazelcast.internal.nearcache.impl.DefaultNearCache) NearCacheRecord(com.hazelcast.internal.nearcache.NearCacheRecord) DefaultNearCache(com.hazelcast.internal.nearcache.impl.DefaultNearCache) NearCache(com.hazelcast.internal.nearcache.NearCache) Data(com.hazelcast.nio.serialization.Data) AbstractNearCacheRecordStore(com.hazelcast.internal.nearcache.impl.store.AbstractNearCacheRecordStore) NearCachedClientMapProxy(com.hazelcast.client.proxy.NearCachedClientMapProxy)

Example 17 with NearCache

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

the class EvictionChecker method getUsedHeapInBytes.

protected long getUsedHeapInBytes(String mapName) {
    long heapCost = 0L;
    final List<Integer> partitionIds = findPartitionIds();
    for (int partitionId : partitionIds) {
        final PartitionContainer container = mapServiceContext.getPartitionContainer(partitionId);
        if (container == null) {
            continue;
        }
        heapCost += getRecordStoreHeapCost(mapName, container);
    }
    MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
    if (!mapContainer.getMapConfig().isNearCacheEnabled()) {
        return heapCost;
    }
    MapNearCacheManager mapNearCacheManager = mapServiceContext.getMapNearCacheManager();
    NearCache nearCache = mapNearCacheManager.getNearCache(mapName);
    NearCacheStats nearCacheStats = nearCache.getNearCacheStats();
    heapCost += nearCacheStats.getOwnedEntryMemoryCost();
    return heapCost;
}
Also used : MapNearCacheManager(com.hazelcast.map.impl.nearcache.MapNearCacheManager) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) NearCacheStats(com.hazelcast.monitor.NearCacheStats) NearCache(com.hazelcast.internal.nearcache.NearCache) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 18 with NearCache

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

the class NearCacheLiteMemberTest method assertNearCacheIsEmptyEventually.

private static void assertNearCacheIsEmptyEventually(HazelcastInstance instance, String mapName) {
    final NearCache nearCache = getNearCache(instance, mapName);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            int size = nearCache.size();
            assertEquals("Lite member Near Cache size should be 0 after evict but was " + size, 0, size);
        }
    });
}
Also used : NearCache(com.hazelcast.internal.nearcache.NearCache) AssertTask(com.hazelcast.test.AssertTask)

Example 19 with NearCache

use of com.hazelcast.internal.nearcache.NearCache 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)

Example 20 with NearCache

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

the class NearCacheBatchInvalidationTest method testMapEvictAll_shouldClearNearCaches_onOwnerAndBackupNodes.

@Test
public void testMapEvictAll_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.evictAll();
    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)

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