Search in sources :

Example 16 with ICache

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");
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICache(com.hazelcast.cache.ICache) EternalExpiryPolicy(javax.cache.expiry.EternalExpiryPolicy) CacheManager(javax.cache.CacheManager) CachingProvider(javax.cache.spi.CachingProvider)

Example 17 with ICache

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);
}
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) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with ICache

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);
}
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 19 with ICache

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));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICache(com.hazelcast.cache.ICache) CacheManager(javax.cache.CacheManager) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with ICache

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;
}
Also used : ICache(com.hazelcast.cache.ICache) CacheManager(javax.cache.CacheManager) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider)

Aggregations

ICache (com.hazelcast.cache.ICache)20 Test (org.junit.Test)16 QuickTest (com.hazelcast.test.annotation.QuickTest)15 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 CacheManager (javax.cache.CacheManager)9 CacheConfig (com.hazelcast.config.CacheConfig)7 Config (com.hazelcast.config.Config)6 CachingProvider (javax.cache.spi.CachingProvider)6 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)5 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)5 HazelcastExpiryPolicy (com.hazelcast.cache.HazelcastExpiryPolicy)5 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)4 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 IList (com.hazelcast.collection.IList)3 Job (com.hazelcast.jet.Job)3 Util.entry (com.hazelcast.jet.Util.entry)3 JobConfig (com.hazelcast.jet.config.JobConfig)3 IMap (com.hazelcast.map.IMap)3