use of org.apache.ignite.events.TransactionStateChangedEvent in project ignite by apache.
the class TxRollbackOnIncorrectParamsTest method testLabelFilledRemoteGuarantee.
/**
*/
@Test
public void testLabelFilledRemoteGuarantee() throws Exception {
Ignite ignite = startGrid(0);
Ignite remote = startGrid(1);
IgniteCache cacheLocal = ignite.getOrCreateCache(defaultCacheConfiguration());
IgniteCache cacheRemote = remote.getOrCreateCache(defaultCacheConfiguration());
ignite.events().remoteListen(null, (IgnitePredicate<Event>) e -> {
assert e instanceof TransactionStateChangedEvent;
TransactionStateChangedEvent evt = (TransactionStateChangedEvent) e;
Transaction tx = evt.tx();
if (tx.label() == null)
tx.setRollbackOnly();
return true;
}, EVT_TX_STARTED);
try (Transaction tx = ignite.transactions().withLabel("test").txStart()) {
cacheLocal.put(1, 1);
tx.commit();
}
try (Transaction tx = remote.transactions().withLabel("test").txStart()) {
cacheRemote.put(1, 2);
tx.commit();
}
try (Transaction tx = ignite.transactions().txStart()) {
cacheLocal.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);
}
try (Transaction tx = remote.transactions().txStart()) {
cacheRemote.put(1, 4);
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.events.TransactionStateChangedEvent in project ignite by apache.
the class TxRollbackOnIncorrectParamsTest method testLabelFilledLocalGuarantee.
/**
*/
@Test
public void testLabelFilledLocalGuarantee() 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.label() == null)
tx.setRollbackOnly();
return true;
}, EVT_TX_STARTED);
IgniteCache cache = ignite.getOrCreateCache(defaultCacheConfiguration());
try (Transaction tx = ignite.transactions().withLabel("test").txStart()) {
cache.put(1, 1);
tx.commit();
}
try (Transaction tx = ignite.transactions().txStart()) {
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);
}
}
use of org.apache.ignite.events.TransactionStateChangedEvent in project ignite by apache.
the class TxRollbackOnIncorrectParamsTest method testTimeoutSetRemoteGuarantee.
/**
*/
@Test
public void testTimeoutSetRemoteGuarantee() throws Exception {
Ignite ignite = startGrid(0);
Ignite remote = startGrid(1);
IgniteCache cacheLocal = ignite.getOrCreateCache(defaultCacheConfiguration());
IgniteCache cacheRemote = remote.getOrCreateCache(defaultCacheConfiguration());
ignite.events().remoteListen(null, (IgnitePredicate<Event>) e -> {
assert e instanceof TransactionStateChangedEvent;
TransactionStateChangedEvent evt = (TransactionStateChangedEvent) e;
Transaction tx = evt.tx();
if (tx.timeout() == 0)
tx.setRollbackOnly();
return true;
}, EVT_TX_STARTED);
try (Transaction tx = ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ, 100, 2)) {
cacheLocal.put(1, 1);
tx.commit();
}
try (Transaction tx = remote.transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ, 100, 2)) {
cacheRemote.put(1, 2);
tx.commit();
}
try (Transaction tx = ignite.transactions().txStart()) {
cacheLocal.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);
}
try (Transaction tx = remote.transactions().txStart()) {
cacheRemote.put(1, 4);
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.events.TransactionStateChangedEvent in project ignite by apache.
the class TxStateChangeEventTest method check.
/**
*/
private void check(boolean loc) throws Exception {
Ignite ignite = startGrids(5);
final IgniteEvents evts = loc ? ignite.events() : grid(3).events();
if (loc)
evts.localListen((IgnitePredicate<Event>) e -> {
assert e instanceof TransactionStateChangedEvent;
checkEvent((TransactionStateChangedEvent) e);
return true;
}, EVTS_TX);
else
evts.remoteListen(null, (IgnitePredicate<Event>) e -> {
assert e instanceof TransactionStateChangedEvent;
checkEvent((TransactionStateChangedEvent) e);
return false;
}, EVTS_TX);
IgniteTransactions txs = ignite.transactions();
IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(getCacheConfig());
checkCommit(txs, cache);
if (!MvccFeatureChecker.forcedMvcc())
checkSuspendResume(txs, cache);
checkRollback(txs, cache);
}
use of org.apache.ignite.events.TransactionStateChangedEvent 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);
}
}
Aggregations