org.infinispan.Cache.remove()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(233)

本文整理了Java中org.infinispan.Cache.remove()方法的一些代码示例,展示了Cache.remove()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.remove()方法的具体详情如下:
包路径:org.infinispan.Cache
类名称:Cache
方法名:remove

Cache.remove介绍

暂无

代码示例

代码示例来源:origin: org.infinispan/infinispan-lucene-directory

public void clearLock() {
 Object lockOwner = noCacheStoreCache.get(keyOfLock);
 if (lockOwner == null || valueOfLock.equals(lockOwner)) {
   Object previousValue = noCacheStoreCache.remove(keyOfLock);
   log.tracef("Lock: %s removed for index: %s from %s (was %s)", lockName, indexName, valueOfLock, previousValue);
 } else {
   log.tracef("Lock: %s not cleared for index: %s from %s, was taken already by %s.", lockName,
      indexName, valueOfLock, lockOwner);
 }
}

代码示例来源:origin: org.infinispan/infinispan-core

public void update(Cache<Object, Object> cache) {
  if (this == PUT) {
   cache.put("key", "value1");
  } else {
   cache.remove("key");
  }
}

代码示例来源:origin: org.infinispan/infinispan-core

@Override
 public void run() {
   Object key = Generator.getRandomElement(keys);
   cache.get(key);
   cache.put(key, "Value");
   cache.remove(key);
 }
});

代码示例来源:origin: org.infinispan/infinispan-core

@Override
  public void call() {
   cache.put("k1", "v1");
   cache.remove("k1");
   assertEquals("cache size must be 0", 0, cache.getAdvancedCache().getDataContainer().size());
  }
});

代码示例来源:origin: org.infinispan/infinispan-core

public void testEvictAndRemove() throws PersistenceException {
 assertNotInCacheAndStore("k1", "k2");
 cache.put("k1", "v1");
 cache.put("k2", "v2", lifespan, MILLISECONDS);
 cache.evict("k1");
 cache.evict("k2");
 assertEquals("v1", cache.remove("k1"));
 assertEquals("v2", cache.remove("k2"));
}

代码示例来源:origin: org.infinispan/infinispan-compatibility-mode-it

public void testMemcachedPutEmbeddedGet() throws Exception {
 // 1. Put with Memcached
 for (int i = 0; i != numEntries; i++) {
   Future<Boolean> f = cacheFactory2.getMemcachedClient().set("k" + i, 0, "v" + i);
   assertTrue(f.get(60, TimeUnit.SECONDS));
 }
 // 2. Get with Embedded from a different node
 for (int i = 0; i != numEntries; i++) {
   assertEquals("v" + i, cacheFactory1.getEmbeddedCache().get("k" + i));
   cacheFactory1.getEmbeddedCache().remove("k" + i);
 }
}

代码示例来源:origin: org.infinispan/infinispan-query

private void testConditionalRemoveFrom(Ownership owneship) throws Exception {
 prepareTestData();
 CacheQuery<Object> query = Search.getSearchManager(cache2).getQuery(new MatchAllDocsQuery());
 Cache<Object, Person> cache = findCache(owneship, key1).orElse(cache2);
 cache.remove(key1, person1);
 assertEquals(query.list().size(), 2);
 assertEquals(countIndex(cache), 2);
 cache.remove(key1, person1);
 assertEquals(query.list().size(), 2);
 assertEquals(countIndex(cache), 2);
 cache = findCache(owneship, key3).orElse(cache2);
 cache.remove(key3);
 assertEquals(query.list().size(), 1);
 assertEquals(countIndex(cache), 1);
 StaticTestingErrorHandler.assertAllGood(cache1, cache2);
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testRemoteCacheListener() throws Exception {
 Integer age;
 RemoteListener lis = new RemoteListener();
 cache2.addListener(lis);
 try {
   cache1.put("age", 38);
   // value on cache2 must be 38
   age = (Integer) cache2.get("age");
   assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
   assertTrue("\"age\" must be 38", age == 38);
   cache1.remove("age");
 } finally {
   cache2.removeListener(lis);
 }
}

代码示例来源:origin: org.infinispan/infinispan-compatibility-mode-it

public void testEmbeddedPutIfAbsentHotRodGet() {
 final Integer key = 3;
 Cache<Integer, String> embedded = getEmbeddedCache();
 RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache();
 assertEquals(null, embedded.putIfAbsent(key, "v1"));
 assertEquals("v1", remote.get(key));
 assertEquals("v1", embedded.putIfAbsent(key, "v2"));
 assertEquals("v1", remote.get(key));
 assertEquals("v1", embedded.remove(key));
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testPutIfAbsentFromMainOwner() {
   Object k = getKeyForCache(0);
   cache(0).put(k, "0");
   cache(0).putIfAbsent(k, "1");

   assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "0");
   assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "0");

   cache(0).remove(k);

   cache(0).putIfAbsent(k, "1");
   assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "1");
   assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "1");
  }
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testPutIfAbsentAfterRemoveInTx() throws Exception {
 String key = "key_1", old_value = "old_value";
 cache.put(key, old_value);
 assertEquals(old_value, cache.get(key));
 TransactionManager tm = TestingUtil.getTransactionManager(cache);
 withTx(tm, () -> {
   assertEquals(old_value, cache.remove(key));
   assertNull(cache.get(key));
   assertEquals(cache.putIfAbsent(key, "new_value"), null);
   tm.setRollbackOnly();
   return null;
 });
 assertEquals(old_value, cache.get(key));
}

