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);
}
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);
}
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));
}
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();
}
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)));
}
}
Aggregations