Search in sources :

Example 6 with CachePartitionLostListener

use of com.hazelcast.cache.impl.event.CachePartitionLostListener in project hazelcast by hazelcast.

the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_registered.

@Test
public void test_cachePartitionLostListener_registered() {
    final String cacheName = randomName();
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    final CachingProvider cachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
    final CacheManager cacheManager = cachingProvider.getCacheManager();
    final CacheConfig<Integer, String> cacheConfig = new CacheConfig<Integer, String>();
    final Cache<Integer, String> cache = cacheManager.createCache(cacheName, cacheConfig);
    final ICache iCache = cache.unwrap(ICache.class);
    iCache.addPartitionLostListener(new CachePartitionLostListener() {

        @Override
        public void partitionLost(CachePartitionLostEvent event) {
        }
    });
    assertRegistrationsSizeEventually(instance, cacheName, 1);
}
Also used : CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CachePartitionLostEvent(com.hazelcast.cache.impl.event.CachePartitionLostEvent) ICache(com.hazelcast.cache.ICache) CacheManager(javax.cache.CacheManager) CacheConfig(com.hazelcast.config.CacheConfig) 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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with CachePartitionLostListener

use of com.hazelcast.cache.impl.event.CachePartitionLostListener in project hazelcast by hazelcast.

the class CachePartitionLostListenerConfigTest method testCachePartitionLostListener_registeredViaImplementationInConfigObject.

@Test
public void testCachePartitionLostListener_registeredViaImplementationInConfigObject() {
    final String cacheName = "myCache";
    Config config = new Config();
    CacheSimpleConfig cacheConfig = config.getCacheConfig(cacheName);
    CachePartitionLostListener listener = mock(CachePartitionLostListener.class);
    cacheConfig.addCachePartitionLostListenerConfig(new CachePartitionLostListenerConfig(listener));
    cacheConfig.setBackupCount(0);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance instance = factory.newHazelcastInstance(config);
    HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    cacheManager.getCache(cacheName);
    final EventService eventService = getNode(instance).getNodeEngine().getEventService();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Collection<EventRegistration> registrations = eventService.getRegistrations(CacheService.SERVICE_NAME, cacheName);
            assertFalse(registrations.isEmpty());
        }
    });
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) Config(com.hazelcast.config.Config) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) EventService(com.hazelcast.spi.EventService) IOException(java.io.IOException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 EventCollectingCachePartitionLostListener (com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener)5 CachePartitionLostListenerConfig (com.hazelcast.config.CachePartitionLostListenerConfig)5 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)2 CachePartitionLostEvent (com.hazelcast.cache.impl.event.CachePartitionLostEvent)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 EventService (com.hazelcast.spi.EventService)2 CacheManager (javax.cache.CacheManager)2 ICache (com.hazelcast.cache.ICache)1 CacheService (com.hazelcast.cache.impl.CacheService)1 HazelcastServerCachingProvider.createCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider.createCachingProvider)1 ICacheService (com.hazelcast.cache.impl.ICacheService)1 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)1 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)1 ClientEndpoint (com.hazelcast.client.ClientEndpoint)1 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1