Search in sources :

Example 1 with PartitionLostEventImpl

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

the class PartitionDataSerializerHook method createFactory.

@Override
public DataSerializableFactory createFactory() {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
    constructors[PARTITION_RUNTIME_STATE] = arg -> new PartitionRuntimeState();
    constructors[ASSIGN_PARTITIONS] = arg -> new AssignPartitions();
    constructors[PARTITION_BACKUP_REPLICA_ANTI_ENTROPY] = arg -> new PartitionBackupReplicaAntiEntropyOperation();
    constructors[FETCH_PARTITION_STATE] = arg -> new FetchPartitionStateOperation();
    constructors[HAS_ONGOING_MIGRATION] = arg -> new HasOngoingMigration();
    constructors[MIGRATION_COMMIT] = arg -> new MigrationCommitOperation();
    constructors[PARTITION_STATE_OP] = arg -> new PartitionStateOperation();
    constructors[PROMOTION_COMMIT] = arg -> new PromotionCommitOperation();
    constructors[REPLICA_SYNC_REQUEST] = arg -> new PartitionReplicaSyncRequest();
    constructors[REPLICA_SYNC_RESPONSE] = arg -> new PartitionReplicaSyncResponse();
    constructors[REPLICA_SYNC_RETRY_RESPONSE] = arg -> new PartitionReplicaSyncRetryResponse();
    constructors[SAFE_STATE_CHECK] = arg -> new SafeStateCheckOperation();
    constructors[SHUTDOWN_REQUEST] = arg -> new ShutdownRequestOperation();
    constructors[SHUTDOWN_RESPONSE] = arg -> new ShutdownResponseOperation();
    constructors[REPLICA_FRAGMENT_MIGRATION_STATE] = arg -> new ReplicaFragmentMigrationState();
    constructors[MIGRATION] = arg -> new MigrationOperation();
    constructors[MIGRATION_REQUEST] = arg -> new MigrationRequestOperation();
    constructors[NON_FRAGMENTED_SERVICE_NAMESPACE] = arg -> NonFragmentedServiceNamespace.INSTANCE;
    constructors[PARTITION_REPLICA] = arg -> new PartitionReplica();
    constructors[PUBLISH_COMPLETED_MIGRATIONS] = arg -> new PublishCompletedMigrationsOperation();
    constructors[PARTITION_STATE_CHECK_OP] = arg -> new PartitionStateCheckOperation();
    constructors[REPLICA_MIGRATION_EVENT] = arg -> new ReplicaMigrationEventImpl();
    constructors[MIGRATION_EVENT] = arg -> new MigrationStateImpl();
    constructors[PARTITION_LOST_EVENT] = arg -> new PartitionLostEventImpl();
    constructors[REPLICA_SYNC_REQUEST_OFFLOADABLE] = arg -> new PartitionReplicaSyncRequestOffloadable();
    return new ArrayDataSerializableFactory(constructors);
}
Also used : HasOngoingMigration(com.hazelcast.internal.partition.operation.HasOngoingMigration) ShutdownResponseOperation(com.hazelcast.internal.partition.operation.ShutdownResponseOperation) PartitionBackupReplicaAntiEntropyOperation(com.hazelcast.internal.partition.operation.PartitionBackupReplicaAntiEntropyOperation) AssignPartitions(com.hazelcast.internal.partition.operation.AssignPartitions) MigrationStateImpl(com.hazelcast.internal.partition.MigrationStateImpl) PartitionStateOperation(com.hazelcast.internal.partition.operation.PartitionStateOperation) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) PartitionReplicaSyncRetryResponse(com.hazelcast.internal.partition.operation.PartitionReplicaSyncRetryResponse) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) ShutdownRequestOperation(com.hazelcast.internal.partition.operation.ShutdownRequestOperation) PartitionReplicaSyncResponse(com.hazelcast.internal.partition.operation.PartitionReplicaSyncResponse) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation) PartitionReplicaSyncRequest(com.hazelcast.internal.partition.operation.PartitionReplicaSyncRequest) MigrationOperation(com.hazelcast.internal.partition.operation.MigrationOperation) MigrationRequestOperation(com.hazelcast.internal.partition.operation.MigrationRequestOperation) PartitionReplicaSyncRequestOffloadable(com.hazelcast.internal.partition.operation.PartitionReplicaSyncRequestOffloadable) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) MigrationCommitOperation(com.hazelcast.internal.partition.operation.MigrationCommitOperation) ReplicaFragmentMigrationState(com.hazelcast.internal.partition.ReplicaFragmentMigrationState) PromotionCommitOperation(com.hazelcast.internal.partition.operation.PromotionCommitOperation) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) PublishCompletedMigrationsOperation(com.hazelcast.internal.partition.operation.PublishCompletedMigrationsOperation) PartitionStateCheckOperation(com.hazelcast.internal.partition.operation.PartitionStateCheckOperation) ReplicaMigrationEventImpl(com.hazelcast.internal.partition.ReplicaMigrationEventImpl) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl)

