Java Code Examples for org.apache.ignite.IgniteCache#getAndRemove()
The following examples show how to use
org.apache.ignite.IgniteCache#getAndRemove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteDbMemoryLeakSqlQueryTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected void operation(IgniteCache<Object, Object> cache) { Object key = key(); Object val = value(key); switch (nextInt(4)) { case 0: cache.getAndPut(key, val); break; case 1: cache.get(key); break; case 2: cache.getAndRemove(key); break; case 3: cache.query(sqlQuery(cache)).getAll(); } }
Example 2
Source File: IgniteDbMemoryLeakAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cache IgniteCache. */ protected void operation(IgniteCache<Object, Object> cache) { Object key = key(); Object val = value(key); switch (nextInt(3)) { case 0: cache.getAndPut(key, val); break; case 1: cache.get(key); break; case 2: cache.getAndRemove(key); } }
Example 3
Source File: CacheClientStoreSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ private void doTestNoStore() throws Exception { factory = null; Ignite ignite = startClientGrid("client-1"); IgniteCache<Object, Object> cache = ignite.cache(CACHE_NAME); cache.get(0); cache.getAll(F.asSet(0, 1)); cache.getAndPut(0, 0); cache.getAndPutIfAbsent(0, 0); cache.getAndRemove(0); cache.getAndReplace(0, 0); cache.put(0, 0); cache.putAll(F.asMap(0, 0, 1, 1)); cache.putIfAbsent(0, 0); cache.remove(0); cache.remove(0, 0); cache.removeAll(F.asSet(0, 1)); cache.removeAll(); cache.invoke(0, new EP()); cache.invokeAll(F.asSet(0, 1), new EP()); }
Example 4
Source File: GridCacheOffheapIndexEntryEvictTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testUpdates() throws Exception { final int ENTRIES = 500; IgniteCache<Integer, TestValue> cache = grid(0).cache(DEFAULT_CACHE_NAME); for (int i = 0; i < ENTRIES; i++) { for (int j = 0; j < 3; j++) { cache.getAndPut(i, new TestValue(i)); assertNotNull(cache.get(i)); assertNotNull(cache.localPeek(i)); } checkQuery(cache, "_key >= 0", i + 1); } for (int i = 0; i < ENTRIES; i++) { if (i % 2 == 0) cache.getAndRemove(i); else cache.remove(i); checkQuery(cache, "_key >= 0", ENTRIES - (i + 1)); } }
Example 5
Source File: CacheClientStoreSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testCorrectStore() throws Exception { nearEnabled = false; cacheMode = CacheMode.PARTITIONED; factory = new Factory1(); startGrids(2); Ignite ignite = startClientGrid("client-1"); IgniteCache<Object, Object> cache = ignite.cache(CACHE_NAME); cache.get(0); cache.getAll(F.asSet(0, 1)); cache.getAndPut(0, 0); cache.getAndPutIfAbsent(0, 0); cache.getAndRemove(0); cache.getAndReplace(0, 0); cache.put(0, 0); cache.putAll(F.asMap(0, 0, 1, 1)); cache.putIfAbsent(0, 0); cache.remove(0); cache.remove(0, 0); cache.removeAll(F.asSet(0, 1)); cache.removeAll(); cache.invoke(0, new EP()); cache.invokeAll(F.asSet(0, 1), new EP()); }
Example 6
Source File: H2IndexingAbstractGeoSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Check geo-index (dynamic). * * @param dynamic Whether index should be created dynamically. * @throws Exception If failed. */ @SuppressWarnings({"unchecked", "ConstantConditions"}) private void checkGeo(boolean dynamic) throws Exception { IgniteCache<Integer, EnemyCamp> cache = createCache("camp", true, Integer.class, EnemyCamp.class, dynamic); try { WKTReader r = new WKTReader(); cache.getAndPut(0, new EnemyCamp(r.read("POINT(25 75)"), "A")); cache.getAndPut(1, new EnemyCamp(r.read("POINT(70 70)"), "B")); cache.getAndPut(2, new EnemyCamp(r.read("POINT(70 30)"), "C")); cache.getAndPut(3, new EnemyCamp(r.read("POINT(75 25)"), "D")); SqlQuery<Integer, EnemyCamp> qry = new SqlQuery(EnemyCamp.class, "coords && ?"); Collection<Cache.Entry<Integer, EnemyCamp>> res = cache.query( qry.setArgs(r.read("POLYGON((5 70, 5 80, 30 80, 30 70, 5 70))"))).getAll(); checkPoints(res, "A"); res = cache.query( qry.setArgs(r.read("POLYGON((10 5, 10 35, 70 30, 75 25, 10 5))"))).getAll(); checkPoints(res, "C", "D"); // Move B to the first polygon. cache.getAndPut(1, new EnemyCamp(r.read("POINT(20 75)"), "B")); res = cache.query( qry.setArgs(r.read("POLYGON((5 70, 5 80, 30 80, 30 70, 5 70))"))).getAll(); checkPoints(res, "A", "B"); // Move B to the second polygon. cache.getAndPut(1, new EnemyCamp(r.read("POINT(30 30)"), "B")); res = cache.query( qry.setArgs(r.read("POLYGON((10 5, 10 35, 70 30, 75 25, 10 5))"))).getAll(); checkPoints(res, "B", "C", "D"); // Remove B. cache.getAndRemove(1); res = cache.query( qry.setArgs(r.read("POLYGON((5 70, 5 80, 30 80, 30 70, 5 70))"))).getAll(); checkPoints(res, "A"); res = cache.query( qry.setArgs(r.read("POLYGON((10 5, 10 35, 70 30, 75 25, 10 5))"))).getAll(); checkPoints(res, "C", "D"); // Check explain request. String plan = cache.query(new SqlFieldsQuery("explain select * from EnemyCamp " + "where coords && 'POINT(25 75)'")).getAll().get(0).get(0).toString().toLowerCase(); assertTrue("__ explain: " + plan, plan.contains("coords_idx")); if (dynamic) cache.query(new SqlFieldsQuery("DROP INDEX \"EnemyCamp_coords_idx\"")).getAll(); } finally { destroy(cache, grid(0), dynamic); } }
Example 7
Source File: IgniteCacheGroupsTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param cache Cache. */ private void cachePutGetAndRemove(IgniteCache cache) { Random rnd = ThreadLocalRandom.current(); Integer key = rnd.nextInt(); Integer val = rnd.nextInt(); cache.put(key, val); Object val0 = cache.getAndRemove(key); assertEquals(val, val0); val0 = cache.get(key); assertNull(val0); tearDown(cache); }
Example 8
Source File: CacheKeepBinaryWithInterceptorTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param ccfg Cache configuration. */ private void keepBinaryWithInterceptorPrimitives(CacheConfiguration ccfg) { ignite(0).createCache(ccfg); try { TestInterceptor2.onAfterRmv = 0; TestInterceptor2.onBeforeRmv = 0; TestInterceptor2.onAfterPut = 0; TestInterceptor2.onBeforePut = 0; TestInterceptor2.onGet = 0; IgniteCache cache = ignite(0).cache(DEFAULT_CACHE_NAME).withKeepBinary(); cache.put(1, 10); cache.put(1, 10); Integer obj = (Integer)cache.get(1); assertEquals((Integer)10, obj); obj = (Integer)cache.getAsync(1).get(); assertEquals((Integer)10, obj); Cache.Entry<Integer, Integer> e = (Cache.Entry)cache.getEntry(1); assertEquals((Integer)1, e.getKey()); assertEquals((Integer)10, e.getValue()); e = (Cache.Entry)cache.getEntryAsync(1).get(); assertEquals((Integer)1, e.getKey()); assertEquals((Integer)10, e.getValue()); obj = (Integer)cache.getAndRemove(1); assertEquals((Integer)10, obj); cache.put(1, 10); assertTrue(cache.remove(1)); assertTrue(TestInterceptor2.onAfterRmv > 0); assertTrue(TestInterceptor2.onBeforeRmv > 0); assertTrue(TestInterceptor2.onAfterPut > 0); assertTrue(TestInterceptor2.onBeforePut > 0); assertTrue(TestInterceptor2.onGet > 0); } finally { ignite(0).destroyCache(ccfg.getName()); } }