Search in sources :

Example 11 with PartitionLostEventImpl

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

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

Example 13 with PartitionLostEventImpl

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

the class PartitionLostListenerTest method test_internalPartitionLostEvent_deserialization.

@Test
public void test_internalPartitionLostEvent_deserialization() throws IOException {
    PartitionLostEventImpl internalEvent = new PartitionLostEventImpl();
    ObjectDataInput input = mock(ObjectDataInput.class);
    when(input.readInt()).thenReturn(1, 2);
    internalEvent.readData(input);
    assertEquals(1, internalEvent.getPartitionId());
    assertEquals(2, internalEvent.getLostReplicaIndex());
}
Also used : ObjectDataInput(com.hazelcast.nio.ObjectDataInput) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with PartitionLostEventImpl

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

the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_invoked.

@Test
public void test_cachePartitionLostListener_invoked() {
    final String cacheName = randomName();
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    final HazelcastServerCachingProvider cachingProvider = createServerCachingProvider(instance);
    final CacheManager cacheManager = cachingProvider.getCacheManager();
    final CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
    config.setBackupCount(0);
    cacheManager.createCache(cacheName, config);
    final CachingProvider clientCachingProvider = createClientCachingProvider(client);
    final CacheManager clientCacheManager = clientCachingProvider.getCacheManager();
    final Cache<Integer, String> cache = clientCacheManager.getCache(cacheName);
    final ICache iCache = cache.unwrap(ICache.class);
    final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener();
    iCache.addPartitionLostListener(listener);
    final CacheService cacheService = getNode(instance).getNodeEngine().getService(CacheService.SERVICE_NAME);
    final int partitionId = 5;
    cacheService.onPartitionLost(new PartitionLostEventImpl(partitionId, 0, null));
    assertCachePartitionLostEventEventually(listener, partitionId);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICache(com.hazelcast.cache.ICache) CacheManager(javax.cache.CacheManager) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheConfig(com.hazelcast.config.CacheConfig) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) CacheService(com.hazelcast.cache.impl.CacheService) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with PartitionLostEventImpl

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

the class ClientMapPartitionLostListenerTest method test_mapPartitionLostListener_invoked_fromOtherNode.

@Test
public void test_mapPartitionLostListener_invoked_fromOtherNode() {
    String mapName = randomMapName();
    Config config = getConfig();
    config.getMapConfig(mapName).setBackupCount(0);
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(config);
    ClientConfig clientConfig = getClientConfig();
    clientConfig.getNetworkConfig().setSmartRouting(false);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(config);
    TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
    client.getMap(mapName).addPartitionLostListener(listener);
    assertRegistrationEventually(instance1, mapName, true);
    assertRegistrationEventually(instance2, mapName, true);
    assertProxyExistsEventually(instance1, mapName);
    assertProxyExistsEventually(instance2, mapName);
    MapService mapService = getNode(instance2).getNodeEngine().getService(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)

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