本文整理了Java中org.infinispan.Cache.compute()
方法的一些代码示例,展示了Cache.compute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.compute()
方法的具体详情如下:
包路径:org.infinispan.Cache
类名称:Cache
方法名:compute
暂无
代码示例来源:origin: org.infinispan/infinispan-core
@SuppressWarnings("ConstantConditions")
public void testComputeNullParameters() {
expectException(NullPointerException.class, "Null keys are not supported!",
() -> cache.compute(null, (o, o2) -> "X"));
expectException(NullPointerException.class, "Null functions are not supported!", () -> cache.compute("k", null));
expectException(NullPointerException.class, "Null keys are not supported!",
() -> cache.computeIfAbsent(null, o -> "X"));
expectException(NullPointerException.class, "Null functions are not supported!",
() -> cache.computeIfAbsent("k", null));
expectException(NullPointerException.class, "Null keys are not supported!",
() -> cache.computeIfPresent(null, (o, o2) -> "X"));
expectException(NullPointerException.class, "Null functions are not supported!",
() -> cache.computeIfPresent("k", null));
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test(enabled = false, description = "ISPN-7590")
public void testComputeRemove() {
test(c -> c.compute(KEY, (k, old) -> null), sm -> {});
}
代码示例来源:origin: org.infinispan/infinispan-core
(BiConsumer<Cache<Object, Object>, CacheEntry<Object, Object>>) (c, e) -> c.compute(e.getKey(), (k, v) -> v + "-other"),
代码示例来源:origin: org.infinispan/infinispan-query
public void testCompute() {
test(c -> c.compute(KEY, (k, old) -> FLUFFY), this::assertFluffyIndexed, false);
}
代码示例来源:origin: org.infinispan/infinispan-query
public void testComputeRemove() {
test(c -> c.compute(KEY, (k, old) -> null), sm -> {}, true);
}
代码示例来源:origin: org.infinispan/infinispan-query
public void testCompute() {
test(c -> c.compute(KEY, (k, old) -> FLUFFY), this::assertFluffyIndexed);
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testCompute() {
BiFunction<Object, Object, String> mappingFunction = (k, v) -> "hello_" + k + ":" + v;
cache.put("es", "hola");
assertEquals("hello_es:hola", cache.compute("es", mappingFunction));
assertEquals("hello_es:hola", cache.get("es"));
BiFunction<Object, Object, String> mappingForNotPresentKey = (k, v) -> "absent_" + k + ":" + v;
assertEquals("absent_fr:null", cache.compute("fr", mappingForNotPresentKey));
assertEquals("absent_fr:null", cache.get("fr"));
BiFunction<Object, Object, String> mappingToNull = (k, v) -> null;
assertNull(cache.compute("es", mappingToNull), "mapping to null returns null");
assertNull(cache.get("es"), "the key is removed");
int cacheSizeBeforeNullValueCompute = cache.size();
assertNull(cache.compute("eus", mappingToNull), "mapping to null returns null");
assertNull(cache.get("eus"), "the key does not exist");
assertEquals(cacheSizeBeforeNullValueCompute, cache.size());
RuntimeException computeRaisedException = new RuntimeException("hi there");
BiFunction<Object, Object, String> mappingToException = (k, v) -> {
throw computeRaisedException;
};
expectException(RuntimeException.class, "hi there", () -> cache.compute("es", mappingToException));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testRemoveViaComputeOnEvictedEntry() throws Exception {
Cache<String, String> testCache = cacheManager.getCache(CACHE_NAME);
for (int i = 0; i < EVICTION_MAX_ENTRIES + 1; i++) {
testCache.put("key" + i, "value" + i);
}
String evictedKey = evictionListener.getEvictedKey();
assertTrue(isEntryInStore(evictedKey));
testCache.compute(evictedKey, (k ,v) -> null);
assertFalse(testCache.containsKey(evictedKey));
assertFalse(isEntryInStore(evictedKey));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testComputeOnEvictedEntry() throws Exception {
Cache<String, String> testCache = cacheManager.getCache(CACHE_NAME);
for (int i = 0; i < EVICTION_MAX_ENTRIES + 1; i++) {
testCache.put("key" + i, "value" + i);
}
String evictedKey = evictionListener.getEvictedKey();
assertTrue(isEntryInStore(evictedKey));
testCache.compute(evictedKey, (k ,v) -> v + "-modfied");
assertFalse(isEntryInStore(evictedKey));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testCompute() {
BiFunction<Object, Object, String> mappingFunction = (k, v) -> "hello_" + k + ":" + v;
cache.put("es", "hola");
assertEquals("hello_es:hola", cache.compute("es", mappingFunction));
assertEquals("hello_es:hola", cache.get("es"));
BiFunction<Object, Object, String> mappingForNotPresentKey = (k, v) -> "absent_" + k + ":" + v;
assertEquals("absent_fr:null", cache.compute("fr", mappingForNotPresentKey));
assertEquals("absent_fr:null", cache.get("fr"));
BiFunction<Object, Object, String> mappingToNull = (k, v) -> null;
assertNull("mapping to null returns null", cache.compute("es", mappingToNull));
assertNull("the key is removed", cache.get("es"));
int cacheSizeBeforeNullValueCompute = cache.size();
assertNull("mapping to null returns null", cache.compute("eus", mappingToNull));
assertNull("the key does not exist", cache.get("eus"));
assertEquals(cacheSizeBeforeNullValueCompute, cache.size());
RuntimeException computeRaisedException = new RuntimeException("hi there");
BiFunction<Object, Object, String> mappingToException = (k, v) -> {
throw computeRaisedException;
};
expectException(RuntimeException.class, "hi there", () -> cache.compute("es", mappingToException));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testComputeFromNonOwner() throws InterruptedException {
// compute function applied
initAndTest();
Object retval = getFirstNonOwner("k1").compute("k1", (k, v) -> "computed_" + k + "_" + v);
asyncWait("k1", ComputeCommand.class);
if (testRetVals) assertEquals("computed_k1_value", retval);
assertOnAllCachesAndOwnership("k1", "computed_k1_value");
// remove if after compute value is null
retval = getFirstNonOwner("k1").compute("k1", (v1, v2) -> null);
asyncWait("k1", ComputeCommand.class);
if (testRetVals) assertNull(retval);
assertRemovedOnAllCaches("k1");
// put computed value if absent
retval = getFirstNonOwner("notThere").compute("notThere", (k, v) -> "add_" + k);
asyncWait("notThere", ComputeCommand.class);
if (testRetVals) assertEquals("add_notThere", retval);
assertOnAllCachesAndOwnership("notThere", "add_notThere");
RuntimeException computeRaisedException = new RuntimeException("hi there");
SerializableBiFunction<Object, Object, String> mappingToException = (k, v) -> {
throw computeRaisedException;
};
expectException(RemoteException.class, () -> getFirstNonOwner("k1").compute("k1", mappingToException));
}
代码示例来源:origin: org.infinispan/infinispan-query
cache2.compute(key, remappingFunction);
if (transactionsEnabled()) transactionManager.commit();
StaticTestingErrorHandler.assertAllGood(cache1, cache2);
cache2.compute(key, remappingExisting);
if (transactionsEnabled()) transactionManager.commit();
StaticTestingErrorHandler.assertAllGood(cache1, cache2);
cache2.compute(key, remappingToNull);
if (transactionsEnabled()) transactionManager.commit();
StaticTestingErrorHandler.assertAllGood(cache1, cache2);
代码示例来源:origin: org.infinispan/infinispan-remote-query-server
public void testUnsupportedCommands() {
Cache<String, String> cache0 = cache(0);
assertTrue(cache0.isEmpty());
try {
cache0.compute("test.proto", (k, v) -> "import \"missing.proto\";");
} catch (Exception e) {
assertTrue(e instanceof CacheException);
assertTrue(e.getMessage().contains("ISPN028014"));
}
assertTrue(cache0.isEmpty());
try {
FunctionalMap.ReadWriteMap<String, String> rwMap = ReadWriteMapImpl.create(FunctionalMapImpl.create(cache0.getAdvancedCache()));
rwMap.eval("test.proto", "val", (value, view) -> {
view.set(value);
return "ret";
}).join();
} catch (CompletionException e) {
assertTrue(e.getCause() instanceof CacheException);
assertTrue(e.getCause().getMessage().contains("ISPN028014"));
}
assertTrue(cache0.isEmpty());
assertNoTransactionsAndLocks();
}
代码示例来源:origin: org.infinispan/infinispan-core
cache(1, cacheName).put(key, "a");
assertEquals("ab", cache(2, cacheName).compute(key, (k, v) -> v + "b"));
assertLocalValue(0, key, "ab");
assertLocalValue(1, key, "a");
assertEquals("abc", cache(0, cacheName).compute(key, (k, v) -> v + "c"));
assertLocalValue(0, key, "abc");
assertEquals(null, cache(1, cacheName).compute(key, (k, v) -> "abc".equals(v) ? null : "unexpected"));
assertLocalValue(0, key, null);
assertLocalValue(1, key, null);
assertEquals("x", cache(1, cacheName).compute(otherKey, (k, v) -> v == null ? "x" : "unexpected"));
assertLocalValue(0, otherKey, "x");
assertLocalValue(1, otherKey, "x");
assertEquals(null, cache(0, cacheName).compute(otherKey, (k, v) -> "x".equals(v) ? null : "unexpected"));
assertLocalValue(0, otherKey, null);
assertEquals("y", cache(0, cacheName).compute(otherKey, (k, v) -> v == null ? "y" : "unexpected"));
assertLocalValue(0, otherKey, "y");
assertOwnershipAndNonOwnership(otherKey, false);
内容来源于网络,如有侵权,请联系作者删除!