use of org.apache.ignite.transactions.TransactionConcurrency in project ignite by apache.
the class GridCacheInterceptorAbstractSelfTest method testNearNodeKey.
/**
* @throws Exception If failed.
*/
public void testNearNodeKey() throws Exception {
if (cacheMode() != PARTITIONED)
return;
if (atomicityMode() == TRANSACTIONAL) {
for (TransactionConcurrency txConcurrency : TransactionConcurrency.values()) {
for (TransactionIsolation txIsolation : TransactionIsolation.values()) {
for (Operation op : Operation.values()) {
testNearNodeKey(txConcurrency, txIsolation, op);
afterTest();
}
}
}
}
testNearNodeKey(null, null, null);
}
use of org.apache.ignite.transactions.TransactionConcurrency 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.TransactionConcurrency in project ignite by apache.
the class IgniteCacheNoLoadPreviousValueAbstractTest method testNoLoadPreviousValue.
/**
* @throws Exception If failed.
*/
public void testNoLoadPreviousValue() throws Exception {
IgniteCache<Integer, Integer> cache = jcache(0);
for (Integer key : keys()) {
log.info("Test [key=" + key + ']');
storeMap.put(key, key);
assertEquals(key, cache.get(key));
assertEquals(key, storeMap.get(key));
cache.remove(key);
assertNull(storeMap.get(key));
storeMap.put(key, key);
assertNull("Invalid for key: " + key, cache.getAndPut(key, -1));
assertEquals(-1, storeMap.get(key));
cache.remove(key);
assertNull(storeMap.get(key));
storeMap.put(key, key);
assertTrue(cache.putIfAbsent(key, -1));
assertEquals(-1, storeMap.get(key));
cache.remove(key);
assertNull(storeMap.get(key));
storeMap.put(key, key);
assertNull(cache.getAndRemove(key));
assertNull(storeMap.get(key));
storeMap.put(key, key);
assertNull(cache.getAndPutIfAbsent(key, -1));
assertEquals(-1, storeMap.get(key));
cache.remove(key);
assertNull(storeMap.get(key));
storeMap.put(key, key);
assertFalse(cache.replace(key, -1));
assertEquals(key, storeMap.get(key));
assertNull(cache.getAndReplace(key, -1));
assertEquals(key, storeMap.get(key));
assertFalse(cache.replace(key, key, -1));
assertEquals(key, storeMap.get(key));
}
Map<Integer, Integer> expData = new HashMap<>();
for (int i = 1000_0000; i < 1000_0000 + 1000; i++) {
storeMap.put(i, i);
expData.put(i, i);
}
assertEquals(expData, cache.getAll(expData.keySet()));
if (atomicityMode() == TRANSACTIONAL) {
for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
for (Integer key : keys()) {
log.info("Test tx [key=" + key + ", concurrency=" + concurrency + ", isolation=" + isolation + ']');
storeMap.put(key, key);
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
assertNull("Invalid value [concurrency=" + concurrency + ", isolation=" + isolation + ']', cache.getAndPut(key, -1));
tx.commit();
}
assertEquals(-1, storeMap.get(key));
cache.remove(key);
assertNull(storeMap.get(key));
storeMap.put(key, key);
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
assertTrue(cache.putIfAbsent(key, -1));
tx.commit();
}
assertEquals(-1, storeMap.get(key));
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
assertEquals(expData, cache.getAll(expData.keySet()));
tx.commit();
}
}
}
}
}
}
use of org.apache.ignite.transactions.TransactionConcurrency in project ignite by apache.
the class IgniteCacheNoWriteThroughAbstractTest method testNoWriteThrough.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("UnnecessaryLocalVariable")
public void testNoWriteThrough() throws Exception {
IgniteCache<Integer, Integer> cache = jcache(0);
for (Integer key : keys()) {
log.info("Test [key=" + key + ']');
final Integer storeVal = key;
storeMap.put(key, storeVal);
assertEquals(key, cache.get(key));
cache.remove(key);
assertEquals(storeVal, storeMap.get(key));
storeMap.remove(key);
assertNull(cache.get(key));
assertTrue(cache.putIfAbsent(key, key));
assertNull(storeMap.get(key));
assertEquals(key, cache.get(key));
cache.remove(key);
storeMap.put(key, storeVal);
Integer val = key + 1;
assertFalse(cache.putIfAbsent(key, val));
assertEquals(storeVal, storeMap.get(key));
cache.put(key, val);
assertEquals(val, cache.get(key));
assertEquals(storeVal, storeMap.get(key));
val = val + 1;
assertTrue(cache.replace(key, val));
assertEquals(val, cache.get(key));
assertEquals(storeVal, storeMap.get(key));
cache.remove(key);
assertEquals(storeVal, storeMap.get(key));
storeMap.remove(key);
assertNull(cache.get(key));
storeMap.put(key, storeVal);
val = val + 1;
assertEquals(storeVal, cache.getAndPut(key, val));
assertEquals(storeVal, storeMap.get(key));
assertEquals(val, cache.get(key));
cache.remove(key);
assertEquals(storeVal, storeMap.get(key));
assertEquals(storeVal, cache.getAndRemove(key));
cache.remove(key);
assertEquals(storeVal, storeMap.get(key));
Object ret = cache.invoke(key, new EntryProcessor<Integer, Integer, Object>() {
@Override
public Object process(MutableEntry<Integer, Integer> entry, Object... args) {
Integer val = entry.getValue();
entry.setValue(val + 1);
return String.valueOf(val);
}
});
assertEquals(String.valueOf(storeVal), ret);
assertEquals(storeVal + 1, (int) cache.get(key));
assertEquals(storeVal, storeMap.get(key));
assertTrue(cache.replace(key, storeVal + 1, storeVal + 2));
assertEquals(storeVal, storeMap.get(key));
assertEquals(storeVal + 2, (int) cache.get(key));
}
Map<Integer, Integer> expData = new HashMap<>();
for (int i = 1000_0000; i < 1000_0000 + 1000; i++) {
storeMap.put(i, i);
expData.put(i, i);
}
assertEquals(expData, cache.getAll(expData.keySet()));
storeMap.clear();
cache.putAll(expData);
assertTrue(storeMap.isEmpty());
assertEquals(expData, cache.getAll(expData.keySet()));
Map<Integer, Integer> expData0 = new HashMap<>();
for (int i = 1000_0000; i < 1000_0000 + 1000; i++) expData0.put(i, 1);
cache.invokeAll(expData.keySet(), new EntryProcessor<Integer, Integer, Object>() {
@Override
public Object process(MutableEntry<Integer, Integer> entry, Object... args) {
entry.setValue(1);
return null;
}
});
assertEquals(expData0, cache.getAll(expData0.keySet()));
assertTrue(storeMap.isEmpty());
storeMap.putAll(expData);
cache.removeAll(expData.keySet());
assertEquals(1000, storeMap.size());
storeMap.clear();
assertTrue(cache.getAll(expData.keySet()).isEmpty());
if (atomicityMode() == TRANSACTIONAL) {
for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
for (Integer key : keys()) {
log.info("Test tx [key=" + key + ", concurrency=" + concurrency + ", isolation=" + isolation + ']');
storeMap.put(key, key);
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
assertEquals("For concurrency=" + concurrency + ", isolation=" + isolation + ']', key, cache.getAndPut(key, -1));
tx.commit();
}
assertEquals(-1, (int) cache.get(key));
assertEquals(key, storeMap.get(key));
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
cache.put(key, -2);
tx.commit();
}
assertEquals(-2, (int) cache.get(key));
assertEquals(key, storeMap.get(key));
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
assertEquals(-2, (int) cache.getAndRemove(key));
tx.commit();
}
assertEquals(key, storeMap.get(key));
storeMap.remove(key);
assertNull(cache.get(key));
storeMap.put(key, key);
cache.put(key, key);
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
assertTrue(cache.replace(key, -1));
tx.commit();
}
assertEquals(-1, (int) cache.get(key));
assertEquals(key, storeMap.get(key));
cache.remove(key);
storeMap.clear();
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
cache.putAll(expData);
tx.commit();
}
assertTrue(storeMap.isEmpty());
assertEquals(expData, cache.getAll(expData.keySet()));
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
cache.invokeAll(expData.keySet(), new EntryProcessor<Integer, Integer, Object>() {
@Override
public Object process(MutableEntry<Integer, Integer> entry, Object... args) {
entry.setValue(1);
return null;
}
});
tx.commit();
}
assertEquals(expData0, cache.getAll(expData.keySet()));
assertTrue(storeMap.isEmpty());
storeMap.putAll(expData);
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
cache.removeAll(expData.keySet());
tx.commit();
}
assertEquals(1000, storeMap.size());
storeMap.clear();
assertTrue(cache.getAll(expData.keySet()).isEmpty());
}
}
}
}
}
use of org.apache.ignite.transactions.TransactionConcurrency in project ignite by apache.
the class IgniteCacheExpiryPolicyAbstractTest method testAccess.
/**
* @throws Exception If failed.
*/
public void testAccess() throws Exception {
fail("https://issues.apache.org/jira/browse/IGNITE-305");
factory = new FactoryBuilder.SingletonFactory<>(new TestPolicy(60_000L, 61_000L, 62_000L));
startGrids();
for (final Integer key : keys()) {
log.info("Test access [key=" + key + ']');
access(key);
}
accessGetAll();
for (final Integer key : keys()) {
log.info("Test filterAccessRemove access [key=" + key + ']');
filterAccessRemove(key);
}
for (final Integer key : keys()) {
log.info("Test filterAccessReplace access [key=" + key + ']');
filterAccessReplace(key);
}
if (atomicityMode() == TRANSACTIONAL) {
TransactionConcurrency[] txModes = { PESSIMISTIC };
for (TransactionConcurrency txMode : txModes) {
for (final Integer key : keys()) {
log.info("Test txGet [key=" + key + ", txMode=" + txMode + ']');
txGet(key, txMode);
}
}
for (TransactionConcurrency txMode : txModes) {
log.info("Test txGetAll [txMode=" + txMode + ']');
txGetAll(txMode);
}
}
IgniteCache<Integer, Integer> cache = jcache(0);
Collection<Integer> putKeys = keys();
info("Put keys: " + putKeys);
for (final Integer key : putKeys) cache.put(key, key);
Iterator<Cache.Entry<Integer, Integer>> it = cache.iterator();
List<Integer> itKeys = new ArrayList<>();
while (it.hasNext()) itKeys.add(it.next().getKey());
info("It keys: " + itKeys);
assertTrue(itKeys.size() >= putKeys.size());
for (Integer key : itKeys) {
info("Checking iterator key: " + key);
checkTtl(key, 62_000L, true);
}
}
Aggregations