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

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

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

Cache.startBatch介绍

暂无

代码示例

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

@Override
public Result execute(Session session) {
 Cache<Object, Object> cache = session.getCache(cacheName);
 boolean b = cache.startBatch();
 return b ? EmptyResult.RESULT : new StringResult("Batch for cache already started");
}

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

@Override
public Result execute(Session session) {
 Cache<Object, Object> cache = session.getCache(cacheName);
 boolean b = cache.startBatch();
 return b ? EmptyResult.RESULT : new StringResult("Batch for cache already started");
}

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

@Override
  public <K, V, R> R invoke(Cache<K, V> cache, Operation<K, V, R> operation, Flag... flags) {
    boolean started = cache.startBatch();
    boolean success = false;
    try {
      R result = this.invoker.invoke(cache, operation, flags);
      success = true;
      return result;
    } finally {
      if (started) {
        cache.endBatch(success);
      }
    }
  }
}

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

String getOnDifferentThread(final Cache<String, String> cache, final String key) throws Exception {
 Future<String> f = fork(() -> {
   cache.startBatch();
   String v = cache.get(key);
   cache.endBatch(true);
   return v;
 });
 return f.get();
}

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

public void testStartBatchIdempotency(Method method) {
 Cache<String, String> cache = createCache(method.getName());
 cache.startBatch();
 cache.put("k", "v");
 cache.startBatch();     // again
 cache.put("k2", "v2");
 cache.endBatch(true);
 AssertJUnit.assertEquals("v", cache.get("k"));
 AssertJUnit.assertEquals("v2", cache.get("k2"));
}

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

public void testActivationPutAllInBatchRolledBack() throws Exception {
 Cache<String, String> testCache = cacheManager.getCache(CACHE_NAME);
 final String key = "X";
 final String value = "4567";
 testCache.clear();
 testCache.put(key, value);
 testCache.evict(key);
 // Now make sure the act of activation for the entry is not tied to the transaction
 testCache.startBatch();
 testCache.putAll(Collections.singletonMap(key, value + "-putall"));
 testCache.endBatch(false);
 // The data should still be present even if a rollback occurred
 assertEquals(value, testCache.get(key));
}

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

public void testActivationWithAnotherConcurrentRequest() throws Exception {
 final Cache<String, String> testCache = cacheManager.getCache(CACHE_NAME);
 final String key = "Y";
 final String value = "4568";
 testCache.clear();
 testCache.put(key, value);
 testCache.evict(key);
 // Now make sure the act of activation for the entry is not tied to the transaction
 testCache.startBatch();
 assertEquals(value, testCache.get(key));
 // Another thread should be able to see the data as well!
 Future<String> future = testCache.getAsync(key);
 assertEquals(value, future.get(10, TimeUnit.SECONDS));
 assertEquals(value, testCache.get(key));
 testCache.endBatch(true);
 // Lastly try the retrieval after batch was committed
 assertEquals(value, testCache.get(key));
}

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

public void testActivationInBatchRolledBack() {
 Cache<String, String> testCache = cacheManager.getCache(CACHE_NAME);
 final String key = "X";
 final String value = "4567";
 testCache.clear();
 testCache.put(key, value);
 testCache.evict(key);
 // Now make sure the act of activation for the entry is not tied to the transaction
 testCache.startBatch();
 assertEquals(value, testCache.get(key));
 testCache.endBatch(false);
 // The data should still be present even if a rollback occurred
 assertEquals(value, testCache.get(key));
}

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

public void testLockWithBatchingRollback() {
 cache.startBatch();
 cache.getAdvancedCache().lock("k");
 assertTrue(lockManager().isLocked("k"));
 cache().endBatch(false);
 assertFalse(lockManager().isLocked("k"));
}

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

public void testLockWithBatchingCommit() {
 cache.startBatch();
 cache.getAdvancedCache().lock("k");
 assertTrue(lockManager().isLocked("k"));
 cache().endBatch(true);
 assertFalse(lockManager().isLocked("k"));
}

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

public void testExpectedEnlistmentMode() {
 TransactionManager tm = cache.getAdvancedCache().getTransactionManager();
 assert tm instanceof BatchModeTransactionManager;
 TransactionTable tt = TestingUtil.getTransactionTable(cache);
 assertEquals(tt.getClass(), TransactionTable.class);
 BatchContainer bc = TestingUtil.extractComponent(cache, BatchContainer.class);
 cache.startBatch();
 cache.put("k", "v");
 assert getBatchTx(bc).getEnlistedSynchronization().size() == 1;
 assert getBatchTx(bc).getEnlistedResources().size() == 0;
 cache.endBatch(true);
 assert getBatchTx(bc) == null;
}

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

