Search in sources :

Example 46 with TransactionConcurrency

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

the class IgniteCacheInvokeReadThroughAbstractTest method invokeReadThrough.

/**
     * @param ccfg Cache configuration.
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
protected void invokeReadThrough(CacheConfiguration ccfg) throws Exception {
    Ignite ignite0 = ignite(0);
    ignite0.createCache(ccfg);
    try {
        int key = 0;
        for (Ignite node : G.allGrids()) {
            if (node.configuration().isClientMode() && ccfg.getNearConfiguration() != null)
                node.createNearCache(ccfg.getName(), ccfg.getNearConfiguration());
        }
        for (Ignite node : G.allGrids()) {
            log.info("Test for node: " + node.name());
            IgniteCache<Object, Object> cache = node.cache(ccfg.getName());
            for (int i = 0; i < 50; i++) checkReadThrough(cache, key++, null, null);
            Set<Object> keys = new HashSet<>();
            for (int i = 0; i < 5; i++) keys.add(key++);
            checkReadThroughInvokeAll(cache, keys, null, null);
            keys = new HashSet<>();
            for (int i = 0; i < 100; i++) keys.add(key++);
            checkReadThroughInvokeAll(cache, keys, null, null);
            if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
                for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                    for (TransactionIsolation isolation : TransactionIsolation.values()) {
                        log.info("Test tx [concurrency=" + concurrency + ", isolation=" + isolation + ']');
                        for (int i = 0; i < 50; i++) checkReadThrough(cache, key++, concurrency, isolation);
                        keys = new HashSet<>();
                        for (int i = 0; i < 5; i++) keys.add(key++);
                        checkReadThroughInvokeAll(cache, keys, concurrency, isolation);
                        keys = new HashSet<>();
                        for (int i = 0; i < 100; i++) keys.add(key++);
                        checkReadThroughInvokeAll(cache, keys, concurrency, isolation);
                    }
                }
                for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                    for (TransactionIsolation isolation : TransactionIsolation.values()) {
                        log.info("Test tx2 [concurrency=" + concurrency + ", isolation=" + isolation + ']');
                        for (int i = 0; i < 50; i++) checkReadThroughGetAndInvoke(cache, key++, concurrency, isolation);
                    }
                }
            }
        }
        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) HashSet(java.util.HashSet)

Example 47 with TransactionConcurrency

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

the class GridCacheBinaryObjectsAbstractSelfTest method testKeepBinaryTxOverwrite.

/**
     * @throws Exception if failed.
     */
public void testKeepBinaryTxOverwrite() throws Exception {
    if (atomicityMode() != TRANSACTIONAL)
        return;
    IgniteCache<Integer, TestObject> cache = ignite(0).cache(DEFAULT_CACHE_NAME);
    cache.put(0, new TestObject(1));
    for (TransactionConcurrency conc : TransactionConcurrency.values()) {
        for (TransactionIsolation iso : TransactionIsolation.values()) {
            try (Transaction tx = ignite(0).transactions().txStart(conc, iso)) {
                cache.withKeepBinary().get(0);
                cache.invoke(0, new ObjectEntryProcessor());
                tx.commit();
            }
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Example 48 with TransactionConcurrency

use of org.apache.ignite.transactions.TransactionConcurrency 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)

Aggregations

TransactionConcurrency (org.apache.ignite.transactions.TransactionConcurrency)48 TransactionIsolation (org.apache.ignite.transactions.TransactionIsolation)42 Transaction (org.apache.ignite.transactions.Transaction)27 Ignite (org.apache.ignite.Ignite)18 IgniteTransactions (org.apache.ignite.IgniteTransactions)11 IgniteCache (org.apache.ignite.IgniteCache)7 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IgniteException (org.apache.ignite.IgniteException)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 CacheException (javax.cache.CacheException)4 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 Callable (java.util.concurrent.Callable)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 HashSet (java.util.HashSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 FactoryBuilder (javax.cache.configuration.FactoryBuilder)2 MutableEntry (javax.cache.processor.MutableEntry)2