Search in sources :

Example 6 with PartitionLostEventImpl

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

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

the class PartitionLostListenerTest method test_internalPartitionLostEvent_serialization.

@Test
public void test_internalPartitionLostEvent_serialization() throws IOException {
    Address address = new Address();
    PartitionLostEventImpl internalEvent = new PartitionLostEventImpl(1, 2, address);
    ObjectDataOutput output = mock(ObjectDataOutput.class);
    internalEvent.writeData(output);
    verify(output).writeInt(1);
    verify(output).writeInt(2);
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) Address(com.hazelcast.cluster.Address) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with PartitionLostEventImpl

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

use of com.hazelcast.internal.partition.PartitionLostEventImpl 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);
}
Also used : IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl)

Example 10 with PartitionLostEventImpl

use of com.hazelcast.internal.partition.PartitionLostEventImpl 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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapService(com.hazelcast.map.impl.MapService) IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) 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