Search in sources :

Example 6 with LifecycleServiceImpl

use of com.hazelcast.instance.impl.LifecycleServiceImpl in project hazelcast by hazelcast.

the class MapExpirationManagerTest 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 AtomicInteger expirationCounter = new AtomicInteger();
    IMap<Integer, Integer> map = node.getMap("test");
    map.addEntryListener((EntryExpiredListener) event -> expirationCounter.incrementAndGet(), true);
    map.put(1, 1, 3, TimeUnit.SECONDS);
    ((LifecycleServiceImpl) node.getLifecycleService()).fireLifecycleEvent(MERGING);
    ((LifecycleServiceImpl) node.getLifecycleService()).fireLifecycleEvent(MERGED);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            int expirationCount = expirationCounter.get();
            assertEquals(format("Expecting 1 expiration but found:%d", expirationCount), 1, expirationCount);
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) MERGING(com.hazelcast.core.LifecycleEvent.LifecycleState.MERGING) MERGED(com.hazelcast.core.LifecycleEvent.LifecycleState.MERGED) LifecycleServiceImpl(com.hazelcast.instance.impl.LifecycleServiceImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PROP_PRIMARY_DRIVES_BACKUP(com.hazelcast.map.impl.eviction.MapClearExpiredRecordsTask.PROP_PRIMARY_DRIVES_BACKUP) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) System.getProperty(java.lang.System.getProperty) SHUTTING_DOWN(com.hazelcast.core.LifecycleEvent.LifecycleState.SHUTTING_DOWN) System.setProperty(java.lang.System.setProperty) EntryEvent(com.hazelcast.core.EntryEvent) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) LifecycleEvent(com.hazelcast.core.LifecycleEvent) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MapService(com.hazelcast.map.impl.MapService) Category(org.junit.experimental.categories.Category) EntryExpiredListener(com.hazelcast.map.listener.EntryExpiredListener) String.format(java.lang.String.format) TimeUnit(java.util.concurrent.TimeUnit) SERVICE_NAME(com.hazelcast.map.impl.MapService.SERVICE_NAME) MapClearExpiredRecordsTask(com.hazelcast.map.impl.eviction.MapClearExpiredRecordsTask) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) AssertTask(com.hazelcast.test.AssertTask) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) LifecycleServiceImpl(com.hazelcast.instance.impl.LifecycleServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with LifecycleServiceImpl

use of com.hazelcast.instance.impl.LifecycleServiceImpl in project hazelcast by hazelcast.

the class NodeQueryCacheContext method flushPublishersOnNodeShutdown.

/**
 * This is a best effort approach; there is no guarantee that events in publishers internal buffers will be fired,
 * {@link EventService} can drop them.
 */
private void flushPublishersOnNodeShutdown() {
    Node node = ((NodeEngineImpl) this.nodeEngine).getNode();
    LifecycleServiceImpl lifecycleService = node.hazelcastInstance.getLifecycleService();
    lifecycleService.addLifecycleListener(event -> {
        if (SHUTTING_DOWN == event.getState()) {
            publisherContext.flush();
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Node(com.hazelcast.instance.impl.Node) 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