private void doAfterCompletionFailTest(Collection<RegisterTransaction> registerTransactionCollection) throws Exception { EmbeddedTransactionManager transactionManager = EmbeddedTransactionManager.getInstance(); transactionManager.begin(); for (RegisterTransaction registerTransaction : registerTransactionCollection) { registerTransaction.register(transactionManager); } transactionManager.commit(); assertData(); assertNoTxInAllCaches(); assertNull(transactionManager.getTransaction()); }
private void checkNewTransactionFails(Object key) throws NotSupportedException, SystemException, HeuristicMixedException, HeuristicRollbackException { EmbeddedTransactionManager otherTM = embeddedTm(OTHER_INDEX); otherTM.begin(); otherCache.put(key, "should fail"); try { otherTM.commit(); fail("RollbackException should have been thrown here."); } catch (RollbackException e) { //expected } }
public static EmbeddedTransaction beginAndSuspendTx(Cache cache, Object key) { EmbeddedTransactionManager dummyTm = (EmbeddedTransactionManager) TestingUtil.getTransactionManager(cache); try { dummyTm.begin(); cache.put(key, "v"); return (EmbeddedTransaction) dummyTm.suspend(); } catch (Exception e) { throw new RuntimeException(e); } } }
public void testConcurrentWriters() throws Exception { LockTestData tl = lockTestData; Cache<String, String> cache = tl.cache; EmbeddedTransactionManager tm = tl.tm; tm.begin(); cache.put("k", "v"); final EmbeddedTransaction transaction = tm.getTransaction(); assertTrue(transaction.runPrepare()); tm.suspend(); tm.begin(); cache.put("k", "v"); assert !tm.getTransaction().runPrepare(); tm.rollback(); tm.resume(transaction); transaction.runCommit(false); assertNoLocks(); }
private void doRollbackWithHeuristicExceptionTest(Collection<RegisterTransaction> registerTransactionCollection) throws Exception { EmbeddedTransactionManager transactionManager = EmbeddedTransactionManager.getInstance(); transactionManager.begin(); for (RegisterTransaction registerTransaction : registerTransactionCollection) { registerTransaction.register(transactionManager); } try { transactionManager.rollback(); AssertJUnit.fail("SystemException expected!"); } catch (SystemException e) { //expected } assertEmpty(); assertNoTxInAllCaches(); assertNull(transactionManager.getTransaction()); }
try { Fqn fqn = Generator.getRandomElement(fqns); EmbeddedTransactionManager.getInstance().begin(); cache.get(fqn, "key"); EmbeddedTransactionManager.getInstance().commit(); EmbeddedTransactionManager.getInstance().begin(); cache.put(fqn, "key", "Value"); EmbeddedTransactionManager.getInstance().commit(); EmbeddedTransactionManager.getInstance().begin(); cache.remove(fqn, "key"); EmbeddedTransactionManager.getInstance().commit();
@Override public TransactionConfiguration get() { TransactionConfigurationBuilder builder = new ConfigurationBuilder().transaction() .lockingMode(this.locking) .cacheStopTimeout(this.timeout) .transactionMode((this.mode == TransactionMode.NONE) ? org.infinispan.transaction.TransactionMode.NON_TRANSACTIONAL : org.infinispan.transaction.TransactionMode.TRANSACTIONAL) .useSynchronization(this.mode == TransactionMode.NON_XA) .recovery().enabled(this.mode == TransactionMode.FULL_XA).transaction() ; switch (this.mode) { case NONE: { break; } case BATCH: { builder.transactionManagerLookup(new TransactionManagerProvider(EmbeddedTransactionManager.getInstance())); break; } case NON_XA: { builder.transactionSynchronizationRegistryLookup(new TransactionSynchronizationRegistryProvider(this.tsrDependency.get())); // fall through } default: { builder.transactionManagerLookup(new TransactionManagerProvider(ContextTransactionManager.getInstance())); } } return builder.create(); } }
public void testNumberOfLocksHeld() throws Exception { EmbeddedTransactionManager tm = (EmbeddedTransactionManager) tm(); tm.begin(); cache.put("key", "value"); tm.getTransaction().runPrepare(); assertAttributeValue("NumberOfLocksHeld", 1); tm.getTransaction().runCommit(false); assertAttributeValue("NumberOfLocksHeld", 0); }
public void testVisibilityOfCommittedDataPut() throws Exception { Cache<String, String> c = lockTestData.cache; c.put("k", "v"); assertEquals("v", c.get("k")); // start a tx and read K lockTestData.tm.begin(); assertEquals("v", c.get("k")); assertEquals("v", c.get("k")); Transaction reader = lockTestData.tm.suspend(); lockTestData.tm.begin(); c.put("k", "v2"); Transaction writer = lockTestData.tm.suspend(); lockTestData.tm.resume(reader); assertEquals("Should not read uncommitted data", "v", c.get("k")); reader = lockTestData.tm.suspend(); lockTestData.tm.resume(writer); lockTestData.tm.commit(); lockTestData.tm.resume(reader); assertEquals("Should read committed data", "v2", c.get("k")); lockTestData.tm.commit(); }
@Override public void testLocksOnPutKeyVal() throws Exception { LockTestData tl = lockTestData; Cache<String, String> cache = tl.cache; EmbeddedTransactionManager tm = tl.tm; tm.begin(); cache.put("k", "v"); tm.getTransaction().runPrepare(); assertLocked("k"); tm.getTransaction().runCommit(false); tm.suspend(); assertNoLocks(); tm.begin(); assertEquals(cache.get("k"), "v"); assertNotLocked("k"); tm.commit(); assertNoLocks(); tm.begin(); cache.remove("k"); tm.getTransaction().runPrepare(); assertLocked("k"); tm.getTransaction().runCommit(false); assertNoLocks(); }
if (useTx) { mgr = (EmbeddedTransactionManager) TestingUtil.getTransactionManager(sameNode ? cache1 : cache2); mgr.begin(); if (!mgr.getTransaction().runPrepare()) { //couldn't prepare latch.countDown(); mgr.rollback(); if (useTx) { try { mgr.commit(); } catch (Exception e1) {
public void testLocksOnPutKeyVal() throws Exception { Cache<String, String> cache = lockTestData.cache; EmbeddedTransactionManager tm = lockTestData.tm; tm.begin(); cache.put("k", "v"); assertTrue(tm.getTransaction().runPrepare()); assertLocked("k"); tm.getTransaction().runCommit(false); assertNoLocks(); tm.begin(); assertEquals("v", cache.get("k")); assertNotLocked("k"); tm.commit(); assertNoLocks(); tm.begin(); cache.remove("k"); assertTrue(tm.getTransaction().runPrepare()); assertLocked("k"); tm.getTransaction().runCommit(false); assertNoLocks(); }
public void testOneTx() throws Exception { embeddedTm().begin(); cache.put("k", "v"); TransactionXaAdapter xaRes = (TransactionXaAdapter) embeddedTm().firstEnlistedResource(); assertPrepared(0, embeddedTm().getTransaction()); xaRes.prepare(xaRes.getLocalTransaction().getXid()); assertPrepared(1, embeddedTm().getTransaction()); final EmbeddedTransaction suspend = (EmbeddedTransaction) embeddedTm().suspend(); xaRes.commit(xaRes.getLocalTransaction().getXid(), false); assertPrepared(0, suspend); assertEquals(0, TestingUtil.getTransactionTable(cache).getLocalTxCount()); }
@Test(groups = "functional", expectedExceptions = { CacheException.class }) public void testLockAcquisitionTimeout() throws Exception { AdvancedCache<Object, Object> cache1 = advancedCache(0, "syncReplCache"); AdvancedCache<Object, Object> cache2 = advancedCache(1, "syncReplCache"); cache1.getCacheConfiguration().locking().lockAcquisitionTimeout(10); cache2.getCacheConfiguration().locking().lockAcquisitionTimeout(10); TestingUtil.blockUntilViewsReceived(10000, cache1, cache2); // get a lock on cache 2 and hold on to it. EmbeddedTransactionManager tm = (EmbeddedTransactionManager) TestingUtil.getTransactionManager(cache2); tm.begin(); cache2.put("block", "block"); assertTrue(tm.getTransaction().runPrepare()); tm.suspend(); cache1.put("block", "v"); }
protected void commit() { EmbeddedTransactionManager dtm = (EmbeddedTransactionManager) tm(0); try { dtm.getTransaction().runCommit(false); } catch (HeuristicMixedException | HeuristicRollbackException | RollbackException e) { throw new RuntimeException(e); } }
protected void commit() { EmbeddedTransactionManager dtm = (EmbeddedTransactionManager) tm(); try { dtm.firstEnlistedResource().commit(getXid(), true); } catch (Throwable e) { throw new RuntimeException(e); } }
writeResponse(header, createTransactionResponse(header, prepareCoordinator.rollback())); } finally { EmbeddedTransactionManager.dissociateTransaction();
private void testLockMigrationAfterPrepare(Object key) throws Exception { final EmbeddedTransactionManager tm = embeddedTm(ORIGINATOR_INDEX); tm.begin(); originatorCache.put(key, "value"); EmbeddedTransaction tx = tm.getTransaction(); boolean prepareSuccess = tx.runPrepare(); assert prepareSuccess; tm.suspend(); log.trace("Lock transfer happens here"); killCache(); checkNewTransactionFails(key); log.trace("About to commit existing transaction."); tm.resume(tx); tx.runCommit(false); // read the data from the container, just to make sure all replicas are correctly set checkValue(key, "value"); }
private EmbeddedTransaction newTx(Xid xid) { EmbeddedTransaction tx = new EmbeddedTransaction(EmbeddedTransactionManager.getInstance()); tx.setXid(xid); return tx; }
public void testLocksOnRemoveNonexistent() throws Exception { LockTestData tl = lockTestData; Cache<String, String> cache = tl.cache; EmbeddedTransactionManager tm = tl.tm; assert !cache.containsKey("k") : "Should not exist"; tm.begin(); cache.remove("k"); tm.getTransaction().runPrepare(); assertLocked("k"); tm.getTransaction().runCommit(false); assert !cache.containsKey("k") : "Should not exist"; assertNoLocks(); }