Search in sources :

Example 31 with CacheConfig

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

the class InvalidationMetadataDistortionTest method createCacheConfig.

@Override
protected CacheConfig createCacheConfig(InMemoryFormat inMemoryFormat) {
    CacheConfig cacheConfig = super.createCacheConfig(inMemoryFormat);
    cacheConfig.getEvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(MAX_VALUE);
    return cacheConfig;
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 32 with CacheConfig

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

the class ClientCacheConfigTest method createCacheConfigOnAllNodes.

@Test
public void createCacheConfigOnAllNodes() {
    final String CACHE_NAME = "myCache";
    HazelcastInstance client = null;
    HazelcastInstance server1 = null;
    HazelcastInstance server2 = null;
    try {
        Config config = new Config();
        CacheSimpleConfig cacheSimpleConfig = new CacheSimpleConfig().setName(CACHE_NAME).setBackupCount(// Be sure that cache put operation is mirrored to backup node
        1);
        config.addCacheConfig(cacheSimpleConfig);
        // Create servers with configured caches
        server1 = Hazelcast.newHazelcastInstance(config);
        server2 = Hazelcast.newHazelcastInstance(config);
        ICacheService cacheService1 = getCacheService(server1);
        ICacheService cacheService2 = getCacheService(server2);
        // Create the hazelcast client instance
        client = HazelcastClient.newHazelcastClient();
        // Create the client cache manager
        CachingProvider cachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
        CacheManager cacheManager = cachingProvider.getCacheManager();
        Cache<String, String> cache = cacheManager.getCache(CACHE_NAME);
        assertNotNull(cache);
        CacheConfig cacheConfig = cache.getConfiguration(CacheConfig.class);
        assertNotNull(cacheService1.getCacheConfig(cacheConfig.getNameWithPrefix()));
        assertNotNull(cacheService2.getCacheConfig(cacheConfig.getNameWithPrefix()));
        // First attempt to use the cache will trigger to create its record store.
        // So, we are testing also this case. There should not be any exception.
        // In here, we are testing both of nodes since there is a backup,
        // put is also applied to other (backup node).
        cache.put("key", "value");
    } finally {
        if (client != null) {
            client.shutdown();
        }
        if (server1 != null) {
            server1.shutdown();
        }
        if (server2 != null) {
            server2.shutdown();
        }
    }
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICacheService(com.hazelcast.cache.impl.ICacheService) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) CacheManager(javax.cache.CacheManager) CacheConfig(com.hazelcast.config.CacheConfig) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 33 with CacheConfig

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

the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_removed.

@Test
public void test_cachePartitionLostListener_removed() {
    final String cacheName = randomName();
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    final HazelcastServerCachingProvider cachingProvider = createCachingProvider(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 = HazelcastClientCachingProvider.createCachingProvider(client);
    final CacheManager clientCacheManager = clientCachingProvider.getCacheManager();
    final Cache<Integer, String> cache = clientCacheManager.getCache(cacheName);
    final ICache iCache = cache.unwrap(ICache.class);
    final String registrationId = iCache.addPartitionLostListener(mock(CachePartitionLostListener.class));
    assertRegistrationsSizeEventually(instance, cacheName, 1);
    assertTrue(iCache.removePartitionLostListener(registrationId));
    assertRegistrationsSizeEventually(instance, cacheName, 0);
}
Also used : CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) 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) 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 34 with CacheConfig

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

the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_invoked_fromOtherNode.

@Test
public void test_cachePartitionLostListener_invoked_fromOtherNode() {
    final String cacheName = randomName();
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    final HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance1);
    final CacheManager cacheManager = cachingProvider.getCacheManager();
    final CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
    config.setBackupCount(0);
    cacheManager.createCache(cacheName, config);
    final CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(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);
    assertRegistrationsSizeEventually(instance1, cacheName, 1);
    assertRegistrationsSizeEventually(instance2, cacheName, 1);
    final CacheService cacheService1 = getNode(instance1).getNodeEngine().getService(CacheService.SERVICE_NAME);
    final CacheService cacheService2 = getNode(instance2).getNodeEngine().getService(CacheService.SERVICE_NAME);
    final int partitionId = 5;
    cacheService1.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
    cacheService2.onPartitionLost(new IPartitionLostEvent(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) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) 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) CacheService(com.hazelcast.cache.impl.CacheService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 35 with CacheConfig

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

the class CallbackAwareClientDelegatingFutureTest method createCache.

private Cache createCache(int blockMilis, boolean throwError) {
    CachingProvider cachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfiguration cacheConfig = new CacheConfig().setReadThrough(true).setCacheLoaderFactory(new BlockableCacheLoaderFactory(blockMilis, throwError));
    return cacheManager.createCache(CACHE_NAME, cacheConfig);
}
Also used : HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) CacheManager(javax.cache.CacheManager) CacheConfig(com.hazelcast.config.CacheConfig) CacheConfiguration(com.hazelcast.config.CacheConfiguration) CachingProvider(javax.cache.spi.CachingProvider)

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