/** * Synchronously waits for all futures in the collection. * * @param futs Futures to wait for. */ public static void waitAll(@Nullable Iterable<IgniteFuture<?>> futs) { if (F.isEmpty(futs)) return; for (IgniteFuture fut : futs) fut.get(); }
@Override public Void call() throws Exception { fut.get(); return null; } }, ClusterGroupEmptyException.class, null);
@Override public void apply(IgniteFuture fut) { try { fut.get(); resFut.onDone(); } catch (Exception e) { resFut.onDone(e); } } });
@Override public void apply(IgniteFuture<String> fut) { assertEquals("test", fut.get()); lsnr1Cnt.incrementAndGet(); } };
@Override public void apply(IgniteFuture<Integer> fut) { assertEquals(10, (int)fut.get()); lsnrCnt.incrementAndGet(); } });
@Override public Object call() throws Exception { fut.chain(new IgniteClosure<IgniteFuture, Object>() { @Override public Object apply(IgniteFuture o) { return o.get(); } }); fut.get(); return null; } }, EntryProcessorException.class, null);
/** * @param cache Cache. * @param key Key. * @param val Value. * @return Remove result. */ private <K, V> boolean removeAsync(IgniteCache<K, V> cache, K key, V val) { return cache.removeAsync(key, val).get(); } }
@Override public Object call() throws Exception { Collection<IgniteFuture<?>> futs = new ArrayList<>(cnt); for (int i = 0; i < cnt; i++) { final int key = idxGen.decrementAndGet(); futs.add(rmvLdr.removeData(key)); } l2.countDown(); for (IgniteFuture<?> fut : futs) fut.get(); return null; } }, threads);
@Override public void apply(IgniteFuture<Integer> fut) { try { fut.get(); fail(); } catch (IgniteException | CacheException err) { assertExpectedException(err, err0); lsnrPassed.set(true); } } };
/** * @param e Client disconnected exception. */ protected void checkAndWait(CacheException e) { check(e).get(); }
@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(); assert cache.getAndPutAsync(key, val).get() == null; assert cache.containsKey(key); assert val.equals(cache.getAsync(key).get()); assert val.equals(cache.getAndRemoveAsync(key).get()); assert !cache.containsKey(key); } }, F.t(EVT_CACHE_OBJECT_PUT, gridCnt), F.t(EVT_CACHE_OBJECT_READ, 3), F.t(EVT_CACHE_OBJECT_REMOVED, gridCnt));
/** * @throws Exception In case of error. */ @Test public void testPutIfAbsentAsyncConcurrent() throws Exception { IgniteCache cache = jcache(); IgniteFuture<Boolean> fut1 = cache.putIfAbsentAsync("key1", 1); IgniteFuture<Boolean> fut2 = cache.putIfAbsentAsync("key2", 2); assert fut1.get(); assert fut2.get(); }
/** * @param cache Cache. */ private void cachePutRemoveAsync(IgniteCache cache) { Random rnd = ThreadLocalRandom.current(); Integer key = rnd.nextInt(); Integer val = rnd.nextInt(); cache.putAsync(key, val).get(ASYNC_TIMEOUT); assertTrue((Boolean)cache.removeAsync(key).get(ASYNC_TIMEOUT)); assertNull(cache.get(key)); tearDown(cache); }
@Override public void applyx(IgniteCache<String, Integer> cache) { int rnd = random(); IgniteCache<String, Integer> cacheAsync = cache.withAsync(); cacheAsync.get("key" + rnd); assert cacheAsync.<Integer>future().get() == rnd; cacheAsync.get("wrongKey"); assert cacheAsync.future().get() == null; } });
@Override public void apply(IgniteFuture<String> f) { String val = f.get(); if (val != null) { log.info("Completed by get: " + id); (((GridFutureAdapter)((IgniteFutureImpl)promise).internalFuture())).onDone("by async get"); } } });
/** {@inheritDoc} */ @Override public Void call() { IgniteCache<K, V> cache = cache(); cache.removeAll(); if (async) cache.future().get(); return null; } }
@Override public void test(Factory factory, Ignite ignite) throws Exception { final Collection<Object> resultsAllNull = ignite.compute() .broadcast((IgniteClosure<Object, Object>)factory.create(), null); assertEquals("Result's size mismatch: job must be run on all server nodes", gridCount() - clientsCount(), resultsAllNull.size()); for (Object o : resultsAllNull) assertNull("All results must be null", o); IgniteFuture<Collection<Object>> fut = ignite.compute() .broadcastAsync((IgniteClosure<Object, Object>)factory.create(), value(0)); checkResultsClassCount(gridCount() - clientsCount(), fut.get(), value(0).getClass()); } });
/** * @param e Client disconnected exception. */ protected void checkAndWait(IgniteClientDisconnectedException e) { log.info("Expected exception: " + e); assertNotNull(e.reconnectFuture()); e.reconnectFuture().get(); }
/** * @throws Exception If failed. */ @Test public void testPutAsyncAvgTime() throws Exception { IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME); assertEquals(0.0, cache.localMetrics().getAveragePutTime(), 0.0); assertEquals(0, cache.localMetrics().getCachePuts()); cache.putAsync(1, 1).get(); TimeUnit.MILLISECONDS.sleep(100L); assert cache.localMetrics().getAveragePutTime() > 0; }
/** * @throws IgniteCheckedException If failed. */ @Test public void testInvokeAsyncAvgTime() throws IgniteCheckedException { IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME); assertEquals(0.0, cache.localMetrics().getEntryProcessorAverageInvocationTime(), 0.001f); final Integer key = primaryKey(cache); cache.invokeAsync(key, updatingProcessor).get(); U.sleep(100); assertTrue(cache.localMetrics().getEntryProcessorAverageInvocationTime() > 0.0); }