Search in sources :

Example 1 with MERGED

use of com.hazelcast.core.LifecycleEvent.LifecycleState.MERGED 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)

Aggregations

Config (com.hazelcast.config.Config)1 EntryEvent (com.hazelcast.core.EntryEvent)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)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 LifecycleServiceImpl (com.hazelcast.instance.impl.LifecycleServiceImpl)1 IMap (com.hazelcast.map.IMap)1 MapService (com.hazelcast.map.impl.MapService)1 SERVICE_NAME (com.hazelcast.map.impl.MapService.SERVICE_NAME)1 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)1 MapClearExpiredRecordsTask (com.hazelcast.map.impl.eviction.MapClearExpiredRecordsTask)1 PROP_PRIMARY_DRIVES_BACKUP (com.hazelcast.map.impl.eviction.MapClearExpiredRecordsTask.PROP_PRIMARY_DRIVES_BACKUP)1 EntryExpiredListener (com.hazelcast.map.listener.EntryExpiredListener)1 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)1 AssertTask (com.hazelcast.test.AssertTask)1 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1