Search in sources :

Example 1 with EmbeddedTransactionManager

use of org.infinispan.transaction.tm.EmbeddedTransactionManager 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 2 with EmbeddedTransactionManager

use of org.infinispan.transaction.tm.EmbeddedTransactionManager 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 3 with EmbeddedTransactionManager

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

the class AbstractClusteredTxTest method prepare.

protected void prepare() {
    EmbeddedTransactionManager dtm = (EmbeddedTransactionManager) tm(0);
    dtm.getTransaction().runPrepare();
}
Also used : EmbeddedTransactionManager(org.infinispan.transaction.tm.EmbeddedTransactionManager)

Example 4 with EmbeddedTransactionManager

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

the class LockTestBase method testLocksOnPutKeyVal.

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();
}
Also used : EmbeddedTransactionManager(org.infinispan.transaction.tm.EmbeddedTransactionManager)

Example 5 with EmbeddedTransactionManager

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

the class LockTestBase method testConcurrentWriters.

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();
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) EmbeddedTransactionManager(org.infinispan.transaction.tm.EmbeddedTransactionManager)

Aggregations

EmbeddedTransactionManager (org.infinispan.transaction.tm.EmbeddedTransactionManager)31 EmbeddedTransaction (org.infinispan.transaction.tm.EmbeddedTransaction)14 RollbackException (javax.transaction.RollbackException)3 TransactionManager (javax.transaction.TransactionManager)3 MagicKey (org.infinispan.distribution.MagicKey)3 TransactionTable (org.infinispan.transaction.impl.TransactionTable)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)2 XAException (javax.transaction.xa.XAException)2 Cache (org.infinispan.Cache)2 TxCompletionNotificationCommand (org.infinispan.commands.remote.recovery.TxCompletionNotificationCommand)2 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)2 GlobalTransaction (org.infinispan.transaction.xa.GlobalTransaction)2 ControlledRpcManager (org.infinispan.util.ControlledRpcManager)2 Test (org.testng.annotations.Test)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 SystemException (javax.transaction.SystemException)1 CommitCommand (org.infinispan.commands.tx.CommitCommand)1