Search in sources :

Example 76 with IgniteTransactions

use of org.apache.ignite.IgniteTransactions in project ignite by apache.

the class GridTransformSpringInjectionSelfTest method testTransformResourceInjection.

/**
     * @throws Exception If failed.
     */
public void testTransformResourceInjection() throws Exception {
    Ignite grid = grid(0);
    IgniteCache<String, Integer> cache = grid.createCache(cacheConfiguration(ATOMIC));
    try {
        doTransformResourceInjection(cache);
    } finally {
        cache.destroy();
    }
    cache = grid.createCache(cacheConfiguration(TRANSACTIONAL));
    try {
        doTransformResourceInjection(cache);
        for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
            for (TransactionIsolation isolation : TransactionIsolation.values()) {
                IgniteTransactions txs = grid.transactions();
                try (Transaction tx = txs.txStart(concurrency, isolation)) {
                    doTransformResourceInjection(cache);
                    tx.commit();
                }
            }
        }
    } finally {
        cache.destroy();
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Ignite(org.apache.ignite.Ignite) IgniteTransactions(org.apache.ignite.IgniteTransactions)

Example 77 with IgniteTransactions

use of org.apache.ignite.IgniteTransactions in project ignite by apache.

the class IgniteNativeTxBenchmark method test.

/** {@inheritDoc} */
@SuppressWarnings("SimplifiableIfStatement")
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
    long aid = ThreadLocalRandom.current().nextLong(accRows);
    long bid = ThreadLocalRandom.current().nextLong(branchRows);
    long tid = ThreadLocalRandom.current().nextLong(tellRows);
    final long delta = ThreadLocalRandom.current().nextLong(1000);
    IgniteTransactions transactions = ignite().transactions();
    try (Transaction tx = transactions.txStart(args.txConcurrency(), args.txIsolation())) {
        accounts.invoke(aid, new EntryProcessor<Long, Accounts, Object>() {

            @Override
            public Long process(MutableEntry<Long, Accounts> entry, Object... objects) throws EntryProcessorException {
                long newVal = entry.getValue().getVal() + delta;
                entry.setValue(entry.getValue().setVal(newVal));
                return newVal;
            }
        });
        tellers.invoke(tid, new EntryProcessor<Long, Tellers, Object>() {

            @Override
            public Long process(MutableEntry<Long, Tellers> entry, Object... objects) throws EntryProcessorException {
                long newVal = entry.getValue().getVal() + delta;
                entry.setValue(entry.getValue().setVal(newVal));
                return null;
            }
        });
        branches.invoke(bid, new EntryProcessor<Long, Branches, Object>() {

            @Override
            public Long process(MutableEntry<Long, Branches> entry, Object... objects) throws EntryProcessorException {
                long newVal = entry.getValue().getVal() + delta;
                entry.setValue(entry.getValue().setVal(newVal));
                return null;
            }
        });
        hist.put(cnt.getAndIncrement(), new History(tid, bid, aid, delta));
        tx.commit();
    }
    return true;
}
Also used : Branches(org.apache.ignite.yardstick.cache.model.Branches) IgniteTransactions(org.apache.ignite.IgniteTransactions) History(org.apache.ignite.yardstick.cache.model.History) Transaction(org.apache.ignite.transactions.Transaction) EntryProcessorException(javax.cache.processor.EntryProcessorException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Tellers(org.apache.ignite.yardstick.cache.model.Tellers) Accounts(org.apache.ignite.yardstick.cache.model.Accounts)

Aggregations

IgniteTransactions (org.apache.ignite.IgniteTransactions)77 Transaction (org.apache.ignite.transactions.Transaction)75 Ignite (org.apache.ignite.Ignite)55 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)54 TransactionOptimisticException (org.apache.ignite.transactions.TransactionOptimisticException)28 IgniteCache (org.apache.ignite.IgniteCache)22 IgniteException (org.apache.ignite.IgniteException)18 CacheException (javax.cache.CacheException)17 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)13 HashMap (java.util.HashMap)12 TransactionConcurrency (org.apache.ignite.transactions.TransactionConcurrency)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Callable (java.util.concurrent.Callable)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)9 TransactionIsolation (org.apache.ignite.transactions.TransactionIsolation)9 ArrayList (java.util.ArrayList)8 LinkedHashMap (java.util.LinkedHashMap)8 CyclicBarrier (java.util.concurrent.CyclicBarrier)8 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)8