Search in sources :

Example 1 with NearCache

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

the class DefaultNearCacheManager method destroyAllNearCaches.

@Override
public void destroyAllNearCaches() {
    for (NearCache nearCache : new HashSet<NearCache>(nearCacheMap.values())) {
        nearCacheMap.remove(nearCache.getName());
        nearCache.destroy();
    }
    for (ScheduledFuture preloadTaskFuture : preloadTaskFutures) {
        preloadTaskFuture.cancel(true);
    }
    if (storageTaskFuture != null) {
        storageTaskFuture.cancel(true);
    }
}
Also used : NearCache(com.hazelcast.internal.nearcache.NearCache) ScheduledFuture(java.util.concurrent.ScheduledFuture) HashSet(java.util.HashSet)

Example 2 with NearCache

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

the class NearCacheBatchInvalidationTest method testBatchInvalidationRemovesEntries.

@Test
public void testBatchInvalidationRemovesEntries() throws Exception {
    String mapName = randomMapName();
    Config config = newConfig(mapName);
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    configureBatching(config, true, 12, 1);
    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);
    }
    // generate invalidation data
    for (int i = 0; i < size; i++) {
        map1.put(i, i);
    }
    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 3 with NearCache

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

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

the class NearCacheLiteMemberTest method assertLiteMemberNearCacheNonEmpty.

private static void assertLiteMemberNearCacheNonEmpty(HazelcastInstance instance, String mapName) {
    NearCache nearCache = getNearCache(instance, mapName);
    int sizeAfterPut = nearCache.size();
    assertTrue("Near Cache size should be > 0 but was " + sizeAfterPut, sizeAfterPut > 0);
}
Also used : NearCache(com.hazelcast.internal.nearcache.NearCache)

Example 5 with NearCache

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

the class ClientCacheRecordStateStressTest method assertFinalRecordStateIsReadPermitted.

private void assertFinalRecordStateIsReadPermitted(Cache clientCache, HazelcastInstance member) {
    ClientCacheProxy proxy = ((ClientCacheProxy) clientCache);
    NearCache nearCache = proxy.getNearCache();
    DefaultNearCache unwrap = (DefaultNearCache) nearCache.unwrap(DefaultNearCache.class);
    InternalSerializationService ss = getSerializationService(member);
    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 : ClientCacheProxy(com.hazelcast.client.cache.impl.ClientCacheProxy) 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) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService)

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