Search in sources :

Example 6 with TransactionConcurrency

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

the class IgniteCacheTxStoreSessionTest method testStoreSessionTx.

/**
     * @throws Exception If failed.
     */
public void testStoreSessionTx() throws Exception {
    testTxPut(jcache(0), null, null);
    testTxPut(ignite(0).cache(CACHE_NAME1), null, null);
    testTxRemove(null, null);
    testTxPutRemove(null, null);
    for (TransactionConcurrency concurrency : F.asList(PESSIMISTIC)) {
        for (TransactionIsolation isolation : F.asList(REPEATABLE_READ)) {
            testTxPut(jcache(0), concurrency, isolation);
            testTxRemove(concurrency, isolation);
            testTxPutRemove(concurrency, isolation);
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Example 7 with TransactionConcurrency

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

the class GridCacheStopSelfTest method testStop.

/**
     * @param startTx If {@code true} starts transactions.
     * @throws Exception If failed.
     */
private void testStop(final boolean startTx) throws Exception {
    for (int i = 0; i < 10; i++) {
        startGrid(0);
        final int PUT_THREADS = 50;
        final CountDownLatch stopLatch = new CountDownLatch(1);
        final CountDownLatch readyLatch = new CountDownLatch(PUT_THREADS);
        final IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
        assertNotNull(cache);
        CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class);
        assertEquals(atomic ? ATOMIC : TRANSACTIONAL, ccfg.getAtomicityMode());
        assertEquals(replicated ? REPLICATED : PARTITIONED, ccfg.getCacheMode());
        Collection<IgniteInternalFuture<?>> putFuts = new ArrayList<>();
        for (int j = 0; j < PUT_THREADS; j++) {
            final int key = j;
            putFuts.add(GridTestUtils.runAsync(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    try {
                        if (startTx) {
                            TransactionConcurrency concurrency = key % 2 == 0 ? OPTIMISTIC : PESSIMISTIC;
                            try (Transaction tx = grid(0).transactions().txStart(concurrency, REPEATABLE_READ)) {
                                cache.put(key, key);
                                readyLatch.countDown();
                                stopLatch.await();
                                tx.commit();
                            }
                        } else {
                            readyLatch.countDown();
                            stopLatch.await();
                            cache.put(key, key);
                        }
                    } catch (CacheException | IgniteException | IllegalStateException e) {
                        log.info("Ignore error: " + e);
                    }
                    return null;
                }
            }, "cache-thread"));
        }
        readyLatch.await();
        stopLatch.countDown();
        stopGrid(0);
        for (IgniteInternalFuture<?> fut : putFuts) fut.get();
        try {
            cache.put(1, 1);
        } catch (IllegalStateException e) {
            if (!e.getMessage().startsWith(EXPECTED_MSG))
                e.printStackTrace();
            assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().startsWith(EXPECTED_MSG));
        }
    }
}
Also used : CacheException(javax.cache.CacheException) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) IgniteException(org.apache.ignite.IgniteException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 8 with TransactionConcurrency

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

the class IgniteTxStoreExceptionAbstractSelfTest method testPutMultipleKeysTx.

/**
     * @throws Exception If failed.
     */
public void testPutMultipleKeysTx() throws Exception {
    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            checkPutTx(true, concurrency, isolation, keyForNode(grid(0).localNode(), PRIMARY), keyForNode(grid(0).localNode(), PRIMARY), keyForNode(grid(0).localNode(), PRIMARY));
            checkPutTx(false, concurrency, isolation, keyForNode(grid(0).localNode(), PRIMARY), keyForNode(grid(0).localNode(), PRIMARY), keyForNode(grid(0).localNode(), PRIMARY));
            if (gridCount() > 1) {
                checkPutTx(true, concurrency, isolation, keyForNode(grid(1).localNode(), PRIMARY), keyForNode(grid(1).localNode(), PRIMARY), keyForNode(grid(1).localNode(), PRIMARY));
                checkPutTx(false, concurrency, isolation, keyForNode(grid(1).localNode(), PRIMARY), keyForNode(grid(1).localNode(), PRIMARY), keyForNode(grid(1).localNode(), PRIMARY));
            }
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Example 9 with TransactionConcurrency

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

the class IgniteTxExceptionAbstractSelfTest method testPutMultipleKeysTx.

/**
     * @throws Exception If failed.
     */
public void testPutMultipleKeysTx() throws Exception {
    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            checkPutTx(true, concurrency, isolation, keyForNode(grid(0).localNode(), PRIMARY), keyForNode(grid(0).localNode(), PRIMARY), keyForNode(grid(0).localNode(), PRIMARY));
            checkPutTx(false, concurrency, isolation, keyForNode(grid(0).localNode(), PRIMARY), keyForNode(grid(0).localNode(), PRIMARY), keyForNode(grid(0).localNode(), PRIMARY));
            if (gridCount() > 1) {
                checkPutTx(true, concurrency, isolation, keyForNode(grid(1).localNode(), PRIMARY), keyForNode(grid(1).localNode(), PRIMARY), keyForNode(grid(1).localNode(), PRIMARY));
                checkPutTx(false, concurrency, isolation, keyForNode(grid(1).localNode(), PRIMARY), keyForNode(grid(1).localNode(), PRIMARY), keyForNode(grid(1).localNode(), PRIMARY));
            }
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Example 10 with TransactionConcurrency

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

the class IgniteTxExceptionAbstractSelfTest method testPutBackupTx.

/**
     * @throws Exception If failed.
     */
public void testPutBackupTx() throws Exception {
    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            checkPutTx(true, concurrency, isolation, keyForNode(grid(0).localNode(), BACKUP));
            checkPutTx(false, concurrency, isolation, keyForNode(grid(0).localNode(), BACKUP));
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) 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