Search in sources :

Example 6 with EventCollectingPartitionLostListener

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());
            }
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) AssertTask(com.hazelcast.test.AssertTask) List(java.util.List) IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) InternalPartition(com.hazelcast.internal.partition.InternalPartition) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with EventCollectingPartitionLostListener

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

HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 EventCollectingPartitionLostListener (com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 PartitionLostEventImpl (com.hazelcast.internal.partition.PartitionLostEventImpl)5 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)5 Address (com.hazelcast.cluster.Address)4 IPartitionLostEvent (com.hazelcast.internal.partition.IPartitionLostEvent)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 AssertTask (com.hazelcast.test.AssertTask)2 List (java.util.List)2 Config (com.hazelcast.config.Config)1 ListenerConfig (com.hazelcast.config.ListenerConfig)1 Node (com.hazelcast.instance.impl.Node)1 InternalPartition (com.hazelcast.internal.partition.InternalPartition)1 Accessors.getNode (com.hazelcast.test.Accessors.getNode)1 HashSet (java.util.HashSet)1