use of javax.cache.CacheManager in project cache2k by cache2k.
the class CacheManagerTest method create_config_cache2k_types.
@Test
@Ignore("not yet")
public void create_config_cache2k_types() {
CachingProvider p = Caching.getCachingProvider();
CacheManager cm = p.getCacheManager();
ExtendedMutableConfiguration<String, BigDecimal> mc = new ExtendedMutableConfiguration<String, BigDecimal>();
mc.setCache2kConfiguration(new Cache2kBuilder<String, BigDecimal>() {
}.toConfiguration());
Cache<String, BigDecimal> c = cm.createCache("aCache", mc);
assertEquals("aCache", c.getName());
assertEquals(String.class, c.getConfiguration(Configuration.class).getKeyType());
assertEquals(BigDecimal.class, c.getConfiguration(Configuration.class).getValueType());
c.close();
}
use of javax.cache.CacheManager in project cache2k by cache2k.
the class CacheManagerTest method create_empty_config.
@Test
public void create_empty_config() {
CachingProvider p = Caching.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);
assertEquals("aCache", c.getName());
assertEquals(String.class, c.getConfiguration(Configuration.class).getKeyType());
assertEquals(BigDecimal.class, c.getConfiguration(Configuration.class).getValueType());
c.close();
}
use of javax.cache.CacheManager in project cache2k by cache2k.
the class CacheManagerTest method create_cache2k_config_nowrap.
@Test
public void create_cache2k_config_nowrap() {
CachingProvider p = Caching.getCachingProvider();
CacheManager cm = p.getCacheManager();
Cache<Long, Double> cache = cm.createCache("aCache", ExtendedMutableConfiguration.of(new Cache2kBuilder<Long, Double>() {
}.entryCapacity(10000).expireAfterWrite(5, TimeUnit.MINUTES)));
assertFalse(cache instanceof CopyCacheProxy);
cache.close();
}
use of javax.cache.CacheManager in project cache2k by cache2k.
the class CachingProviderClassLoaderTest method getCacheManagerSingleton.
/**
* Multiple invocations of {@link javax.cache.spi.CachingProvider#getCacheManager()}
* will return the same instance.
*/
@Test
public void getCacheManagerSingleton() {
// obtain the default caching provider
CachingProvider provider = Caching.getCachingProvider();
// obtain the default class loader
ClassLoader classLoader = Caching.getDefaultClassLoader();
// obtain the default cache manager
CacheManager manager = provider.getCacheManager();
assertNotNull(classLoader);
assertNotNull(manager);
// ensure the default manager is the same as asking the provider
// for a cache manager using the default URI and classloader
assertSame(manager, provider.getCacheManager());
assertSame(manager, provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader()));
// using a different ClassLoader
ClassLoader otherLoader = new MyClassLoader(classLoader);
CachingProvider otherProvider = Caching.getCachingProvider(otherLoader);
CacheManager otherManager = otherProvider.getCacheManager();
assertSame(otherManager, otherProvider.getCacheManager());
assertSame(otherManager, otherProvider.getCacheManager(otherProvider.getDefaultURI(), otherProvider.getDefaultClassLoader()));
}
use of javax.cache.CacheManager in project cache2k by cache2k.
the class CachingProviderClassLoaderTest method closeClassLoader.
/**
* Attempt to close CacheManagers using URIs and/or ClassLoaders that don't
* have associated CacheManagers.
*/
@Test
public void closeClassLoader() throws Exception {
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
CachingProvider provider = Caching.getCachingProvider(contextLoader);
URI uri = provider.getDefaultURI();
ClassLoader loader1 = new MyClassLoader(contextLoader);
CacheManager manager1 = provider.getCacheManager(uri, loader1);
ClassLoader loader2 = new MyClassLoader(contextLoader);
CacheManager manager2 = provider.getCacheManager(uri, loader2);
ClassLoader loader3 = new MyClassLoader(contextLoader);
CacheManager manager3 = provider.getCacheManager(uri, loader3);
provider.close(contextLoader);
provider.close(provider.getDefaultURI(), contextLoader);
provider.close(provider.getDefaultURI(), contextLoader);
provider.close(provider.getDefaultURI(), contextLoader);
assertSame(manager1, provider.getCacheManager(uri, loader1));
assertSame(manager2, provider.getCacheManager(uri, loader2));
assertSame(manager3, provider.getCacheManager(uri, loader3));
}
Aggregations