Search in sources :

Example 36 with TransactionConfiguration

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;
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 37 with TransactionConfiguration

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;
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 38 with TransactionConfiguration

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();
    }
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) Transaction(javax.transaction.Transaction) TransactionManager(javax.transaction.TransactionManager) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 39 with TransactionConfiguration

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();
    }
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) Transaction(javax.transaction.Transaction) TransactionManager(javax.transaction.TransactionManager) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 40 with TransactionConfiguration

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);
            }
        }
    }
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) RollbackException(javax.transaction.RollbackException) CacheTmLookup(org.apache.ignite.cache.jta.CacheTmLookup) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Aggregations

TransactionConfiguration (org.apache.ignite.configuration.TransactionConfiguration)40 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)22 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)11 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)7 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)4 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)4 StopNodeFailureHandler (org.apache.ignite.failure.StopNodeFailureHandler)4 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)4 HashMap (java.util.HashMap)3 Transaction (javax.transaction.Transaction)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 Test (org.junit.Test)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 TransactionManager (javax.transaction.TransactionManager)2 IGNITE_CACHE_RETRIES_COUNT (org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT)2 BinaryBasicNameMapper (org.apache.ignite.binary.BinaryBasicNameMapper)2 AtomicConfiguration (org.apache.ignite.configuration.AtomicConfiguration)2