Search in sources :

Example 76 with TransactionIsolation

use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.

the class IgniteCacheClusterReadOnlyModeSelfTest method testGetAllOutTxAsyncAllowed.

/**
 */
@Test
public void testGetAllOutTxAsyncAllowed() {
    performAction((node, cache) -> {
        for (TransactionConcurrency level : TransactionConcurrency.values()) {
            for (TransactionIsolation isolation : TransactionIsolation.values()) {
                CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class);
                if (level == OPTIMISTIC && cfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT) {
                    // Only pessimistic transactions are supported when MVCC is enabled.
                    continue;
                }
                Transaction tx = node.transactions().txStart(level, isolation);
                try {
                    cache.get(UNKNOWN_KEY);
                    assertEquals(kvMap, cache.getAllOutTxAsync(kvMap.keySet()).get());
                    tx.commit();
                } catch (Exception e) {
                    RuntimeException ex = new RuntimeException(new AssertionError("Got exception on node: " + node.name() + " cache: " + cache.getName() + " isolation: " + isolation + " txLevel: " + level, e));
                    log.error("", ex);
                    tx.rollback();
                    throw ex;
                }
            }
        }
    }, TX_CACHES_PRED.or(MVCC_CACHES_PRED));
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 77 with TransactionIsolation

use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.

the class IgniteCacheClusterReadOnlyModeSelfTest method testGetAllOutTxAllowed.

/**
 */
@Test
public void testGetAllOutTxAllowed() {
    performAction((node, cache) -> {
        for (TransactionConcurrency level : TransactionConcurrency.values()) {
            for (TransactionIsolation isolation : TransactionIsolation.values()) {
                CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class);
                if (level == OPTIMISTIC && cfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT) {
                    // Only pessimistic transactions are supported when MVCC is enabled.
                    continue;
                }
                Transaction tx = node.transactions().txStart(level, isolation);
                try {
                    cache.get(UNKNOWN_KEY);
                    assertEquals(kvMap, cache.getAllOutTx(kvMap.keySet()));
                    tx.commit();
                } catch (Exception e) {
                    RuntimeException ex = new RuntimeException(new AssertionError("Got exception on node: " + node.name() + " cache: " + cache.getName() + " isolation: " + isolation + " txLevel: " + level, e));
                    log.error("", ex);
                    tx.rollback();
                    throw ex;
                }
            }
        }
    }, TX_CACHES_PRED.or(MVCC_CACHES_PRED));
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 78 with TransactionIsolation

use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.

the class CacheLateAffinityAssignmentTest method cacheOperations.

/**
 * @param cache Cache
 */
private void cacheOperations(IgniteCache<Object, Object> cache) {
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    final int KEYS = 10_000;
    try {
        cache.get(rnd.nextInt(KEYS));
        cache.put(rnd.nextInt(KEYS), rnd.nextInt(10));
        cache.getAndPut(rnd.nextInt(KEYS), rnd.nextInt(10));
        cache.remove(rnd.nextInt(KEYS));
        cache.getAndRemove(rnd.nextInt(KEYS));
        cache.remove(rnd.nextInt(KEYS), rnd.nextInt(10));
        cache.putIfAbsent(rnd.nextInt(KEYS), rnd.nextInt(10));
        cache.replace(rnd.nextInt(KEYS), rnd.nextInt(10));
        cache.replace(rnd.nextInt(KEYS), rnd.nextInt(10), rnd.nextInt(10));
        cache.invoke(rnd.nextInt(KEYS), new TestEntryProcessor(rnd.nextInt(10)));
        if (cache.getConfiguration(CacheConfiguration.class).getAtomicityMode() == TRANSACTIONAL) {
            IgniteTransactions txs = cache.unwrap(Ignite.class).transactions();
            for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                for (TransactionIsolation isolation : TransactionIsolation.values()) {
                    try (Transaction tx = txs.txStart(concurrency, isolation)) {
                        Integer key = rnd.nextInt(KEYS);
                        cache.getAndPut(key, rnd.nextInt(10));
                        cache.invoke(key + 1, new TestEntryProcessor(rnd.nextInt(10)));
                        cache.get(key + 2);
                        tx.commit();
                    }
                }
            }
        }
    } catch (Exception e) {
        log.info("Cache operation failed: " + e);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) IgniteTransactions(org.apache.ignite.IgniteTransactions) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)

Example 79 with TransactionIsolation

use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.

the class TxOptimisticPrepareOnUnstableTopologyTest method testPrepareOnUnstableTopology.

/**
 */
@Test
public void testPrepareOnUnstableTopology() throws Exception {
    for (TransactionIsolation isolation : TransactionIsolation.values()) {
        doPrepareOnUnstableTopology(4, false, isolation, 0);
        doPrepareOnUnstableTopology(4, true, isolation, 0);
        doPrepareOnUnstableTopology(4, false, isolation, TimeUnit.DAYS.toMillis(1));
        doPrepareOnUnstableTopology(4, true, isolation, TimeUnit.DAYS.toMillis(1));
    }
}
Also used : TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 80 with TransactionIsolation

use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.

the class TxRollbackOnTimeoutTest method testTimeoutOnPrimaryDHTNode.

/**
 * Tests timeout on DHT primary node for all tx configurations.
 *
 * @throws Exception If failed.
 */
@Test
public void testTimeoutOnPrimaryDHTNode() throws Exception {
    final ClusterNode n0 = grid(0).affinity(CACHE_NAME).mapKeyToNode(0);
    final Ignite prim = G.ignite(n0.id());
    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) testTimeoutOnPrimaryDhtNode0(prim, concurrency, isolation);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

TransactionIsolation (org.apache.ignite.transactions.TransactionIsolation)88 TransactionConcurrency (org.apache.ignite.transactions.TransactionConcurrency)71 Test (org.junit.Test)53 Transaction (org.apache.ignite.transactions.Transaction)52 Ignite (org.apache.ignite.Ignite)33 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)27 IgniteCache (org.apache.ignite.IgniteCache)14 IgniteTransactions (org.apache.ignite.IgniteTransactions)13 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)12 ArrayList (java.util.ArrayList)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 IgniteEx (org.apache.ignite.internal.IgniteEx)9 IgniteException (org.apache.ignite.IgniteException)8 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)7 HashMap (java.util.HashMap)6 Map (java.util.Map)5 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)5 TransactionTimeoutException (org.apache.ignite.transactions.TransactionTimeoutException)5 List (java.util.List)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4