use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class WithKeepBinaryCacheFullApiTest method testInvokeTx.
/**
* @throws Exception If failed.
*/
@Test
public void testInvokeTx() throws Exception {
if (!txShouldBeUsed())
return;
for (TransactionConcurrency conc : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
info(">>>>> Executing test using explicit txs [concurrency=" + conc + ", isolation=" + isolation + "]");
checkInvokeTx(conc, isolation);
jcache().removeAll();
}
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteAbstractTxSuspendResumeTest method testResumeTxInAnotherThread.
/**
* Test for transaction starting in one thread, continuing in another.
*
* @throws Exception If failed.
*/
@Test
public void testResumeTxInAnotherThread() throws Exception {
executeTestForAllCaches(new CI2Exc<Ignite, IgniteCache<Integer, Integer>>() {
@Override
public void applyx(Ignite ignite, final IgniteCache<Integer, Integer> cache) throws Exception {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
final Transaction tx = ignite.transactions().txStart(transactionConcurrency(), isolation);
final AtomicInteger cntr = new AtomicInteger(0);
for (int j = -1; j > -10; j--) cache.put(j, j);
cache.put(cntr.get(), cntr.getAndIncrement());
tx.suspend();
assertEquals(SUSPENDED, tx.state());
assertNull("Thread already have tx", ignite.transactions().tx());
assertNull(cache.get(-1));
assertNull(cache.get(cntr.get()));
for (int i = 0; i < 10; i++) {
GridTestUtils.runAsync(() -> {
assertEquals(SUSPENDED, tx.state());
tx.resume();
assertEquals(ACTIVE, tx.state());
for (int j = -1; j > -10; j--) cache.put(j, j);
cache.put(cntr.get(), cntr.getAndIncrement());
tx.suspend();
}).get(FUT_TIMEOUT);
}
tx.resume();
for (int j = -1; j > -10; j--) cache.remove(j);
tx.commit();
assertEquals(COMMITTED, tx.state());
for (int i = 0; i < cntr.get(); i++) assertEquals(i, (int) cache.get(i));
assertFalse(cache.containsKey(-1));
cache.removeAll();
}
}
});
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteAbstractTxSuspendResumeTest method testMultiTxSuspendResume.
/**
* Test for starting and suspending transactions, and then resuming and committing in another thread.
*
* @throws Exception If failed.
*/
@Test
public void testMultiTxSuspendResume() throws Exception {
executeTestForAllCaches(new CI2Exc<Ignite, IgniteCache<Integer, Integer>>() {
@Override
public void applyx(Ignite ignite, final IgniteCache<Integer, Integer> cache) throws Exception {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
final List<Transaction> clientTxs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Transaction tx = ignite.transactions().txStart(transactionConcurrency(), isolation);
cache.put(i, i);
tx.suspend();
clientTxs.add(tx);
}
GridTestUtils.runMultiThreaded(new CI1<Integer>() {
@Override
public void apply(Integer idx) {
Transaction tx = clientTxs.get(idx);
assertEquals(SUSPENDED, tx.state());
tx.resume();
assertEquals(ACTIVE, tx.state());
tx.commit();
}
}, 10, "th-suspend");
for (int i = 0; i < 10; i++) assertEquals(i, (int) cache.get(i));
cache.removeAll();
}
}
});
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteCacheTxIteratorSelfTest method checkTxCache.
/**
* @throws Exception If failed.
*/
private void checkTxCache(CacheMode mode, CacheAtomicityMode atomMode, boolean nearEnabled, boolean useEvicPlc) throws Exception {
if (atomMode == CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) {
if (!MvccFeatureChecker.isSupported(mode) || (nearEnabled && !MvccFeatureChecker.isSupported(Feature.NEAR_CACHE)) || (useEvicPlc && !MvccFeatureChecker.isSupported(Feature.EVICTION)))
// Nothing to do. Mode is not supported.
return;
}
final Ignite ignite = grid(0);
final CacheConfiguration<String, TestClass> ccfg = cacheConfiguration(mode, atomMode, nearEnabled, useEvicPlc);
final IgniteCache<String, TestClass> cache = ignite.createCache(ccfg).withAllowAtomicOpsInTx();
info("Checking cache [mode=" + mode + ", atomMode=" + atomMode + ", near=" + nearEnabled + ", evict=" + useEvicPlc + ']');
try {
for (int i = 0; i < 30; i++) {
final TestClass val = new TestClass("data");
final String key = "key-" + i;
cache.put(key, val);
assertEquals(i + 1, cache.size());
for (TransactionIsolation iso : TransactionIsolation.values()) {
for (TransactionConcurrency con : TransactionConcurrency.values()) {
if (atomMode == CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT && !MvccFeatureChecker.isSupported(con, iso))
// Mode not supported.
continue;
try (Transaction transaction = ignite.transactions().txStart(con, iso)) {
assertEquals(val, cache.get(key));
transaction.commit();
}
int cnt = iterateOverKeys(cache);
assertEquals("Failed [con=" + con + ", iso=" + iso + ']', i + 1, cnt);
assertEquals("Failed [con=" + con + ", iso=" + iso + ']', i + 1, cache.size());
}
}
}
} finally {
grid(0).destroyCache(CACHE_NAME);
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class WrongQueryEntityFieldTypeTest method testPutFromThinClientTx.
/**
*/
@Test
public void testPutFromThinClientTx() throws Exception {
if (mode == ATOMIC)
return;
withThinClient((cli, cache) -> {
for (TransactionConcurrency conc : TransactionConcurrency.values()) {
for (TransactionIsolation iso : TransactionIsolation.values()) {
if (conc == OPTIMISTIC && mode == TRANSACTIONAL_SNAPSHOT)
continue;
assertThrowsWithCause(() -> {
try (ClientTransaction tx = cli.transactions().txStart(conc, iso)) {
cache.put(1, val.get());
tx.commit();
}
}, ClientException.class);
assertNull(cache.withKeepBinary().get(1));
}
}
});
}
Aggregations