Search in sources :

Example 16 with TransactionConcurrency

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

the class IndexingSpiQueryTxSelfTest method testIndexingSpiWithTx.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testIndexingSpiWithTx() throws Exception {
    IgniteEx ignite = grid(0);
    final IgniteCache<Integer, Integer> cache = ignite.cache("test-cache");
    final IgniteTransactions txs = ignite.transactions();
    for (final TransactionConcurrency concurrency : TransactionConcurrency.values()) {
        for (final TransactionIsolation isolation : TransactionIsolation.values()) {
            System.out.println("Run in transaction: " + concurrency + " " + isolation);
            GridTestUtils.assertThrowsWithCause(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    Transaction tx;
                    try (Transaction tx0 = tx = txs.txStart(concurrency, isolation)) {
                        cache.put(1, 1);
                        tx0.commit();
                    }
                    assertEquals(TransactionState.ROLLED_BACK, tx.state());
                    return null;
                }
            }, IgniteTxHeuristicCheckedException.class);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) IgniteTransactions(org.apache.ignite.IgniteTransactions) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 17 with TransactionConcurrency

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

the class CacheStoreUsageMultinodeAbstractTest method checkStoreUpdate.

/**
     * @param clientStore {@code True} if store configured on client node.
     * @throws Exception If failed.
     */
protected void checkStoreUpdate(boolean clientStore) throws Exception {
    Ignite client = grid(3);
    assertTrue(client.configuration().isClientMode());
    awaitPartitionMapExchange();
    IgniteCache<Object, Object> cache0 = ignite(0).cache(DEFAULT_CACHE_NAME);
    IgniteCache<Object, Object> cache1 = ignite(1).cache(DEFAULT_CACHE_NAME);
    IgniteCache<Object, Object> clientCache = client.cache(DEFAULT_CACHE_NAME);
    assertTrue(((IgniteCacheProxy) cache0).context().store().configured());
    assertEquals(clientStore, ((IgniteCacheProxy) clientCache).context().store().configured());
    List<TransactionConcurrency> tcList = new ArrayList<>();
    tcList.add(null);
    if (atomicityMode() == TRANSACTIONAL) {
        tcList.add(TransactionConcurrency.OPTIMISTIC);
        tcList.add(TransactionConcurrency.PESSIMISTIC);
    }
    log.info("Start test [atomicityMode=" + atomicityMode() + ", locStore=" + locStore + ", writeBehind=" + writeBehind + ", nearCache=" + nearCache + ", clientStore=" + clientStore + ']');
    for (TransactionConcurrency tc : tcList) {
        testStoreUpdate(cache0, primaryKey(cache0), tc);
        testStoreUpdate(cache0, backupKey(cache0), tc);
        testStoreUpdate(cache0, nearKey(cache0), tc);
        testStoreUpdate(cache0, primaryKey(cache1), tc);
        testStoreUpdate(clientCache, primaryKey(cache0), tc);
        testStoreUpdate(clientCache, primaryKey(cache1), tc);
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) ArrayList(java.util.ArrayList) Ignite(org.apache.ignite.Ignite)

Example 18 with TransactionConcurrency

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

the class WithKeepBinaryCacheFullApiTest method testInvokeAsyncTx.

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

Example 19 with TransactionConcurrency

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

the class WithKeepBinaryCacheFullApiTest method runInAllTxModes.

/**
     * @param task Task.
     * @throws Exception If failed.
     */
protected void runInAllTxModes(TestRunnable task) throws Exception {
    info("Executing implicite tx");
    task.run();
    if (txShouldBeUsed()) {
        for (TransactionConcurrency conc : TransactionConcurrency.values()) {
            for (TransactionIsolation isolation : TransactionIsolation.values()) {
                try (Transaction tx = testedGrid().transactions().txStart(conc, isolation)) {
                    info("Executing explicite tx [isolation" + isolation + ", concurrency=" + conc + "]");
                    task.run();
                    tx.commit();
                }
            }
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Example 20 with TransactionConcurrency

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

the class CacheGetEntryAbstractTest method test.

/**
     * @param cfg Cache configuration.
     * @param oneEntry If {@code true} then single entry is tested.
     * @throws Exception If failed.
     */
private void test(CacheConfiguration cfg, final boolean oneEntry) throws Exception {
    final IgniteCache<Integer, TestValue> cache = grid(0).createCache(cfg);
    try {
        init(cache);
        test(cache, null, null, null, oneEntry);
        if (cfg.getAtomicityMode() == TRANSACTIONAL) {
            TransactionConcurrency txConcurrency = concurrency();
            TransactionIsolation txIsolation = isolation();
            try (Transaction tx = grid(0).transactions().txStart(txConcurrency, txIsolation)) {
                initTx(cache);
                test(cache, txConcurrency, txIsolation, tx, oneEntry);
                tx.commit();
            }
            testConcurrentTx(cache, OPTIMISTIC, REPEATABLE_READ, oneEntry);
            testConcurrentTx(cache, OPTIMISTIC, READ_COMMITTED, oneEntry);
            testConcurrentTx(cache, PESSIMISTIC, REPEATABLE_READ, oneEntry);
            testConcurrentTx(cache, PESSIMISTIC, READ_COMMITTED, oneEntry);
            testConcurrentOptimisticTxGet(cache, REPEATABLE_READ);
            testConcurrentOptimisticTxGet(cache, READ_COMMITTED);
            testConcurrentOptimisticTxGet(cache, SERIALIZABLE);
        }
    } finally {
        cache.destroy();
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

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