Search in sources :

Example 31 with CacheManager

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

the class CacheManagerTest method close_twice.

@Test
public void close_twice() {
    CacheManager cacheManager = getCacheManager();
    cacheManager.close();
    cacheManager.close();
}
Also used : CacheManager(javax.cache.CacheManager) Test(org.junit.Test)

Example 32 with CacheManager

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

the class CacheManagerTest method getUnsafeTypedCacheRequest.

/**
 * https://github.com/jsr107/jsr107spec/issues/340
 * in 1.1 we relaxed {@link CacheManager#getCache(String)} to not enforce a check.
 */
@Test
public void getUnsafeTypedCacheRequest() {
    CacheManager cacheManager = getCacheManager();
    MutableConfiguration<String, Long> config = new MutableConfiguration<String, Long>().setTypes(String.class, Long.class);
    cacheManager.createCache("typed-cache", config);
    Cache cache = cacheManager.getCache("typed-cache");
    assertNotNull("getCache() returns cache reference for typed caches, since 1.1", cache);
}
Also used : CacheManager(javax.cache.CacheManager) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 33 with CacheManager

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

the class CacheManagerTest method testReuseCacheManager.

@Test
public void testReuseCacheManager() throws Exception {
    CachingProvider provider = Caching.getCachingProvider();
    URI uri = provider.getDefaultURI();
    CacheManager cacheManager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
    assertFalse(cacheManager.isClosed());
    cacheManager.close();
    assertTrue(cacheManager.isClosed());
    try {
        cacheManager.createCache("Dog", new MutableConfiguration());
        fail();
    } catch (IllegalStateException e) {
    // expected
    }
    CacheManager otherCacheManager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
    assertFalse(otherCacheManager.isClosed());
    assertNotSame(cacheManager, otherCacheManager);
}
Also used : CacheManager(javax.cache.CacheManager) URI(java.net.URI) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 34 with CacheManager

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

the class CacheManagerTest method getCaches_MutateReturn.

@Test
public void getCaches_MutateReturn() {
    CacheManager cacheManager = getCacheManager();
    cacheManager.createCache("c1", new MutableConfiguration());
    Cache cache1 = cacheManager.getCache("c1");
    try {
        Iterator iterator = cacheManager.getCacheNames().iterator();
        iterator.next();
        iterator.remove();
        fail();
    } catch (UnsupportedOperationException e) {
    // immutable
    }
}
Also used : Iterator(java.util.Iterator) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 35 with CacheManager

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

the class CacheManagerTest method removeCache_There.

@Test
public void removeCache_There() {
    CacheManager cacheManager = getCacheManager();
    String name1 = "c1";
    cacheManager.createCache(name1, new MutableConfiguration());
    cacheManager.destroyCache(name1);
    assertFalse(cacheManager.getCacheNames().iterator().hasNext());
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Test(org.junit.Test)

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