Search in sources :

Example 21 with CacheManager

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

the class CacheManagerTest method testReuseCacheManagerGetCache.

/**
 * https://github.com/jsr107/jsr107tck/issues/104
 * Changed in 1.1, don't do getCache(..., null, null)
 */
@Test
public void testReuseCacheManagerGetCache() 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.getCache("nonExistent", Integer.class, Integer.class);
        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) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 22 with CacheManager

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

the class CacheManagerTest method getIncorrectCacheValueType.

@Test(expected = ClassCastException.class)
public void getIncorrectCacheValueType() {
    CacheManager cacheManager = getCacheManager();
    MutableConfiguration<String, Long> config = new MutableConfiguration<String, Long>().setTypes(String.class, Long.class);
    cacheManager.createCache("typed-cache", config);
    Cache<String, String> cache = cacheManager.getCache("typed-cache", String.class, String.class);
}
Also used : CacheManager(javax.cache.CacheManager) Test(org.junit.Test)

Example 23 with CacheManager

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

the class CacheManagerTest method enableStatistics_nullCacheName.

@Test(expected = NullPointerException.class)
public void enableStatistics_nullCacheName() {
    CacheManager cacheManager = getCacheManager();
    final String NULL_CACHE_NAME = null;
    cacheManager.enableStatistics(NULL_CACHE_NAME, true);
    fail();
}
Also used : CacheManager(javax.cache.CacheManager) Test(org.junit.Test)

Example 24 with CacheManager

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

the class CacheManagerTest method getCache_There.

@Test
public void getCache_There() {
    String name = this.toString();
    CacheManager cacheManager = getCacheManager();
    cacheManager.createCache(name, new MutableConfiguration());
    Cache cache = cacheManager.getCache(name);
    assertSame(cache, cacheManager.getCache(name));
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 25 with CacheManager

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

the class CacheManagerTest method getUntypedCache.

@Test
public void getUntypedCache() {
    CacheManager cacheManager = getCacheManager();
    // configure an un-typed Cache
    MutableConfiguration config = new MutableConfiguration();
    cacheManager.createCache("untyped-cache", config);
    Cache cache = cacheManager.getCache("untyped-cache");
    assertNotNull(cache);
    assertEquals(Object.class, cache.getConfiguration(CompleteConfiguration.class).getKeyType());
    assertEquals(Object.class, cache.getConfiguration(CompleteConfiguration.class).getValueType());
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache) 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