/** {@inheritDoc} */ @Override public void testEvictExpired() throws Exception { if (isMultiJvm()) fail("https://issues.apache.org/jira/browse/IGNITE-1113"); IgniteCache<String, Integer> cache = jcache(); String key = primaryKeysForCache(cache, 1).get(0); cache.put(key, 1); assertEquals((Integer) 1, cache.get(key)); long ttl = 500; grid(0) .cache(null) .withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl))) .put(key, 1); Thread.sleep(ttl + 100); // Expired entry should not be swapped. cache.localEvict(Collections.singleton(key)); assertNull(cache.localPeek(key, CachePeekMode.ONHEAP)); cache.localPromote(Collections.singleton(key)); assertNull(cache.localPeek(key, CachePeekMode.ONHEAP)); assertTrue(cache.localSize() == 0); load(cache, key, true); Affinity<String> aff = ignite(0).affinity(null); for (int i = 0; i < gridCount(); i++) { if (aff.isPrimaryOrBackup(grid(i).cluster().localNode(), key)) assertEquals((Integer) 1, peek(jcache(i), key)); } }
/** {@inheritDoc} */ @Override public void testClear() throws Exception { IgniteCache<String, Integer> nearCache = jcache(); IgniteCache<String, Integer> primary = fullCache(); Collection<String> keys = primaryKeysForCache(primary, 3); Map<String, Integer> vals = new HashMap<>(); int i = 0; for (String key : keys) { nearCache.put(key, i); vals.put(key, i); i++; } i = 0; for (String key : keys) assertEquals((Integer) i++, nearCache.localPeek(key, CachePeekMode.ONHEAP)); nearCache.clear(); for (String key : keys) assertNull(nearCache.localPeek(key, CachePeekMode.ONHEAP)); for (Map.Entry<String, Integer> entry : vals.entrySet()) nearCache.put(entry.getKey(), entry.getValue()); i = 0; for (String key : keys) assertEquals((Integer) i++, nearCache.localPeek(key, CachePeekMode.ONHEAP)); }
/** * @param cache Cache. * @param key Key. * @return {@code True} if cache contains given key. * @throws Exception If failed. */ @SuppressWarnings("unchecked") protected boolean containsKey(IgniteCache cache, Object key) throws Exception { return offheapTiered(cache) ? cache.localPeek(key, CachePeekMode.OFFHEAP) != null : cache.containsKey(key); }
/** * Executes regular peek or peek from swap. * * @param cache Cache projection. * @param key Key. * @return Value. */ @Nullable protected <K, V> V peek(IgniteCache<K, V> cache, K key) { return offheapTiered(cache) ? cache.localPeek(key, CachePeekMode.SWAP, CachePeekMode.OFFHEAP) : cache.localPeek(key, CachePeekMode.ONHEAP); }