Search in sources :

Example 21 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class BaseCacheEvictionPolicyComparatorTest method do_test_evictionPolicyComparator.

void do_test_evictionPolicyComparator(EvictionConfig evictionConfig, int iterationCount) {
    HazelcastInstance instance = createInstance(createConfig());
    CachingProvider cachingProvider = createCachingProvider(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfig cacheConfig = createCacheConfig(CACHE_NAME);
    cacheConfig.setEvictionConfig(evictionConfig);
    Cache cache = cacheManager.createCache(CACHE_NAME, cacheConfig);
    for (int i = 0; i < iterationCount; i++) {
        cache.put(i, "Value-" + i);
    }
    AtomicLong callCounter = (AtomicLong) getUserContext(instance).get("callCounter");
    assertTrue(callCounter.get() > 0);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) CacheConfig(com.hazelcast.config.CacheConfig) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache)

Example 22 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class CacheLoadAllTest method createCacheConfig.

@Override
protected <K, V> CacheConfig<K, V> createCacheConfig() {
    CacheConfig cacheConfig = super.createCacheConfig();
    cacheConfig.setBackupCount(INSTANCE_COUNT - 1);
    cacheConfig.setReadThrough(true);
    cacheConfig.setCacheLoaderFactory(FactoryBuilder.factoryOf(TestCacheLoader.class));
    return cacheConfig;
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig)

Example 23 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class CacheManagementTest method doCacheManagement.

private void doCacheManagement(boolean enable, boolean stats) {
    String cacheName = randomName();
    CacheConfig cacheConfig = super.createCacheConfig();
    cacheConfig.setManagementEnabled(false);
    cacheConfig.setStatisticsEnabled(false);
    CachingProvider cachingProvider = getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    cacheManager.createCache(cacheName, cacheConfig);
    if (enable) {
        if (stats) {
            cacheManager.enableStatistics(cacheName, true);
        } else {
            cacheManager.enableManagement(cacheName, true);
        }
    }
    if (enable) {
        assertTrue(MXBeanUtil.isRegistered("hazelcast", cacheName, stats));
    } else {
        assertFalse(MXBeanUtil.isRegistered("hazelcast", cacheName, stats));
    }
}
Also used : CacheManager(javax.cache.CacheManager) CacheConfig(com.hazelcast.config.CacheConfig) CachingProvider(javax.cache.spi.CachingProvider)

Example 24 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class CachePartitionLostListenerTest method test_partitionLostListenerInvoked_whenNodeCrashed.

@Test
public void test_partitionLostListenerInvoked_whenNodeCrashed() {
    List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(2);
    HazelcastInstance survivingInstance = instances.get(0);
    HazelcastInstance terminatingInstance = instances.get(1);
    HazelcastServerCachingProvider cachingProvider = createCachingProvider(survivingInstance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
    config.setBackupCount(0);
    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 Set<Integer> survivingPartitionIds = new HashSet<Integer>();
    Node survivingNode = getNode(survivingInstance);
    Address survivingAddress = survivingNode.getThisAddress();
    for (IPartition partition : survivingNode.getPartitionService().getPartitions()) {
        if (survivingAddress.equals(partition.getReplicaAddress(0))) {
            survivingPartitionIds.add(partition.getPartitionId());
        }
    }
    terminatingInstance.getLifecycleService().terminate();
    waitAllForSafeState(survivingInstance);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            final List<CachePartitionLostEvent> events = listener.getEvents();
            assertFalse(events.isEmpty());
            for (CachePartitionLostEvent event : events) {
                assertFalse(survivingPartitionIds.contains(event.getPartitionId()));
            }
        }
    });
    cacheManager.destroyCache(getIthCacheName(0));
    cacheManager.close();
    cachingProvider.close();
}
Also used : Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node) 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) IPartition(com.hazelcast.spi.partition.IPartition) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with CacheConfig

use of com.hazelcast.config.CacheConfig 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 = createCachingProvider(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 IPartitionLostEvent(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.spi.partition.IPartitionLostEvent) CacheService(com.hazelcast.cache.impl.CacheService) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

CacheConfig (com.hazelcast.config.CacheConfig)77 Test (org.junit.Test)30 CacheManager (javax.cache.CacheManager)28 QuickTest (com.hazelcast.test.annotation.QuickTest)27 ParallelTest (com.hazelcast.test.annotation.ParallelTest)25 CachingProvider (javax.cache.spi.CachingProvider)16 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)14 AssertTask (com.hazelcast.test.AssertTask)13 NearCacheConfig (com.hazelcast.config.NearCacheConfig)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ICacheService (com.hazelcast.cache.impl.ICacheService)8 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)8 ICache (com.hazelcast.cache.ICache)5 ClientConfig (com.hazelcast.client.config.ClientConfig)5 Config (com.hazelcast.config.Config)5 Data (com.hazelcast.nio.serialization.Data)5 CacheService (com.hazelcast.cache.impl.CacheService)4 HazelcastServerCachingProvider.createCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider.createCachingProvider)4 Map (java.util.Map)4