Search in sources :

Example 1 with IPartitionLostEvent

use of com.hazelcast.internal.partition.IPartitionLostEvent in project hazelcast by hazelcast.

the class PartitionEventManager method onPartitionLost.

public void onPartitionLost(IPartitionLostEvent event) {
    assert event instanceof PartitionLostEvent;
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, PARTITION_LOST_EVENT_TOPIC);
    eventService.publishEvent(SERVICE_NAME, registrations, event, event.getPartitionId());
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) PartitionLostEvent(com.hazelcast.partition.PartitionLostEvent) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 2 with IPartitionLostEvent

use of com.hazelcast.internal.partition.IPartitionLostEvent in project hazelcast by hazelcast.

the class CachePartitionLostListenerTest method test_partitionLostListenerInvoked.

@Test
public void test_partitionLostListenerInvoked() {
    List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(1);
    final HazelcastInstance instance = instances.get(0);
    HazelcastServerCachingProvider cachingProvider = createServerCachingProvider(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
    Cache<Integer, String> cache = cacheManager.createCache(getIthCacheName(0), config);
    ICache iCache = cache.unwrap(ICache.class);
    final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(0);
    iCache.addPartitionLostListener(listener);
    final IPartitionLostEvent internalEvent = new PartitionLostEventImpl(1, 1, null);
    CacheService cacheService = getNode(instance).getNodeEngine().getService(CacheService.SERVICE_NAME);
    cacheService.onPartitionLost(internalEvent);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            List<CachePartitionLostEvent> events = listener.getEvents();
            assertEquals(1, events.size());
            CachePartitionLostEvent event = events.get(0);
            assertEquals(internalEvent.getPartitionId(), event.getPartitionId());
            assertEquals(getIthCacheName(0), event.getSource());
            assertEquals(getIthCacheName(0), event.getName());
            assertEquals(instance.getCluster().getLocalMember(), event.getMember());
            assertEquals(CacheEventType.PARTITION_LOST, event.getEventType());
        }
    });
    cacheManager.destroyCache(getIthCacheName(0));
    cacheManager.close();
    cachingProvider.close();
}
Also used : IOException(java.io.IOException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CachePartitionLostEvent(com.hazelcast.cache.impl.event.CachePartitionLostEvent) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheConfig(com.hazelcast.config.CacheConfig) IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) CacheService(com.hazelcast.cache.impl.CacheService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test)

Example 3 with IPartitionLostEvent

use of com.hazelcast.internal.partition.IPartitionLostEvent in project hazelcast by hazelcast.

the class MapPartitionLostListenerTest method test_partitionLostListenerInvoked.

@Test
public void test_partitionLostListenerInvoked() {
    List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(1);
    HazelcastInstance instance = instances.get(0);
    final TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
    instance.getMap(getIthMapName(0)).addPartitionLostListener(listener);
    final IPartitionLostEvent internalEvent = new PartitionLostEventImpl(1, 0, null);
    MapService mapService = getNode(instance).getNodeEngine().getService(MapService.SERVICE_NAME);
    mapService.onPartitionLost(internalEvent);
    assertEventEventually(listener, internalEvent);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapService(com.hazelcast.map.impl.MapService) IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test)

Example 4 with IPartitionLostEvent

use of com.hazelcast.internal.partition.IPartitionLostEvent in project hazelcast by hazelcast.

the class MapPartitionLostListenerTest method test_partitionLostListenerInvoked_whenEntryListenerIsAlsoRegistered.

@Test
public void test_partitionLostListenerInvoked_whenEntryListenerIsAlsoRegistered() {
    List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(1);
    HazelcastInstance instance = instances.get(0);
    final TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
    instance.getMap(getIthMapName(0)).addPartitionLostListener(listener);
    instance.getMap(getIthMapName(0)).addEntryListener(mock(EntryAddedListener.class), true);
    final IPartitionLostEvent internalEvent = new PartitionLostEventImpl(1, 0, null);
    MapService mapService = getNode(instance).getNodeEngine().getService(MapService.SERVICE_NAME);
    mapService.onPartitionLost(internalEvent);
    assertEventEventually(listener, internalEvent);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapService(com.hazelcast.map.impl.MapService) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test)

Example 5 with IPartitionLostEvent

use of com.hazelcast.internal.partition.IPartitionLostEvent in project hazelcast by hazelcast.

the class PartitionLostListenerTest method test_partitionLostListenerInvoked.

@Test
public void test_partitionLostListenerInvoked() {
    HazelcastInstance instance = instances[0];
    EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
    instance.getPartitionService().addPartitionLostListener(listener);
    IPartitionLostEvent internalEvent = new PartitionLostEventImpl(1, 0, null);
    NodeEngineImpl nodeEngine = getNode(instance).getNodeEngine();
    InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
    partitionService.onPartitionLost(internalEvent);
    assertEventEventually(listener, internalEvent);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IPartitionLostEvent (com.hazelcast.internal.partition.IPartitionLostEvent)9 PartitionLostEventImpl (com.hazelcast.internal.partition.PartitionLostEventImpl)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 AbstractPartitionLostListenerTest (com.hazelcast.partition.AbstractPartitionLostListenerTest)4 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)3 MapService (com.hazelcast.map.impl.MapService)3 EventCollectingPartitionLostListener (com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 CacheService (com.hazelcast.cache.impl.CacheService)1 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)1 CachePartitionLostEvent (com.hazelcast.cache.impl.event.CachePartitionLostEvent)1 CacheConfig (com.hazelcast.config.CacheConfig)1 EntryAddedListener (com.hazelcast.map.listener.EntryAddedListener)1 PartitionLostEvent (com.hazelcast.partition.PartitionLostEvent)1 IScheduledExecutorService (com.hazelcast.scheduledexecutor.IScheduledExecutorService)1 IScheduledFuture (com.hazelcast.scheduledexecutor.IScheduledFuture)1 ScheduledTaskHandler (com.hazelcast.scheduledexecutor.ScheduledTaskHandler)1