Search in sources :

Example 1 with CacheManager

use of javax.cache.CacheManager in project hibernate-orm by hibernate.

the class JCacheRegionFactoryTest method testStopsCacheManagerOnShutdown.

@Test
public void testStopsCacheManagerOnShutdown() {
    factory.start(null, EMPTY_MAP);
    final CacheManager cacheManager = factory.getCacheManager();
    assertThat(cacheManager.isClosed(), is(false));
    factory.stop();
    assertThat(cacheManager.isClosed(), is(true));
}
Also used : CacheManager(javax.cache.CacheManager) Test(org.junit.Test)

Example 2 with CacheManager

use of javax.cache.CacheManager in project hibernate-orm by hibernate.

the class JCacheRegionTest method testDestroyCallsDestroyCacheOnCacheManager.

@Test
public void testDestroyCallsDestroyCacheOnCacheManager() {
    final Cache<Object, Object> cache = region.getCache();
    CacheManager cacheManager = Mockito.mock(CacheManager.class);
    when(cache.getCacheManager()).thenReturn(cacheManager);
    when(cacheManager.getCache(CACHE_NAME)).thenReturn(cache);
    region.destroy();
    verify(cacheManager).destroyCache(CACHE_NAME);
}
Also used : CacheManager(javax.cache.CacheManager) Test(org.junit.Test)

Example 3 with CacheManager

use of javax.cache.CacheManager in project caffeine by ben-manes.

the class CaffeineCachingProvider method close.

@Override
public void close(URI uri, ClassLoader classLoader) {
    synchronized (cacheManagers) {
        ClassLoader managerClassLoader = getManagerClassLoader(classLoader);
        Map<URI, CacheManager> cacheManagersByURI = cacheManagers.get(managerClassLoader);
        if (cacheManagersByURI != null) {
            CacheManager cacheManager = cacheManagersByURI.remove(getManagerUri(uri));
            if (cacheManager != null) {
                cacheManager.close();
            }
            if (cacheManagersByURI.isEmpty()) {
                cacheManagers.remove(managerClassLoader);
            }
        }
    }
}
Also used : CacheManager(javax.cache.CacheManager) URI(java.net.URI)

Example 4 with CacheManager

use of javax.cache.CacheManager 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 5 with CacheManager

use of javax.cache.CacheManager in project hazelcast by hazelcast.

the class CacheHazelcastInstanceAwareTest method test_inject_hazelcastInstance_to_cacheWriter_if_itIs_hazelcastInstanceAware.

@Test
public void test_inject_hazelcastInstance_to_cacheWriter_if_itIs_hazelcastInstanceAware() {
    long id1 = generateUniqueHazelcastInjectionId();
    long id2 = generateUniqueHazelcastInjectionId();
    CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(CACHE_NAME);
    cacheConfig.setCacheWriterFactory(new HazelcastInstanceAwareCacheWriterFactory(id1, id2));
    HazelcastInstance hazelcastInstance = createInstance();
    CacheManager cacheManager = createCachingProvider(hazelcastInstance).getCacheManager();
    Cache<Integer, Integer> cache = cacheManager.createCache(CACHE_NAME, cacheConfig);
    cache.put(1, 1);
    assertEquals("Hazelcast instance has not been injected into cache writer factory!", Boolean.TRUE, HAZELCAST_INSTANCE_INJECTION_RESULT_MAP.get(id1));
    assertEquals("Hazelcast instance has not been injected into cache writer!", Boolean.TRUE, HAZELCAST_INSTANCE_INJECTION_RESULT_MAP.get(id2));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

CacheManager (javax.cache.CacheManager)284 Test (org.junit.Test)182 CachingProvider (javax.cache.spi.CachingProvider)113 QuickTest (com.hazelcast.test.annotation.QuickTest)78 HazelcastInstance (com.hazelcast.core.HazelcastInstance)69 MutableConfiguration (javax.cache.configuration.MutableConfiguration)56 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)55 CacheConfig (com.hazelcast.config.CacheConfig)54 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)50 Cache (javax.cache.Cache)41 URI (java.net.URI)31 AssertTask (com.hazelcast.test.AssertTask)26 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 Config (com.hazelcast.config.Config)20 ClientConfig (com.hazelcast.client.config.ClientConfig)17 SlowTest (com.hazelcast.test.annotation.SlowTest)17 Before (org.junit.Before)17 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)16 HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)16 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)16