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