use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.
the class InvokeProcessorTest method invokeProcessor.
private void invokeProcessor(Method m, final MutableConfiguration<String, Entry> jcacheCfg) {
final String name = getName(m);
CacheManager cm = new JCacheManager(URI.create(name), TestCacheManagerFactory.createCacheManager(JCacheTestSCI.INSTANCE), null);
Cache<String, Entry> cache = cm.createCache(name, jcacheCfg);
ArrayList<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3));
final String query = "select * from x";
cache.put(query, new Entry(list));
cache.invoke(query, new TestEntryProcessor());
assertEquals(new ArrayList<>(Arrays.asList(1, 2, 3, 4)), cache.get(query).integers);
}
use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.
the class InvokeProcessorTest method invokeProcessorThrowsException.
private void invokeProcessorThrowsException(Method m, final MutableConfiguration<String, Entry> jcacheCfg, final List<Integer> expectedValue) {
final String name = getName(m);
CacheManager cm = new JCacheManager(URI.create(name), TestCacheManagerFactory.createCacheManager(JCacheTestSCI.INSTANCE), null);
Cache<String, Entry> cache = cm.createCache(name, jcacheCfg);
final String query = "select * from x";
cache.put(query, new Entry(new ArrayList<>(Arrays.asList(1, 2, 3))));
try {
cache.invoke(query, new TestExceptionThrowingEntryProcessor());
fail("Expected an exception to be thrown");
} catch (CacheException e) {
assertTrue(e.getCause() instanceof UnexpectedException);
}
assertEquals(expectedValue, cache.get(query).integers);
}
use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.
the class JCacheConfigurationTest method testNamedCacheConfiguration.
public void testNamedCacheConfiguration() {
withCacheManager(TestCacheManagerFactory.createCacheManager(false), cm -> {
cm.defineConfiguration("oneCache", new ConfigurationBuilder().build());
JCacheManager jCacheManager = new JCacheManager(URI.create("oneCacheManager"), cm, null);
assertNotNull(jCacheManager.getCache("oneCache"));
});
}
use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.
the class InjectedCacheResolver method resolveCache.
@Override
public <K, V> Cache<K, V> resolveCache(final CacheInvocationContext<? extends Annotation> cacheInvocationContext) {
Contracts.assertNotNull(cacheInvocationContext, "cacheInvocationContext parameter must not be null");
final String cacheName = cacheInvocationContext.getCacheName();
// If the cache name is empty the default cache of the default cache manager is returned.
if (cacheName.trim().isEmpty()) {
if (log.isTraceEnabled())
log.tracef("Resolved cache %s on %s", cacheName, defaultJCacheManager.getURI());
return getCacheFromDefaultCacheManager(cacheName);
}
// interceptor could use a specific cache manager.
for (final EmbeddedCacheManager cm : jcacheManagers.keySet()) {
final Set<String> cacheNames = cm.getCacheNames();
for (final String name : cacheNames) {
if (name.equals(cacheName)) {
final JCacheManager jcacheManager = jcacheManagers.get(cm);
final Cache<K, V> cache = jcacheManager.getCache(cacheName);
if (cache != null)
return cache;
if (log.isTraceEnabled())
log.tracef("Resolved cache %s on %s", cacheName, jcacheManager.getURI());
return jcacheManager.getOrCreateCache(cacheName, cm.<K, V>getCache(cacheName).getAdvancedCache());
}
}
}
// cache manager with the default configuration.
return getCacheFromDefaultCacheManager(cacheName);
}
Aggregations