use of org.apache.ignite.transactions.TransactionConcurrency 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 {
final Ignite ignite = grid(0);
final CacheConfiguration<String, TestClass> ccfg = cacheConfiguration(mode, atomMode, nearEnabled, useEvicPlc);
final IgniteCache<String, TestClass> cache = ignite.createCache(ccfg);
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()) {
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.TransactionConcurrency in project ignite by apache.
the class GridCacheEmptyEntriesAbstractSelfTest method checkPolicy0.
/**
* Tests preset eviction policy.
*
* @throws Exception If failed.
*/
private void checkPolicy0() throws Exception {
for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
txConcurrency = concurrency;
for (TransactionIsolation isolation : TransactionIsolation.values()) {
txIsolation = isolation;
Ignite g = startGrids();
IgniteCache<String, String> cache = g.cache(DEFAULT_CACHE_NAME);
try {
info(">>> Checking policy [txConcurrency=" + txConcurrency + ", txIsolation=" + txIsolation + ", plc=" + plc + ", nearPlc=" + nearPlc + ']');
checkExplicitTx(g, cache);
checkImplicitTx(cache);
} finally {
stopAllGrids();
}
}
}
}
use of org.apache.ignite.transactions.TransactionConcurrency in project ignite by apache.
the class IgniteCacheExpiryPolicyAbstractTest method testCreateUpdate.
/**
* @throws Exception If failed.
*/
public void testCreateUpdate() throws Exception {
factory = new FactoryBuilder.SingletonFactory<>(new TestPolicy(60_000L, 61_000L, null));
startGrids();
for (final Integer key : keys()) {
log.info("Test createUpdate [key=" + key + ']');
createUpdate(key, null);
}
for (final Integer key : keys()) {
log.info("Test createUpdateCustomPolicy [key=" + key + ']');
createUpdateCustomPolicy(key, null);
}
createUpdatePutAll(null);
if (atomicityMode() == TRANSACTIONAL) {
TransactionConcurrency[] txModes = new TransactionConcurrency[] { PESSIMISTIC, OPTIMISTIC };
for (TransactionConcurrency tx : txModes) {
for (final Integer key : keys()) {
log.info("Test createUpdate [key=" + key + ", tx=" + tx + ']');
createUpdate(key, tx);
}
for (final Integer key : keys()) {
log.info("Test createUpdateCustomPolicy [key=" + key + ", tx=" + tx + ']');
createUpdateCustomPolicy(key, tx);
}
createUpdatePutAll(tx);
}
}
}
use of org.apache.ignite.transactions.TransactionConcurrency 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 {
Ignite ignite = ignite(0);
IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
try {
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()) {
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