Search in sources :

Example 51 with NearCacheConfig

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

the class ClientNearCacheConfigTest method testSpecificNearCacheConfig_whenAsteriskAtTheBeginning.

@Test
public void testSpecificNearCacheConfig_whenAsteriskAtTheBeginning() {
    final ClientConfig clientConfig = new ClientConfig();
    final NearCacheConfig genericNearCacheConfig = new NearCacheConfig();
    genericNearCacheConfig.setName("*Map");
    clientConfig.addNearCacheConfig(genericNearCacheConfig);
    final NearCacheConfig specificNearCacheConfig = new NearCacheConfig();
    specificNearCacheConfig.setName("*MapStudent");
    clientConfig.addNearCacheConfig(specificNearCacheConfig);
    final NearCacheConfig mapFoo = clientConfig.getNearCacheConfig("fooMap");
    final NearCacheConfig mapStudentFoo = clientConfig.getNearCacheConfig("fooMapStudent");
    assertEquals(genericNearCacheConfig, mapFoo);
    assertEquals(specificNearCacheConfig, mapStudentFoo);
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 52 with NearCacheConfig

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

the class ClientNearCacheConfigTest method testSpecificNearCacheConfig_whenAsteriskInTheMiddle.

@Test
public void testSpecificNearCacheConfig_whenAsteriskInTheMiddle() {
    final ClientConfig clientConfig = new ClientConfig();
    final NearCacheConfig genericNearCacheConfig = new NearCacheConfig();
    genericNearCacheConfig.setName("map*Bar");
    clientConfig.addNearCacheConfig(genericNearCacheConfig);
    final NearCacheConfig specificNearCacheConfig = new NearCacheConfig();
    specificNearCacheConfig.setName("mapStudent*Bar");
    clientConfig.addNearCacheConfig(specificNearCacheConfig);
    final NearCacheConfig mapFoo = clientConfig.getNearCacheConfig("mapFooBar");
    final NearCacheConfig mapStudentFoo = clientConfig.getNearCacheConfig("mapStudentFooBar");
    assertEquals(genericNearCacheConfig, mapFoo);
    assertEquals(specificNearCacheConfig, mapStudentFoo);
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 53 with NearCacheConfig

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

the class ClientCacheNearCacheCacheOnUpdateTest method newNearCachedCache.

private ICache<Integer, Integer> newNearCachedCache(NearCacheConfig.LocalUpdatePolicy localUpdatePolicy) {
    NearCacheConfig nearCacheConfig = getNearCacheConfig(localUpdatePolicy);
    ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider provider = new HazelcastClientCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    return cacheManager.createCache(DEFAULT_CACHE_NAME, newCacheConfig(InMemoryFormat.BINARY));
}
Also used : HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 54 with NearCacheConfig

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

the class ClientCacheNearCacheInvalidationTest method setup.

@Before
public void setup() {
    hazelcastFactory = new TestHazelcastFactory();
    HazelcastInstance[] allMembers = new HazelcastInstance[MEMBER_COUNT];
    for (int i = 0; i < MEMBER_COUNT; i++) {
        // every instance should have its own getConfig() call because an existing EE test relies on this
        Config config = getConfig().setProperty(CACHE_INVALIDATION_MESSAGE_BATCH_ENABLED.getName(), "false");
        allMembers[i] = hazelcastFactory.newHazelcastInstance(config);
    }
    waitAllForSafeState(allMembers);
    NearCacheConfig nearCacheConfig = getNearCacheConfig(inMemoryFormat);
    ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider provider = createClientCachingProvider(client);
    HazelcastServerCachingProvider memberProvider = createServerCachingProvider(allMembers[0]);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
    CacheConfig<Integer, String> cacheConfig = getCacheConfig(inMemoryFormat);
    ICache<Integer, String> cache = cacheManager.createCache(DEFAULT_CACHE_NAME, cacheConfig);
    ICache<Integer, String> memberCache = memberCacheManager.getCache(getPrefixedCacheName(DEFAULT_CACHE_NAME, null, null));
    NearCacheManager nearCacheManager = ((ClientCacheProxy) cache).getContext().getNearCacheManager(cache.getServiceName());
    NearCache<Object, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(DEFAULT_CACHE_NAME));
    SerializationService serializationService = client.getSerializationService();
    invalidationListener = createInvalidationEventHandler(cache);
    NearCacheTestContextBuilder<Integer, String, Object, String> builder = new NearCacheTestContextBuilder<>(nearCacheConfig, serializationService);
    testContext = builder.setDataInstance(allMembers[0]).setNearCacheInstance(client).setDataAdapter(new ICacheDataStructureAdapter<>(memberCache)).setNearCacheAdapter(new ICacheDataStructureAdapter<>(cache)).setMemberCacheManager(memberCacheManager).setCacheManager(cacheManager).setNearCacheManager(nearCacheManager).setNearCache(nearCache).build();
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheTestUtils.getBaseConfig(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) SerializationService(com.hazelcast.internal.serialization.SerializationService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheTestContextBuilder(com.hazelcast.internal.nearcache.impl.NearCacheTestContextBuilder) ICacheDataStructureAdapter(com.hazelcast.internal.adapter.ICacheDataStructureAdapter) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager) Before(org.junit.Before)

Example 55 with NearCacheConfig

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

the class ClientCacheNearCacheInvalidationTest method putToCacheAndGetInvalidationEventWhenNodeShutdown.

@Test
public void putToCacheAndGetInvalidationEventWhenNodeShutdown() {
    Config config = getConfig().setProperty(CACHE_INVALIDATION_MESSAGE_BATCH_ENABLED.getName(), "true").setProperty(CACHE_INVALIDATION_MESSAGE_BATCH_SIZE.getName(), String.valueOf(Integer.MAX_VALUE)).setProperty(CACHE_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS.getName(), String.valueOf(Integer.MAX_VALUE));
    HazelcastInstance instanceToShutdown = hazelcastFactory.newHazelcastInstance(config);
    warmUpPartitions(testContext.dataInstance, instanceToShutdown);
    waitAllForSafeState(testContext.dataInstance, instanceToShutdown);
    NearCacheConfig nearCacheConfig = getNearCacheConfig(inMemoryFormat).setInvalidateOnChange(true).setLocalUpdatePolicy(LocalUpdatePolicy.CACHE_ON_UPDATE);
    CacheConfig<String, String> cacheConfig = getCacheConfig(inMemoryFormat);
    final NearCacheTestContext<String, String, Object, String> nearCacheTestContext1 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig, cacheConfig);
    final NearCacheTestContext<String, String, Object, String> nearCacheTestContext2 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig, cacheConfig);
    Map<String, String> keyAndValues = new HashMap<>();
    // put cache record from client-1 to instance which is going to be shutdown
    for (int i = 0; i < INITIAL_POPULATION_COUNT; i++) {
        String key = generateKeyOwnedBy(instanceToShutdown);
        String value = generateValueFromKey(i);
        nearCacheTestContext1.nearCacheAdapter.put(key, value);
        keyAndValues.put(key, value);
    }
    // verify that records are exist at Near Cache of client-1 because `local-update-policy` is `CACHE_ON_UPDATE`
    for (Map.Entry<String, String> entry : keyAndValues.entrySet()) {
        String key = entry.getKey();
        String exceptedValue = entry.getValue();
        String actualValue = getFromNearCache(nearCacheTestContext1, key);
        assertEquals(exceptedValue, actualValue);
    }
    // to send to client to invalidate its Near Cache
    for (Map.Entry<String, String> entry : keyAndValues.entrySet()) {
        nearCacheTestContext2.nearCacheAdapter.remove(entry.getKey());
    }
    // we don't shutdown the instance because in case of shutdown even though events are published to event queue,
    // they may not be processed in the event queue due to shutdown event queue executor or may not be sent
    // to client endpoint due to IO handler shutdown
    // for not to making test fragile, we just simulate shutting down by sending its event through `LifeCycleService`,
    // so the node should flush invalidation events before shutdown
    ((LifecycleServiceImpl) instanceToShutdown.getLifecycleService()).fireLifecycleEvent(LifecycleEvent.LifecycleState.SHUTTING_DOWN);
    // verify that records in the Near Cache of client-1 are invalidated eventually when instance shutdown
    for (Map.Entry<String, String> entry : keyAndValues.entrySet()) {
        final String key = entry.getKey();
        assertTrueEventually(() -> assertNull(getFromNearCache(nearCacheTestContext1, key)));
    }
}
Also used : HashMap(java.util.HashMap) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheTestUtils.getBaseConfig(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) LifecycleServiceImpl(com.hazelcast.instance.impl.LifecycleServiceImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Map(java.util.Map) HashMap(java.util.HashMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

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