use of org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.SQL in project ignite by apache.
the class MvccRepeatableReadOperationsTest method testPutIfAbsentConsistency.
/**
* Check getAndPut/getAndRemove operations consistency.
*
* @throws IgniteCheckedException If failed.
*/
@Test
public void testPutIfAbsentConsistency() throws IgniteCheckedException {
Ignite node1 = grid(0);
TestCache<Integer, MvccTestAccount> cache1 = new TestCache<>(node1.cache(DEFAULT_CACHE_NAME));
final Set<Integer> keysForCreate = new HashSet<>(3);
final Set<Integer> keysForUpdate = new HashSet<>(3);
final Set<Integer> allKeys = generateKeySet(grid(0).cache(DEFAULT_CACHE_NAME), keysForCreate, keysForUpdate);
final Map<Integer, MvccTestAccount> initialMap = keysForUpdate.stream().collect(Collectors.toMap(k -> k, k -> new MvccTestAccount(k, 1)));
Map<Integer, MvccTestAccount> updatedMap = allKeys.stream().collect(Collectors.toMap(k -> k, k -> new MvccTestAccount(k, 1)));
cache1.cache.putAll(initialMap);
IgniteTransactions txs = node1.transactions();
try (Transaction tx = txs.txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) {
for (Integer key : keysForUpdate) // Check update.
assertFalse(cache1.cache.putIfAbsent(key, new MvccTestAccount(key, 2)));
for (Integer key : keysForCreate) // Check create.
assertTrue(cache1.cache.putIfAbsent(key, new MvccTestAccount(key, 1)));
assertEquals(updatedMap, getEntries(cache1, allKeys, SQL));
tx.commit();
}
assertEquals(updatedMap, getEntries(cache1, allKeys, SQL));
assertEquals(updatedMap, getEntries(cache1, allKeys, GET));
}
Aggregations