Search in sources :

Example 61 with CacheConfig

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

the class AbstractClientCachePartitionIteratorTest method getCacheProxy.

private <K, V> ClientCacheProxy<K, V> getCacheProxy() {
    String cacheName = randomString();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfig<K, V> config = new CacheConfig<K, V>();
    config.getEvictionConfig().setMaximumSizePolicy(EvictionConfig.MaxSizePolicy.ENTRY_COUNT).setSize(10000000);
    return (ClientCacheProxy<K, V>) cacheManager.createCache(cacheName, config);
}
Also used : ClientCacheProxy(com.hazelcast.client.cache.impl.ClientCacheProxy) CacheManager(javax.cache.CacheManager) CacheConfig(com.hazelcast.config.CacheConfig)

Example 62 with CacheConfig

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

the class ClientCacheClearTest method testClientInvalidationListenerCallCount.

@Test
public void testClientInvalidationListenerCallCount() {
    ICache<String, String> cache = createCache();
    Map<String, String> entries = createAndFillEntries();
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        cache.put(entry.getKey(), entry.getValue());
    }
    // Verify that put works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        String actualValue = cache.get(key);
        assertEquals(expectedValue, actualValue);
    }
    final AtomicInteger counter = new AtomicInteger(0);
    CacheConfig config = cache.getConfiguration(CacheConfig.class);
    registerInvalidationListener(new EventHandler() {

        @Override
        public void handle(Object event) {
            counter.getAndIncrement();
        }

        @Override
        public void beforeListenerRegister() {
        }

        @Override
        public void onListenerRegister() {
        }
    }, config.getNameWithPrefix());
    cache.clear();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, counter.get());
        }
    }, 2);
    // Make sure that the callback is not called for a while
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(counter.get() <= 1);
        }
    }, 3);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventHandler(com.hazelcast.client.spi.EventHandler) AssertTask(com.hazelcast.test.AssertTask) Map(java.util.Map) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest) CacheClearTest(com.hazelcast.cache.CacheClearTest)

Example 63 with CacheConfig

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

the class ClientCacheClearTest method testClientInvalidationListenerCallCountWhenServerCacheClearUsed.

@Test
public void testClientInvalidationListenerCallCountWhenServerCacheClearUsed() {
    ICache<String, String> cache = createCache();
    Map<String, String> entries = createAndFillEntries();
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        cache.put(entry.getKey(), entry.getValue());
    }
    // Verify that put works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        String actualValue = cache.get(key);
        assertEquals(expectedValue, actualValue);
    }
    final AtomicInteger counter = new AtomicInteger(0);
    CacheConfig config = cache.getConfiguration(CacheConfig.class);
    registerInvalidationListener(new EventHandler() {

        @Override
        public void handle(Object event) {
            counter.getAndIncrement();
        }

        @Override
        public void beforeListenerRegister() {
        }

        @Override
        public void onListenerRegister() {
        }
    }, config.getNameWithPrefix());
    ICache<Object, Object> serverCache = getHazelcastInstance().getCacheManager().getCache(config.getName());
    serverCache.clear();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, counter.get());
        }
    }, 2);
    // Make sure that the callback is not called for a while
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(counter.get() <= 1);
        }
    }, 3);
}
Also used : EventHandler(com.hazelcast.client.spi.EventHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertTask(com.hazelcast.test.AssertTask) Map(java.util.Map) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest) CacheClearTest(com.hazelcast.cache.CacheClearTest)

Example 64 with CacheConfig

use of com.hazelcast.config.CacheConfig 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);
}
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) 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 65 with CacheConfig

use of com.hazelcast.config.CacheConfig 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 = 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 EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener();
    iCache.addPartitionLostListener(listener);
    final CacheService cacheService = getNode(instance).getNodeEngine().getService(CacheService.SERVICE_NAME);
    final int partitionId = 5;
    cacheService.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)

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