use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteCacheThreadLocalTxTest method threadLocalTx.
/**
* @param node Node.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void threadLocalTx(Ignite node) throws Exception {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setAtomicityMode(TRANSACTIONAL);
ccfg.setBackups(2);
IgniteCache<Object, Object> cache = node.getOrCreateCache(ccfg);
checkNoTx(node);
boolean[] reads = { true, false };
boolean[] writes = { true, false };
int endOps = 5;
for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
for (boolean read : reads) {
for (boolean write : writes) {
for (int i = 0; i < endOps; i++) checkTx(concurrency, isolation, node, cache, read, write, i);
}
}
}
}
checkNoTx(node);
cache.put(1, 1);
checkNoTx(node);
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteTxCachePrimarySyncTest method singleKeyPrimaryNodeLeft.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void singleKeyPrimaryNodeLeft(CacheConfiguration<Object, Object> ccfg) throws Exception {
Ignite ignite = ignite(0);
IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
try {
ignite(NODES - 1).createNearCache(ccfg.getName(), new NearCacheConfiguration<>());
for (int i = 0; i < NODES; i++) {
Ignite node = ignite(i);
singleKeyPrimaryNodeLeft(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()) {
singleKeyPrimaryNodeLeft(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 checkOnePhaseMessages.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void checkOnePhaseMessages(CacheConfiguration<Object, Object> ccfg) throws Exception {
Ignite ignite = ignite(0);
IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
try {
for (int i = 1; i < NODES; i++) {
Ignite node = ignite(i);
log.info("Test node: " + node.name());
checkOnePhaseMessages(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()) {
checkOnePhaseMessages(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 CacheTxFastFinishTest method fastFinishTx.
/**
* @param ignite Node.
*/
private 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);
}
try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.get(i);
checkNormalTxFinish(tx, commit);
}
}
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);
}
}
}
}
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class CacheReadThroughRestartSelfTest method testReadThroughInTx.
/**
* @throws Exception If failed.
*/
private void testReadThroughInTx(boolean needVer) throws Exception {
IgniteCache<String, Integer> cache = grid(1).cache(DEFAULT_CACHE_NAME);
for (int k = 0; k < 1000; k++) cache.put("key" + k, k);
stopAllGrids();
startGrids(2);
awaitPartitionMapExchange();
Ignite ignite = grid(1);
cache = ignite.cache(DEFAULT_CACHE_NAME);
for (TransactionConcurrency txConcurrency : TransactionConcurrency.values()) {
for (TransactionIsolation txIsolation : TransactionIsolation.values()) {
try (Transaction tx = ignite.transactions().txStart(txConcurrency, txIsolation, 100000, 1000)) {
for (int k = 0; k < 1000; k++) {
String key = "key" + k;
if (needVer) {
assertNotNull("Null value for key: " + key, cache.getEntry(key));
assertNotNull("Null value for key: " + key, cache.getEntry(key));
} else {
assertNotNull("Null value for key: " + key, cache.get(key));
assertNotNull("Null value for key: " + key, cache.get(key));
}
}
tx.commit();
}
}
}
}
Aggregations