use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class GridJtaTransactionManagerSelfTest method testJtaTxContextSwitch.
/**
* Test for switching tx context by JTA Manager.
*
* @throws Exception If failed.
*/
@Test
public void testJtaTxContextSwitch() throws Exception {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
TransactionConfiguration cfg = grid().context().config().getTransactionConfiguration();
cfg.setDefaultTxConcurrency(txConcurrency);
cfg.setDefaultTxIsolation(isolation);
TransactionManager jtaTm = jotm.getTransactionManager();
IgniteCache<Integer, String> cache = jcache();
assertNull(grid().transactions().tx());
jtaTm.begin();
Transaction tx1 = jtaTm.getTransaction();
cache.put(1, Integer.toString(1));
assertNotNull(grid().transactions().tx());
assertEquals(ACTIVE, grid().transactions().tx().state());
assertEquals(Integer.toString(1), cache.get(1));
jtaTm.suspend();
assertNull(grid().transactions().tx());
assertNull(cache.get(1));
jtaTm.begin();
Transaction tx2 = jtaTm.getTransaction();
assertNotSame(tx1, tx2);
cache.put(2, Integer.toString(2));
assertNotNull(grid().transactions().tx());
assertEquals(ACTIVE, grid().transactions().tx().state());
assertEquals(Integer.toString(2), cache.get(2));
jtaTm.commit();
assertNull(grid().transactions().tx());
assertEquals(Integer.toString(2), cache.get(2));
jtaTm.resume(tx1);
assertNotNull(grid().transactions().tx());
assertEquals(ACTIVE, grid().transactions().tx().state());
cache.put(3, Integer.toString(3));
jtaTm.commit();
assertEquals("1", cache.get(1));
assertEquals("2", cache.get(2));
assertEquals("3", cache.get(3));
assertNull(grid().transactions().tx());
cache.removeAll();
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class GridJtaTransactionManagerSelfTest method testJtaTxContextSwitchWithExistingTx.
/**
* @throws Exception If failed.
*/
@Test
public void testJtaTxContextSwitchWithExistingTx() throws Exception {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
TransactionConfiguration cfg = grid().context().config().getTransactionConfiguration();
cfg.setDefaultTxConcurrency(txConcurrency);
cfg.setDefaultTxIsolation(isolation);
TransactionManager jtaTm = jotm.getTransactionManager();
IgniteCache<Integer, String> cache = jcache();
jtaTm.begin();
Transaction tx1 = jtaTm.getTransaction();
cache.put(1, Integer.toString(1));
assertNotNull(grid().transactions().tx());
assertEquals(ACTIVE, grid().transactions().tx().state());
assertEquals(Integer.toString(1), cache.get(1));
jtaTm.suspend();
jtaTm.begin();
Transaction tx2 = jtaTm.getTransaction();
assertNotSame(tx1, tx2);
cache.put(2, Integer.toString(2));
try {
jtaTm.resume(tx1);
fail("jtaTm.resume shouldn't success.");
} catch (IllegalStateException ignored) {
// No-op.
} finally {
// rolling back tx2
jtaTm.rollback();
}
jtaTm.resume(tx1);
jtaTm.rollback();
cache.removeAll();
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteCacheInvokeReadThroughAbstractTest method invokeReadThrough.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
protected void invokeReadThrough(CacheConfiguration ccfg) throws Exception {
Ignite ignite0 = ignite(0);
ignite0.createCache(ccfg);
int key = 0;
for (Ignite node : G.allGrids()) {
if (node.configuration().isClientMode() && ccfg.getNearConfiguration() != null)
node.createNearCache(ccfg.getName(), ccfg.getNearConfiguration());
}
for (Ignite node : G.allGrids()) {
log.info("Test for node: " + node.name());
IgniteCache<Object, Object> cache = node.cache(ccfg.getName());
for (int i = 0; i < 50; i++) checkReadThrough(cache, key++, null, null);
Set<Object> keys = new HashSet<>();
for (int i = 0; i < 5; i++) keys.add(key++);
checkReadThroughInvokeAll(cache, keys, null, null);
keys = new HashSet<>();
for (int i = 0; i < 100; i++) keys.add(key++);
checkReadThroughInvokeAll(cache, keys, null, null);
if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
log.info("Test tx [concurrency=" + concurrency + ", isolation=" + isolation + ']');
for (int i = 0; i < 50; i++) checkReadThrough(cache, key++, concurrency, isolation);
keys = new HashSet<>();
for (int i = 0; i < 5; i++) keys.add(key++);
checkReadThroughInvokeAll(cache, keys, concurrency, isolation);
keys = new HashSet<>();
for (int i = 0; i < 100; i++) keys.add(key++);
checkReadThroughInvokeAll(cache, keys, concurrency, isolation);
}
}
for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
log.info("Test tx2 [concurrency=" + concurrency + ", isolation=" + isolation + ']');
for (int i = 0; i < 50; i++) checkReadThroughGetAndInvoke(cache, key++, concurrency, isolation);
}
}
}
}
ignite0.cache(ccfg.getName()).removeAll();
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteCacheReadThroughStoreCallTest method checkLoadCount.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void checkLoadCount(CacheConfiguration<Object, Object> ccfg) throws Exception {
storeMap.clear();
Ignite ignite0 = ignite(0);
ignite0.createCache(ccfg);
try {
int key = 0;
for (Ignite node : G.allGrids()) {
log.info("Test for node: " + node.name());
final IgniteCache<Object, Object> cache = node.cache(ccfg.getName());
for (int i = 0; i < 50; i++) {
final int k = key++;
checkReadThrough(cache, new IgniteRunnable() {
@Override
public void run() {
cache.invoke(k, new TestEntryProcessor());
}
}, null, null, 1);
}
for (int i = 0; i < 50; i++) {
final int k = key++;
checkReadThrough(cache, new IgniteRunnable() {
@Override
public void run() {
cache.put(k, k);
}
}, null, null, 0);
}
if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : values()) {
log.info("Test tx [concurrency=" + concurrency + ", isolation=" + isolation + ']');
for (int i = 0; i < 50; i++) {
final int k = key++;
checkReadThrough(cache, new IgniteRunnable() {
@Override
public void run() {
cache.invoke(k, new TestEntryProcessor());
}
}, concurrency, isolation, 2);
}
}
}
}
}
ignite0.cache(ccfg.getName()).removeAll();
} finally {
ignite0.destroyCache(ccfg.getName());
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class TxOnCachesStopTest method runTxOnCacheStop.
/**
* @param block {@code True} To block GridNearTxPrepareRequest message.
*/
private void runTxOnCacheStop(boolean block) throws Exception {
startGridsMultiThreaded(2);
IgniteEx ig = startClientGrid("client");
ig.cluster().active(true);
for (TransactionConcurrency conc : TransactionConcurrency.values()) {
for (TransactionIsolation iso : TransactionIsolation.values()) runTxOnCacheStop(conc, iso, ig, block);
}
}
Aggregations