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

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

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

Cache.put介绍

暂无

代码示例

代码示例来源:origin: brianfrankcooper/YCSB

public Status update(String table, String key, Map<String, ByteIterator> values) {
 try {
  if (clustered) {
   AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key);
   StringByteIterator.putAllAsStrings(row, values);
  } else {
   Cache<String, Map<String, String>> cache = infinispanManager.getCache(table);
   Map<String, String> row = cache.get(key);
   if (row == null) {
    row = StringByteIterator.getStringMap(values);
    cache.put(key, row);
   } else {
    StringByteIterator.putAllAsStrings(row, values);
   }
  }
  return Status.OK;
 } catch (Exception e) {
  LOGGER.error(e);
  return Status.ERROR;
 }
}

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

/** Checks that multiple modifications compare the initial value and the write skew does not fire */
public void testNoWriteSkewWithMultipleModifications() throws Exception {
 cache.put("k1", "init");
 tm.begin();
 assertEquals("init", cache.get("k1"));
 cache.put("k1", "v2");
 cache.put("k2", "v3");
 commit();
}

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

@Override
 public String call() throws Exception {
   TransactionManager mgr = TestingUtil.getTransactionManager(nonOwner);
   mgr.begin();
   try {
    return owner.put(key, otherValue);
   } finally {
    mgr.commit();
   }
 }
});

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

public void testObjCollect() {
 Cache<Integer, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
 List<Map.Entry<Integer, String>> list = createStream(entrySet).collect(ArrayList::new,
    ArrayList::add, ArrayList::addAll);
 assertEquals(cache.size(), list.size());
 list.parallelStream().forEach(e -> assertEquals(cache.get(e.getKey()), e.getValue()));
}

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

@Override
  public void call() {
   List<AsyncInterceptor> interceptors =
      cacheManager.getCache().getAdvancedCache().getAsyncInterceptorChain()
            .getInterceptors();
   Object o = interceptors.get(interceptors.size() - 2);
   assertEquals(FooInterceptor.class, o.getClass());
   assertFalse(interceptor.putInvoked);
   cacheManager.getCache().put("k", "v");
   assertEquals("v", cacheManager.getCache().get("k"));
   assertTrue(interceptor.putInvoked);
  }
});

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

public void testReplaceAll() {
 BiFunction<Object, Object, String> mappingFunction = (k, v) -> "hello_" + k + ":" + v;
 cache.put("es", "hola");
 cache.put("cz", "ahoj");
 cache.replaceAll(mappingFunction);
 assertEquals("hello_es:hola", cache.get("es"));
 assertEquals("hello_cz:ahoj", cache.get("cz"));
 BiFunction<Object, Object, String> mappingToNull = (k, v) -> null;
 expectException(NullPointerException.class, () -> cache.replaceAll(mappingToNull));
 assertEquals("hello_es:hola", cache.get("es"));
 assertEquals("hello_cz:ahoj", cache.get("cz"));
}

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

public void testTxCommit1() throws Exception {
 TransactionManager tm = TestingUtil.getTransactionManager(cache);
 tm.begin();
 cache.put("key", "value");
 Transaction t = tm.suspend();
 assertTrue(cache.isEmpty());
 tm.resume(t);
 tm.commit();
 assertFalse(cache.isEmpty());
}

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

public void testRollbackSpanningCaches2() throws Exception {
 startAllCaches();
 Cache<String, String> c1 = cache(0, "c1");
 assertTrue(c1.getCacheConfiguration().clustering().cacheMode().isClustered());
 Cache<String, String> c1Replica = cache(1, "c1");
 assertTrue(c1.isEmpty());
 assertTrue(c1Replica.isEmpty());
 c1.put("c1key", "c1value");
 assertEquals(c1.get("c1key"), "c1value");
 assertEquals(c1Replica.get("c1key"), "c1value");
}

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

public void testSilentMultiLockFailure() throws Exception {
 Cache<String, String> cache1 = cache(0), cache2 = cache(1);
 cache1.put("k1", "v");
 cache1.put("k2", "v");
 cache1.put("k3", "v");
 tm(1).begin();
 cache2.put("k3", "v2");
 tm(1).suspend();
 tm(0).begin();
 assert !cache1.getAdvancedCache().withFlags(FAIL_SILENTLY).lock(Arrays.asList("k1", "k2", "k3"));
 tm(0).rollback();
}

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

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

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

public void testCorrectFunctionalityOnUnconditionalWrite() {
 MagicKey k1 = getMagicKey();
 c1.put(k1, "value");
 assertIsInContainerImmortal(c1, k1);
 assertIsInContainerImmortal(c2, k1);
 assertIsNotInL1(c3, k1);
 assertIsNotInL1(c4, k1);
 assertNull(c4.getAdvancedCache().withFlags(SKIP_REMOTE_LOOKUP).put(k1, "new_val"));
 assertEquals(c3.get(k1), "new_val");
 assertOnAllCachesAndOwnership(k1, "new_val");
}

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

