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

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

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

Cache.putForExternalRead介绍

暂无

代码示例

代码示例来源:origin: org.keycloak/keycloak-invalidation-cache-infinispan

@Override
public void addCachedGroup(CachedGroup role) {
  if (!enabled) return;
  logger.tracev("Adding group {0}", role.getId());
  cache.putForExternalRead(role.getId(), role);
}

代码示例来源:origin: org.keycloak/keycloak-invalidation-cache-infinispan

@Override
public void addCachedUser(String realmId, CachedUser user) {
  logger.tracev("Adding user {0}", user.getId());
  cache.putForExternalRead(user.getId(), user);
}

代码示例来源:origin: org.keycloak/keycloak-invalidation-cache-infinispan

@Override
public void addCachedClientTemplate(CachedClientTemplate app) {
  if (!enabled) return;
  logger.tracev("Adding client template {0}", app.getId());
  cache.putForExternalRead(app.getId(), app);
}

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

public void testPferNoAutoCommit() throws Exception {
 cache.putForExternalRead("k2","v");
 assert cache.get("k2").equals("v"); //here is the failure!
}

代码示例来源:origin: org.keycloak/keycloak-invalidation-cache-infinispan

@Override
public void addCachedClient(CachedClient app) {
  if (!enabled) return;
  logger.tracev("Adding application {0}", app.getId());
  cache.putForExternalRead(app.getId(), app);
}

代码示例来源:origin: org.keycloak/keycloak-invalidation-cache-infinispan

@Override
public void addCachedRole(CachedRole role) {
  if (!enabled) return;
  logger.tracev("Adding role {0}", role.getId());
  cache.putForExternalRead(role.getId(), role);
}

代码示例来源:origin: org.keycloak/keycloak-invalidation-cache-infinispan

@Override
public void addCachedRealm(CachedRealm realm) {
  if (!enabled) return;
  logger.tracev("Adding realm {0}", realm.getId());
  cache.putForExternalRead(realm.getId(), realm);
  realmLookup.put(realm.getName(), realm.getId());
}

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

public void testStoresPutForExternalRead() throws Exception {
 assertStores(0);
 cache.putForExternalRead("key", "value");
 assertStores(1);
 cache.putForExternalRead("key", "value");
 assertStores(1);
}

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

public void testPferNoAutoCommitExplicitTransaction() throws Exception {
 tm().begin();
 cache.putForExternalRead("k1","v");
 tm().commit();
 assert cache.get("k1").equals("v"); //here is the failure!
}

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

public void testReadOwnWrites() {
 Cache<Integer, String> c0 = cache(0);
 Cache<Integer, String> c1 = cache(1);
 c0.putForExternalRead(1, "v1");
 assertEquals("v1", c0.get(1));
 c1.putForExternalRead(1, "v1");
 assertEquals("v1", c1.get(1));
}

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

public void testMultipleIdenticalPutForExternalReadCalls() {
 final Cache<String, String> cache1 = cache(0, CACHE_NAME);
 final Cache<String, String> cache2 = cache(1, CACHE_NAME);
 cache1.putForExternalRead(key, value);
 // wait for command the finish executing asynchronously
 eventually(() -> cache1.containsKey(key) && cache2.containsKey(key));
 cache1.putForExternalRead(key, value2);
 assertEquals(value, cache1.get(key));
}

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

public void testNoOpWhenKeyPresent() {
 final Cache<String, String> cache1 = cache(0, CACHE_NAME);
 final Cache<String, String> cache2 = cache(1, CACHE_NAME);
 cache1.putForExternalRead(key, value);
 eventually(() -> value.equals(cache1.get(key)) && value.equals(cache2.get(key)));
 // reset
 cache1.remove(key);
 eventually(() -> cache1.isEmpty() && cache2.isEmpty());
 cache1.put(key, value);
 eventually(() -> value.equals(cache1.get(key)) && value.equals(cache2.get(key)));
 // now this pfer should be a no-op
 cache1.putForExternalRead(key, value2);
 assertEquals("PFER should have been a no-op", value, cache1.get(key));
 assertEquals("PFER should have been a no-op", value, cache2.get(key));
}

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

@InTransactionMode(TransactionMode.TRANSACTIONAL)
public void testTxSuspension() throws Exception {
 final Cache<String, String> cache1 = cache(0, CACHE_NAME);
 final Cache<String, String> cache2 = cache(1, CACHE_NAME);
 cache1.put(key + "0", value);
 eventually(() -> value.equals(cache2.get(key+"0")));
 // start a tx and do some stuff.
 tm(0, CACHE_NAME).begin();
 cache1.get(key + "0");
 cache1.putForExternalRead(key, value); // should have happened in a separate tx and have committed already.
 Transaction t = tm(0, CACHE_NAME).suspend();
 eventually(() -> value.equals(cache1.get(key)) && value.equals(cache2.get(key)));
 tm(0, CACHE_NAME).resume(t);
 tm(0, CACHE_NAME).commit();
 eventually(() -> value.equals(cache1.get(key + "0")) && value.equals(cache2.get(key + "0")));
}

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

