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

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

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

Cache.putAllAsync介绍

暂无

代码示例

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

@Override
public <K> Future<?> perform(Cache<K, Object> cache, K key) {
 Map<K, Object> map = new HashMap<>();
 map.put(key, finalValue());
 return cache.putAllAsync(map);
}

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

public void testAsyncOps() throws Exception {

   CompletableFuture<Object> result = cache.putAsync("k", "v");
   assert result.get() == null;

   result = cache.removeAsync("k");
   assert result.get().equals("v");

   final CompletableFuture<Void> voidNotifyingFuture = cache.putAllAsync(Collections.singletonMap("k", "v"));
   voidNotifyingFuture.get();

   assert cache.get("k").equals("v");
  }
}

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

public void testPutAllAsyncSingleKeyValue() throws Exception {
 CompletableFuture<Void> f = c.putAllAsync(Collections.singletonMap("k", "v"));
 assertFutureResult(f, null);
 assertEquals("v", c.get("k"));
}

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

public void testPutAllAsyncMultipleKeyValue() throws Exception {
 Map<String, String> map = new HashMap<>();
 map.put("one-key", "one");
 map.put("two-key", "two");
 CompletableFuture<Void> putAllF = c.putAllAsync(map);
 assertFutureResult(putAllF, null);
 assertEquals("one", c.get("one-key"));
 assertEquals("two", c.get("two-key"));
}

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

public void testPutAllAsyncWithLifespanAndMaxIdle() throws Exception {
 // putAll lifespan only
 Future<Void> f = c.putAllAsync(Collections.singletonMap("k", "v1"), 1000, TimeUnit.MILLISECONDS);
 markStartTime();
 assertFutureResult(f, null);
 verifyEviction("k", "v1", 1000, 500, true);
 // putAll lifespan and max idle (test max idle)
 f = c.putAllAsync(Collections.singletonMap("k", "v2"), 3000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
 markStartTime();
 assertFutureResult(f, null);
 verifyEviction("k", "v2", 1000, 500, false);
 // putAll lifespan and max idle (test lifespan)
 f = c.putAllAsync(Collections.singletonMap("k", "v3"), 3000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
 markStartTime();
 assertFutureResult(f, null);
 verifyEviction("k", "v3", 3000, 500, true);
}

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

public void testAsyncOverwriteNotIndexedValue() throws Exception {
 final long id = 10;
 cache.put(id, new NotIndexedType("name1"));
 Map<Object, Object> map = new HashMap<>();
 map.put(id, new TestEntity("name2", "surname2", id, "note"));
 Future futureTask = cache.putAllAsync(map);
 futureTask.get();
 assertTrue(futureTask.isDone());
 CacheQuery<?> q1 = queryByNameField("name2", AnotherTestEntity.class);
 assertEquals(1, q1.getResultSize());
 assertEquals(TestEntity.class, q1.list().get(0).getClass());
 StaticTestingErrorHandler.assertAllGood(cache);
}

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

public void testPutMapAsync() throws Exception {
 prepareTestData();
 SearchManager searchManager = Search.getSearchManager(cache2);
 QueryBuilder queryBuilder = searchManager
    .buildQueryBuilderForClass(Person.class)
    .get();
 Query allQuery = queryBuilder.all().createQuery();
 assert searchManager.getQuery(allQuery, Person.class).list().size() == 3;
 person4 = new Person();
 person4.setName("New Goat");
 person4.setBlurb("Also eats grass");
 Map<String, Person> allWrites = new HashMap<>();
 allWrites.put(key1, person1);
 allWrites.put(key2, person2);
 allWrites.put(key3, person3);
 allWrites.put("newGoat", person4);
 Future futureTask = cache2.putAllAsync(allWrites);
 futureTask.get();
 assert futureTask.isDone();
 List<Person> found = searchManager.<Person>getQuery(allQuery, Person.class).list();
 assertEquals(4, found.size());
 assert found.contains(person4);
 futureTask = cache1.putAllAsync(allWrites);
 futureTask.get();
 assert futureTask.isDone();
 found = searchManager.<Person>getQuery(allQuery, Person.class).list();
 assertEquals(4, found.size());
 assert found.contains(person4);
 StaticTestingErrorHandler.assertAllGood(cache1, cache2);
}

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

public void testAsyncOverwriteWithNonIndexedValue() throws Exception {
 final long id = 10;
 cache.put(id, new TestEntity("name1", "surname1", id, "note"));
 CacheQuery<?> q1 = queryByNameField("name1", TestEntity.class);
 assertEquals(1, q1.getResultSize());
 assertEquals(TestEntity.class, q1.list().get(0).getClass());
 Map<Object, Object> map = new HashMap<>();
 map.put(id, new NotIndexedType("name2"));
 Future futureTask = cache.putAllAsync(map);
 futureTask.get();
 assertTrue(futureTask.isDone());
 CacheQuery<?> q2 = queryByNameField("name1", TestEntity.class);
 assertEquals(0, q2.getResultSize());
 CacheQuery<?> q3 = queryByNameField("name2", TestEntity.class);
 assertEquals(0, q3.getResultSize());
 StaticTestingErrorHandler.assertAllGood(cache);
}

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

final Future<Void> f2 = c1.putAllAsync(Collections.singletonMap(key, v3));
assert f2 != null;
eventually(f2::isDone);

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

private void testPutMapCommand(boolean sync, boolean putOnPrimary) throws Exception {
   MagicKey key = new MagicKey("key", cache(0));

   if (sync) {
     cache(putOnPrimary ? 0 : 1).putAll(Collections.singletonMap(key, "value"));
   } else {
     Future<Void> f = cache(putOnPrimary ? 0 : 1).putAllAsync(Collections.singletonMap(key, "value"));
     assertNotNull(f);
     assertNull(f.get());
     assertTrue(f.isDone());
     assertFalse(f.isCancelled());
   }

   if (cacheMode.isScattered()) {
     int hasValue = 0;
     for (Cache c : caches()) {
      Object value = c.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.SKIP_OWNERSHIP_CHECK).get(key);
      if ("value".equals(value)) {
        hasValue++;
      } else assertNull(value);
     }
     assertEquals(2, hasValue);
   } else {
     assertEquals("value", cache(0).getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP).get(key));
     assertEquals("value", cache(1).getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP).get(key));
     assertEquals("value", cache(2).getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP).get(key));
   }
  }
}

相关文章