Search in sources :

Example 21 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class CacheEntryProcessorTest method executeEntryProcessor.

private void executeEntryProcessor(Integer key, EntryProcessor<Integer, String, Void> entryProcessor, String cacheName) {
    CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(node1);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CompleteConfiguration<Integer, String> config = new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class);
    Cache<Integer, String> cache = cacheManager.createCache(cacheName, config);
    cache.invoke(key, entryProcessor);
}
Also used : CacheManager(javax.cache.CacheManager) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider)

Example 22 with CachingProvider

use of javax.cache.spi.CachingProvider 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 23 with CachingProvider

use of javax.cache.spi.CachingProvider 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 CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class CacheBackupTest method entrySuccessfullyRetrievedFromBackup.

private void entrySuccessfullyRetrievedFromBackup(int backupCount, boolean sync) {
    final String KEY = "key";
    final String VALUE = "value";
    final int nodeCount = backupCount + 1;
    final TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    for (int i = 0; i < instances.length; i++) {
        instances[i] = instanceFactory.newHazelcastInstance();
    }
    final HazelcastInstance hz = instances[0];
    final CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(hz);
    final CacheManager cacheManager = cachingProvider.getCacheManager();
    final String cacheName = randomName();
    final CacheConfig cacheConfig = new CacheConfig().setName(cacheName);
    if (sync) {
        cacheConfig.setBackupCount(backupCount);
    } else {
        cacheConfig.setAsyncBackupCount(backupCount);
    }
    final Cache cache = cacheManager.createCache(cacheName, cacheConfig);
    warmUpPartitions(instances);
    waitAllForSafeState(instances);
    cache.put(KEY, VALUE);
    final Node node = getNode(hz);
    final InternalPartitionService partitionService = node.getPartitionService();
    final int keyPartitionId = partitionService.getPartitionId(KEY);
    for (int i = 1; i <= backupCount; i++) {
        final Node backupNode = getNode(instances[i]);
        final SerializationService serializationService = backupNode.getSerializationService();
        final ICacheService cacheService = backupNode.getNodeEngine().getService(ICacheService.SERVICE_NAME);
        if (sync) {
            checkSavedRecordOnBackup(KEY, VALUE, cacheName, keyPartitionId, serializationService, cacheService);
        } else {
            assertTrueEventually(new AssertTask() {

                @Override
                public void run() throws Exception {
                    checkSavedRecordOnBackup(KEY, VALUE, cacheName, keyPartitionId, serializationService, cacheService);
                }
            });
        }
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.Node) SerializationService(com.hazelcast.spi.serialization.SerializationService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICacheService(com.hazelcast.cache.impl.ICacheService) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) CacheConfig(com.hazelcast.config.CacheConfig) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache)

Example 25 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class CacheContextTest method cacheEntryListenerCountIncreasedAndDecreasedCorrectly.

protected void cacheEntryListenerCountIncreasedAndDecreasedCorrectly(DecreaseType decreaseType) {
    final String CACHE_NAME = "MyCache";
    final String CACHE_NAME_WITH_PREFIX = "/hz/" + CACHE_NAME;
    CachingProvider provider = initAndGetCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    CacheEntryListenerConfiguration<String, String> cacheEntryListenerConfig = new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(new TestListener()), null, true, true);
    CompleteConfiguration<String, String> cacheConfig = new MutableConfiguration<String, String>();
    Cache<String, String> cache = cacheManager.createCache(CACHE_NAME, cacheConfig);
    cache.registerCacheEntryListener(cacheEntryListenerConfig);
    final CacheService cacheService1 = getCacheService(hazelcastInstance1);
    final CacheService cacheService2 = getCacheService(hazelcastInstance2);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNotNull(cacheService1.getCacheContext(CACHE_NAME_WITH_PREFIX));
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNotNull(cacheService2.getCacheContext(CACHE_NAME_WITH_PREFIX));
        }
    });
    final CacheContext cacheContext1 = cacheService1.getCacheContext(CACHE_NAME_WITH_PREFIX);
    final CacheContext cacheContext2 = cacheService2.getCacheContext(CACHE_NAME_WITH_PREFIX);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, cacheContext1.getCacheEntryListenerCount());
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, cacheContext2.getCacheEntryListenerCount());
        }
    });
    switch(decreaseType) {
        case DEREGISTER:
            cache.deregisterCacheEntryListener(cacheEntryListenerConfig);
            break;
        case SHUTDOWN:
            driverInstance.getLifecycleService().shutdown();
            break;
        case TERMINATE:
            driverInstance.getLifecycleService().terminate();
            break;
        default:
            throw new IllegalArgumentException("Unsupported decrease type: " + decreaseType);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(0, cacheContext1.getCacheEntryListenerCount());
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(0, cacheContext2.getCacheEntryListenerCount());
        }
    });
}
Also used : MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) CacheContext(com.hazelcast.cache.impl.CacheContext) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) CacheService(com.hazelcast.cache.impl.CacheService)

Aggregations

CachingProvider (javax.cache.spi.CachingProvider)66 CacheManager (javax.cache.CacheManager)48 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)42 Test (org.junit.Test)33 QuickTest (com.hazelcast.test.annotation.QuickTest)28 HazelcastInstance (com.hazelcast.core.HazelcastInstance)24 ParallelTest (com.hazelcast.test.annotation.ParallelTest)24 CacheConfig (com.hazelcast.config.CacheConfig)21 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)18 ClientConfig (com.hazelcast.client.config.ClientConfig)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 MutableConfiguration (javax.cache.configuration.MutableConfiguration)12 ICache (com.hazelcast.cache.ICache)10 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)10 Cache (javax.cache.Cache)10 HazelcastCachingProvider (com.hazelcast.cache.HazelcastCachingProvider)9 Config (com.hazelcast.config.Config)8 Data (com.hazelcast.nio.serialization.Data)8 Before (org.junit.Before)8 HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)7