use of org.apache.ignite.transactions.TransactionConcurrency in project ignite by apache.
the class IndexingSpiQueryTxSelfTest method testIndexingSpiWithTx.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testIndexingSpiWithTx() throws Exception {
IgniteEx ignite = grid(0);
final IgniteCache<Integer, Integer> cache = ignite.cache("test-cache");
final IgniteTransactions txs = ignite.transactions();
for (final TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (final TransactionIsolation isolation : TransactionIsolation.values()) {
System.out.println("Run in transaction: " + concurrency + " " + isolation);
GridTestUtils.assertThrowsWithCause(new Callable<Void>() {
@Override
public Void call() throws Exception {
Transaction tx;
try (Transaction tx0 = tx = txs.txStart(concurrency, isolation)) {
cache.put(1, 1);
tx0.commit();
}
assertEquals(TransactionState.ROLLED_BACK, tx.state());
return null;
}
}, IgniteTxHeuristicCheckedException.class);
}
}
}
use of org.apache.ignite.transactions.TransactionConcurrency in project ignite by apache.
the class CacheStoreUsageMultinodeAbstractTest method checkStoreUpdate.
/**
* @param clientStore {@code True} if store configured on client node.
* @throws Exception If failed.
*/
protected void checkStoreUpdate(boolean clientStore) throws Exception {
Ignite client = grid(3);
assertTrue(client.configuration().isClientMode());
awaitPartitionMapExchange();
IgniteCache<Object, Object> cache0 = ignite(0).cache(DEFAULT_CACHE_NAME);
IgniteCache<Object, Object> cache1 = ignite(1).cache(DEFAULT_CACHE_NAME);
IgniteCache<Object, Object> clientCache = client.cache(DEFAULT_CACHE_NAME);
assertTrue(((IgniteCacheProxy) cache0).context().store().configured());
assertEquals(clientStore, ((IgniteCacheProxy) clientCache).context().store().configured());
List<TransactionConcurrency> tcList = new ArrayList<>();
tcList.add(null);
if (atomicityMode() == TRANSACTIONAL) {
tcList.add(TransactionConcurrency.OPTIMISTIC);
tcList.add(TransactionConcurrency.PESSIMISTIC);
}
log.info("Start test [atomicityMode=" + atomicityMode() + ", locStore=" + locStore + ", writeBehind=" + writeBehind + ", nearCache=" + nearCache + ", clientStore=" + clientStore + ']');
for (TransactionConcurrency tc : tcList) {
testStoreUpdate(cache0, primaryKey(cache0), tc);
testStoreUpdate(cache0, backupKey(cache0), tc);
testStoreUpdate(cache0, nearKey(cache0), tc);
testStoreUpdate(cache0, primaryKey(cache1), tc);
testStoreUpdate(clientCache, primaryKey(cache0), tc);
testStoreUpdate(clientCache, primaryKey(cache1), tc);
}
}
use of org.apache.ignite.transactions.TransactionConcurrency in project ignite by apache.
the class WithKeepBinaryCacheFullApiTest method testInvokeAsyncTx.
/**
* @throws Exception If failed.
*/
public void testInvokeAsyncTx() throws Exception {
if (!txShouldBeUsed())
return;
for (TransactionConcurrency conc : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
checkInvokeAsyncTx(conc, isolation);
jcache().removeAll();
}
}
}
use of org.apache.ignite.transactions.TransactionConcurrency in project ignite by apache.
the class WithKeepBinaryCacheFullApiTest method runInAllTxModes.
/**
* @param task Task.
* @throws Exception If failed.
*/
protected void runInAllTxModes(TestRunnable task) throws Exception {
info("Executing implicite tx");
task.run();
if (txShouldBeUsed()) {
for (TransactionConcurrency conc : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
try (Transaction tx = testedGrid().transactions().txStart(conc, isolation)) {
info("Executing explicite tx [isolation" + isolation + ", concurrency=" + conc + "]");
task.run();
tx.commit();
}
}
}
}
}
use of org.apache.ignite.transactions.TransactionConcurrency in project ignite by apache.
the class CacheGetEntryAbstractTest method test.
/**
* @param cfg Cache configuration.
* @param oneEntry If {@code true} then single entry is tested.
* @throws Exception If failed.
*/
private void test(CacheConfiguration cfg, final boolean oneEntry) throws Exception {
final IgniteCache<Integer, TestValue> cache = grid(0).createCache(cfg);
try {
init(cache);
test(cache, null, null, null, oneEntry);
if (cfg.getAtomicityMode() == TRANSACTIONAL) {
TransactionConcurrency txConcurrency = concurrency();
TransactionIsolation txIsolation = isolation();
try (Transaction tx = grid(0).transactions().txStart(txConcurrency, txIsolation)) {
initTx(cache);
test(cache, txConcurrency, txIsolation, tx, oneEntry);
tx.commit();
}
testConcurrentTx(cache, OPTIMISTIC, REPEATABLE_READ, oneEntry);
testConcurrentTx(cache, OPTIMISTIC, READ_COMMITTED, oneEntry);
testConcurrentTx(cache, PESSIMISTIC, REPEATABLE_READ, oneEntry);
testConcurrentTx(cache, PESSIMISTIC, READ_COMMITTED, oneEntry);
testConcurrentOptimisticTxGet(cache, REPEATABLE_READ);
testConcurrentOptimisticTxGet(cache, READ_COMMITTED);
testConcurrentOptimisticTxGet(cache, SERIALIZABLE);
}
} finally {
cache.destroy();
}
}
Aggregations