Search in sources :

Example 36 with CacheManager

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

the class CacheManagerTest method close_cachesClosed.

@Test
public void close_cachesClosed() {
    CacheManager cacheManager = getCacheManager();
    cacheManager.createCache("c1", new MutableConfiguration());
    Cache cache1 = cacheManager.getCache("c1");
    cacheManager.createCache("c2", new MutableConfiguration());
    Cache cache2 = cacheManager.getCache("c2");
    cacheManager.close();
    ensureClosed(cache1);
    ensureClosed(cache2);
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 37 with CacheManager

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

the class CachingTest method getCacheManager_URI.

/**
 * Multiple invocations of {@link CachingProvider#getCacheManager(java.net.URI, ClassLoader)} with the same name
 * return the same CacheManager instance
 */
@Test
public void getCacheManager_URI() throws Exception {
    CachingProvider provider = Caching.getCachingProvider();
    URI uri = provider.getDefaultURI();
    CacheManager manager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
    assertNotNull(manager);
    assertSame(manager, provider.getCacheManager(uri, provider.getDefaultClassLoader()));
    assertEquals(uri, manager.getURI());
}
Also used : CacheManager(javax.cache.CacheManager) URI(java.net.URI) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 38 with CacheManager

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

the class CacheManagerClassLoadingTest method testCorrectClassLoaderForKey.

/**
 * Request cache manager with different class loader and put a key in the cache that
 * was loaded by that class loader. equals() needs to work and class loaders needs to be
 * identical
 */
@Test
public void testCorrectClassLoaderForKey() throws Exception {
    SpecialClassLoader loader = new SpecialClassLoader();
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager mgr = Caching.getCachingProvider().getCacheManager(provider.getDefaultURI(), loader);
    Cache<Object, Object> cache = mgr.createCache(CACHE_NAME, new MutableConfiguration());
    Class keyClass = loader.loadSpecial(DomainKey.class);
    assertEquals(keyClass.getClassLoader(), loader);
    Object key = keyClass.newInstance();
    setValue(key, "someKey");
    String someValue = "Value";
    cache.put(key, someValue);
    Cache.Entry e = cache.iterator().next();
    assertSame("class loaders identical", key.getClass().getClassLoader(), e.getKey().getClass().getClassLoader());
    assertEquals(key, e.getKey());
    mgr.close();
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 39 with CacheManager

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

the class CacheManagerClassLoadingTest method testCorrectClassLoaderForValue.

/**
 * Request cache manager with different class loader and put a value in the cache that
 * was loaded by that class loader. equals() needs to work and class loaders needs to be
 * identical
 */
@Test
public void testCorrectClassLoaderForValue() throws Exception {
    SpecialClassLoader loader = new SpecialClassLoader();
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager mgr = Caching.getCachingProvider().getCacheManager(provider.getDefaultURI(), loader);
    Cache<Object, Object> cache = mgr.createCache(CACHE_NAME, new MutableConfiguration());
    Class valueClass = loader.loadSpecial(DomainValue.class);
    assertEquals(valueClass.getClassLoader(), loader);
    Object value = valueClass.newInstance();
    setValue(value, "someValue");
    String someKey = "Key";
    cache.put(someKey, value);
    Cache.Entry e = cache.iterator().next();
    assertSame("class loaders identical", value.getClass().getClassLoader(), e.getValue().getClass().getClassLoader());
    assertEquals(value, e.getValue());
    mgr.close();
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 40 with CacheManager

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

the class CacheManagerTest method create_cache2k_config_key_type_mismatch.

@Test(expected = IllegalArgumentException.class)
public void create_cache2k_config_key_type_mismatch() {
    CachingProvider p = Caching.getCachingProvider();
    CacheManager cm = p.getCacheManager();
    MutableConfiguration cfg = ExtendedMutableConfiguration.of(new Cache2kBuilder<Long, Double>() {
    });
    Cache<Integer, Double> cache = cm.createCache("aCache", cfg.setTypes(Integer.class, Double.class));
    cache.close();
}
Also used : CacheManager(javax.cache.CacheManager) ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) 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