Search in sources :

Example 36 with TransactionIsolation

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

the class IgniteOnePhaseCommitNearSelfTest method checkKey.

/**
 * @param transactions Transactions instance.
 * @param cache Cache instance.
 * @param key Key.
 */
private void checkKey(IgniteTransactions transactions, Cache<Object, Object> cache, int key) throws Exception {
    cache.put(key, key);
    finalCheck(key, true);
    TransactionIsolation[] isolations = { READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE };
    TransactionConcurrency[] concurrencies = { OPTIMISTIC, PESSIMISTIC };
    for (TransactionIsolation isolation : isolations) {
        for (TransactionConcurrency concurrency : concurrencies) {
            info("Checking transaction [isolation=" + isolation + ", concurrency=" + concurrency + ']');
            try (Transaction tx = transactions.txStart(concurrency, isolation)) {
                cache.put(key, isolation + "-" + concurrency);
                tx.commit();
            }
            finalCheck(key, true);
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Example 37 with TransactionIsolation

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

the class IgniteCacheReadThroughStoreCallTest method checkLoadCount.

/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
private void checkLoadCount(CacheConfiguration<Object, Object> ccfg) throws Exception {
    storeMap.clear();
    Ignite ignite0 = ignite(0);
    ignite0.createCache(ccfg);
    try {
        int key = 0;
        for (Ignite node : G.allGrids()) {
            log.info("Test for node: " + node.name());
            final IgniteCache<Object, Object> cache = node.cache(ccfg.getName());
            for (int i = 0; i < 50; i++) {
                final int k = key++;
                checkReadThrough(cache, new IgniteRunnable() {

                    @Override
                    public void run() {
                        cache.invoke(k, new TestEntryProcessor());
                    }
                }, null, null, 1);
            }
            for (int i = 0; i < 50; i++) {
                final int k = key++;
                checkReadThrough(cache, new IgniteRunnable() {

                    @Override
                    public void run() {
                        cache.put(k, k);
                    }
                }, null, null, 0);
            }
            if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
                for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                    for (TransactionIsolation isolation : values()) {
                        log.info("Test tx [concurrency=" + concurrency + ", isolation=" + isolation + ']');
                        for (int i = 0; i < 50; i++) {
                            final int k = key++;
                            checkReadThrough(cache, new IgniteRunnable() {

                                @Override
                                public void run() {
                                    cache.invoke(k, new TestEntryProcessor());
                                }
                            }, concurrency, isolation, 2);
                        }
                    }
                }
            }
        }
        ignite0.cache(ccfg.getName()).removeAll();
    } finally {
        ignite0.destroyCache(ccfg.getName());
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Ignite(org.apache.ignite.Ignite) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 38 with TransactionIsolation

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

the class IgniteTxStoreExceptionAbstractSelfTest method testPutBackupTx.

/**
 * @throws Exception If failed.
 */
public void testPutBackupTx() throws Exception {
    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            checkPutTx(true, concurrency, isolation, keyForNode(grid(0).localNode(), BACKUP));
            checkPutTx(false, concurrency, isolation, keyForNode(grid(0).localNode(), BACKUP));
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Example 39 with TransactionIsolation

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

the class IgniteTxStoreExceptionAbstractSelfTest method testPutPrimaryTx.

/**
 * @throws Exception If failed.
 */
public void testPutPrimaryTx() throws Exception {
    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            checkPutTx(true, concurrency, isolation, keyForNode(grid(0).localNode(), PRIMARY));
            checkPutTx(false, concurrency, isolation, keyForNode(grid(0).localNode(), PRIMARY));
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Example 40 with TransactionIsolation

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

the class WithKeepBinaryCacheFullApiTest method testInvokeAllTx.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("serial")
public void testInvokeAllTx() throws Exception {
    if (!txShouldBeUsed())
        return;
    for (TransactionConcurrency conc : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            checkInvokeAllTx(conc, isolation);
            jcache().removeAll();
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Aggregations

TransactionIsolation (org.apache.ignite.transactions.TransactionIsolation)52 TransactionConcurrency (org.apache.ignite.transactions.TransactionConcurrency)48 Transaction (org.apache.ignite.transactions.Transaction)29 Ignite (org.apache.ignite.Ignite)21 IgniteTransactions (org.apache.ignite.IgniteTransactions)10 IgniteCache (org.apache.ignite.IgniteCache)7 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 IgniteException (org.apache.ignite.IgniteException)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CacheException (javax.cache.CacheException)2 Transaction (javax.transaction.Transaction)2 TransactionConfiguration (org.apache.ignite.configuration.TransactionConfiguration)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2