代码示例来源:origin: org.infinispan/infinispan-compatibility-mode-it

public void testEmbeddedPutHotRodGet() {
 final Integer key = 1;
 Cache<Integer, String> embedded = getEmbeddedCache();
 RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache();
 assertEquals(null, embedded.put(key, "v1"));
 assertEquals("v1", remote.get(key));
 assertEquals("v1", embedded.put(key, "v2"));
 assertEquals("v2", remote.get(key));
 assertEquals("v2", embedded.remove(key));
}

代码示例来源:origin: org.infinispan/infinispan-core

@Override
  public void call() {
   cache.put("k1", "v1");
   cache.put("k2", "v2"); // force eviction of "k1"
   eventually(() -> store.load("k1") != null);
   // simulate slow back end store
   store.lock.lock();
   try {
     cache.remove("k1");
     TestingUtil.sleepThread(100); // wait until the first AsyncProcessor thread is blocked
     cache.remove("k1"); // make second AsyncProcessor thread burn asyncProcessorIds
     TestingUtil.sleepThread(200); // wait for reaper to collect InternalNullEntry
     assert null == cache.get("k1") : "cache must return k1 == null (was: " + cache.get("k1") + ")";
   } finally {
     store.lock.unlock();
   }
  }
});

代码示例来源:origin: org.infinispan/infinispan-core

public void testRemove() throws Exception {
 doPutWithDisabledBlockingInterceptor();
 cache("LON", 1).remove("k");
 blockingInterceptor.invocationReceivedLatch.await(20000, TimeUnit.MILLISECONDS);
 assertNull(cache("LON", 0).get("k"));
 assertNull(cache("LON", 1).get("k"));
 assertEquals("v", backup("LON").get("k"));
 blockingInterceptor.waitingLatch.countDown();
 eventuallyEquals(null, () -> backup("LON").get("k"));
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testRemoveFromNonOwner() {
 initAndTest();
 Object retval = getFirstNonOwner("k1").remove("k1");
 asyncWait("k1", RemoveCommand.class);
 if (testRetVals) assertEquals("value", retval);
 assertRemovedOnAllCaches("k1");
}

代码示例来源:origin: org.infinispan/infinispan-core

@Override
  public void call() {
   cache.put("k1", "v1");
   cache.remove("k1");
   // this causes NPE in AsyncCacheWriter.isLocked(InternalNullEntry.getKey())
   cache.put("k2", "v2");
  }
});

代码示例来源:origin: org.infinispan/infinispan-embedded-query

public void clearLock() {
 Object lockOwner = noCacheStoreCache.get(keyOfLock);
 if (lockOwner == null || valueOfLock.equals(lockOwner)) {
   Object previousValue = noCacheStoreCache.remove(keyOfLock);
   log.tracef("Lock: %s removed for index: %s from %s (was %s)", lockName, indexName, valueOfLock, previousValue);
 } else {
   log.tracef("Lock: %s not cleared for index: %s from %s, was taken already by %s.", lockName,
      indexName, valueOfLock, lockOwner);
 }
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testPutIfAbsentFromMainOwner() {
   Object k = getKeyForCache(0);
   cache(0).put(k, "0");
   cache(0).putIfAbsent(k, "1");

   assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "0");
   assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "0");

   cache(0).remove(k);

   cache(0).putIfAbsent(k, "1");
   assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "1");
   assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "1");
  }
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testRepeatableReadWithNullRemoval() throws Exception {
 LockTestData tl = lockTestData;
 Cache<String, String> cache = tl.cache;
 TransactionManager tm = tl.tm;
 // start with an empty cache
 tm.begin();
 cache.get("a");
 Transaction tx = tm.suspend();
 cache.put("a", "v2");
 assertEquals(cache.get("a"), "v2");
 tm.resume(tx);
 assertEquals(null, cache.get("a"));
 cache.remove("a");
 Exceptions.expectException(RollbackException.class, tm::commit);
 assertEquals(cache.get("a"), "v2");
}

代码示例来源:origin: org.infinispan/infinispan-compatibility-mode-it

public void testEmbeddedRemoveHotRodGet() {
 final Integer key = 9;
 Cache<Integer, String> embedded = getEmbeddedCache();
 RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache();
 assertEquals(null, embedded.put(key, "v1"));
 assertEquals("v1", embedded.remove(key));
 assertEquals(null, remote.get(key));
}

相关文章