use of org.apache.ignite.configuration.TransactionConfiguration in project ignite by apache.
the class GridJtaTransactionManagerSelfTest method testJtaTxContextSwitch.
/**
* Test for switching tx context by JTA Manager.
*
* @throws Exception If failed.
*/
public void testJtaTxContextSwitch() throws Exception {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
TransactionConfiguration cfg = grid().context().config().getTransactionConfiguration();
cfg.setDefaultTxConcurrency(TransactionConcurrency.OPTIMISTIC);
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.configuration.TransactionConfiguration in project ignite by apache.
the class GridJtaTransactionManagerSelfTest method testJtaTxContextSwitchWithExistingTx.
/**
* @throws Exception If failed.
*/
public void testJtaTxContextSwitchWithExistingTx() throws Exception {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
TransactionConfiguration cfg = grid().context().config().getTransactionConfiguration();
cfg.setDefaultTxConcurrency(TransactionConcurrency.OPTIMISTIC);
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.configuration.TransactionConfiguration in project ignite by apache.
the class GridCachePartitionedTxTimeoutSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
TransactionConfiguration txCfg = c.getTransactionConfiguration();
txCfg.setTxSerializableEnabled(true);
txCfg.setDefaultTxTimeout(TIMEOUT);
TcpDiscoverySpi spi = new TcpDiscoverySpi();
spi.setIpFinder(ipFinder);
c.setDiscoverySpi(spi);
CacheConfiguration cc = defaultCacheConfiguration();
cc.setCacheMode(PARTITIONED);
cc.setBackups(1);
cc.setAtomicityMode(TRANSACTIONAL);
// cacheCfg.setPreloadMode(NONE);
c.setCacheConfiguration(cc);
return c;
}
Aggregations