use of com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener in project hazelcast by hazelcast.
the class PartitionLostListenerTest method test_partitionLostListenerInvoked_whenNodeCrashed.
@Test
public void test_partitionLostListenerInvoked_whenNodeCrashed() {
HazelcastInstance survivingInstance = instances[0];
HazelcastInstance terminatingInstance = instances[1];
warmUpPartitions(instances);
waitAllForSafeState(instances);
final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
survivingInstance.getPartitionService().addPartitionLostListener(listener);
Node survivingNode = getNode(survivingInstance);
final Address survivingAddress = survivingNode.getThisAddress();
final Set<Integer> survivingPartitionIds = new HashSet<Integer>();
for (InternalPartition partition : survivingNode.getPartitionService().getInternalPartitions()) {
if (survivingAddress.equals(partition.getReplicaAddress(0))) {
survivingPartitionIds.add(partition.getPartitionId());
}
}
terminatingInstance.getLifecycleService().terminate();
waitAllForSafeState(survivingInstance);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
List<PartitionLostEvent> events = listener.getEvents();
assertFalse(events.isEmpty());
for (PartitionLostEvent event : events) {
assertEquals(survivingAddress, event.getEventSource());
assertFalse(survivingPartitionIds.contains(event.getPartitionId()));
assertEquals(0, event.getLostBackupCount());
assertFalse(event.allReplicasInPartitionLost());
}
}
});
}
use of com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener 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