use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class AbstractCacheEvictionPolicyComparatorTest method testEvictionPolicyComparator.
void testEvictionPolicyComparator(EvictionConfig evictionConfig, int iterationCount) {
HazelcastInstance instance = createInstance(createConfig());
CachingProvider cachingProvider = createCachingProvider(instance);
CacheManager cacheManager = cachingProvider.getCacheManager();
CacheConfig<Integer, String> cacheConfig = createCacheConfig(CACHE_NAME);
cacheConfig.setEvictionConfig(evictionConfig);
Cache<Integer, String> cache = cacheManager.createCache(CACHE_NAME, cacheConfig);
ICache icache = cache.unwrap(ICache.class);
for (int i = 0; i < iterationCount; i++) {
icache.put(i, "Value-" + i);
icache.setExpiryPolicy(i, new EternalExpiryPolicy());
AtomicLong callCounter = (AtomicLong) getUserContext(instance).get("callCounter");
if (callCounter != null && callCounter.get() > 0) {
return;
}
}
fail("CacheEvictionPolicyComparator was not invoked");
}
use of com.hazelcast.cache.ICache 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 = createClientCachingProvider(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.ICache 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);
}
use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class CacheHazelcastInstanceAwareTest method test_injectDependenciesTo_partitionLostListener.
@Test
public void test_injectDependenciesTo_partitionLostListener() {
long id = generateUniqueHazelcastInjectionId();
CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(CACHE_NAME);
HazelcastInstance hazelcastInstance = createInstance();
CacheManager cacheManager = createCachingProvider(hazelcastInstance).getCacheManager();
ICache<Integer, Integer> cache = (ICache<Integer, Integer>) cacheManager.createCache(CACHE_NAME, cacheConfig);
cache.addPartitionLostListener(new CachePartitionLostListenerWithDependencies(id));
assertEquals("Hazelcast instance has not been injected into partition lost listener!", Boolean.TRUE, HAZELCAST_INSTANCE_INJECTION_RESULT_MAP.get(id));
// Node is only injected on member side listeners
if (!ClassLoaderUtil.isClassAvailable(null, "com.hazelcast.client.HazelcastClient")) {
assertEquals("Node instance has not been injected into partition lost listener!", Boolean.TRUE, NODE_INJECTION_RESULT_MAP.get(id));
}
}
use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class ClientCacheMetaDataGeneratorTest method createCacheFromNewClient.
private ICache<Integer, Integer> createCacheFromNewClient() {
HazelcastClientProxy client = (HazelcastClientProxy) factory.newHazelcastClient(clientConfig);
CachingProvider clientCachingProvider = createClientCachingProvider(client);
CacheManager cacheManager = clientCachingProvider.getCacheManager();
ICache<Integer, Integer> cache = (ICache<Integer, Integer>) cacheManager.createCache(CACHE_NAME, cacheConfig);
assertInstanceOf(NearCachedClientCacheProxy.class, cache);
return cache;
}
Aggregations