Search in sources :

Example 11 with IPartitionLostEvent

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

the class PartitionLostListenerTest method test_internalPartitionLostEvent_deserialization.

@Test
public void test_internalPartitionLostEvent_deserialization() throws IOException {
    IPartitionLostEvent internalEvent = new IPartitionLostEvent();
    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) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with IPartitionLostEvent

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

the class ScheduledExecutorServiceBasicTest method schedule_whenPartitionLost.

@Test()
public void schedule_whenPartitionLost() throws ExecutionException, InterruptedException {
    int delay = 1;
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    final IScheduledFuture future = executorService.schedule(new PlainCallableTask(), delay, SECONDS);
    ScheduledTaskHandler handler = future.getHandler();
    int partitionOwner = handler.getPartitionId();
    IPartitionLostEvent internalEvent = new IPartitionLostEvent(partitionOwner, 1, null);
    ((InternalPartitionServiceImpl) getNodeEngineImpl(instances[0]).getPartitionService()).onPartitionLost(internalEvent);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            try {
                future.get();
            } catch (IllegalStateException ex) {
                assertEquals("Partition holding this Scheduled task was lost along with all backups.", ex.getMessage());
            }
        }
    });
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) TimeoutException(java.util.concurrent.TimeoutException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExpectedException(org.junit.rules.ExpectedException) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with IPartitionLostEvent

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

the class ClientMapPartitionLostListenerTest method test_mapPartitionLostListener_invoked_fromOtherNode.

@Test
public void test_mapPartitionLostListener_invoked_fromOtherNode() {
    final String mapName = randomMapName();
    final Config config = new Config();
    config.getMapConfig(mapName).setBackupCount(0);
    final HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(config);
    final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(config);
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setSmartRouting(false);
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    final Address clientOwnerAddress = clientInstanceImpl.getClientClusterService().getOwnerConnectionAddress();
    final HazelcastInstance other = getAddress(instance1).equals(clientOwnerAddress) ? instance2 : instance1;
    final TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
    client.getMap(mapName).addPartitionLostListener(listener);
    assertRegistrationEventually(instance1, mapName, true);
    assertRegistrationEventually(instance2, mapName, true);
    assertProxyExistsEventually(instance1, mapName);
    assertProxyExistsEventually(instance2, mapName);
    final MapService mapService = getNode(other).getNodeEngine().getService(SERVICE_NAME);
    final int partitionId = 5;
    mapService.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
    assertMapPartitionLostEventEventually(listener, partitionId);
}
Also used : TestEventCollectingMapPartitionLostListener(com.hazelcast.map.TestEventCollectingMapPartitionLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) HazelcastTestSupport.getAddress(com.hazelcast.test.HazelcastTestSupport.getAddress) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) ClientTestUtil.getHazelcastClientInstanceImpl(com.hazelcast.client.impl.ClientTestUtil.getHazelcastClientInstanceImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) MapService(com.hazelcast.map.impl.MapService) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with IPartitionLostEvent

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

the class ClientMapPartitionLostListenerTest method test_mapPartitionLostListener_invoked.

@Test
public void test_mapPartitionLostListener_invoked() {
    final String mapName = randomMapName();
    final Config config = new Config();
    config.getMapConfig(mapName).setBackupCount(0);
    final HazelcastInstance instance = hazelcastFactory.newHazelcastInstance(config);
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    warmUpPartitions(instance, client);
    final TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
    client.getMap(mapName).addPartitionLostListener(listener);
    final MapService mapService = getNode(instance).getNodeEngine().getService(MapService.SERVICE_NAME);
    final int partitionId = 5;
    mapService.onPartitionLost(new IPartitionLostEvent(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) MapService(com.hazelcast.map.impl.MapService) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with IPartitionLostEvent

use of com.hazelcast.spi.partition.IPartitionLostEvent 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 = createCachingProvider(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 = HazelcastClientCachingProvider.createCachingProvider(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 IPartitionLostEvent(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) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastServerCachingProvider.createCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider.createCachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) CacheService(com.hazelcast.cache.impl.CacheService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

IPartitionLostEvent (com.hazelcast.spi.partition.IPartitionLostEvent)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 Test (org.junit.Test)15 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)5 MapService (com.hazelcast.map.impl.MapService)5 AbstractPartitionLostListenerTest (com.hazelcast.partition.AbstractPartitionLostListenerTest)4 EventCollectingPartitionLostListener (com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener)4 CacheService (com.hazelcast.cache.impl.CacheService)3 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)3 ClientConfig (com.hazelcast.client.config.ClientConfig)3 CacheConfig (com.hazelcast.config.CacheConfig)3 Address (com.hazelcast.nio.Address)3 CacheManager (javax.cache.CacheManager)3 ICache (com.hazelcast.cache.ICache)2 HazelcastServerCachingProvider.createCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider.createCachingProvider)2 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)2 ClientTestUtil.getHazelcastClientInstanceImpl (com.hazelcast.client.impl.ClientTestUtil.getHazelcastClientInstanceImpl)2 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)2