use of javax.cache.integration.CompletionListenerFuture in project ignite by apache.
the class IgniteCacheNoReadThroughAbstractTest method testNoReadThrough.
/**
* @throws Exception If failed.
*/
@Test
public void testNoReadThrough() throws Exception {
IgniteCache<Integer, Integer> cache = jcache(0);
for (Integer key : keys()) {
log.info("Test [key=" + key + ']');
storeMap.put(key, key);
assertNull(cache.get(key));
assertEquals(key, storeMap.get(key));
assertNull(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);
Object ret = cache.invoke(key, new EntryProcessor<Integer, Integer, Object>() {
@Override
public Object process(MutableEntry<Integer, Integer> e, Object... args) {
Integer val = e.getValue();
assertFalse(e.exists());
assertNull(val);
e.setValue(-1);
return String.valueOf(val);
}
});
assertEquals("null", ret);
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));
}
Set<Integer> keys = new HashSet<>();
for (int i = 1000_0000; i < 1000_0000 + 1000; i++) {
keys.add(i);
storeMap.put(i, i);
}
assertTrue(cache.getAll(keys).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)) {
assertNull(cache.get(key));
tx.commit();
}
assertEquals(key, storeMap.get(key));
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
assertNull(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));
cache.remove(key);
assertNull(storeMap.get(key));
storeMap.put(key, key);
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
Object ret = cache.invoke(key, new EntryProcessor<Integer, Integer, Object>() {
@Override
public Object process(MutableEntry<Integer, Integer> e, Object... args) {
Integer val = e.getValue();
assertFalse(e.exists());
assertNull(val);
e.setValue(-1);
return String.valueOf(val);
}
});
assertEquals("null", ret);
tx.commit();
}
assertEquals(-1, storeMap.get(key));
try (Transaction tx = ignite(0).transactions().txStart(concurrency, isolation)) {
assertTrue(cache.getAll(keys).isEmpty());
tx.commit();
}
}
}
}
}
// Check can load cache when read-through is disabled.
allowLoad = true;
Integer key = 1;
cache.remove(key);
storeMap.clear();
storeMap.put(key, 10);
cache.loadCache(null);
assertEquals(10, (int) cache.get(key));
cache.remove(key);
storeMap.put(key, 11);
CompletionListenerFuture fut = new CompletionListenerFuture();
cache.loadAll(F.asSet(key), true, fut);
fut.get();
assertEquals(11, (int) cache.get(key));
}
use of javax.cache.integration.CompletionListenerFuture in project ignite by apache.
the class GridCachePartitionedReloadAllAbstractSelfTest method testReloadAll.
/**
* @throws Exception If test failed.
*/
@Test
public void testReloadAll() throws Exception {
// Fill caches with values.
for (IgniteCache<Integer, String> cache : caches) {
Iterable<Integer> keys = primaryKeys(cache, 100);
info("Values [cache=" + caches.indexOf(cache) + ", size=" + F.size(keys.iterator()) + ", keys=" + keys + "]");
for (Integer key : keys) map.put(key, "val" + key);
}
CompletionListenerFuture fut = new CompletionListenerFuture();
caches.get(0).loadAll(map.keySet(), false, fut);
fut.get();
Affinity aff = ignite(0).affinity(DEFAULT_CACHE_NAME);
for (IgniteCache<Integer, String> cache : caches) {
for (Integer key : map.keySet()) {
if (aff.isPrimaryOrBackup(grid(caches.indexOf(cache)).localNode(), key))
assertEquals(map.get(key), cache.localPeek(key));
else
assertNull(cache.localPeek(key));
}
}
}
Aggregations