/** {@inheritDoc} */ @Override public void run() { try { startSignal.await(); Object res = fut.get(); info("Task result: " + res); } catch (Throwable e) { failed.set(true); // Make sure that message contains info about stopping grid. assert e.getMessage().startsWith("Task failed due to stopping of the grid:"); } finally { latch.countDown(); } }
/** {@inheritDoc} */ @Override protected ResultT run(VisorIdleVerifyTaskArg arg) throws IgniteException { if (fut == null) { fut = ignite.compute().executeAsync(taskCls, arg); if (!fut.isDone()) { jobCtx.holdcc(); fut.listen((IgniteInClosure<IgniteFuture<ResultT>>)f -> jobCtx.callcc()); return null; } } return fut.get(); }
/** * Cancel a random task when required. */ private void performCancel() { iteration++; if (iteration % cancelRate == 0) { // Here we should have mostly running futures so just pick one. ComputeTaskFuture<Integer> futToCancel = futures.get( new Random().nextInt(futures.size()) ); try { futToCancel.cancel(); ignite.log().info("Task canceled: " + futToCancel.getTaskSession().getId()); } catch (IgniteException e) { ignite.log().warning(">>> Future cancellation failed: " + futToCancel.getTaskSession().getId(), e); } } } }
/** {@inheritDoc} */ @Override public Object execute() throws IgniteException { if (future == null) { IgniteCompute compute = ignite.compute().withAsync(); compute.execute(remoteTask, arg); ComputeTaskFuture<R> future = compute.future(); this.future = future; jobCtx.holdcc(); future.listen(new IgniteInClosure<IgniteFuture<R>>() { @Override public void apply(IgniteFuture<R> future) { jobCtx.callcc(); } }); return null; } else { return future.get(); } } }
/** * @param num Number. * @throws InterruptedException if failed. */ private void checkTask(int num) throws InterruptedException { Ignite ignite = G.ignite(getTestIgniteInstanceName()); ComputeTaskFuture<?> fut = ignite.compute().executeAsync(GridTaskSessionTestTask.class.getName(), num); assert fut != null; try { // Wait until task receive results from jobs. boolean await = startSignal[num].await(WAIT_TIME, TimeUnit.MILLISECONDS); assert await : "Jobs did not executed."; String val = fut.getTaskSession().waitForAttribute("testName", 100000); info("Received attribute 'testName': " + val); // Signal jobs to finish work. stopSignal[num].countDown(); assert "testVal".equals(val) : "Invalid attribute value: " + val; Object res = fut.get(); assert (Integer)res == SPLIT_COUNT : "Invalid result [num=" + num + ", fut=" + fut + ']'; } finally { // We must wait for the jobs to be sure that they have completed // their execution since they use static variable (shared for the tests). fut.get(); } }
/** * Finds completed tasks in the queue and removes them. */ private void checkCompletion() { for (Iterator<ComputeTaskFuture<Integer>> iter = futures.iterator(); iter.hasNext();) { ComputeTaskFuture<Integer> fut = iter.next(); if (fut.isDone()) { try { Integer res = fut.get(); assert res == params.getJobsCount() : "Task returned wrong result [taskIs=" + fut.getTaskSession().getId() + ", result=" + res + "]"; ignite.log().info(">>> Task completed successfully. Task id: " + fut.getTaskSession().getId()); } catch (IgniteFutureCancelledException ignored) { ignite.log().info(">>> Task cancelled: " + fut.getTaskSession().getId()); } catch (IgniteException e) { ignite.log().warning( ">>> Get operation for completed task failed: " + fut.getTaskSession().getId(), e); } finally { iter.remove(); } } } }
@Nullable @Override public Object call() throws Exception { sem.acquire(); g.compute().executeAsync(GridJobExecutionLoadTestTask.class, null).listen(lsnr); iterCntr.increment(); return null; } }, threadCnt, dur > 0 ? dur : Long.MAX_VALUE);
/** {@inheritDoc} */ @Override protected Void run(VisorComputeCancelSessionsTaskArg arg) { Set<IgniteUuid> sesIds = arg.getSessionIds(); if (sesIds != null && !sesIds.isEmpty()) { IgniteCompute compute = ignite.compute(ignite.cluster().forLocal()); Map<IgniteUuid, ComputeTaskFuture<Object>> futs = compute.activeTaskFutures(); for (IgniteUuid sesId : sesIds) { ComputeTaskFuture<Object> fut = futs.get(sesId); if (fut != null) fut.cancel(); } } return null; }
Iterable<UUID> nodeIds = (Iterable<UUID>)fut.getTaskSession().getAttribute("nodes");
/** * @param num Number. * @throws InterruptedException if failed. * @throws IgniteCheckedException if failed. */ private void checkTask(int num) throws InterruptedException, IgniteCheckedException { Ignite ignite = G.ignite(getTestIgniteInstanceName()); ComputeTaskFuture<?> fut = executeAsync(ignite.compute(), GridTaskSessionTestTask.class.getName(), num); assert fut != null; try { // Wait until task receive results from jobs. boolean await = startSignal[num].await(WAIT_TIME, TimeUnit.MILLISECONDS); assert await : "Jobs did not executed."; String val = fut.getTaskSession().waitForAttribute("testName", WAIT_TIME); info("Received attribute 'testName': " + val); // Signal task to finish work. stopSignal[num].countDown(); assert "testVal".equals(val) : "Invalid attribute value: " + val; Object res = fut.get(); assert (Integer)res == SPLIT_COUNT : "Invalid result [num=" + num + ", fut=" + fut + ']'; } finally { // We must wait for the jobs to be sure that they have completed // their execution since they use static variable (shared for the tests). fut.get(); } }
/** {@inheritDoc} */ @Nullable @Override public Object call() throws Exception { final IgniteInClosure<IgniteFuture<?>> lsnr = new CI1<IgniteFuture<?>>() { @Override public void apply(IgniteFuture<?> t) { tasksSem.release(); } }; ClusterGroup rmts = g.cluster().forRemotes(); while (!finish) { tasksSem.acquire(); g.compute(rmts).executeAsync(GridJobExecutionLoadTestTask.class, null).listen(lsnr); txCnt.increment(); } return null; }
fut.cancel();
/** * @throws Exception If failed. */ @Test public void testAsynchronousTimeout() throws Exception { Ignite ignite = G.ignite(getTestIgniteInstanceName()); ignite.compute().localDeployTask(GridTaskTimeoutTestTask.class, GridTaskTimeoutTestTask.class.getClassLoader()); ComputeTaskFuture<?> fut = executeAsync(ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null); // Allow timed out events to be executed. Thread.sleep(TIMEOUT + 500); checkTimedOutEvents(fut.getTaskSession().getId()); }
@Override public void run() { while (!finish.get()) { try { ComputeTaskFuture<?> fut = executeAsync( ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null); fut.get(); assert false : "Task has not been timed out. Future: " + fut; } catch (ComputeTaskTimeoutException ignored) { // Expected. } catch (IgniteCheckedException e) { throw new IllegalStateException(e); //shouldn't happen } finally { int cnt0 = cnt.incrementAndGet(); if (cnt0 % 100 == 0) info("Tasks finished: " + cnt0); } } info("Thread " + Thread.currentThread().getId() + " finishing."); finishLatch.countDown(); } }, N_THREADS);
/** {@inheritDoc} */ @Override protected VisorIdleVerifyTaskResult run(VisorIdleVerifyTaskArg arg) throws IgniteException { if (fut == null) { fut = ignite.compute().executeAsync(VerifyBackupPartitionsTask.class, arg.getCaches()); if (!fut.isDone()) { jobCtx.holdcc(); fut.listen(new IgniteInClosure<IgniteFuture<Map<PartitionKey, List<PartitionHashRecord>>>>() { @Override public void apply(IgniteFuture<Map<PartitionKey, List<PartitionHashRecord>>> f) { jobCtx.callcc(); } }); return null; } } return new VisorIdleVerifyTaskResult(fut.get()); }
/** * @param num Number. * @throws InterruptedException if failed. * @throws IgniteCheckedException if failed. */ private void checkTask(int num) throws InterruptedException, IgniteCheckedException { Ignite ignite = G.ignite(getTestIgniteInstanceName()); ComputeTaskFuture<?> fut = executeAsync(ignite.compute(), GridTaskSessionTestTask.class, num); assert fut != null; try { // Wait until jobs begin execution. boolean await = startSignal[num].await(WAIT_TIME, TimeUnit.MILLISECONDS); assert await : "Jobs did not start."; info("Set attribute 'testName'."); fut.getTaskSession().setAttribute("testName", "testVal"); Object res = fut.get(); assert (Integer)res == SPLIT_COUNT : "Invalid result [num=" + num + ", fut=" + fut + ']'; } finally { // We must wait for the jobs to be sure that they have completed // their execution since they use static variable (shared for the tests). fut.get(); } }
/** {@inheritDoc} */ @Override public Object execute() throws IgniteException { if (future == null) { IgniteCompute compute = ignite.compute().withAsync(); compute.execute(remoteTask, arg); ComputeTaskFuture<R> future = compute.future(); this.future = future; jobCtx.holdcc(); future.listen(new IgniteInClosure<IgniteFuture<R>>() { @Override public void apply(IgniteFuture<R> future) { jobCtx.callcc(); } }); return null; } else { return future.get(); } } }