本文整理了Java中org.infinispan.Cache.replace()
方法的一些代码示例,展示了Cache.replace()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.replace()
方法的具体详情如下:
包路径:org.infinispan.Cache
类名称:Cache
方法名:replace
暂无
代码示例来源:origin: org.infinispan/infinispan-core
@Override
public boolean execute(Cache cache, String sharedKey, Object existing, String targetValue) {
try {
return cache.replace(SHARED_KEY, existing, targetValue);
} catch (CacheException e) {
return false;
}
}
代码示例来源:origin: org.infinispan/infinispan-core
@Override
public void execute() {
cache(0).replace(key, "", "");
}
});
代码示例来源:origin: org.infinispan/infinispan-core
@Override
public void execute() {
cache(1).replace(key, "", "v");
}
});
代码示例来源:origin: org.infinispan/infinispan-core
@Override
public void execute() {
cache(1).replace(key, "", "v");
}
});
代码示例来源:origin: org.infinispan/infinispan-core
private static Map<?, ?> replace(Cache<Object, Object> cache, Collection<?> keys) {
Map<Object, Object> map = new HashMap<>();
int i = 0;
for (Object key : keys) {
Object value = cache.replace(key, "other" + (i++));
if (value != null) {
map.put(key, value);
}
}
return map;
}
代码示例来源:origin: org.infinispan/infinispan-core
@SuppressWarnings("ConstantConditions")
public void testReplaceNullParameters() {
expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.replace(null, null));
expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.replace(null, "X"));
expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.replace(null, "X", "Y"));
expectException(NullPointerException.class, "Null values are not supported!",
() -> cache.replace("hello", null, "X"));
expectException(NullPointerException.class, "Null values are not supported!",
() -> cache.replace("hello", "X", null));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testConditionalReplace() {
final MagicKey KEY = new MagicKey(cache(0));
cache(0).put(KEY, VALUE1);
assertTrue(cache(0).replace(KEY, VALUE1, VALUE2));
assertFalse(cache(0).replace(KEY, VALUE1, VALUE3));
assertTrue(cache(1).replace(KEY, VALUE2, VALUE3));
assertFalse(cache(1).replace(KEY, VALUE2, VALUE1));
assertTrue(cache(2).replace(KEY, VALUE3, VALUE1));
assertFalse(cache(2).replace(KEY, VALUE3, VALUE2));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testConditionalReplaceFromNonOwner() {
initAndTest();
Cache<Object, String> nonOwner = getFirstNonOwner("k1");
boolean success = nonOwner.replace("k1", "blah", "value2");
assert !success;
assertOnAllCachesAndOwnership("k1", "value");
success = nonOwner.replace("k1", "value", "value2");
assert success;
assertOnAllCachesAndOwnership("k1", "value2");
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testReplaceNotification() throws Exception {
Matcher<FlagAffectedCommand> matcher = getFlagMatcher();
initCacheData(cache, Collections.singletonMap("key", "value"));
cache.replace("key", "value", "value2");
verify(getMockNotifier(cache)).notifyCacheEntryModified(eq("key"), eq("value2"), any(Metadata.class), eq("value"),
any(Metadata.class), eq(true), isA(InvocationContext.class), argThat(matcher));
verify(getMockNotifier(cache)).notifyCacheEntryModified(eq("key"), eq("value2"), any(Metadata.class), eq("value"),
any(Metadata.class), eq(false), isA(InvocationContext.class), argThat(matcher));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testReplace(Method m) {
CustomPojo key = new CustomPojo(m.getName());
cache.put(key, "1");
assert "1".equals(cache.get(new CustomPojo(m.getName())));
Object oldValue = cache.replace(new CustomPojo(m.getName()), "2");
assert "1".equals(oldValue);
assert "2".equals(cache.get(new CustomPojo(m.getName())));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testReplaceCommand() throws Exception {
assertStoreAccess(0, 0, 0);
cache.put("key", "value");
assertStoreAccess(0, 1, 1);
assert cache.replace("key", "value2").equals("value");
assertStoreAccess(0, 1, 2);
store.write(new MarshalledEntryImpl("a", "b", null, marshaller()));
assert cache.replace("a", "c").equals("b");
assertStoreAccess(1, 1, 3);
assert cache.replace("no_such_key", "c") == null;
assertStoreAccess(1, 2, 3);
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testReplace() {
cache(0).put("k", "v1");
for (int i = 0; i < nodes; i++) {
assertEquals("v1", cache(i).get("k"));
}
assert cache(0).replace("k", "v2") != null;
assert cache(0).replace("k", "v2", "v3");
assertEquals(cache(0).get("k"), "v3");
}
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testReplaceFromNonOwner() throws Exception {
String key = "k1", value = "value", value2 = "v2";
initAndTest();
assertInStores(key, value, true);
Object retval = getFirstNonOwner(key).replace(key, value2);
if (testRetVals) assert value.equals(retval);
assertInStores(key, value2, true);
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testReplace() throws Exception {
tm(0).begin();
cache(0).replace(k, "v1");
assertLockingNoChanges();
// if the key doesn't exist, replace is a no-op, so it shouldn't acquire locks
cache(0).put(k, "v1");
tm(0).begin();
cache(0).replace(k, "v2");
assertLocking();
}
代码示例来源:origin: org.infinispan/infinispan-core
@Test
public void testL1UpdatedOnReplaceOperationFailure() {
final Cache<Object, String> nonOwnerCache = getFirstNonOwner(key);
final Cache<Object, String> ownerCache = getFirstOwner(key);
ownerCache.put(key, firstValue);
assertIsNotInL1(nonOwnerCache, key);
assertFalse(nonOwnerCache.replace(key, "not-same", secondValue));
assertIsInL1(nonOwnerCache, key);
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testReplaceWithOldVal() {
assertEmpty(KEY_1);
cache(1).put(KEY_1, VALUE_1);
assertCacheValue(1, KEY_1, VALUE_1);
cache(0).put(KEY_1, VALUE_2);
assertCacheValue(0, KEY_1, VALUE_2);
cache(0).replace(KEY_1, VALUE_3, VALUE_4);
assertCacheValue(0, KEY_1, VALUE_2);
cache(0).replace(KEY_1, VALUE_2, VALUE_4);
assertCacheValue(0, KEY_1, VALUE_4);
assertNoTransactions();
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testReplaceFromNonOwner(Method m) {
final String k = k(m);
final String v = v(m);
getOwners(k)[0].put(k, v);
getNonOwners(k)[0].replace(k, v(m, 1));
}
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testReplace() throws Exception {
doPutWithDisabledBlockingInterceptor();
cache("LON", 1).replace("k", "v2");
blockingInterceptor.invocationReceivedLatch.await(20000, TimeUnit.MILLISECONDS);
assertEquals("v2", cache("LON", 0).get("k"));
assertEquals("v2", cache("LON", 1).get("k"));
assertEquals("v", backup("LON").get("k"));
blockingInterceptor.waitingLatch.countDown();
eventuallyEquals("v2", () -> backup("LON").get("k"));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testActivationOnReplace(Method m) throws Exception {
assertActivationCount(0);
assert cache.get(k(m)) == null;
assertActivationCount(0);
loader.write(new MarshalledEntryImpl(k(m), v(m), null, marshaller()));
assert loader.contains(k(m));
assert cache.replace(k(m), v(m, 2)).equals(v(m));
assertActivationCount(1);
assert !loader.contains(k(m));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testDefaultLifespanReplace() {
cache().put(1, "v1");
cache().replace(1, "v11");
expectCachedThenExpired(1, "v11");
cache().getAdvancedCache().put(2, "v2", new EmbeddedMetadata.Builder().build());
cache().getAdvancedCache().replace(2, "v22", new EmbeddedMetadata.Builder().build());
expectCachedThenExpired(2, "v22");
}
内容来源于网络,如有侵权,请联系作者删除!