Search in sources :

Example 41 with TransactionConcurrency

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

the class IgniteTxStoreExceptionAbstractSelfTest 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)

Example 42 with TransactionConcurrency

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

the class IgniteTxStoreExceptionAbstractSelfTest method testPutPrimaryTx.

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

Example 43 with TransactionConcurrency

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

the class WithKeepBinaryCacheFullApiTest method testInvokeAllTx.

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

Example 44 with TransactionConcurrency

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

the class IgniteCacheNoReadThroughAbstractTest method testNoReadThrough.

/**
 * @throws Exception If failed.
 */
public void testNoReadThrough() throws Exception {
    IgniteCache<Integer, Integer> cache = jcache(0);
    for (Integer key : keys()) {
        log.info("Test [key=" + key + ']');
        storeMap.put(key, key);
        assertNull(cache.get(key));
        assertEquals(key, storeMap.get(key));
        assertNull(cache.getAndPut(key, -1));
        assertEquals(-1, storeMap.get(key));
        cache.remove(key);
        assertNull(storeMap.get(key));
        storeMap.put(key, key);
        assertTrue(cache.putIfAbsent(key, -1));
        assertEquals(-1, storeMap.get(key));
        cache.remove(key);
        assertNull(storeMap.get(key));
        storeMap.put(key, key);
        assertNull(cache.getAndRemove(key));
        assertNull(storeMap.get(key));
        storeMap.put(key, key);
        assertNull(cache.getAndPutIfAbsent(key, -1));
        assertEquals(-1, storeMap.get(key));
        cache.remove(key);
        assertNull(storeMap.get(key));
        storeMap.put(key, key);
        Object ret = cache.invoke(key, new EntryProcessor<Integer, Integer, Object>() {

            @Override
            public Object process(MutableEntry<Integer, Integer> e, Object... args) {
                Integer val = e.getValue();
                assertFalse(e.exists());
                assertNull(val);
                e.setValue(-1);
                return String.valueOf(val);
            }
        });
        assertEquals("null", ret);
        assertEquals(-1, storeMap.get(key));
        cache.remove(key);
        assertNull(storeMap.get(key));
        storeMap.put(key, key);
        assertFalse(cache.replace(key, -1));
        assertEquals(key, storeMap.get(key));
        assertNull(cache.getAndReplace(key, -1));
        assertEquals(key, storeMap.get(key));
        assertFalse(cache.replace(key, key, -1));
        assertEquals(key, storeMap.get(key));
    }
    Set<Integer> keys = new HashSet<>();
    for (int i = 1000_0000; i < 1000_0000 + 1000; i++) {
        keys.add(i);
        storeMap.put(i, i);
    }
    assertTrue(cache.getAll(keys).isEmpty());
    if (atomicityMode() == TRANSACTIONAL) {
        for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
            for (TransactionIsolation isolation : TransactionIsolation.values()) {
                for (Integer key : keys()) {
                    log.info("Test tx [key=" + key + ", concurrency=" + concurrency + ", isolation=" + isolation + ']');
                    storeMap.put(key, key);
                    try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
                        assertNull(cache.get(key));
                        tx.commit();
                    }
                    assertEquals(key, storeMap.get(key));
                    try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
                        assertNull(cache.getAndPut(key, -1));
                        tx.commit();
                    }
                    assertEquals(-1, storeMap.get(key));
                    cache.remove(key);
                    assertNull(storeMap.get(key));
                    storeMap.put(key, key);
                    try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
                        assertTrue(cache.putIfAbsent(key, -1));
                        tx.commit();
                    }
                    assertEquals(-1, storeMap.get(key));
                    cache.remove(key);
                    assertNull(storeMap.get(key));
                    storeMap.put(key, key);
                    try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
                        Object ret = cache.invoke(key, new EntryProcessor<Integer, Integer, Object>() {

                            @Override
                            public Object process(MutableEntry<Integer, Integer> e, Object... args) {
                                Integer val = e.getValue();
                                assertFalse(e.exists());
                                assertNull(val);
                                e.setValue(-1);
                                return String.valueOf(val);
                            }
                        });
                        assertEquals("null", ret);
                        tx.commit();
                    }
                    assertEquals(-1, storeMap.get(key));
                    try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
                        assertTrue(cache.getAll(keys).isEmpty());
                        tx.commit();
                    }
                }
            }
        }
    }
    // Check can load cache when read-through is disabled.
    allowLoad = true;
    Integer key = 1;
    cache.remove(key);
    storeMap.clear();
    storeMap.put(key, 10);
    cache.loadCache(null);
    assertEquals(10, (int) cache.get(key));
    cache.remove(key);
    storeMap.put(key, 11);
    CompletionListenerFuture fut = new CompletionListenerFuture();
    cache.loadAll(F.asSet(key), true, fut);
    fut.get();
    assertEquals(11, (int) cache.get(key));
}
Also used : TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) CompletionListenerFuture(javax.cache.integration.CompletionListenerFuture) HashSet(java.util.HashSet)

Example 45 with TransactionConcurrency

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

the class WithKeepBinaryCacheFullApiTest method testInvokeTx.

/**
 * @throws Exception If failed.
 */
public void testInvokeTx() throws Exception {
    if (!txShouldBeUsed())
        return;
    for (TransactionConcurrency conc : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            info(">>>>> Executing test using explicit txs [concurrency=" + conc + ", isolation=" + isolation + "]");
            checkInvokeTx(conc, isolation);
            jcache().removeAll();
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

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