use of org.infinispan.functional.impl.FunctionalMapImpl in project bucket4j-spring-boot-starter by MarcGiffing.
the class InfinispanJCacheCacheResolver method resolve.
public ProxyManager<String> resolve(String cacheName) {
Cache<Object, Object> cache = cacheContainer.getCache(cacheName);
if (cache == null) {
throw new JCacheNotFoundException(cacheName);
}
FunctionalMapImpl functionalMap = FunctionalMapImpl.create(cache.getAdvancedCache());
return new InfinispanProxyManager<>(ReadWriteMapImpl.create(functionalMap));
}
use of org.infinispan.functional.impl.FunctionalMapImpl in project infinispan by infinispan.
the class CacheOperationsTest method testFunctional.
private void testFunctional(String site) throws Exception {
FunctionalMapImpl<Object, Object> fmap = FunctionalMapImpl.create(cache(site, 0).getAdvancedCache());
WriteOnlyMap<Object, Object> wo = WriteOnlyMapImpl.create(fmap);
ReadWriteMap<Object, Object> rw = ReadWriteMapImpl.create(fmap);
Cache<Object, Object> backup = backup(site);
Object[] keys = { new MagicKey("k0", cache(site, 0), cache(site, 1)), new MagicKey("k1", cache(site, 1), cache(site, 0)), new MagicKey("k2", cache(site, 1), cache(site, 2)) };
for (Object key : keys) {
wo.eval(key, "v0", MarshallableFunctions.setValueConsumer()).join();
assertEquals("v0", backup.get(key));
}
for (Object key : keys) {
wo.eval(key, MarshallableFunctions.removeConsumer()).join();
assertEquals(null, backup.get(key));
}
wo.evalMany(map(keys, "v1"), MarshallableFunctions.setValueConsumer()).join();
for (Object key : keys) {
assertEquals("v1", backup.get(key));
}
for (Object key : keys) {
rw.eval(key, view -> view.set(view.get() + "+2")).join();
assertEquals("v1+2", backup.get(key));
}
rw.evalMany(Util.asSet(keys), view -> view.set(view.get() + "+3")).forEach(ret -> assertEquals(null, ret));
for (Object key : keys) {
assertEquals("v1+2+3", backup.get(key));
}
wo.evalMany(Util.asSet(keys), MarshallableFunctions.removeConsumer()).join();
for (Object key : keys) {
assertEquals(null, backup.get(key));
}
rw.evalMany(Util.asSet(keys), view -> view.find().orElse("none")).forEach(ret -> assertEquals("none", ret));
for (Object key : keys) {
assertEquals(null, backup.get(key));
}
if (transactional) {
TransactionManager tm = cache(site, 0).getAdvancedCache().getTransactionManager();
tm.begin();
rw.eval(keys[0], "v4", MarshallableFunctions.setValueReturnPrevOrNull()).join();
// read-only evalMany
rw.evalMany(Util.asSet(keys[1], keys[2]), view -> view.find().orElse("none")).forEach(ret -> assertEquals("none", ret));
tm.commit();
assertEquals("v4", backup.get(keys[0]));
assertEquals(null, backup.get(keys[1]));
assertEquals(null, backup.get(keys[2]));
}
}
Aggregations