use of org.apache.ignite.cache.CacheEntry in project ignite by apache.
the class GridCacheQueryManager method sharedCacheSetIterator.
/**
* @param qry Query.
* @return Cache set items iterator.
*/
private GridCloseableIterator<IgniteBiTuple<K, V>> sharedCacheSetIterator(GridCacheQueryAdapter<?> qry) throws IgniteCheckedException {
final GridSetQueryPredicate filter = (GridSetQueryPredicate) qry.scanFilter();
IgniteUuid id = filter.setId();
GridCacheQueryAdapter<CacheEntry<K, ?>> qry0 = new GridCacheQueryAdapter<>(cctx, SCAN, new IgniteBiPredicate<Object, Object>() {
@Override
public boolean apply(Object k, Object v) {
return k instanceof SetItemKey && id.equals(((SetItemKey) k).setId());
}
}, new IgniteClosure<Map.Entry, Object>() {
@Override
public Object apply(Map.Entry entry) {
return new IgniteBiTuple<K, V>((K) ((SetItemKey) entry.getKey()).item(), (V) Boolean.TRUE);
}
}, qry.partition(), false, true, qry.isDataPageScanEnabled());
return scanQueryLocal(qry0, false);
}
use of org.apache.ignite.cache.CacheEntry in project ignite by apache.
the class CacheSerializableTransactionsTest method testTxCommitReadOnlyGetAll.
/**
* @throws Exception If failed.
*/
private void testTxCommitReadOnlyGetAll(boolean needVer) throws Exception {
Ignite ignite0 = ignite(0);
final IgniteTransactions txs = ignite0.transactions();
for (CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
logCacheInfo(ccfg);
try {
IgniteCache<Integer, Integer> cache = ignite0.createCache(ccfg);
Set<Integer> keys = new HashSet<>();
for (int i = 0; i < 100; i++) keys.add(i);
try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
if (needVer) {
Collection<CacheEntry<Integer, Integer>> c = cache.getEntries(keys);
assertTrue(c.isEmpty());
} else {
Map<Integer, Integer> map = cache.getAll(keys);
assertTrue(map.isEmpty());
}
tx.commit();
}
for (Integer key : keys) checkValue(key, null, cache.getName());
try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
if (needVer) {
Collection<CacheEntry<Integer, Integer>> c = cache.getEntries(keys);
assertTrue(c.isEmpty());
} else {
Map<Integer, Integer> map = cache.getAll(keys);
assertTrue(map.isEmpty());
}
tx.rollback();
}
for (Integer key : keys) checkValue(key, null, cache.getName());
} finally {
destroyCache(ccfg.getName());
}
}
}
use of org.apache.ignite.cache.CacheEntry in project ignite by apache.
the class GridCacheAbstractFullApiSelfTest method testGetEntries.
/**
* @throws Exception In case of error.
*/
@Test
public void testGetEntries() throws Exception {
Transaction tx = txShouldBeUsed() ? transactions().txStart() : null;
final IgniteCache<String, Integer> cache = jcache();
try {
cache.put("key1", 1);
cache.put("key2", 2);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
cache.getEntries(null).isEmpty();
return null;
}
}, NullPointerException.class, null);
assert cache.getEntries(Collections.<String>emptySet()).isEmpty();
Collection<CacheEntry<String, Integer>> c1 = cache.getEntries(ImmutableSet.of("key1", "key2", "key9999"));
info("Retrieved c1: " + c1);
assert 2 == c1.size() : "Invalid collection: " + c1;
boolean b1 = false;
boolean b2 = false;
for (CacheEntry<String, Integer> e : c1) {
if (e.getKey().equals("key1") && e.getValue().equals(1))
b1 = true;
if (e.getKey().equals("key2") && e.getValue().equals(2))
b2 = true;
}
assertTrue(b1 && b2);
Collection<CacheEntry<String, Integer>> c2 = cache.getEntries(ImmutableSet.of("key1", "key2", "key9999"));
info("Retrieved c2: " + c2);
assert 2 == c2.size() : "Invalid collection: " + c2;
b1 = false;
b2 = false;
for (CacheEntry<String, Integer> e : c2) {
if (e.getKey().equals("key1") && e.getValue().equals(1))
b1 = true;
if (e.getKey().equals("key2") && e.getValue().equals(2))
b2 = true;
}
assertTrue(b1 && b2);
// Now do the same checks but within transaction.
if (txShouldBeUsed()) {
try (Transaction tx0 = transactions().txStart()) {
assert cache.getEntries(Collections.<String>emptySet()).isEmpty();
c1 = cache.getEntries(ImmutableSet.of("key1", "key2", "key9999"));
info("Retrieved c1: " + c1);
assert 2 == c1.size() : "Invalid collection: " + c1;
b1 = false;
b2 = false;
for (CacheEntry<String, Integer> e : c1) {
if (e.getKey().equals("key1") && e.getValue().equals(1))
b1 = true;
if (e.getKey().equals("key2") && e.getValue().equals(2))
b2 = true;
}
assertTrue(b1 && b2);
c2 = cache.getEntries(ImmutableSet.of("key1", "key2", "key9999"));
info("Retrieved c2: " + c2);
assert 2 == c2.size() : "Invalid collection: " + c2;
b1 = false;
b2 = false;
for (CacheEntry<String, Integer> e : c2) {
if (e.getKey().equals("key1") && e.getValue().equals(1))
b1 = true;
if (e.getKey().equals("key2") && e.getValue().equals(2))
b2 = true;
}
assertTrue(b1 && b2);
tx0.commit();
}
}
}
use of org.apache.ignite.cache.CacheEntry in project ignite by apache.
the class GridCacheInterceptorAbstractSelfTest method testGetAll.
/**
* @throws Exception If failed.
*/
private void testGetAll(boolean needVer) throws Exception {
Set<String> keys = new LinkedHashSet<>();
for (int i = 0; i < 1000; i++) keys.add(String.valueOf(i));
interceptor.retInterceptor = new NullGetInterceptor();
IgniteCache<String, Integer> cache = jcache(0);
Collection<CacheEntry<String, Integer>> c;
Map<String, Integer> map;
if (needVer) {
c = cache.getEntries(keys);
assertTrue(c.isEmpty());
} else {
map = cache.getAll(keys);
for (String key : keys) assertEquals(null, map.get(key));
}
assertEquals(1000, interceptor.invokeCnt.get());
interceptor.reset();
interceptor.retInterceptor = new GetAllInterceptor1();
if (needVer) {
c = cache.getEntries(keys);
assertEquals(500, c.size());
for (CacheEntry<String, Integer> e : c) {
int k = Integer.valueOf(e.getKey());
assertEquals((Integer) (k * 2), e.getValue());
}
} else {
map = cache.getAll(keys);
for (String key : keys) {
int k = Integer.valueOf(key);
if (k % 2 == 0)
assertEquals(null, map.get(key));
else
assertEquals((Integer) (k * 2), map.get(key));
}
}
assertEquals(1000, interceptor.invokeCnt.get());
// Put some values in cache.
interceptor.disabled = true;
for (int i = 0; i < 500; i++) cache.put(String.valueOf(i), i);
interceptor.disabled = false;
for (int j = 0; j < 2; j++) {
interceptor.reset();
interceptor.retInterceptor = new GetAllInterceptor2();
if (needVer) {
if (j == 0)
c = cache.getEntries(keys);
else
c = cache.getEntriesAsync(keys).get();
for (CacheEntry<String, Integer> e : c) {
int k = Integer.valueOf(e.getKey());
switch(k % 3) {
case 1:
Integer exp = k < 500 ? k : null;
assertEquals(exp, e.getValue());
break;
case 2:
assertEquals((Integer) (k * 3), e.getValue());
break;
default:
fail();
}
}
} else {
if (j == 0)
map = cache.getAll(keys);
else
map = cache.getAllAsync(keys).get();
int i = 0;
for (String key : keys) {
switch(i % 3) {
case 0:
assertEquals(null, map.get(key));
break;
case 1:
Integer exp = i < 500 ? i : null;
assertEquals(exp, map.get(key));
break;
case 2:
assertEquals((Integer) (i * 3), map.get(key));
break;
default:
fail();
}
i++;
}
}
assertEquals(1000, interceptor.invokeCnt.get());
}
}
use of org.apache.ignite.cache.CacheEntry in project ignite by apache.
the class GridCacheVersionTopologyChangeTest method checkVersionIncrease.
/**
* @param cache Cache.
* @param vers Current versions.
*/
@SuppressWarnings("unchecked")
private void checkVersionIncrease(IgniteCache<Object, Object> cache, Map<Integer, Comparable> vers) {
for (Integer k : vers.keySet()) {
cache.put(k, k);
Comparable curVer = vers.get(k);
CacheEntry entry = cache.getEntry(k);
if (entry != null) {
Comparable newVer = entry.version();
assertTrue(newVer.compareTo(curVer) > 0);
vers.put(k, newVer);
} else {
CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class);
assertEquals(0, ccfg.getBackups());
}
}
}
Aggregations