use of javax.cache.configuration.MutableConfiguration 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();
}
use of javax.cache.configuration.MutableConfiguration in project tutorials by eugenp.
the class CacheLoaderTest method setup.
@Before
public void setup() {
CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<Integer, String> config = new MutableConfiguration<Integer, String>().setReadThrough(true).setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<>(new SimpleCacheLoader()));
this.cache = cacheManager.createCache("SimpleCache", config);
}
use of javax.cache.configuration.MutableConfiguration in project tutorials by eugenp.
the class JCacheIntegrationTest method instantiateCache.
@Test
public void instantiateCache() {
CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<String, String> config = new MutableConfiguration<>();
Cache<String, String> cache = cacheManager.createCache("simpleCache", config);
cache.put("key1", "value1");
cache.put("key2", "value2");
assertEquals("value1", cache.get("key1"));
assertEquals("value2", cache.get("key2"));
cacheManager.close();
}
use of javax.cache.configuration.MutableConfiguration in project micrometer by micrometer-metrics.
the class JCacheMetricsCompatibilityTest method createCache.
@Override
public Cache<String, String> createCache() {
CacheManager cacheManager = new RICachingProvider().getCacheManager();
MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
configuration.setTypes(String.class, String.class).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR)).setStatisticsEnabled(true);
return cacheManager.createCache("mycache", configuration);
}
use of javax.cache.configuration.MutableConfiguration 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 = getCachingProvider();
CacheManager mgr = getCachingProvider().getCacheManager(provider.getDefaultURI(), loader);
Cache<Object, Object> cache = mgr.createCache(CACHE_NAME, new MutableConfiguration());
Class keyClass = loader.loadSpecial(DomainKey.class);
assertThat(loader).isEqualTo(keyClass.getClassLoader());
Object key = keyClass.newInstance();
setValue(key, "someKey");
String someValue = "Value";
cache.put(key, someValue);
Entry e = cache.iterator().next();
Assertions.assertSame(key.getClass().getClassLoader(), e.getKey().getClass().getClassLoader(), "class loaders identical");
assertThat(e.getKey()).isEqualTo(key);
mgr.close();
}
Aggregations