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());
}
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());
}
Aggregations