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