use of com.hazelcast.internal.partition.IPartitionLostEvent in project hazelcast by hazelcast.
the class PartitionEventManager method sendPartitionLostEvent.
public void sendPartitionLostEvent(int partitionId, int lostReplicaIndex) {
IPartitionLostEvent event = new PartitionLostEventImpl(partitionId, lostReplicaIndex, nodeEngine.getThisAddress());
InternalPartitionLostEventPublisher publisher = new InternalPartitionLostEventPublisher(nodeEngine, event);
nodeEngine.getExecutionService().execute(SYSTEM_EXECUTOR, publisher);
}
use of com.hazelcast.internal.partition.IPartitionLostEvent in project hazelcast by hazelcast.
the class MapPartitionLostListenerTest method test_allPartitionLostListenersInvoked.
@Test
public void test_allPartitionLostListenersInvoked() {
List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(2);
HazelcastInstance instance1 = instances.get(0);
HazelcastInstance instance2 = instances.get(0);
final TestEventCollectingMapPartitionLostListener listener1 = new TestEventCollectingMapPartitionLostListener(0);
final TestEventCollectingMapPartitionLostListener listener2 = new TestEventCollectingMapPartitionLostListener(0);
instance1.getMap(getIthMapName(0)).addPartitionLostListener(listener1);
instance2.getMap(getIthMapName(0)).addPartitionLostListener(listener2);
final IPartitionLostEvent internalEvent = new PartitionLostEventImpl(1, 0, null);
MapService mapService = getNode(instance1).getNodeEngine().getService(MapService.SERVICE_NAME);
mapService.onPartitionLost(internalEvent);
assertEventEventually(listener1, internalEvent);
assertEventEventually(listener2, internalEvent);
}
use of com.hazelcast.internal.partition.IPartitionLostEvent in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_testPartitionLostEvent.
public void schedule_testPartitionLostEvent(int replicaLostCount) {
int delay = 1;
HazelcastInstance[] instances = createClusterWithCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
final IScheduledFuture future = executorService.schedule(new PlainCallableTask(), delay, SECONDS);
// Used to make sure both futures (on the same handler) get the event.
// Catching possible equal/hashcode issues in the Map
final IScheduledFuture futureCopyInstance = (IScheduledFuture) ((List) executorService.getAllScheduledFutures().values().toArray()[0]).get(0);
ScheduledTaskHandler handler = future.getHandler();
int partitionOwner = handler.getPartitionId();
IPartitionLostEvent internalEvent = new PartitionLostEventImpl(partitionOwner, replicaLostCount, null);
((InternalPartitionServiceImpl) getNodeEngineImpl(instances[0]).getPartitionService()).onPartitionLost(internalEvent);
assertTrueEventually(() -> {
try {
future.get();
fail();
} catch (IllegalStateException ex) {
try {
futureCopyInstance.get();
fail();
} catch (IllegalStateException ex2) {
assertEquals(format("Partition %d, holding this scheduled task was lost along with all backups.", future.getHandler().getPartitionId()), ex.getMessage());
assertEquals(format("Partition %d, holding this scheduled task was lost along with all backups.", future.getHandler().getPartitionId()), ex2.getMessage());
}
}
});
}
use of com.hazelcast.internal.partition.IPartitionLostEvent in project hazelcast by hazelcast.
the class PartitionLostListenerTest method test_allPartitionLostListenersInvoked.
@Test
public void test_allPartitionLostListenersInvoked() {
HazelcastInstance instance1 = instances[0];
HazelcastInstance instance2 = instances[1];
EventCollectingPartitionLostListener listener1 = new EventCollectingPartitionLostListener();
EventCollectingPartitionLostListener listener2 = new EventCollectingPartitionLostListener();
instance1.getPartitionService().addPartitionLostListener(listener1);
instance2.getPartitionService().addPartitionLostListener(listener2);
IPartitionLostEvent internalEvent = new PartitionLostEventImpl(1, 0, null);
NodeEngineImpl nodeEngine = getNode(instance1).getNodeEngine();
InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
partitionService.onPartitionLost(internalEvent);
assertEventEventually(listener1, internalEvent);
assertEventEventually(listener2, internalEvent);
}
Aggregations