/** {@inheritDoc} */ @Override public Object call() throws Exception { IgniteCache cache = ignite.cache(cacheName); if (withExpiryPlc) cache = cache.withExpiryPolicy(ModifiedExpiryPolicy.factoryOf(Duration.FIVE_MINUTES).create()); Map vals = cache.getAll(keys); Collection<CacheEntry> entries = cache.getEntries(keys); assertEquals(vals.size(), entries.size()); for (CacheEntry entry : entries) { Object val = vals.get(entry.getKey()); assertEquals(val, entry.getValue()); } return vals; } }
@Override public void run() throws Exception { Map<String, Integer> vals = new HashMap<>(); for (int i = 0; i < CNT; i++) vals.put("key" + i, i); jcache(0).putAll(vals); for (int i = 0; i < gridCount(); i++) { assertEquals(0, jcache(i).getEntry("key0").getValue()); assertEquals(0, jcache(i).getEntryAsync("key0").get().getValue()); assertTrue( F.transform( jcache(i).getEntries(vals.keySet()), new IgniteClosure<CacheEntry<Object, Object>, Object>() { @Override public Object apply(CacheEntry<Object, Object> entry) { return entry.getValue(); } }).containsAll(vals.values())); assertTrue( F.transform( jcache(i).getEntriesAsync(vals.keySet()).get(), new IgniteClosure<CacheEntry<Object, Object>, Object>() { @Override public Object apply(CacheEntry<Object, Object> entry) { return entry.getValue(); } }).containsAll(vals.values())); } } });
@Override public Void call() throws Exception { e.version(); return null; } }, IgniteException.class, null);
/** * @param e Entry. * @param cache Cache. * @throws Exception If failed. */ private void compareVersionWithPrimaryNode(CacheEntry<Integer, ?> e, IgniteCache<Integer, TestValue> cache) throws Exception { CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class); if (cfg.getCacheMode() != LOCAL) { Ignite prim = primaryNode(e.getKey(), cache.getName()); GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal)prim).internalCache(cache.getName()); if (cfg.getNearConfiguration() != null) cacheAdapter = ((GridNearCacheAdapter)cacheAdapter).dht(); IgniteCacheObjectProcessor cacheObjects = cacheAdapter.context().cacheObjects(); CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext(); GridCacheEntryEx mapEntry = cacheAdapter.entryEx(cacheObjects.toCacheKeyObject( cacheObjCtx, cacheAdapter.context(), e.getKey(), true)); mapEntry.unswap(); assertNotNull("No entry for key: " + e.getKey(), mapEntry); assertEquals(mapEntry.version(), e.version()); } }
/** {@inheritDoc} */ @Override public Object call() throws Exception { IgniteCache cache = ignite.cache(cacheName); if (withExpiryPlc) cache = cache.withExpiryPolicy(ModifiedExpiryPolicy.factoryOf(Duration.FIVE_MINUTES).create()); Object val = cache.get(key); CacheEntry e = cache.getEntry(key); assertEquals(val, e.getValue()); return val; } }
@Override public Void call() throws Exception { e.version(); return null; } }, IgniteException.class, null);
if (e.getKey().equals("key1") && e.getValue().equals(1)) b1 = true; if (e.getKey().equals("key2") && e.getValue().equals(2)) b2 = true; if (e.getKey().equals("key1") && e.getValue().equals(1)) b1 = true; if (e.getKey().equals("key2") && e.getValue().equals(2)) b2 = true; if (e.getKey().equals("key1") && e.getValue().equals(1)) b1 = true; if (e.getKey().equals("key2") && e.getValue().equals(2)) b2 = true; if (e.getKey().equals("key1") && e.getValue().equals(1)) b1 = true; if (e.getKey().equals("key2") && e.getValue().equals(2)) b2 = true;
/** * @throws Exception In case of error. */ @Test public void testGetEntry() throws Exception { IgniteCache<String, Integer> cache = jcache(); cache.put("key1", 1); cache.put("key2", 2); CacheEntry<String, Integer> key1e = cache.getEntry("key1"); CacheEntry<String, Integer> key2e = cache.getEntry("key2"); CacheEntry<String, Integer> wrongKeye = cache.getEntry("wrongKey"); assert key1e.getValue() == 1; assert key1e.getKey().equals("key1"); assert key1e.version() != null; assert key2e.getValue() == 2; assert key2e.getKey().equals("key2"); assert key2e.version() != null; assert wrongKeye == null; }
/** {@inheritDoc} */ @Nullable @Override public CacheEntry<K, V> getEntry(K key) throws IgniteCheckedException { A.notNull(key, "key"); boolean statsEnabled = ctx.statisticsEnabled(); long start = statsEnabled ? System.nanoTime() : 0L; boolean keepBinary = ctx.keepBinary(); if (keepBinary) key = (K)ctx.toCacheKeyObject(key); EntryGetResult t = (EntryGetResult)get(key, !keepBinary, true); CacheEntry<K, V> val = t != null ? new CacheEntryImplEx<>( keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key, true, false) : key, (V)t.value(), t.version()) : null; if (ctx.config().getInterceptor() != null) { key = keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key, true, false) : key; V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null); val = (val0 != null) ? new CacheEntryImplEx<>(key, val0, t != null ? t.version() : null) : null; } if (statsEnabled) metrics0().addGetTimeNanos(System.nanoTime() - start); return val; }
@Override public Void call() throws Exception { e.version(); return null; } }, IgniteException.class, null);
assertEquals((Integer)1, needVer ? cache.getEntry(key).getValue() : cache.get(key)); assertEquals((Integer)101, needVer ? cache.getEntry(key).getValue() : cache.get(key)); assertEquals((Integer)101, cache.getEntryAsync(key).get().getValue()); else assertEquals((Integer)101, cache.getAsync(key).get());
@Override public Void call() throws Exception { e.version(); return null; } }, IgniteException.class, null);
assertEquals(1, srvCache.getEntry(1).getValue());
@Override public Object process(MutableEntry<Integer, String> entry, Object... args) { CacheEntry<Integer, String> verEntry = entry.unwrap(CacheEntry.class); checkVersionedEntry(verEntry); return verEntry.version(); } });
@Override public Object process(MutableEntry<Integer, String> entry, Object... args) { CacheEntry<Integer, String> verEntry = entry.unwrap(CacheEntry.class); checkVersionedEntry(verEntry); return verEntry.version(); } }));