Search in sources :

Example 1 with EmbeddedTransaction

use of org.infinispan.transaction.tm.EmbeddedTransaction in project infinispan by infinispan.

the class TxInvalidationLockingTest method testOptimisticPrepareAcquiresGlobalLock.

public void testOptimisticPrepareAcquiresGlobalLock() throws Exception {
    CheckPoint checkPoint = new CheckPoint();
    Future<Void> tx2Future;
    Cache<Object, Object> cache1 = cache(0, OPTIMISTIC_CACHE);
    tm(cache1).begin();
    EmbeddedTransaction tx1 = null;
    try {
        Object initialValue = cache1.put(KEY, VALUE1);
        assertNull(initialValue);
        tx1 = (EmbeddedTransaction) tm(cache1).getTransaction();
        tx1.runPrepare();
        tx2Future = fork(() -> {
            AdvancedCache<Object, Object> cache2 = advancedCache(1, OPTIMISTIC_CACHE);
            tm(cache2).begin();
            try {
                assertNull(cache2.get(KEY));
                checkPoint.trigger("tx2_read");
                cache2.put(KEY, VALUE2);
            } finally {
                tm(cache2).commit();
            }
        });
        checkPoint.awaitStrict("tx2_read", 10, TimeUnit.SECONDS);
        Thread.sleep(10);
        assertFalse(tx2Future.isDone());
    } finally {
        if (tx1 != null) {
            tx1.runCommit(false);
        }
    }
    // No WriteSkewException
    tx2Future.get(30, TimeUnit.SECONDS);
    assertEquals(VALUE2, cache1.get(KEY));
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) AdvancedCache(org.infinispan.AdvancedCache) CheckPoint(org.infinispan.test.fwk.CheckPoint)

Example 2 with EmbeddedTransaction

use of org.infinispan.transaction.tm.EmbeddedTransaction in project infinispan by infinispan.

the class TxDuringStateTransferTest method performTest.

private void performTest(Operation operation) throws Exception {
    assertClusterSize("Wrong number of caches.", 4);
    final Object key = new MagicKey(cache(0), cache(1), cache(2));
    // init
    operation.init(cache(0), key);
    final EmbeddedTransactionManager transactionManager = (EmbeddedTransactionManager) tm(0);
    transactionManager.begin();
    operation.perform(cache(0), key);
    final EmbeddedTransaction transaction = transactionManager.getTransaction();
    transaction.runPrepare();
    assertEquals("Wrong transaction status before killing backup owner.", Status.STATUS_PREPARED, transaction.getStatus());
    // now, we kill cache(1). the transaction is prepared in cache(1) and it should be forward to cache(3)
    killMember(1);
    assertEquals("Wrong transaction status after killing backup owner.", Status.STATUS_PREPARED, transaction.getStatus());
    transaction.runCommit(false);
    for (Cache<Object, Object> cache : caches()) {
        // all the caches are owner
        operation.check(cache, key, valueOf(address(cache)));
    }
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) EmbeddedTransactionManager(org.infinispan.transaction.tm.EmbeddedTransactionManager) MagicKey(org.infinispan.distribution.MagicKey)

Example 3 with EmbeddedTransaction

use of org.infinispan.transaction.tm.EmbeddedTransaction in project infinispan by infinispan.

the class TxReplayTest method testReplay.

public void testReplay() throws Exception {
    assertClusterSize("Wrong cluster size", 3);
    final Object key = new MagicKey(cache(0), cache(1));
    final Cache<Object, Object> newBackupOwnerCache = cache(2);
    final TxCommandInterceptor interceptor = TxCommandInterceptor.inject(newBackupOwnerCache);
    EmbeddedTransactionManager transactionManager = (EmbeddedTransactionManager) tm(0);
    transactionManager.begin();
    cache(0).put(key, VALUE);
    final EmbeddedTransaction transaction = transactionManager.getTransaction();
    transaction.runPrepare();
    assertEquals("Wrong transaction status before killing backup owner.", Status.STATUS_PREPARED, transaction.getStatus());
    // now, we kill cache(1). the transaction is prepared in cache(1) and it should be forward to cache(2)
    killMember(1);
    checkIfTransactionExists(newBackupOwnerCache);
    assertEquals("Wrong transaction status after killing backup owner.", Status.STATUS_PREPARED, transaction.getStatus());
    transaction.runCommit(false);
    assertNoTransactions();
    assertEquals("Wrong number of prepares!", 1, interceptor.numberPrepares.get());
    assertEquals("Wrong number of commits!", 1, interceptor.numberCommits.get());
    assertEquals("Wrong number of rollbacks!", 0, interceptor.numberRollbacks.get());
    checkKeyInDataContainer(key);
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) EmbeddedTransactionManager(org.infinispan.transaction.tm.EmbeddedTransactionManager) MagicKey(org.infinispan.distribution.MagicKey)