public void testBatchVisibility(Method method) throws Exception {
 Cache<String, String> cache = createCache(method.getName());
 cache.startBatch();
 cache.put("k", "v");
 assertNull("Other thread should not see batch update till batch completes!", getOnDifferentThread(cache, "k"));
 cache.endBatch(true);
 AssertJUnit.assertEquals("v", getOnDifferentThread(cache, "k"));
}

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

public void testBatchWithOngoingTM(Method method) throws Exception {
 Cache<String, String> cache = createCache(method.getName());
 TransactionManager tm = getTransactionManager(cache);
 assertEquals(MyDummyTransactionManager.class, tm.getClass());
 tm.begin();
 cache.put("k", "v");
 cache.startBatch();
 cache.put("k2", "v2");
 tm.commit();
 assertEquals("v", cache.get("k"));
 assertEquals("v2", cache.get("k2"));
 cache.endBatch(false); // should be a no op
 assertEquals("v", cache.get("k"));
 assertEquals("v2", cache.get("k2"));
}

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

public void testClearInBatch(Method method) {
 //tests if the clear 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.put("k2", "v2");
 cache.startBatch();
 cache.clear();
 cache.put("k1", "v1");
 cache.endBatch(true);
 assertEquals(null, cache.get("k2"));
 assertEquals("v1", cache.get("k1"));
}

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

public void testBatchWithOngoingTM(Method method) throws Exception {
 Cache<String, String> cache = createCache(method.getName());
 TransactionManager tm = getTransactionManager(cache);
 assertNoTransaction(tm);
 tm.begin();
 cache.put("k", "v");
 cache.startBatch();
 cache.put("k2", "v2");
 tm.commit();
 assertEquals("v", cache.get("k"));
 assertEquals("v2", cache.get("k2"));
 cache.endBatch(false); // should be a no op
 assertEquals("v", cache.get("k"));
 assertEquals("v2", cache.get("k2"));
}

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

public void testBatchRollback(Method method) throws Exception {
 Cache<String, String> cache = createCache(method.getName());
 cache.startBatch();
 cache.put("k", "v");
 cache.put("k2", "v2");
 assertNull(getOnDifferentThread(cache, "k"));
 assertNull(getOnDifferentThread(cache, "k2"));
 cache.endBatch(false);
 assertNull(getOnDifferentThread(cache, "k"));
 assertNull(getOnDifferentThread(cache, "k2"));
}

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

public void testBatchRollback(Method method) throws Exception {
 Cache<String, String> cache = createCache(method.getName());
 cache.startBatch();
 cache.put("k", "v");
 cache.put("k2", "v2");
 assertNull(getOnDifferentThread(cache, "k"));
 assertNull(getOnDifferentThread(cache, "k2"));
 cache.endBatch(false);
 assertNull(getOnDifferentThread(cache, "k"));
 assertNull(getOnDifferentThread(cache, "k2"));
}

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

public void testBatchRollback(Method method) throws Exception {
 Cache<String, String> cache = createCache(method.getName());
 cache.startBatch();
 cache.put("k", "v");
 cache.put("k2", "v2");
 assertNull(getOnDifferentThread(cache, "k"));
 assertNull(getOnDifferentThread(cache, "k2"));
 cache.endBatch(false);
 assertNull(getOnDifferentThread(cache, "k"));
 assertNull(getOnDifferentThread(cache, "k2"));
}

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

public void testSkipLookupOnGetWhileBatching() {
   MagicKey k1 = new MagicKey(c1, c2);
   c1.put(k1, "batchingMagicValue-h1");

   assertIsInContainerImmortal(c1, k1);
   assertIsInContainerImmortal(c2, k1);
   assertIsNotInL1(c3, k1);
   assertIsNotInL1(c4, k1);

   c4.startBatch();
   assert c4.getAdvancedCache().withFlags(SKIP_REMOTE_LOOKUP).get(k1) == null;
   c4.endBatch(true);

   assertOwnershipAndNonOwnership(k1, false);
  }
}

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

public void testBatchWithoutOngoingTMSuspension(Method method) throws Exception {
 Cache<String, String> cache = createCache(method.getName());
 TransactionManager tm = getTransactionManager(cache);
 assertNoTransaction(tm);
 cache.startBatch();
 cache.put("k", "v");
 assertNoTransaction(tm);
 cache.put("k2", "v2");
 assertNull(getOnDifferentThread(cache, "k"));
 assertNull(getOnDifferentThread(cache, "k2"));
 expectException(IllegalStateException.class, tm::commit);
 assertNoTransaction(tm);
 assertNull(getOnDifferentThread(cache, "k"));
 assertNull(getOnDifferentThread(cache, "k2"));
 cache.endBatch(true);
 assertEquals("v", getOnDifferentThread(cache, "k"));
 assertEquals("v2", getOnDifferentThread(cache, "k2"));
}

相关文章