use of org.apache.ignite.configuration.TransactionConfiguration in project ignite by apache.
the class IgniteTxConfigCacheSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
TcpCommunicationSpi commSpi = new TestCommunicationSpi();
cfg.setCommunicationSpi(commSpi);
CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);
ccfg.setAtomicityMode(atomicityMode());
ccfg.setBackups(1);
cfg.setCacheConfiguration(ccfg);
final TransactionConfiguration txCfg = new TransactionConfiguration();
txCfg.setDefaultTxTimeout(TX_TIMEOUT);
cfg.setTransactionConfiguration(txCfg);
return cfg;
}
use of org.apache.ignite.configuration.TransactionConfiguration in project ignite by apache.
the class GridCacheReplicatedTxMultiThreadedSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
TransactionConfiguration tCfg = new TransactionConfiguration();
c.setTransactionConfiguration(tCfg);
CacheConfiguration cc = defaultCacheConfiguration();
cc.setCacheMode(REPLICATED);
cc.setEvictionPolicy(null);
cc.setWriteSynchronizationMode(FULL_SYNC);
c.setCacheConfiguration(cc);
return c;
}
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.
*/
@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.configuration.TransactionConfiguration 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.configuration.TransactionConfiguration in project ignite by apache.
the class CacheJtaManager method checkJta.
/**
* {@inheritDoc}
*/
@Override
public void checkJta() throws IgniteCheckedException {
if (jtaTm == null) {
try {
CacheTmLookup tmLookup = tmLookupRef.get();
if (tmLookup == null)
return;
jtaTm = tmLookup.getTm();
} catch (Exception e) {
throw new IgniteCheckedException("Failed to get transaction manager: " + e, e);
}
}
if (jtaTm != null) {
CacheJtaResource rsrc = this.rsrc.get();
if (rsrc == null || rsrc.isFinished() || rsrc.cacheTx().state() == SUSPENDED) {
try {
Transaction jtaTx = jtaTm.getTransaction();
if (jtaTx != null) {
GridNearTxLocal tx = cctx.tm().userTx();
if (tx == null) {
TransactionConfiguration tCfg = cctx.kernalContext().config().getTransactionConfiguration();
tx = cctx.tm().newTx(/*implicit*/
false, /*implicit single*/
false, null, tCfg.getDefaultTxConcurrency(), tCfg.getDefaultTxIsolation(), tCfg.getDefaultTxTimeout(), /*store enabled*/
true, /*sql*/
false, /*tx size*/
0, null, false);
}
rsrc = new CacheJtaResource(tx, cctx.kernalContext());
if (useJtaSync)
jtaTx.registerSynchronization(rsrc);
else if (!jtaTx.enlistResource(rsrc))
throw new IgniteCheckedException("Failed to enlist XA resource to JTA user transaction.");
this.rsrc.set(rsrc);
}
} catch (SystemException e) {
throw new IgniteCheckedException("Failed to obtain JTA transaction.", e);
} catch (RollbackException e) {
throw new IgniteCheckedException("Failed to enlist XAResource to JTA transaction.", e);
}
}
}
}
Aggregations