Search in sources :

Example 51 with TransactionConcurrency

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

the class IgniteCacheTxIteratorSelfTest method checkTxCache.

/**
 * @throws Exception If failed.
 */
private void checkTxCache(CacheMode mode, CacheAtomicityMode atomMode, boolean nearEnabled, boolean useEvicPlc) throws Exception {
    final Ignite ignite = grid(0);
    final CacheConfiguration<String, TestClass> ccfg = cacheConfiguration(mode, atomMode, nearEnabled, useEvicPlc);
    final IgniteCache<String, TestClass> cache = ignite.createCache(ccfg);
    info("Checking cache [mode=" + mode + ", atomMode=" + atomMode + ", near=" + nearEnabled + ", evict=" + useEvicPlc + ']');
    try {
        for (int i = 0; i < 30; i++) {
            final TestClass val = new TestClass("data");
            final String key = "key-" + i;
            cache.put(key, val);
            assertEquals(i + 1, cache.size());
            for (TransactionIsolation iso : TransactionIsolation.values()) {
                for (TransactionConcurrency con : TransactionConcurrency.values()) {
                    try (Transaction transaction = ignite.transactions().txStart(con, iso)) {
                        assertEquals(val, cache.get(key));
                        transaction.commit();
                    }
                    int cnt = iterateOverKeys(cache);
                    assertEquals("Failed [con=" + con + ", iso=" + iso + ']', i + 1, cnt);
                    assertEquals("Failed [con=" + con + ", iso=" + iso + ']', i + 1, cache.size());
                }
            }
        }
    } finally {
        grid(0).destroyCache(CACHE_NAME);
    }
}
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)

Example 52 with TransactionConcurrency

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

the class GridCacheEmptyEntriesAbstractSelfTest method checkPolicy0.

/**
 * Tests preset eviction policy.
 *
 * @throws Exception If failed.
 */
private void checkPolicy0() throws Exception {
    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
        txConcurrency = concurrency;
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            txIsolation = isolation;
            Ignite g = startGrids();
            IgniteCache<String, String> cache = g.cache(DEFAULT_CACHE_NAME);
            try {
                info(">>> Checking policy [txConcurrency=" + txConcurrency + ", txIsolation=" + txIsolation + ", plc=" + plc + ", nearPlc=" + nearPlc + ']');
                checkExplicitTx(g, cache);
                checkImplicitTx(cache);
            } finally {
                stopAllGrids();
            }
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Ignite(org.apache.ignite.Ignite)

Example 53 with TransactionConcurrency

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

the class IgniteCacheExpiryPolicyAbstractTest method testCreateUpdate.

/**
 * @throws Exception If failed.
 */
public void testCreateUpdate() throws Exception {
    factory = new FactoryBuilder.SingletonFactory<>(new TestPolicy(60_000L, 61_000L, null));
    startGrids();
    for (final Integer key : keys()) {
        log.info("Test createUpdate [key=" + key + ']');
        createUpdate(key, null);
    }
    for (final Integer key : keys()) {
        log.info("Test createUpdateCustomPolicy [key=" + key + ']');
        createUpdateCustomPolicy(key, null);
    }
    createUpdatePutAll(null);
    if (atomicityMode() == TRANSACTIONAL) {
        TransactionConcurrency[] txModes = new TransactionConcurrency[] { PESSIMISTIC, OPTIMISTIC };
        for (TransactionConcurrency tx : txModes) {
            for (final Integer key : keys()) {
                log.info("Test createUpdate [key=" + key + ", tx=" + tx + ']');
                createUpdate(key, tx);
            }
            for (final Integer key : keys()) {
                log.info("Test createUpdateCustomPolicy [key=" + key + ", tx=" + tx + ']');
                createUpdateCustomPolicy(key, tx);
            }
            createUpdatePutAll(tx);
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) FactoryBuilder(javax.cache.configuration.FactoryBuilder)

Example 54 with TransactionConcurrency

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

the class IgniteTxCachePrimarySyncTest method checkWaitPrimaryResponse.

/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
private void checkWaitPrimaryResponse(CacheConfiguration<Object, Object> ccfg) throws Exception {
    Ignite ignite = ignite(0);
    IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
    try {
        ignite(NODES - 1).createNearCache(ccfg.getName(), new NearCacheConfiguration<>());
        for (int i = 1; i < NODES; i++) {
            Ignite node = ignite(i);
            log.info("Test node: " + node.name());
            checkWaitPrimaryResponse(node, ccfg, new IgniteBiInClosure<Integer, IgniteCache<Object, Object>>() {

                @Override
                public void apply(Integer key, IgniteCache<Object, Object> cache) {
                    cache.put(key, key);
                }
            });
            checkWaitPrimaryResponse(node, ccfg, new IgniteBiInClosure<Integer, IgniteCache<Object, Object>>() {

                @Override
                public void apply(Integer key, IgniteCache<Object, Object> cache) {
                    Map<Integer, Integer> map = new HashMap<>();
                    for (int i = 0; i < 50; i++) map.put(i, i);
                    map.put(key, key);
                    cache.putAll(map);
                }
            });
            for (final TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                for (final TransactionIsolation isolation : TransactionIsolation.values()) {
                    checkWaitPrimaryResponse(node, ccfg, new IgniteBiInClosure<Integer, IgniteCache<Object, Object>>() {

                        @Override
                        public void apply(Integer key, IgniteCache<Object, Object> cache) {
                            Ignite ignite = cache.unwrap(Ignite.class);
                            try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
                                cache.put(key, key);
                                tx.commit();
                            }
                        }
                    });
                    checkWaitPrimaryResponse(node, ccfg, new IgniteBiInClosure<Integer, IgniteCache<Object, Object>>() {

                        @Override
                        public void apply(Integer key, IgniteCache<Object, Object> cache) {
                            Map<Integer, Integer> map = new HashMap<>();
                            for (int i = 0; i < 50; i++) map.put(i, i);
                            map.put(key, key);
                            Ignite ignite = cache.unwrap(Ignite.class);
                            try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
                                cache.putAll(map);
                                tx.commit();
                            }
                        }
                    });
                }
            }
        }
    } finally {
        ignite.destroyCache(cache.getName());
    }
}
Also used : TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) IgniteCache(org.apache.ignite.IgniteCache) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

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