Search in sources :

Example 1 with INVOKE

use of org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.INVOKE in project ignite by apache.

the class MvccRepeatableReadBulkOpsTest method testInvokeConsistency.

/**
 * @throws Exception If failed.
 */
@Test
public void testInvokeConsistency() throws Exception {
    Ignite node = grid(/*requestFromClient ? nodesCount() - 1 :*/
    0);
    TestCache<Integer, MvccTestAccount> cache = new TestCache<>(node.cache(DEFAULT_CACHE_NAME));
    final Set<Integer> keys1 = new HashSet<>(3);
    final Set<Integer> keys2 = new HashSet<>(3);
    Set<Integer> allKeys = generateKeySet(cache.cache, keys1, keys2);
    final Map<Integer, MvccTestAccount> map1 = keys1.stream().collect(Collectors.toMap(k -> k, k -> new MvccTestAccount(k, 1)));
    final Map<Integer, MvccTestAccount> map2 = keys2.stream().collect(Collectors.toMap(k -> k, k -> new MvccTestAccount(k, 1)));
    assertEquals(0, cache.cache.size());
    updateEntries(cache, map1, WriteMode.INVOKE);
    assertEquals(3, cache.cache.size());
    updateEntries(cache, map1, WriteMode.INVOKE);
    assertEquals(3, cache.cache.size());
    getEntries(cache, allKeys, INVOKE);
    assertEquals(3, cache.cache.size());
    updateEntries(cache, map2, WriteMode.INVOKE);
    assertEquals(6, cache.cache.size());
    getEntries(cache, keys2, INVOKE);
    assertEquals(6, cache.cache.size());
    removeEntries(cache, keys1, WriteMode.INVOKE);
    assertEquals(3, cache.cache.size());
    removeEntries(cache, keys1, WriteMode.INVOKE);
    assertEquals(3, cache.cache.size());
    getEntries(cache, allKeys, INVOKE);
    assertEquals(3, cache.cache.size());
    updateEntries(cache, map1, WriteMode.INVOKE);
    assertEquals(6, cache.cache.size());
    removeEntries(cache, allKeys, WriteMode.INVOKE);
    assertEquals(0, cache.cache.size());
    getEntries(cache, allKeys, INVOKE);
    assertEquals(0, cache.cache.size());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) PUT(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.WriteMode.PUT) GET(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.GET) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) Transaction(org.apache.ignite.transactions.Transaction) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Function(java.util.function.Function) EntryProcessorException(javax.cache.processor.EntryProcessorException) SQL(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.SQL) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MutableEntry(javax.cache.processor.MutableEntry) Map(java.util.Map) LinkedHashSet(java.util.LinkedHashSet) F(org.apache.ignite.internal.util.typedef.F) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Set(java.util.Set) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) CacheEntryProcessor(org.apache.ignite.cache.CacheEntryProcessor) INVOKE(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.INVOKE) IgniteTransactions(org.apache.ignite.IgniteTransactions) DML(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.WriteMode.DML) CacheMode(org.apache.ignite.cache.CacheMode) Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 2 with INVOKE

use of org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.INVOKE in project ignite by apache.

the class MvccRepeatableReadBulkOpsTest method checkOperationsConsistency.

/**
 * Checks SQL and CacheAPI operation see consistent results before and after update.
 *
 * @throws Exception If failed.
 */
private void checkOperationsConsistency(WriteMode writeMode, boolean requestFromClient) throws Exception {
    Ignite node = grid(requestFromClient ? nodesCount() - 1 : 0);
    TestCache<Integer, MvccTestAccount> cache = new TestCache<>(node.cache(DEFAULT_CACHE_NAME));
    final Set<Integer> keysForUpdate = new HashSet<>(3);
    final Set<Integer> keysForRemove = new HashSet<>(3);
    final Set<Integer> allKeys = generateKeySet(grid(0).cache(DEFAULT_CACHE_NAME), keysForUpdate, keysForRemove);
    try {
        int updCnt = 1;
        final Map<Integer, MvccTestAccount> initialVals = allKeys.stream().collect(Collectors.toMap(k -> k, k -> new MvccTestAccount(k, 1)));
        updateEntries(cache, initialVals, writeMode);
        assertEquals(initialVals.size(), cache.cache.size());
        IgniteTransactions txs = node.transactions();
        Map<Integer, MvccTestAccount> updatedVals = null;
        try (Transaction tx = txs.txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) {
            Map<Integer, MvccTestAccount> vals1 = getEntries(cache, allKeys, GET);
            Map<Integer, MvccTestAccount> vals2 = getEntries(cache, allKeys, SQL);
            Map<Integer, MvccTestAccount> vals3 = getEntries(cache, allKeys, ReadMode.INVOKE);
            assertEquals(initialVals, vals1);
            assertEquals(initialVals, vals2);
            assertEquals(initialVals, vals3);
            assertEquals(initialVals.size(), cache.cache.size());
            for (ReadMode readMode : new ReadMode[] { GET, SQL, INVOKE }) {
                int updCnt0 = ++updCnt;
                updatedVals = allKeys.stream().collect(Collectors.toMap(Function.identity(), k -> new MvccTestAccount(k, updCnt0)));
                updateEntries(cache, updatedVals, writeMode);
                assertEquals(allKeys.size(), cache.cache.size());
                removeEntries(cache, keysForRemove, writeMode);
                for (Integer key : keysForRemove) updatedVals.remove(key);
                assertEquals(String.valueOf(readMode), updatedVals, getEntries(cache, allKeys, readMode));
            }
            tx.commit();
        }
        try (Transaction tx = txs.txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) {
            assertEquals(updatedVals, getEntries(cache, allKeys, GET));
            assertEquals(updatedVals, getEntries(cache, allKeys, SQL));
            assertEquals(updatedVals, getEntries(cache, allKeys, INVOKE));
            tx.commit();
        }
        assertEquals(updatedVals.size(), cache.cache.size());
    } finally {
        cache.cache.removeAll(keysForUpdate);
    }
    assertEquals(0, cache.cache.size());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) PUT(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.WriteMode.PUT) GET(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.GET) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) Transaction(org.apache.ignite.transactions.Transaction) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Function(java.util.function.Function) EntryProcessorException(javax.cache.processor.EntryProcessorException) SQL(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.SQL) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MutableEntry(javax.cache.processor.MutableEntry) Map(java.util.Map) LinkedHashSet(java.util.LinkedHashSet) F(org.apache.ignite.internal.util.typedef.F) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Set(java.util.Set) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) CacheEntryProcessor(org.apache.ignite.cache.CacheEntryProcessor) INVOKE(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.INVOKE) IgniteTransactions(org.apache.ignite.IgniteTransactions) DML(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.WriteMode.DML) CacheMode(org.apache.ignite.cache.CacheMode) IgniteTransactions(org.apache.ignite.IgniteTransactions) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Callable (java.util.concurrent.Callable)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeUnit (java.util.concurrent.TimeUnit)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 EntryProcessorException (javax.cache.processor.EntryProcessorException)2 EntryProcessorResult (javax.cache.processor.EntryProcessorResult)2 MutableEntry (javax.cache.processor.MutableEntry)2 Ignite (org.apache.ignite.Ignite)2 IgniteCache (org.apache.ignite.IgniteCache)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteTransactions (org.apache.ignite.IgniteTransactions)2 CacheEntryProcessor (org.apache.ignite.cache.CacheEntryProcessor)2