use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.
the class JCacheConfigurationTest method testProgrammaticCacheConfiguration.
public void testProgrammaticCacheConfiguration() throws Exception {
URI uri = JCacheConfigurationTest.class.getClassLoader().getResource("infinispan_uri.xml").toURI();
Properties properties = getProperties();
Function<String, Configuration> f = (s) -> new ConfigurationBuilder().memory().maxCount(1234l).build();
properties.put(JCacheManager.CACHE_CONFIGURATION_FUNCTION, f);
withCachingProvider(provider -> {
try (JCacheManager jCacheManager = new JCacheManager(uri, provider.getClass().getClassLoader(), provider, properties)) {
Cache<Object, Object> cache = jCacheManager.createCache("cache", new MutableConfiguration<>());
org.infinispan.Cache unwrap = cache.unwrap(org.infinispan.Cache.class);
Configuration configuration = unwrap.getCacheConfiguration();
assertEquals(1234l, configuration.memory().maxCount());
}
});
}
use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.
the class InjectedCacheResolver method toJCacheManager.
private JCacheManager toJCacheManager(final EmbeddedCacheManager cacheManager) {
final GlobalConfiguration globalCfg = cacheManager.getCacheManagerConfiguration();
final String name = globalCfg.cacheManagerName();
return new JCacheManager(URI.create(name), cacheManager, Caching.getCachingProvider());
}
use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.
the class JCacheConfigurationTest method testJCacheManagerWherePathContainsFileSchemaAndAbsolutePath.
public void testJCacheManagerWherePathContainsFileSchemaAndAbsolutePath() throws Exception {
URI uri = JCacheConfigurationTest.class.getClassLoader().getResource("infinispan_uri.xml").toURI();
withCachingProvider(provider -> {
Properties properties = getProperties();
try (JCacheManager jCacheManager = new JCacheManager(uri, provider.getClass().getClassLoader(), provider, properties)) {
Cache<Object, Object> cache = jCacheManager.getCache("foo");
assertNotNull(cache);
assertEquals(10000, cache.unwrap(AdvancedCache.class).getCacheConfiguration().memory().maxCount());
}
});
}
use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.
the class JCacheConfigurationTest method testJCacheManagerWithWildcardCacheConfigurations.
public void testJCacheManagerWithWildcardCacheConfigurations() throws Exception {
URI uri = JCacheConfigurationTest.class.getClassLoader().getResource("infinispan_uri.xml").toURI();
withCachingProvider(provider -> {
try (JCacheManager jCacheManager = new JCacheManager(uri, provider.getClass().getClassLoader(), provider, getProperties())) {
Cache<Object, Object> wildcache1 = jCacheManager.createCache("wildcache1", new MutableConfiguration<>());
org.infinispan.Cache unwrap = wildcache1.unwrap(org.infinispan.Cache.class);
Configuration configuration = unwrap.getCacheConfiguration();
assertEquals(10500, configuration.expiration().wakeUpInterval());
assertEquals(11, configuration.expiration().lifespan());
assertEquals(11, configuration.expiration().maxIdle());
}
});
}
use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.
the class JCacheLoaderTest method testLoadUnmarshallableValue.
public void testLoadUnmarshallableValue(Method m) {
final String cacheName = m.getName();
NonMarshallablePojo v1 = new NonMarshallablePojo("v1");
NonMarshallablePojo v2 = new NonMarshallablePojo("v2");
withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createCacheManager(false)) {
@Override
public void call() {
JCacheManager jCacheManager = createJCacheManager(cm, this);
InMemoryJCacheLoader<Integer, NonMarshallablePojo> cacheLoader = new InMemoryJCacheLoader<>();
cacheLoader.store(1, v1).store(2, v2);
MutableConfiguration<Integer, NonMarshallablePojo> cfg = new MutableConfiguration<>();
cfg.setStoreByValue(false);
cfg.setReadThrough(true);
cfg.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
Cache<Integer, NonMarshallablePojo> cache = jCacheManager.createCache(cacheName, cfg);
assertEquals(v2, cache.get(2));
assertEquals(v1, cache.get(1));
DataContainer<Integer, String> dc = cache.unwrap(AdvancedCache.class).getDataContainer();
assertEquals(v2, dc.peek(2).getValue());
assertEquals(v1, dc.peek(1).getValue());
}
});
}
Aggregations