Search in sources :

Example 6 with IPartitionLostEvent

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

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

Example 8 with IPartitionLostEvent

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

the class ScheduledExecutorServiceBasicTest method schedule_testPartitionLostEvent.

public void schedule_testPartitionLostEvent(int replicaLostCount) {
    int delay = 1;
    HazelcastInstance[] instances = createClusterWithCount(1);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    final IScheduledFuture future = executorService.schedule(new PlainCallableTask(), delay, SECONDS);
    // Used to make sure both futures (on the same handler) get the event.
    // Catching possible equal/hashcode issues in the Map
    final IScheduledFuture futureCopyInstance = (IScheduledFuture) ((List) executorService.getAllScheduledFutures().values().toArray()[0]).get(0);
    ScheduledTaskHandler handler = future.getHandler();
    int partitionOwner = handler.getPartitionId();
    IPartitionLostEvent internalEvent = new PartitionLostEventImpl(partitionOwner, replicaLostCount, null);
    ((InternalPartitionServiceImpl) getNodeEngineImpl(instances[0]).getPartitionService()).onPartitionLost(internalEvent);
    assertTrueEventually(() -> {
        try {
            future.get();
            fail();
        } catch (IllegalStateException ex) {
            try {
                futureCopyInstance.get();
                fail();
            } catch (IllegalStateException ex2) {
                assertEquals(format("Partition %d, holding this scheduled task was lost along with all backups.", future.getHandler().getPartitionId()), ex.getMessage());
                assertEquals(format("Partition %d, holding this scheduled task was lost along with all backups.", future.getHandler().getPartitionId()), ex2.getMessage());
            }
        }
    });
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl)

Example 9 with IPartitionLostEvent

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

IPartitionLostEvent (com.hazelcast.internal.partition.IPartitionLostEvent)9 PartitionLostEventImpl (com.hazelcast.internal.partition.PartitionLostEventImpl)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 AbstractPartitionLostListenerTest (com.hazelcast.partition.AbstractPartitionLostListenerTest)4 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)3 MapService (com.hazelcast.map.impl.MapService)3 EventCollectingPartitionLostListener (com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 CacheService (com.hazelcast.cache.impl.CacheService)1 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)1 CachePartitionLostEvent (com.hazelcast.cache.impl.event.CachePartitionLostEvent)1 CacheConfig (com.hazelcast.config.CacheConfig)1 EntryAddedListener (com.hazelcast.map.listener.EntryAddedListener)1 PartitionLostEvent (com.hazelcast.partition.PartitionLostEvent)1 IScheduledExecutorService (com.hazelcast.scheduledexecutor.IScheduledExecutorService)1 IScheduledFuture (com.hazelcast.scheduledexecutor.IScheduledFuture)1 ScheduledTaskHandler (com.hazelcast.scheduledexecutor.ScheduledTaskHandler)1