Search in sources :

Example 16 with PartitionLostEventImpl

use of com.hazelcast.internal.partition.PartitionLostEventImpl in project hazelcast by hazelcast.

the class ClientMapPartitionLostListenerTest method test_mapPartitionLostListener_invoked.

@Test
public void test_mapPartitionLostListener_invoked() {
    String mapName = randomMapName();
    Config config = getConfig();
    config.getMapConfig(mapName).setBackupCount(0);
    ClientConfig clientConfig = getClientConfig();
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    warmUpPartitions(instance, client);
    TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
    client.getMap(mapName).addPartitionLostListener(listener);
    MapService mapService = getNode(instance).getNodeEngine().getService(MapService.SERVICE_NAME);
    int partitionId = 5;
    mapService.onPartitionLost(new PartitionLostEventImpl(partitionId, 0, null));
    assertMapPartitionLostEventEventually(listener, partitionId);
}
Also used : TestEventCollectingMapPartitionLostListener(com.hazelcast.map.TestEventCollectingMapPartitionLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) MapService(com.hazelcast.map.impl.MapService) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with PartitionLostEventImpl

use of com.hazelcast.internal.partition.PartitionLostEventImpl 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 18 with PartitionLostEventImpl

use of com.hazelcast.internal.partition.PartitionLostEventImpl 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

PartitionLostEventImpl (com.hazelcast.internal.partition.PartitionLostEventImpl)18 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 Test (org.junit.Test)15 HazelcastInstance (com.hazelcast.core.HazelcastInstance)14 IPartitionLostEvent (com.hazelcast.internal.partition.IPartitionLostEvent)8 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)6 MapService (com.hazelcast.map.impl.MapService)5 EventCollectingPartitionLostListener (com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener)5 ClientConfig (com.hazelcast.client.config.ClientConfig)4 Address (com.hazelcast.cluster.Address)4 AbstractPartitionLostListenerTest (com.hazelcast.partition.AbstractPartitionLostListenerTest)4 CacheService (com.hazelcast.cache.impl.CacheService)3 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)3 CacheConfig (com.hazelcast.config.CacheConfig)3 CacheManager (javax.cache.CacheManager)3 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)2 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)2 ICache (com.hazelcast.cache.ICache)2 Config (com.hazelcast.config.Config)2