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);
}
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());
}
});
}
Aggregations