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);
}
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());
}
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();
}
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();
}
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();
}
Aggregations