Example 4 with EmbeddedTransaction

use of org.infinispan.transaction.tm.EmbeddedTransaction in project infinispan by infinispan.

the class InDoubtXidReturnedOnceTest method testXidReturnedOnlyOnce.

public void testXidReturnedOnlyOnce() throws Throwable {
    EmbeddedTransaction tx = beginAndSuspendTx(this.cache(3));
    prepareTransaction(tx);
    manager(3).stop();
    TestingUtil.blockUntilViewsReceived(60000, false, cache(0), cache(1), cache(2));
    TestingUtil.waitForNoRebalance(cache(0), cache(1), cache(2));
    EmbeddedTransaction tx2 = beginAndSuspendTx(this.cache(0));
    Xid[] recover = tx2.firstEnlistedResource().recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN);
    assertEquals(recover.length, 1);
    assertEquals(tx.getXid(), recover[0]);
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) Xid(javax.transaction.xa.Xid)

Example 5 with EmbeddedTransaction

use of org.infinispan.transaction.tm.EmbeddedTransaction in project infinispan by infinispan.

the class CommitFailsTest method setUpTx.

@BeforeMethod
protected void setUpTx() throws Exception {
    failureInterceptor0.fail = true;
    failureInterceptor1.fail = true;
    tm(2).begin();
    cache(2).put(this.key, "newValue");
    EmbeddedTransaction tx = (EmbeddedTransaction) tm(2).suspend();
    prepareTransaction(tx);
    try {
        commitTransaction(tx);
        assert false;
    } catch (XAException e) {
    // expected
    }
    assertEquals(countInDoubtTx(recoveryOps(2).showInDoubtTransactions()), 1);
    log.trace("here is the remote get...");
    assertEquals(countInDoubtTx(recoveryOps(0).showInDoubtTransactions()), 1);
    assertEquals(countInDoubtTx(recoveryOps(1).showInDoubtTransactions()), 1);
    failureInterceptor0.fail = false;
    failureInterceptor1.fail = false;
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) XAException(javax.transaction.xa.XAException) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

EmbeddedTransaction (org.infinispan.transaction.tm.EmbeddedTransaction)56 EmbeddedTransactionManager (org.infinispan.transaction.tm.EmbeddedTransactionManager)14 MagicKey (org.infinispan.distribution.MagicKey)9 TransactionTable (org.infinispan.transaction.impl.TransactionTable)5 Transaction (javax.transaction.Transaction)4 HashMap (java.util.HashMap)3 RollbackException (javax.transaction.RollbackException)3 XAException (javax.transaction.xa.XAException)3 XidImpl (org.infinispan.commons.tx.XidImpl)3 ComponentRegistry (org.infinispan.factories.ComponentRegistry)3 TransactionXaAdapter (org.infinispan.transaction.xa.TransactionXaAdapter)3 TxCompletionNotificationCommand (org.infinispan.commands.remote.recovery.TxCompletionNotificationCommand)2 CacheException (org.infinispan.commons.CacheException)2 Configuration (org.infinispan.configuration.cache.Configuration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 DistributionManager (org.infinispan.distribution.DistributionManager)2 LocalizedCacheTopology (org.infinispan.distribution.LocalizedCacheTopology)2 GlobalComponentRegistry (org.infinispan.factories.GlobalComponentRegistry)2 RpcManager (org.infinispan.remoting.rpc.RpcManager)2 SetCompletedTransactionFunction (org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction)2