Search in sources :

Example 1 with EventCollectingPartitionLostListener

use of com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener in project hazelcast by hazelcast.

the class PartitionLostListenerTest method test_partitionLostListenerInvoked_whenAllPartitionReplicasCrashed.

@Test
public void test_partitionLostListenerInvoked_whenAllPartitionReplicasCrashed() {
    HazelcastInstance lite = factory.newHazelcastInstance(new Config().setLiteMember(true));
    warmUpPartitions(instances);
    warmUpPartitions(lite);
    waitAllForSafeState(instances);
    waitInstanceForSafeState(lite);
    final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
    lite.getPartitionService().addPartitionLostListener(listener);
    instances[0].getLifecycleService().terminate();
    instances[1].getLifecycleService().terminate();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            List<PartitionLostEvent> events = listener.getEvents();
            assertFalse(events.isEmpty());
            assertTrue(getLast(events).allReplicasInPartitionLost());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) List(java.util.List) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with EventCollectingPartitionLostListener

use of com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener 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)

Example 3 with EventCollectingPartitionLostListener

use of com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener in project hazelcast by hazelcast.

the class ClientPartitionLostListenerTest method test_partitionLostListener_invoked_fromOtherNode.

@Test
public void test_partitionLostListener_invoked_fromOtherNode() {
    final HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setSmartRouting(false);
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    warmUpPartitions(instance1, instance2, client);
    final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
    client.getPartitionService().addPartitionLostListener(listener);
    // Expected = 2 -> 1 added & 1 from {@link com.hazelcast.scheduledexecutor.impl.DistributedScheduledExecutorService}
    // + 2 from map and cache ExpirationManagers * instances
    assertRegistrationsSizeEventually(instance1, 7);
    assertRegistrationsSizeEventually(instance2, 7);
    final InternalPartitionServiceImpl partitionService = getNode(instance2).getNodeEngine().getService(SERVICE_NAME);
    final int partitionId = 5;
    Address address = instance1.getCluster().getLocalMember().getAddress();
    partitionService.onPartitionLost(new PartitionLostEventImpl(partitionId, 0, address));
    assertPartitionLostEventEventually(listener, partitionId);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with EventCollectingPartitionLostListener

use of com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener in project hazelcast by hazelcast.

the class ClientPartitionLostListenerTest method test_partitionLostListener_registeredByConfig_invoked.

@Test
public void test_partitionLostListener_registeredByConfig_invoked() {
    final HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
    final ClientConfig clientConfig = new ClientConfig().addListenerConfig(new ListenerConfig(listener));
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    warmUpPartitions(instance, client);
    // Expected = 4 -> 1 added & 1 from {@link com.hazelcast.scheduledexecutor.impl.DistributedScheduledExecutorService}
    // + 2 from map and cache ExpirationManagers
    assertRegistrationsSizeEventually(instance, 4);
    final InternalPartitionServiceImpl partitionService = getNode(instance).getNodeEngine().getService(SERVICE_NAME);
    final int partitionId = 5;
    Address address = instance.getCluster().getLocalMember().getAddress();
    partitionService.onPartitionLost(new PartitionLostEventImpl(partitionId, 0, address));
    assertPartitionLostEventEventually(listener, partitionId);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with EventCollectingPartitionLostListener

use of com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener in project hazelcast by hazelcast.

the class ClientPartitionLostListenerTest method test_partitionLostListener_invoked.

@Test
public void test_partitionLostListener_invoked() {
    final HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    warmUpPartitions(instance, client);
    final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
    client.getPartitionService().addPartitionLostListener(listener);
    // Expected = 4 -> 1 added & 1 from {@link com.hazelcast.scheduledexecutor.impl.DistributedScheduledExecutorService}
    // + 2 from map and cache ExpirationManagers
    assertRegistrationsSizeEventually(instance, 4);
    final InternalPartitionServiceImpl partitionService = getNode(instance).getNodeEngine().getService(SERVICE_NAME);
    final int partitionId = 5;
    Address address = instance.getCluster().getLocalMember().getAddress();
    partitionService.onPartitionLost(new PartitionLostEventImpl(partitionId, 0, address));
    assertPartitionLostEventEventually(listener, partitionId);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) 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