use of javax.cache.configuration.MutableConfiguration 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 = getCachingProvider();
CacheManager mgr = getCachingProvider().getCacheManager(provider.getDefaultURI(), loader);
Cache<Object, Object> cache = mgr.createCache(CACHE_NAME, new MutableConfiguration());
Class valueClass = loader.loadSpecial(DomainValue.class);
assertThat(loader).isEqualTo(valueClass.getClassLoader());
Object value = valueClass.newInstance();
setValue(value, "someValue");
String someKey = "Key";
cache.put(someKey, value);
Entry e = cache.iterator().next();
Assertions.assertSame(value.getClass().getClassLoader(), e.getValue().getClass().getClassLoader(), "class loaders identical");
assertThat(e.getValue()).isEqualTo(value);
mgr.close();
}
use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.
the class CacheManagerTest method create_empty_config.
@Test
public void create_empty_config() {
CachingProvider p = getCachingProvider();
CacheManager cm = p.getCacheManager();
MutableConfiguration<String, BigDecimal> mc = new ExtendedMutableConfiguration<String, BigDecimal>();
mc.setTypes(String.class, BigDecimal.class);
Cache<String, BigDecimal> c = cm.createCache("aCache", mc);
assertThat(c.getName()).isEqualTo("aCache");
assertThat(c.getConfiguration(Configuration.class).getKeyType()).isEqualTo(String.class);
assertThat(c.getConfiguration(Configuration.class).getValueType()).isEqualTo(BigDecimal.class);
c.close();
}
use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.
the class XmlConfigurationTest method configurationPresent_defaults.
@Test
public void configurationPresent_defaults() throws Exception {
javax.cache.CacheManager manager = getCachingProvider().getCacheManager(new URI(MANAGER_NAME), null);
JCacheBuilder b = new JCacheBuilder("default", (JCacheManagerAdapter) manager);
b.setConfiguration(new MutableConfiguration());
assertThat(b.getExtraConfiguration().isCopyAlwaysIfRequested()).isEqualTo(false);
}
use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.
the class CacheManagerTest method cachingProviderGetCache.
@Test
public void cachingProviderGetCache() {
String name = "c1";
getCacheManager().createCache(name, new MutableConfiguration().setTypes(Long.class, String.class));
Cache cache = Caching.getCache(name, Long.class, String.class);
assertEquals(name, cache.getName());
}
use of javax.cache.configuration.MutableConfiguration 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);
}
Aggregations