private void doTest(boolean owner) {
   final Cache<MagicKey, String> cache1 = cache(0);
   final Cache<MagicKey, String> cache2 = cache(1);
   final MagicKey magicKey = new MagicKey(cache1);

   if (owner) {
     cache1.putForExternalRead(magicKey, VALUE);
   } else {
     cache2.putForExternalRead(magicKey, VALUE);
   }

   eventually(new Condition() {
     @Override
     public boolean isSatisfied() throws Exception {
      return cache1.containsKey(magicKey) && cache2.containsKey(magicKey);
     }
   });
   assertEquals(VALUE, cache1.get(magicKey));
   assertEquals(VALUE, cache2.get(magicKey));
   assertNotLocked(magicKey);
  }
}

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

public void testPutIfAbsentLockCleanup() {
 assertNoLocks(cache);
 cache.put("key", "value");
 assertNoLocks(cache);
 // This call should fail.
 cache.putForExternalRead("key", "value2");
 assertNoLocks(cache);
 assertEquals("value", cache.get("key"));
}

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

public void testDefaultLifespanPutForExternalRead() {
 cache().putForExternalRead(1, "v1");
 expectCachedThenExpired(1, "v1");
 cache().getAdvancedCache().putForExternalRead(2, "v2", new EmbeddedMetadata.Builder().build());
 expectCachedThenExpired(2, "v2");
}

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

public void testPutForExternalReadInBatch(Method method) {
 //tests if the putForExternalRead doesn't leak the batch transaction.
 //if it does, the get() will be executed against a committed transaction and it will fail.
 Cache<String, String> cache = createCache(method.getName());
 cache.startBatch();
 cache.putForExternalRead("k1", "v1");
 cache.put("k2", "v2");
 cache.endBatch(true);
 assertEquals("v1", cache.get("k1"));
 assertEquals("v2", cache.get("k2"));
 cache.startBatch();
 cache.putForExternalRead("k3", "v3");
 cache.put("k1", "v2");
 cache.endBatch(false);
 assertEquals("v1", cache.get("k1"));
 assertEquals("v2", cache.get("k2"));
 assertEquals("v3", cache.get("k3"));
}

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

public void testPutForExternalRead() 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");
 cache2.putForExternalRead("newGoat", person4);
 eventually(() -> cache2.get("newGoat") != null);
 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.");
 cache2.putForExternalRead("newGoat", person5);
 found = searchManager.<Person>getQuery(allQuery, Person.class).list();
 assertEquals(4, found.size());
 assertFalse(found.contains(person5));
 assertTrue(found.contains(person4));
 StaticTestingErrorHandler.assertAllGood(cache1, cache2);
}

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

public void testInvalidationDuringStateTransfer() throws Exception {
 EmbeddedCacheManager node1 = manager(0);
 Cache<String, Object> node1Cache = node1.getCache();
 EmbeddedCacheManager node2 = manager(1);
 Cache<String, Object> node2Cache = node2.getCache();
 CountDownLatch latch = new CountDownLatch(1);
 node2Cache.getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new BaseCustomAsyncInterceptor() {
   @Override
   public Object visitInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws
      Throwable {
    latch.await(10, TimeUnit.SECONDS);
    return super.visitInvalidateCommand(ctx, command);
   }
 }, 0);
 String key = "key";
 Future<?> future = fork(() -> {
   node1Cache.putForExternalRead(key, new Object());
   node1Cache.remove(key);
 });
 EmbeddedCacheManager node3 = addClusterEnabledCacheManager(dccc);
 Cache<Object, Object> node3Cache = node3.getCache();
 TestingUtil.waitForNoRebalance(caches());
 log.info("Node 3 started");
 latch.countDown();
 future.get(30, TimeUnit.SECONDS);
 assertNull(node1Cache.get(key));
 assertNull(node2Cache.get(key));
 assertNull(node3Cache.get(key));
}

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

public void testBasicPropagation() throws Exception {
 final Cache<String, String> cache1 = cache(0, CACHE_NAME);
 final Cache<String, String> cache2 = cache(1, CACHE_NAME);
 assertFalse(cache1.containsKey(key));
 assertFalse(cache2.containsKey(key));
 ReplListener replListener2 = replListener(cache2);
 replListener2.expect(PutKeyValueCommand.class);
 cache1.putForExternalRead(key, value);
 replListener2.waitForRpc();
 // wait for command the finish executing asynchronously
 eventually(() -> cache1.containsKey(key) && cache2.containsKey(key));
 assertEquals("PFER updated cache1", value, cache1.get(key));
 assertEquals("PFER propagated to cache2 as expected", value, cache2.get(key));
 // replication to cache 1 should NOT happen.
 cache2.putForExternalRead(key, value + "0");
 assertEquals("PFER updated cache2", value, cache2.get(key));
 assertEquals("Cache1 should be unaffected", value, cache1.get(key));
}

相关文章