use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class CacheTxFastFinishTest method fastFinishTx.
/**
* @param ignite Node.
*/
protected void fastFinishTx(Ignite ignite) {
IgniteTransactions txs = ignite.transactions();
IgniteCache cache = ignite.cache(DEFAULT_CACHE_NAME);
for (boolean commit : new boolean[] { true, false }) {
for (TransactionConcurrency c : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
try (Transaction tx = txs.txStart(c, isolation)) {
checkFastTxFinish(tx, commit);
}
}
}
for (int i = 0; i < 100; i++) {
try (Transaction tx = txs.txStart(OPTIMISTIC, REPEATABLE_READ)) {
cache.get(i);
checkFastTxFinish(tx, commit);
}
try (Transaction tx = txs.txStart(OPTIMISTIC, READ_COMMITTED)) {
cache.get(i);
checkFastTxFinish(tx, commit);
}
}
for (int i = 0; i < 100; i++) {
try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
cache.get(i);
checkNormalTxFinish(tx, commit, true);
}
try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.get(i);
checkNormalTxFinish(tx, commit, true);
}
}
for (int i = 0; i < 100; i++) {
for (TransactionConcurrency c : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
try (Transaction tx = txs.txStart(c, isolation)) {
cache.put(i, i);
checkNormalTxFinish(tx, commit, false);
}
}
}
}
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method testKeepBinaryTxOverwrite.
/**
* @throws Exception if failed.
*/
@Test
public void testKeepBinaryTxOverwrite() throws Exception {
if (atomicityMode() != TRANSACTIONAL)
return;
IgniteCache<Integer, TestObject> cache = ignite(0).cache(DEFAULT_CACHE_NAME);
cache.put(0, new TestObject(1));
for (TransactionConcurrency conc : TransactionConcurrency.values()) {
for (TransactionIsolation iso : TransactionIsolation.values()) {
try (Transaction tx = ignite(0).transactions().txStart(conc, iso)) {
cache.withKeepBinary().get(0);
cache.invoke(0, new ObjectEntryProcessor());
tx.commit();
}
}
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgnitePessimisticTxSuspendResumeTest method testExplicitLockAndSuspendResume.
/**
* Test explicit locks, implicit transactions and suspend/resume of pessimistic transactions.
*
* @throws Exception If failed.
*/
@Test
public void testExplicitLockAndSuspendResume() throws Exception {
// TODO: IGNITE-9324 Lock operations are not supported when MVCC is enabled.
if (FORCE_MVCC)
return;
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()) {
List<Lock> locks = new ArrayList<>(10);
for (int j = 0; j < 10; j++) {
cache.put(j, j);
Lock lock = cache.lock(j);
locks.add(lock);
lock.lock();
// Re-enter.
if (j >= 5) {
lock = cache.lock(j);
locks.add(lock);
lock.lock();
}
cache.put(j, j);
}
final Transaction tx = ignite.transactions().txStart(transactionConcurrency(), isolation);
for (int j = 10; j < 20; j++) cache.put(j, j);
tx.suspend();
assertNull(cache.get(10));
for (int j = 10; j < 20; j++) assertFalse("Locked key " + j, cache.lock(j).tryLock());
for (int i = 0; i < 10; i++) {
final int key = i;
GridTestUtils.runAsync(() -> {
tx.resume();
cache.put(key + 10, key + 10);
cache.put(key + 20, key + 20);
tx.suspend();
assertFalse("Locked key " + key, cache.lock(key).tryLock());
assertFalse("Locked key " + (key + 10), cache.lock(key + 10).tryLock());
assertFalse("Locked key " + (key + 20), cache.lock(key + 20).tryLock());
cache.put(key + 30, key + 30);
Lock lock = cache.lock(key + 30);
assertTrue("Can't lock key " + (key + 30), lock.tryLock());
cache.put(key + 30, key + 30);
lock.unlock();
cache.put(key + 30, key + 30);
}).get(FUT_TIMEOUT);
}
for (int j = 10; j < 30; j++) assertFalse("Locked key " + j, cache.lock(j).tryLock());
tx.resume();
tx.commit();
for (Lock lock : locks) lock.unlock();
for (int i = 0; i < 30; i++) assertEquals(i, (int) cache.get(i));
GridTestUtils.runAsync(() -> {
for (int j = 0; j < 40; j++) {
Lock lock = cache.lock(j);
assertTrue("Can't lock key " + j, lock.tryLock());
cache.put(j, j);
lock.unlock();
cache.put(j, j);
}
}).get(FUT_TIMEOUT);
cache.removeAll();
}
}
});
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteTxCachePrimarySyncTest method singleKeyCommitFromPrimary.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void singleKeyCommitFromPrimary(CacheConfiguration<Object, Object> ccfg) throws Exception {
if (MvccFeatureChecker.forcedMvcc()) {
if (ccfg.getCacheStoreFactory() != null && !MvccFeatureChecker.isSupported(Feature.CACHE_STORE))
return;
if (ccfg.getNearConfiguration() != null && !MvccFeatureChecker.isSupported(Feature.NEAR_CACHE))
return;
}
Ignite ignite = ignite(0);
IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
try {
for (int i = 0; i < SRVS; i++) {
Ignite node = ignite(i);
singleKeyCommitFromPrimary(node, ccfg, new IgniteBiInClosure<Integer, IgniteCache<Object, Object>>() {
@Override
public void apply(Integer key, IgniteCache<Object, Object> cache) {
cache.put(key, key);
}
});
for (final TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (final TransactionIsolation isolation : TransactionIsolation.values()) {
if (MvccFeatureChecker.forcedMvcc() && !MvccFeatureChecker.isSupported(concurrency, isolation))
continue;
singleKeyCommitFromPrimary(node, ccfg, new IgniteBiInClosure<Integer, IgniteCache<Object, Object>>() {
@Override
public void apply(Integer key, IgniteCache<Object, Object> cache) {
Ignite ignite = cache.unwrap(Ignite.class);
try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
cache.put(key, key);
tx.commit();
}
}
});
}
}
}
} finally {
ignite.destroyCache(cache.getName());
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteTxCachePrimarySyncTest method checkWaitPrimaryResponse.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void checkWaitPrimaryResponse(CacheConfiguration<Object, Object> ccfg) throws Exception {
if (MvccFeatureChecker.forcedMvcc()) {
if (ccfg.getCacheStoreFactory() != null && !MvccFeatureChecker.isSupported(Feature.CACHE_STORE))
return;
if (ccfg.getNearConfiguration() != null && !MvccFeatureChecker.isSupported(Feature.NEAR_CACHE))
return;
}
Ignite ignite = ignite(0);
IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
try {
if (!MvccFeatureChecker.forcedMvcc() || MvccFeatureChecker.isSupported(Feature.NEAR_CACHE))
ignite(NODES - 1).createNearCache(ccfg.getName(), new NearCacheConfiguration<>());
for (int i = 1; i < NODES; i++) {
Ignite node = ignite(i);
log.info("Test node: " + node.name());
checkWaitPrimaryResponse(node, ccfg, new IgniteBiInClosure<Integer, IgniteCache<Object, Object>>() {
@Override
public void apply(Integer key, IgniteCache<Object, Object> cache) {
cache.put(key, key);
}
});
checkWaitPrimaryResponse(node, ccfg, new IgniteBiInClosure<Integer, IgniteCache<Object, Object>>() {
@Override
public void apply(Integer key, IgniteCache<Object, Object> cache) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < 50; i++) map.put(i, i);
map.put(key, key);
cache.putAll(map);
}
});
for (final TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (final TransactionIsolation isolation : TransactionIsolation.values()) {
if (MvccFeatureChecker.forcedMvcc() && !MvccFeatureChecker.isSupported(concurrency, isolation))
continue;
checkWaitPrimaryResponse(node, ccfg, new IgniteBiInClosure<Integer, IgniteCache<Object, Object>>() {
@Override
public void apply(Integer key, IgniteCache<Object, Object> cache) {
Ignite ignite = cache.unwrap(Ignite.class);
try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
cache.put(key, key);
tx.commit();
}
}
});
checkWaitPrimaryResponse(node, ccfg, new IgniteBiInClosure<Integer, IgniteCache<Object, Object>>() {
@Override
public void apply(Integer key, IgniteCache<Object, Object> cache) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < 50; i++) map.put(i, i);
map.put(key, key);
Ignite ignite = cache.unwrap(Ignite.class);
try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
cache.putAll(map);
tx.commit();
}
}
});
}
}
}
} finally {
ignite.destroyCache(cache.getName());
}
}
Aggregations