use of com.hazelcast.instance.impl.LifecycleServiceImpl in project hazelcast by hazelcast.
the class ClusterServiceImpl method merge.
public void merge(Address newTargetAddress) {
node.getJoiner().setTargetAddress(newTargetAddress);
LifecycleServiceImpl lifecycleService = node.hazelcastInstance.getLifecycleService();
lifecycleService.runUnderLifecycleLock(new ClusterMergeTask(node));
}
use of com.hazelcast.instance.impl.LifecycleServiceImpl 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)));
}
}
use of com.hazelcast.instance.impl.LifecycleServiceImpl in project hazelcast by hazelcast.
the class CacheExpirationManagerTest method backgroundClearTaskStops_whenLifecycleState.
private void backgroundClearTaskStops_whenLifecycleState(LifecycleEvent.LifecycleState lifecycleState) {
Config config = getConfig();
config.setProperty(taskPeriodSecondsPropName(), "1");
HazelcastInstance node = createHazelcastInstance(config);
final SimpleEntryListener simpleEntryListener = new SimpleEntryListener();
CacheManager cacheManager = createCacheManager(node);
CacheConfiguration cacheConfiguration = createCacheConfig(simpleEntryListener, new HazelcastExpiryPolicy(1000, 1000, 1000));
Cache<Integer, Integer> cache = cacheManager.createCache("test", cacheConfiguration);
cache.put(1, 1);
((LifecycleServiceImpl) node.getLifecycleService()).fireLifecycleEvent(lifecycleState);
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() {
int expirationCount = simpleEntryListener.expiredCount.get();
assertEquals(format("Expecting no expiration but found:%d", expirationCount), 0, expirationCount);
}
}, 5);
}
use of com.hazelcast.instance.impl.LifecycleServiceImpl in project hazelcast by hazelcast.
the class CacheExpirationManagerTest method restarts_running_backgroundClearTask_when_lifecycleState_turns_to_MERGED.
@Test
public void restarts_running_backgroundClearTask_when_lifecycleState_turns_to_MERGED() {
Config config = getConfig();
config.setProperty(taskPeriodSecondsPropName(), "1");
HazelcastInstance node = createHazelcastInstance(config);
final SimpleEntryListener<Integer, Integer> simpleEntryListener = new SimpleEntryListener<Integer, Integer>();
CacheManager cacheManager = createCacheManager(node);
CacheConfiguration<Integer, Integer> cacheConfig = createCacheConfig(simpleEntryListener, new HazelcastExpiryPolicy(3000, 3000, 3000));
Cache<Integer, Integer> cache = cacheManager.createCache("test", cacheConfig);
cache.put(1, 1);
((LifecycleServiceImpl) node.getLifecycleService()).fireLifecycleEvent(MERGING);
((LifecycleServiceImpl) node.getLifecycleService()).fireLifecycleEvent(MERGED);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
int expirationCount = simpleEntryListener.expiredCount.get();
assertEquals(format("Expecting 1 expiration but found:%d", expirationCount), 1, expirationCount);
}
});
}
use of com.hazelcast.instance.impl.LifecycleServiceImpl in project hazelcast by hazelcast.
the class MapExpirationManagerTest method backgroundClearTaskStops_whenLifecycleState.
private void backgroundClearTaskStops_whenLifecycleState(LifecycleEvent.LifecycleState lifecycleState) {
Config config = getConfig();
config.setProperty(taskPeriodSecondsPropName(), "1");
HazelcastInstance node = createHazelcastInstance(config);
final AtomicInteger expirationCounter = new AtomicInteger();
IMap<Integer, Integer> map = node.getMap("test");
map.addEntryListener(new EntryExpiredListener() {
@Override
public void entryExpired(EntryEvent event) {
expirationCounter.incrementAndGet();
}
}, true);
map.put(1, 1, 3, TimeUnit.SECONDS);
((LifecycleServiceImpl) node.getLifecycleService()).fireLifecycleEvent(lifecycleState);
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() {
int expirationCount = expirationCounter.get();
assertEquals(format("Expecting no expiration but found:%d", expirationCount), 0, expirationCount);
}
}, 5);
}
Aggregations