Example 2 with PartitionLostEventImpl

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

the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_invoked_fromOtherNode.

@Test
public void test_cachePartitionLostListener_invoked_fromOtherNode() {
    final String cacheName = randomName();
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    final HazelcastServerCachingProvider cachingProvider = createServerCachingProvider(instance1);
    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);
    assertRegistrationsSizeEventually(instance1, cacheName, 1);
    assertRegistrationsSizeEventually(instance2, cacheName, 1);
    final CacheService cacheService1 = getNode(instance1).getNodeEngine().getService(CacheService.SERVICE_NAME);
    final CacheService cacheService2 = getNode(instance2).getNodeEngine().getService(CacheService.SERVICE_NAME);
    final int partitionId = 5;
    cacheService1.onPartitionLost(new PartitionLostEventImpl(partitionId, 0, null));
    cacheService2.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 3 with PartitionLostEventImpl

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

the class CachePartitionLostListenerTest method test_partitionLostListenerInvoked.

@Test
public void test_partitionLostListenerInvoked() {
    List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(1);
    final HazelcastInstance instance = instances.get(0);
    HazelcastServerCachingProvider cachingProvider = createServerCachingProvider(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
    Cache<Integer, String> cache = cacheManager.createCache(getIthCacheName(0), config);
    ICache iCache = cache.unwrap(ICache.class);
    final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(0);
    iCache.addPartitionLostListener(listener);
    final IPartitionLostEvent internalEvent = new PartitionLostEventImpl(1, 1, null);
    CacheService cacheService = getNode(instance).getNodeEngine().getService(CacheService.SERVICE_NAME);
    cacheService.onPartitionLost(internalEvent);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            List<CachePartitionLostEvent> events = listener.getEvents();
            assertEquals(1, events.size());
            CachePartitionLostEvent event = events.get(0);
            assertEquals(internalEvent.getPartitionId(), event.getPartitionId());
            assertEquals(getIthCacheName(0), event.getSource());
            assertEquals(getIthCacheName(0), event.getName());
            assertEquals(instance.getCluster().getLocalMember(), event.getMember());
            assertEquals(CacheEventType.PARTITION_LOST, event.getEventType());
        }
    });
    cacheManager.destroyCache(getIthCacheName(0));
    cacheManager.close();
    cachingProvider.close();
}
Also used : IOException(java.io.IOException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CachePartitionLostEvent(com.hazelcast.cache.impl.event.CachePartitionLostEvent) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheConfig(com.hazelcast.config.CacheConfig) IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl) CacheService(com.hazelcast.cache.impl.CacheService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test)

Example 4 with PartitionLostEventImpl

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

the class MapPartitionLostListenerTest method test_partitionLostListenerInvoked.

@Test
public void test_partitionLostListenerInvoked() {
    List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(1);
    HazelcastInstance instance = instances.get(0);
    final TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
    instance.getMap(getIthMapName(0)).addPartitionLostListener(listener);
    final IPartitionLostEvent internalEvent = new PartitionLostEventImpl(1, 0, null);
    MapService mapService = getNode(instance).getNodeEngine().getService(MapService.SERVICE_NAME);
    mapService.onPartitionLost(internalEvent);
    assertEventEventually(listener, 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 5 with PartitionLostEventImpl

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

the class MapPartitionLostListenerTest method test_partitionLostListenerInvoked_whenEntryListenerIsAlsoRegistered.

@Test
public void test_partitionLostListenerInvoked_whenEntryListenerIsAlsoRegistered() {
    List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(1);
    HazelcastInstance instance = instances.get(0);
    final TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
    instance.getMap(getIthMapName(0)).addPartitionLostListener(listener);
    instance.getMap(getIthMapName(0)).addEntryListener(mock(EntryAddedListener.class), true);
    final IPartitionLostEvent internalEvent = new PartitionLostEventImpl(1, 0, null);
    MapService mapService = getNode(instance).getNodeEngine().getService(MapService.SERVICE_NAME);
    mapService.onPartitionLost(internalEvent);
    assertEventEventually(listener, internalEvent);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapService(com.hazelcast.map.impl.MapService) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) 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