use of org.apache.ignite.transactions.TransactionAlreadyCompletedException in project ignite by apache.
the class TxRollbackOnIncorrectParamsTest method testTimeoutSetLocalGuarantee.
/**
*/
@Test
public void testTimeoutSetLocalGuarantee() throws Exception {
Ignite ignite = startGrid(0);
ignite.events().localListen((IgnitePredicate<Event>) e -> {
assert e instanceof TransactionStateChangedEvent;
TransactionStateChangedEvent evt = (TransactionStateChangedEvent) e;
Transaction tx = evt.tx();
if (tx.timeout() < 200)
tx.setRollbackOnly();
return true;
}, EVT_TX_STARTED);
IgniteCache cache = ignite.getOrCreateCache(defaultCacheConfiguration());
try (Transaction tx = ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ, 200, 2)) {
cache.put(1, 1);
tx.commit();
}
try (Transaction tx = ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ, 100, 2)) {
cache.put(1, 2);
tx.commit();
fail("Should fail prior this line.");
} catch (CacheException ex) {
if (MvccFeatureChecker.forcedMvcc())
assertTrue(ex.toString(), ex.getCause() instanceof TransactionAlreadyCompletedException);
else
assertTrue(ex.toString(), ex.getCause() instanceof TransactionRollbackException);
}
try (Transaction tx = ignite.transactions().txStart()) {
cache.put(1, 3);
tx.commit();
fail("Should fail prior this line.");
} catch (CacheException ex) {
if (MvccFeatureChecker.forcedMvcc())
assertTrue(ex.toString(), ex.getCause() instanceof TransactionAlreadyCompletedException);
else
assertTrue(ex.toString(), ex.getCause() instanceof TransactionRollbackException);
}
}
use of org.apache.ignite.transactions.TransactionAlreadyCompletedException in project ignite by apache.
the class TxRollbackOnIncorrectParamsTest method testRollbackInsideLocalListenerAfterRemoteFilter.
/**
*/
@Test
public void testRollbackInsideLocalListenerAfterRemoteFilter() throws Exception {
Ignite ignite = startGrid(0);
Ignite remote = startGrid(1);
IgniteCache cacheLocal = ignite.getOrCreateCache(defaultCacheConfiguration());
IgniteCache cacheRemote = remote.getOrCreateCache(defaultCacheConfiguration());
AtomicBoolean rollbackFailed = new AtomicBoolean();
AtomicBoolean alreadyRolledBack = new AtomicBoolean();
ignite.events().remoteListen((IgniteBiPredicate<UUID, Event>) (uuid, e) -> {
assert e instanceof TransactionStateChangedEvent;
TransactionStateChangedEvent evt = (TransactionStateChangedEvent) e;
Transaction tx = evt.tx();
try {
tx.setRollbackOnly();
} catch (IgniteException ignored) {
alreadyRolledBack.set(rollbackFailed.getAndSet(true));
}
return true;
}, (IgnitePredicate<Event>) e -> {
assert e instanceof TransactionStateChangedEvent;
return true;
}, EVT_TX_STARTED);
assertFalse(rollbackFailed.get());
assertFalse(alreadyRolledBack.get());
try (Transaction tx = ignite.transactions().txStart()) {
cacheLocal.put(1, 1);
tx.commit();
fail("Should fail prior this line.");
} catch (CacheException ex) {
if (MvccFeatureChecker.forcedMvcc())
assertTrue(ex.toString(), ex.getCause() instanceof TransactionAlreadyCompletedException);
else
assertTrue(ex.toString(), ex.getCause() instanceof TransactionRollbackException);
}
assertFalse(rollbackFailed.get());
assertFalse(alreadyRolledBack.get());
try (Transaction tx = remote.transactions().txStart()) {
cacheRemote.put(1, 2);
tx.commit();
}
assertTrue(GridTestUtils.waitForCondition(rollbackFailed::get, 5_000));
assertFalse(alreadyRolledBack.get());
}
Aggregations