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

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

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

Cache.putIfAbsentAsync介绍

暂无

代码示例

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

@Override
public <K> Future<?> perform(Cache<K, Object> cache, K key) {
 return cache.putIfAbsentAsync(key, "v1");
}

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

@Override
public <K> Future<?> perform(Cache<K, Object> cache, K key) {
 return cache.putIfAbsentAsync(key, finalValue());
}

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

public void testPutIfAbsentAsync() throws Exception {
 CompletableFuture<String> f = c.putIfAbsentAsync("k", "v1");
 assertFutureResult(f, null);
 assertEquals("v1", c.get("k"));
 f = c.putIfAbsentAsync("k", "v2");
 assertFutureResult(f, "v1");
 assertEquals("v1", c.get("k"));
}

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

final Future f1 = c1.putIfAbsentAsync(key, v4);
assert f1 != null;
eventually(f1::isDone);
final Future f4 = c1.putIfAbsentAsync(key, v4);
assert f4 != null;
eventually(f4::isDone);

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

public void testPutIfAbsentAsyncWithLifespanAndMaxIdle() throws Exception {
 // putIfAbsent lifespan only
 c.put("k", "v1");
 CompletableFuture<String> f = c.putIfAbsentAsync("k", "v2", 1000, TimeUnit.MILLISECONDS);
 markStartTime();
 assertFutureResult(f, "v1");
 assertEquals("v1", c.get("k"));
 Thread.sleep(300);
 assertEquals("v1", c.get("k"));
 assertEquals("v1", c.remove("k"));
 assertNull(c.get("k"));
 // now really put (k removed) lifespan only
 f = c.putIfAbsentAsync("k", "v", 1000, TimeUnit.MILLISECONDS);
 markStartTime();
 assertFutureResult(f, null);
 verifyEviction("k", "v", 1000, 500, true);
 // putIfAbsent lifespan and max idle (test max idle)
 f = c.putIfAbsentAsync("k", "v", 3000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
 markStartTime();
 assertFutureResult(f, null);
 verifyEviction("k", "v", 1000, 500, false);
 // putIfAbsent lifespan and max idle (test lifespan)
 f = c.putIfAbsentAsync("k", "v", 3000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
 markStartTime();
 assertFutureResult(f, null);
 verifyEviction("k", "v", 3000, 500, true);
}

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

public void testPutIfAbsentAsync() throws Exception {
 prepareTestData();
 SearchManager searchManager = Search.getSearchManager(cache2);
 QueryBuilder queryBuilder = searchManager
    .buildQueryBuilderForClass(Person.class)
    .get();
 Query allQuery = queryBuilder.all().createQuery();
 assertEquals(3, searchManager.getQuery(allQuery, Person.class).list().size());
 person4 = new Person();
 person4.setName("New Goat");
 person4.setBlurb("Also eats grass");
 Future futureTask = cache2.putIfAbsentAsync("newGoat", person4);
 futureTask.get();
 assertTrue(futureTask.isDone());
 List<Person> found = searchManager.<Person>getQuery(allQuery, Person.class).list();
 assertEquals(4, found.size());
 assertTrue(found.contains(person4));
 Person person5 = new Person();
 person5.setName("Abnormal Goat");
 person5.setBlurb("Plays with grass.");
 futureTask = cache2.putIfAbsentAsync("newGoat", person5);
 futureTask.get();
 assertTrue(futureTask.isDone());
 found = searchManager.<Person>getQuery(allQuery, Person.class).list();
 assertEquals(4, found.size());
 assertFalse(found.contains(person5));
 assertTrue(found.contains(person4));
 StaticTestingErrorHandler.assertAllGood(cache1, cache2);
}

相关文章