@Override public void run(IgniteCache<String, Integer> cache) throws IgniteCheckedException { Map.Entry<String, Integer> e = F.first(pairs(1).entrySet()); assert e != null; String key = e.getKey(); Integer val = e.getValue(); cache.put(key, val); assert cache.containsKey(key); assert cache.remove(key); assert !cache.containsKey(key); } }, F.t(EVT_CACHE_OBJECT_PUT, gridCnt), F.t(EVT_CACHE_OBJECT_REMOVED, gridCnt));
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public <T> T get(Object key, Class<T> type) { Object val = cache.get(key); if (NULL.equals(val)) val = null; if (val != null && type != null && !type.isInstance(val)) throw new IllegalStateException("Cached value is not of required type [cacheName=" + cache.getName() + ", key=" + key + ", val=" + val + ", requiredType=" + type + ']'); return (T)val; }
/** * */ @Test public void testPrimitives() { IgniteCache<Integer, Integer> p = ignite(0).cache("I2I").withKeepBinary(); p.query(new SqlFieldsQuery("merge into Integer(_key, _val) values (1, ?), " + "(?, 4)").setArgs(2, 3)); assertEquals(2, (int)p.get(1)); assertEquals(4, (int)p.get(3)); } }
/** * @throws Exception If failed. */ @Test public void testRemoveAllSkipStore() throws Exception { IgniteCache<String, Integer> jcache = jcache(); jcache.putAll(F.asMap("1", 1, "2", 2, "3", 3)); jcache.withSkipStore().removeAll(); assertEquals((Integer)1, jcache.get("1")); assertEquals((Integer)2, jcache.get("2")); assertEquals((Integer)3, jcache.get("3")); }
/** */ private void verifyCache(IgniteCache cache, BiFunction<String, Integer, String> generatingFunc) { int size = cache.size(CachePeekMode.PRIMARY); String cacheName = cache.getName(); for (int i = 0; i < size; i++) { String value = (String) cache.get(i); assertEquals(generatingFunc.apply(cacheName, i), value); } } }
/** * @throws Exception If failed. */ @Test public void testIllegalBounds() throws Exception { IgniteCache<Integer, Integer> cache = jcache(Integer.class, Integer.class); cache.put(1, 1); cache.put(2, 2); QueryCursor<Cache.Entry<Integer,Integer>> qry = cache.query(new SqlQuery<Integer, Integer>(Integer.class, "_key between 2 and 1")); assertTrue(qry.getAll().isEmpty()); }
@Override public boolean applyx() throws IgniteCheckedException { jcache(fi).removeAll(); if (jcache(fi).size(CachePeekMode.ALL) > 0) { for (Cache.Entry<String, ?> k : jcache(fi).localEntries()) jcache(fi).remove(k.getKey()); } return jcache(fi).localSize(CachePeekMode.ALL) == 0; } },
@Override public void applyx(IgniteCache<String, Integer> cache) { for (int i = 0; i < cnt; i++) { String key = "key" + i; // Use removeAll for serializable tx to avoid version check. if (isolation == TransactionIsolation.SERIALIZABLE) cache.removeAll(Collections.singleton(key)); else cache.remove(key); } } });
@Override public Void call() throws Exception { cache.putAll(m); return null; } }, NullPointerException.class, null);
/** {@inheritDoc} */ @Override protected void initCacheAndDbData() throws Exception { Integer k1 = primaryKey(ignite(0).cache(pCache.getName())); Integer k2 = primaryKey(ignite(1).cache(pCache.getName())); Organization org1 = new Organization(k1, "org", "org1"); Organization org2 = new Organization(k2, "org", "org2"); pCache.put(k1, org1); pCache.put(k2, org2); insertInDb(org1); insertInDb(org2); }
@Override public Void call() throws Exception { cacheAsync.getAll(null); return null; } }, NullPointerException.class, null);