Search in sources :

Example 26 with TransactionIsolation

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

the class IgniteCacheThreadLocalTxTest method threadLocalTx.

/**
 * @param node Node.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void threadLocalTx(Ignite node) throws Exception {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setBackups(2);
    IgniteCache<Object, Object> cache = node.getOrCreateCache(ccfg);
    checkNoTx(node);
    boolean[] reads = { true, false };
    boolean[] writes = { true, false };
    int endOps = 5;
    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            for (boolean read : reads) {
                for (boolean write : writes) {
                    for (int i = 0; i < endOps; i++) checkTx(concurrency, isolation, node, cache, read, write, i);
                }
            }
        }
    }
    checkNoTx(node);
    cache.put(1, 1);
    checkNoTx(node);
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 27 with TransactionIsolation

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

the class IgniteTxCachePrimarySyncTest method singleKeyPrimaryNodeLeft.

/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
private void singleKeyPrimaryNodeLeft(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 = 0; i < NODES; i++) {
            Ignite node = ignite(i);
            singleKeyPrimaryNodeLeft(node, ccfg, new IgniteBiInClosure<Integer, IgniteCache<Object, Object>>() {

                @Override
                public void apply(Integer key, IgniteCache<Object, Object> cache) {
                    cache.put(key, key);
                }
            });
            for (final TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                for (final TransactionIsolation isolation : TransactionIsolation.values()) {
                    singleKeyPrimaryNodeLeft(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();
                            }
                        }
                    });
                }
            }
        }
    } finally {
        ignite.destroyCache(cache.getName());
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite)

Example 28 with TransactionIsolation

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

the class IgniteTxCachePrimarySyncTest method checkOnePhaseMessages.

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

                @Override
                public void apply(Integer key, IgniteCache<Object, Object> cache) {
                    cache.put(key, key);
                }
            });
            for (final TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                for (final TransactionIsolation isolation : TransactionIsolation.values()) {
                    checkOnePhaseMessages(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();
                            }
                        }
                    });
                }
            }
        }
    } finally {
        ignite.destroyCache(cache.getName());
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite)

Example 29 with TransactionIsolation

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

the class CacheTxFastFinishTest method fastFinishTx.

/**
 * @param ignite Node.
 */
private void fastFinishTx(Ignite ignite) {
    IgniteTransactions txs = ignite.transactions();
    IgniteCache cache = ignite.cache(DEFAULT_CACHE_NAME);
    for (boolean commit : new boolean[] { true, false }) {
        for (TransactionConcurrency c : TransactionConcurrency.values()) {
            for (TransactionIsolation isolation : TransactionIsolation.values()) {
                try (Transaction tx = txs.txStart(c, isolation)) {
                    checkFastTxFinish(tx, commit);
                }
            }
        }
        for (int i = 0; i < 100; i++) {
            try (Transaction tx = txs.txStart(OPTIMISTIC, REPEATABLE_READ)) {
                cache.get(i);
                checkFastTxFinish(tx, commit);
            }
            try (Transaction tx = txs.txStart(OPTIMISTIC, READ_COMMITTED)) {
                cache.get(i);
                checkFastTxFinish(tx, commit);
            }
        }
        for (int i = 0; i < 100; i++) {
            try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
                cache.get(i);
                checkNormalTxFinish(tx, commit);
            }
            try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
                cache.get(i);
                checkNormalTxFinish(tx, commit);
            }
        }
        for (int i = 0; i < 100; i++) {
            for (TransactionConcurrency c : TransactionConcurrency.values()) {
                for (TransactionIsolation isolation : TransactionIsolation.values()) {
                    try (Transaction tx = txs.txStart(c, isolation)) {
                        cache.put(i, i);
                        checkNormalTxFinish(tx, commit);
                    }
                }
            }
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) IgniteCache(org.apache.ignite.IgniteCache) IgniteTransactions(org.apache.ignite.IgniteTransactions)

Example 30 with TransactionIsolation

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

the class CacheReadThroughRestartSelfTest method testReadThroughInTx.

/**
 * @throws Exception If failed.
 */
private void testReadThroughInTx(boolean needVer) throws Exception {
    IgniteCache<String, Integer> cache = grid(1).cache(DEFAULT_CACHE_NAME);
    for (int k = 0; k < 1000; k++) cache.put("key" + k, k);
    stopAllGrids();
    startGrids(2);
    awaitPartitionMapExchange();
    Ignite ignite = grid(1);
    cache = ignite.cache(DEFAULT_CACHE_NAME);
    for (TransactionConcurrency txConcurrency : TransactionConcurrency.values()) {
        for (TransactionIsolation txIsolation : TransactionIsolation.values()) {
            try (Transaction tx = ignite.transactions().txStart(txConcurrency, txIsolation, 100000, 1000)) {
                for (int k = 0; k < 1000; k++) {
                    String key = "key" + k;
                    if (needVer) {
                        assertNotNull("Null value for key: " + key, cache.getEntry(key));
                        assertNotNull("Null value for key: " + key, cache.getEntry(key));
                    } else {
                        assertNotNull("Null value for key: " + key, cache.get(key));
                        assertNotNull("Null value for key: " + key, cache.get(key));
                    }
                }
                tx.commit();
            }
        }
    }
}
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)

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