Search in sources :

Example 11 with NearCache

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

the class NearCacheManagerTestSupport method doDestroyNearCacheAndDestroyAllNearCaches.

void doDestroyNearCacheAndDestroyAllNearCaches() {
    NearCacheManager nearCacheManager = createNearCacheManager();
    for (int i = 0; i < DEFAULT_NEAR_CACHE_COUNT; i++) {
        createNearCache(nearCacheManager, DEFAULT_NEAR_CACHE_NAME + "-" + i);
    }
    Collection<NearCache> nearCaches1 = nearCacheManager.listAllNearCaches();
    assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches1.size());
    for (int i = 0; i < DEFAULT_NEAR_CACHE_COUNT; i++) {
        assertTrue(nearCacheManager.destroyNearCache(DEFAULT_NEAR_CACHE_NAME + "-" + i));
    }
    Collection<NearCache> nearCaches2 = nearCacheManager.listAllNearCaches();
    // destroy also removes Near Cache
    assertEquals(0, nearCaches2.size());
    assertFalse(nearCacheManager.clearNearCache(DEFAULT_NEAR_CACHE_NAME + "-" + DEFAULT_NEAR_CACHE_COUNT));
    for (int i = 0; i < DEFAULT_NEAR_CACHE_COUNT; i++) {
        createNearCache(nearCacheManager, DEFAULT_NEAR_CACHE_NAME + "-" + i);
    }
    Collection<NearCache> nearCaches3 = nearCacheManager.listAllNearCaches();
    assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches3.size());
    nearCacheManager.destroyAllNearCaches();
    Collection<NearCache> nearCaches4 = nearCacheManager.listAllNearCaches();
    // destroy all also removes Near Caches
    assertEquals(0, nearCaches4.size());
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCache(com.hazelcast.internal.nearcache.NearCache)

Example 12 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_member.

@Test
public void receives_one_clearEvent_after_mapLoadAll_call_from_member() {
    // 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);
    HazelcastInstance member = hazelcastFactory.getAllHazelcastInstances().iterator().next();
    IMap<Object, Object> memberMap = member.getMap(clientMap.getName());
    memberMap.loadAll(true);
    InternalSerializationService serializationService = getSerializationService(member);
    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)

Example 13 with NearCache

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

the class MapNearCacheInvalidationFromClientTest method testEvict.

@Test
public void testEvict() {
    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.evict(0);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertTrue(nearCache.size() < count);
        }
    });
}
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 14 with NearCache

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

the class MapNearCacheInvalidationFromClientTest method testEvictAll.

@Test
public void testEvictAll() {
    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.evictAll();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertTrue(nearCache.size() < count);
        }
    });
}
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 15 with NearCache

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

the class MapNearCacheInvalidationFromClientTest method testPut.

@Test
public void testPut() {
    IMap<Object, Object> map = client.getMap(mapName);
    int count = 100;
    for (int i = 0; i < count; i++) {
        map.put(i, i);
    }
    IMap<Object, Object> liteMap = lite.getMap(mapName);
    for (int i = 0; i < count; i++) {
        assertNotNull(liteMap.get(i));
    }
    NearCache nearCache = getNearCache(lite, 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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) 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