Search in sources :

Example 26 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.
 */
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();
    }
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) Transaction(javax.transaction.Transaction) TransactionManager(org.objectweb.transaction.jta.TransactionManager) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Example 27 with TransactionConfiguration

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();
    }
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) Transaction(javax.transaction.Transaction) TransactionManager(org.objectweb.transaction.jta.TransactionManager) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Example 28 with TransactionConfiguration

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

Aggregations

TransactionConfiguration (org.apache.ignite.configuration.TransactionConfiguration)28 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)10 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)9 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)6 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)4 TransactionManager (org.objectweb.transaction.jta.TransactionManager)4 HashMap (java.util.HashMap)3 Transaction (javax.transaction.Transaction)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)3 LinkedHashMap (java.util.LinkedHashMap)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 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)2 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)2 BROADCAST (org.apache.ignite.internal.GridClosureCallMode.BROADCAST)2 PlatformDotNetBinaryConfiguration (org.apache.ignite.platform.dotnet.PlatformDotNetBinaryConfiguration)2 NoopEventStorageSpi (org.apache.ignite.spi.eventstorage.NoopEventStorageSpi)2