Search in sources :

Example 56 with CacheManager

use of javax.cache.CacheManager in project ignite by apache.

the class CacheStopAndDestroySelfTest method testTckStyleCreateDestroyClose.

/**
     * Tests start -> destroy -> start -> close using CacheManager.
     */
public void testTckStyleCreateDestroyClose() throws Exception {
    startGridsMultiThreaded(gridCount());
    CacheManager mgr = Caching.getCachingProvider().getCacheManager();
    String cacheName = "cache";
    mgr.createCache(cacheName, new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class));
    mgr.destroyCache(cacheName);
    Cache<Integer, String> cache = mgr.createCache(cacheName, new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class));
    cache.close();
    cache.close();
    try {
        cache.get(1);
        fail();
    } catch (IllegalStateException ignored) {
    // No-op;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration)

Example 57 with CacheManager

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

the class CaffeineCachingProvider method getCacheManager.

@Override
public CacheManager getCacheManager(URI uri, ClassLoader classLoader, Properties properties) {
    URI managerURI = getManagerUri(uri);
    ClassLoader managerClassLoader = getManagerClassLoader(classLoader);
    synchronized (cacheManagers) {
        Map<URI, CacheManager> cacheManagersByURI = cacheManagers.computeIfAbsent(managerClassLoader, any -> new HashMap<>());
        return cacheManagersByURI.computeIfAbsent(managerURI, any -> {
            Properties managerProperties = (properties == null) ? getDefaultProperties() : properties;
            return new CacheManagerImpl(this, managerURI, managerClassLoader, managerProperties);
        });
    }
}
Also used : CacheManager(javax.cache.CacheManager) CacheManagerImpl(com.github.benmanes.caffeine.jcache.CacheManagerImpl) Properties(java.util.Properties) URI(java.net.URI)

Example 58 with CacheManager

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

the class CaffeineCachingProvider method close.

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

Example 59 with CacheManager

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

the class CacheConfigTest method defaultCacheTest.

@Test
public void defaultCacheTest() {
    CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
    assertNotNull(cacheManager);
    Cache testCache = cacheManager.getCache("default");
    assertNull(testCache);
}
Also used : HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) CacheManager(javax.cache.CacheManager) Cache(javax.cache.Cache) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 60 with CacheManager

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

the class CacheConfigTest method testEntryListenerFactoryFromSimpleCacheConfig.

@Test
public void testEntryListenerFactoryFromSimpleCacheConfig() {
    String cacheName = randomString();
    Config config = createConfig(cacheName);
    HazelcastInstance instance = createHazelcastInstance(config);
    HazelcastServerCachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    Cache<Object, Object> cache = cacheManager.getCache(cacheName);
    EntryListener.latch = new CountDownLatch(1);
    cache.put(randomString(), randomString());
    assertOpenEventually(EntryListener.latch);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) CacheManager(javax.cache.CacheManager) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CacheManager (javax.cache.CacheManager)105 Test (org.junit.Test)63 QuickTest (com.hazelcast.test.annotation.QuickTest)56 CachingProvider (javax.cache.spi.CachingProvider)48 ParallelTest (com.hazelcast.test.annotation.ParallelTest)41 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)40 HazelcastInstance (com.hazelcast.core.HazelcastInstance)34 CacheConfig (com.hazelcast.config.CacheConfig)32 AssertTask (com.hazelcast.test.AssertTask)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 MutableConfiguration (javax.cache.configuration.MutableConfiguration)17 URI (java.net.URI)16 Cache (javax.cache.Cache)15 HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)13 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)12 ICache (com.hazelcast.cache.ICache)10 Properties (java.util.Properties)10 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)9 ClientConfig (com.hazelcast.client.config.ClientConfig)8 HazelcastCachingProvider (com.hazelcast.cache.HazelcastCachingProvider)7