public void testEvictAndTx() throws SystemException, NotSupportedException, RollbackException, HeuristicRollbackException, HeuristicMixedException {
 for (int i=0; i<10; i++) {
   tm.begin();
   for (int j=0; j<10; j++) cache.put(String.format("key-%s-%s", i, j), "value");
   tm.commit();
   for (int j=0; j<10; j++) assert "value".equals(cache.get(String.format("key-%s-%s", i, j))) : "Data loss on key " + String.format("key-%s-%s", i, j);
 }
}

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

public void testObjReduce3() {
 Cache<Integer, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
 // This isn't the best usage of this, but should be a usable example
 Integer result = createStream(entrySet).reduce(0, (e1, e2) -> e1 + e2.getKey(), (i1, i2) -> i1 + i2);
 assertEquals((range - 1) * (range / 2), result.intValue());
}

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

public void testLockedStreamSetValue() {
 for (int i = 0; i < 5; i++) {
   cache.put(i, "value" + i);
 }
 cache.getAdvancedCache().lockedStream().forEach((c, e) -> e.setValue(e.getValue() + "-changed"));
 for (int i = 0; i < 5; i++) {
   assertEquals("value" + i + "-changed", cache.get(i));
 }
}

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

public void testRemoteCommit() throws Exception {
 assertCommitRollback(0, 0, txInterceptor2);
 tm.begin();
 assertCommitRollback(0, 0, txInterceptor2);
 //enlist another resource adapter to force TM to execute 2PC (otherwise 1PC)
 tm.getTransaction().enlistResource(new XAResourceAdapter());
 cache2.put("key", "value");
 assertCommitRollback(0, 0, txInterceptor2);
 tm.commit();
 assertCommitRollback(1, 0, txInterceptor2);
}

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

private void initAndCheck(Method m) {
 cache(0).put(key, m.getName());
 assertEquals(m.getName(), cache(1).get(key));
 assertEquals(m.getName(), cache(2).get(key));
}

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

public void testGetCacheEntryNonOwner() {
 byte[] key = {1, 2, 3};
 Cache<byte[], byte[]> owner = getFirstOwner(key, this.<byte[], byte[]>caches());
 Cache<byte[], byte[]> nonOwner = getFirstNonOwner(key, this.<byte[], byte[]>caches());
 owner.put(key, new byte[]{4, 5, 6});
 assertArrayEquals(new byte[]{4, 5, 6}, owner.get(key));
 CacheEntry cacheEntry = nonOwner.getAdvancedCache().getCacheEntry(key);
 assertNotNull(cacheEntry);
 assertArrayEquals(new byte[]{4, 5, 6}, (byte[]) cacheEntry.getValue());
}

代码示例来源:origin: resteasy/Resteasy

@SuppressWarnings("unchecked")
public Entry add(String uri, MediaType mediaType, CacheControl cc, MultivaluedMap<String, Object> headers, byte[] entity, String etag, MultivaluedMap<String, String> varyHeaders)
{
 // there's a race condition here with a concurrent get() method above.  Too bad JBoss Cache doesn't have a way to create
 // a node before hand then insert it
 CacheEntry cacheEntry = new CacheEntry(headers, entity, cc.getMaxAge(), etag, mediaType, varyHeaders);
 StringBuffer varyHeadersString = new StringBuffer();
 varyHeaders.forEach((name, values) -> values.forEach(value -> varyHeadersString.append(name).append(value)));
 String entryName = uri + "    " + mediaType.toString() + "    " + varyHeadersString.toString();
 Set<String> entries = (Set<String>)cache.get(uri);
 Set<String> newEntries = new HashSet<String>();
 newEntries.add(entryName);
 if (entries != null)
 {
   newEntries.addAll(entries);
 }
 cache.put(uri, newEntries);
 cache.put(entryName, cacheEntry, cc.getMaxAge(), TimeUnit.SECONDS);
 return cacheEntry;
}

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

public void simpleReplicationTest() throws Exception {
 TransactionManager tm = TestingUtil.getTransactionManager(cache1);
 tm.begin();
 cache1.put("key", "value");
 tm.commit();
 assertEquals("value", cache2.get("key"));
}

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

public void testObjCollectorGroupBy() {
 Cache<Integer, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
 ConcurrentMap<Boolean, List<Map.Entry<Integer, String>>> grouped = createStream(entrySet).collect(
       () -> Collectors.groupingByConcurrent(k -> k.getKey() % 2 == 0));
 grouped.get(true).parallelStream().forEach(e -> assertTrue(e.getKey() % 2 == 0));
 grouped.get(false).parallelStream().forEach(e -> assertTrue(e.getKey() % 2 == 1));
}

相关文章