Search in sources :

Example 11 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class ClientReplicatedMapProxy method initNearCache.

private void initNearCache() {
    ClientContext context = getContext();
    NearCacheConfig nearCacheConfig = context.getClientConfig().getNearCacheConfig(name);
    if (nearCacheConfig == null) {
        return;
    }
    nearCache = context.getNearCacheManager().getOrCreateNearCache(name, nearCacheConfig);
    if (nearCache.isInvalidatedOnChange()) {
        addNearCacheInvalidateListener();
    }
}
Also used : ClientContext(com.hazelcast.client.spi.ClientContext) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 12 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class NearCachedClientMapProxy method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    ClientContext context = getContext();
    logger = context.getLoggingService().getLogger(getClass());
    NearCacheConfig nearCacheConfig = context.getClientConfig().getNearCacheConfig(name);
    NearCacheManager nearCacheManager = context.getNearCacheManager();
    IMapDataStructureAdapter<K, V> adapter = new IMapDataStructureAdapter<K, V>(this);
    nearCache = nearCacheManager.getOrCreateNearCache(name, nearCacheConfig, adapter);
    invalidateOnChange = nearCache.isInvalidatedOnChange();
    if (invalidateOnChange) {
        addNearCacheInvalidationListener(new ConnectedServerVersionAwareNearCacheEventHandler());
    }
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) ClientContext(com.hazelcast.client.spi.ClientContext) IMapDataStructureAdapter(com.hazelcast.internal.adapter.IMapDataStructureAdapter) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 13 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class ClientCacheRecordStateStressTest method all_records_are_readable_state_in_the_end.

@Test
public void all_records_are_readable_state_in_the_end() throws Exception {
    HazelcastInstance member = factory.newHazelcastInstance();
    CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(member);
    final CacheManager serverCacheManager = provider.getCacheManager();
    factory.newHazelcastInstance();
    factory.newHazelcastInstance();
    // populated from member.
    CacheConfig cacheConfig = new CacheConfig();
    cacheConfig.getEvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(MAX_VALUE);
    final Cache memberCache = serverCacheManager.createCache(cacheName, cacheConfig);
    for (int i = 0; i < KEY_SPACE; i++) {
        memberCache.put(i, i);
    }
    ClientConfig clientConfig = new ClientConfig();
    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setInvalidateOnChange(true).setLocalUpdatePolicy(localUpdatePolicy).getEvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(MAX_VALUE);
    clientConfig.addNearCacheConfig(nearCacheConfig);
    List<Thread> threads = new ArrayList<Thread>();
    // member
    for (int i = 0; i < PUT_THREAD_COUNT; i++) {
        Put put = new Put(memberCache);
        threads.add(put);
    }
    // client
    HazelcastClientProxy client = (HazelcastClientProxy) factory.newHazelcastClient(clientConfig);
    CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
    CacheManager cacheManager = clientCachingProvider.getCacheManager();
    final Cache clientCache = cacheManager.createCache(cacheName, cacheConfig);
    for (int i = 0; i < GET_ALL_THREAD_COUNT; i++) {
        GetAll getAll = new GetAll(clientCache);
        threads.add(getAll);
    }
    for (int i = 0; i < PUT_ALL_THREAD_COUNT; i++) {
        PutAll putAll = new PutAll(clientCache);
        threads.add(putAll);
    }
    for (int i = 0; i < PUT_IF_ABSENT_THREAD_COUNT; i++) {
        PutIfAbsent putIfAbsent = new PutIfAbsent(clientCache);
        threads.add(putIfAbsent);
    }
    for (int i = 0; i < GET_THREAD_COUNT; i++) {
        Get get = new Get(clientCache);
        threads.add(get);
    }
    for (int i = 0; i < REMOVE_THREAD_COUNT; i++) {
        Remove remove = new Remove(clientCache);
        threads.add(remove);
    }
    for (int i = 0; i < CLEAR_THREAD_COUNT; i++) {
        Clear clear = new Clear(clientCache);
        threads.add(clear);
    }
    // start threads
    for (Thread thread : threads) {
        thread.start();
    }
    // stress for a while
    sleepSeconds(TEST_RUN_SECONDS);
    // stop threads
    stop.set(true);
    for (Thread thread : threads) {
        thread.join();
    }
    assertFinalRecordStateIsReadPermitted(clientCache, member);
}
Also used : ArrayList(java.util.ArrayList) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) DefaultNearCache(com.hazelcast.internal.nearcache.impl.DefaultNearCache) Cache(javax.cache.Cache) NearCache(com.hazelcast.internal.nearcache.NearCache) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 14 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class ClientNearCacheTestSupport method testNearCacheExpiration_withTTL.

protected void testNearCacheExpiration_withTTL(InMemoryFormat inMemoryFormat) {
    NearCacheConfig nearCacheConfig = createNearCacheConfig(inMemoryFormat);
    nearCacheConfig.setTimeToLiveSeconds(MAX_TTL_SECONDS);
    testNearCacheExpiration(nearCacheConfig, MAX_TTL_SECONDS);
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 15 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class ClientNearCacheTestSupport method doTestGetAllReturnsFromNearCache.

protected void doTestGetAllReturnsFromNearCache(InMemoryFormat inMemoryFormat) {
    if (inMemoryFormat != InMemoryFormat.OBJECT) {
        return;
    }
    NearCacheConfig nearCacheConfig = createNearCacheConfig(inMemoryFormat);
    NearCacheTestContext nearCacheTestContext = createNearCacheTestAndFillWithData(DEFAULT_CACHE_NAME, nearCacheConfig);
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        assertNull(nearCacheTestContext.nearCache.get(nearCacheTestContext.serializationService.toData(i)));
    }
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        // get records so they will be stored in Near Cache
        nearCacheTestContext.cache.get(i);
    }
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        Data keyData = nearCacheTestContext.serializationService.toData(i);
        // check if same reference to verify data coming from Near Cache
        assertSame(nearCacheTestContext.cache.get(i), nearCacheTestContext.nearCache.get(keyData));
    }
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) Data(com.hazelcast.nio.serialization.Data)

Aggregations

NearCacheConfig (com.hazelcast.config.NearCacheConfig)212 Test (org.junit.Test)89 QuickTest (com.hazelcast.test.annotation.QuickTest)82 Config (com.hazelcast.config.Config)66 HazelcastInstance (com.hazelcast.core.HazelcastInstance)65 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)62 ClientConfig (com.hazelcast.client.config.ClientConfig)51 MapConfig (com.hazelcast.config.MapConfig)37 EvictionConfig (com.hazelcast.config.EvictionConfig)24 Before (org.junit.Before)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)16 CacheConfig (com.hazelcast.config.CacheConfig)15 ParallelTest (com.hazelcast.test.annotation.ParallelTest)15 NearCacheTestUtils.getBaseConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig)14 AssertTask (com.hazelcast.test.AssertTask)14 NightlyTest (com.hazelcast.test.annotation.NightlyTest)12 MapStoreConfig (com.hazelcast.config.MapStoreConfig)11 Data (com.hazelcast.nio.serialization.Data)11 MatchingPointConfigPatternMatcher (com.hazelcast.config.matcher.MatchingPointConfigPatternMatcher)10 CachingProvider (javax.cache.spi.CachingProvider)10