Search in sources :

Example 1 with LifecycleServiceImpl

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));
}
Also used : LifecycleServiceImpl(com.hazelcast.instance.impl.LifecycleServiceImpl)

Example 2 with LifecycleServiceImpl

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

Example 3 with LifecycleServiceImpl

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) HazelcastExpiryPolicy(com.hazelcast.cache.HazelcastExpiryPolicy) LifecycleServiceImpl(com.hazelcast.instance.impl.LifecycleServiceImpl) CacheConfiguration(com.hazelcast.config.CacheConfiguration)

Example 4 with LifecycleServiceImpl

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);
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) HazelcastExpiryPolicy(com.hazelcast.cache.HazelcastExpiryPolicy) LifecycleServiceImpl(com.hazelcast.instance.impl.LifecycleServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with LifecycleServiceImpl

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryExpiredListener(com.hazelcast.map.listener.EntryExpiredListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Config(com.hazelcast.config.Config) EntryEvent(com.hazelcast.core.EntryEvent) AssertTask(com.hazelcast.test.AssertTask) LifecycleServiceImpl(com.hazelcast.instance.impl.LifecycleServiceImpl)

Aggregations

LifecycleServiceImpl (com.hazelcast.instance.impl.LifecycleServiceImpl)7 Config (com.hazelcast.config.Config)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 AssertTask (com.hazelcast.test.AssertTask)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 CacheConfig (com.hazelcast.config.CacheConfig)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 Test (org.junit.Test)3 HazelcastExpiryPolicy (com.hazelcast.cache.HazelcastExpiryPolicy)2 EntryEvent (com.hazelcast.core.EntryEvent)2 EntryExpiredListener (com.hazelcast.map.listener.EntryExpiredListener)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 CacheManager (javax.cache.CacheManager)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 CacheConfiguration (com.hazelcast.config.CacheConfiguration)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 LifecycleEvent (com.hazelcast.core.LifecycleEvent)1 MERGED (com.hazelcast.core.LifecycleEvent.LifecycleState.MERGED)1 MERGING (com.hazelcast.core.LifecycleEvent.LifecycleState.MERGING)1 SHUTTING_DOWN (com.hazelcast.core.LifecycleEvent.LifecycleState.SHUTTING_DOWN)1