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)));
}
}
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);
}
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();
}
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();
}
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();
}
Aggregations