use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteTxStoreExceptionAbstractSelfTest method testPutPrimaryTx.
/**
* @throws Exception If failed.
*/
@Test
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));
}
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteOnePhaseCommitNearSelfTest method checkKey.
/**
* @param transactions Transactions instance.
* @param cache Cache instance.
* @param key Key.
*/
private void checkKey(IgniteTransactions transactions, Cache<Object, Object> cache, int key) throws Exception {
cache.put(key, key);
finalCheck(key, true);
TransactionIsolation[] isolations = { READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE };
TransactionConcurrency[] concurrencies = { OPTIMISTIC, PESSIMISTIC };
for (TransactionIsolation isolation : isolations) {
for (TransactionConcurrency concurrency : concurrencies) {
info("Checking transaction [isolation=" + isolation + ", concurrency=" + concurrency + ']');
try (Transaction tx = transactions.txStart(concurrency, isolation)) {
cache.put(key, isolation + "-" + concurrency);
tx.commit();
}
finalCheck(key, true);
}
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class CacheMvccTransactionsTest method testTxReadIsolationSimple.
/**
* @throws Exception If failed.
*/
@Test
public void testTxReadIsolationSimple() throws Exception {
Ignite srv0 = startGrids(4);
client = true;
startGrid(4);
for (CacheConfiguration ccfg : cacheConfigurations()) {
IgniteCache<Object, Object> cache0 = srv0.createCache(ccfg);
final Map<Integer, Integer> startVals = new HashMap<>();
final int KEYS = 10;
for (int i = 0; i < KEYS; i++) startVals.put(i, 0);
for (final TransactionIsolation isolation : TransactionIsolation.values()) {
for (final Ignite node : G.allGrids()) {
info("Run test [node=" + node.name() + ", isolation=" + isolation + ']');
try (Transaction tx = srv0.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache0.putAll(startVals);
tx.commit();
}
final CountDownLatch readStart = new CountDownLatch(1);
final CountDownLatch readProceed = new CountDownLatch(1);
IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
IgniteCache<Object, Object> cache = node.cache(DEFAULT_CACHE_NAME);
try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
assertEquals(0, checkAndGet(false, cache, 0, SCAN, GET));
readStart.countDown();
assertTrue(readProceed.await(5, TimeUnit.SECONDS));
assertEquals(0, checkAndGet(true, cache, 1, GET, SCAN));
assertEquals(0, checkAndGet(true, cache, 2, GET, SCAN));
Map<Object, Object> res = checkAndGetAll(true, cache, startVals.keySet(), GET, SCAN);
assertEquals(startVals.size(), res.size());
for (Map.Entry<Object, Object> e : res.entrySet()) assertEquals("Invalid value for key: " + e.getKey(), 0, e.getValue());
tx.rollback();
}
return null;
}
});
assertTrue(readStart.await(5, TimeUnit.SECONDS));
for (int i = 0; i < KEYS; i++) {
try (Transaction tx = srv0.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
if (i % 2 == 0)
cache0.put(i, 1);
else
cache0.remove(i);
tx.commit();
}
}
readProceed.countDown();
fut.get();
}
}
srv0.destroyCache(cache0.getName());
}
}
Aggregations