/** * @param comp Compute. * @param taskName Task name. * @param arg Task argument. * @return Task future. * @throws IgniteCheckedException If failed. */ protected <R> ComputeTaskFuture<R> executeAsync(IgniteCompute comp, String taskName, @Nullable Object arg) throws IgniteCheckedException { ComputeTaskFuture<R> fut = comp.executeAsync(taskName, arg); assertNotNull(fut); return fut; }
/** * @param comp Compute. * @param task Task. * @param arg Task argument. * @return Task future. * @throws IgniteCheckedException If failed. */ protected <R> ComputeTaskFuture<R> executeAsync(IgniteCompute comp, ComputeTask task, @Nullable Object arg) throws IgniteCheckedException { ComputeTaskFuture<R> fut = comp.executeAsync(task, arg); assertNotNull(fut); return fut; }
/** * @param comp Compute. * @param taskCls Task class. * @param arg Task argument. * @return Task future. * @throws IgniteCheckedException If failed. */ @SuppressWarnings("unchecked") protected <R> ComputeTaskFuture<R> executeAsync(IgniteCompute comp, Class taskCls, @Nullable Object arg) throws IgniteCheckedException { ComputeTaskFuture<R> fut = comp.executeAsync(taskCls, arg); assertNotNull(fut); return fut; }
/** * @param timeout Timeout. * @param job Job. * @return Task future. * @throws Exception If failed. */ private ComputeTaskFuture<?> generateEvents(@Nullable Long timeout, ComputeJob job) throws Exception { return timeout == null ? ignite.compute().executeAsync(GridAllEventsTestTask.class.getName(), job) : ignite.compute().withTimeout(timeout).executeAsync(GridAllEventsTestTask.class.getName(), job); }
@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 public void run() { try { ComputeTaskFuture<Integer> fut1 = ignite.compute().executeAsync(TestJobsChainTask.class, true); ComputeTaskFuture<Integer> fut2 = ignite.compute().executeAsync(TestJobsChainTask.class, false); assert fut1.get() == 55; assert fut2.get() == 55; } catch (IgniteException e) { assert false : "Test task failed: " + e; } }
/** * @throws Exception If failed. */ @Test public void testCancelingJob() throws Exception { cancelCall = false; try (Ignite g = startGrid(1)) { cnt = new CountDownLatch(1); g.compute().executeAsync(CancelledTask.class, null); cnt.await(); } assert cancelCall; }
/** {@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(); }
/** {@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; }
/** * @param num Number. */ private void checkTask(int num) { Ignite ignite = G.ignite(getTestIgniteInstanceName()); ComputeTaskFuture<?> fut = ignite.compute().executeAsync(GridTaskSessionTestTask.class.getName(), num); Object res = fut.get(); assert (Integer)res == SPLIT_COUNT : "Invalid result [num=" + num + ", fut=" + fut + ']'; }
/** * @param num Number. */ private void checkTask(int num) { Ignite ignite = G.ignite(getTestIgniteInstanceName()); ComputeTaskFuture<?> fut = ignite.compute().executeAsync(GridTaskSessionTestTask.class.getName(), num); Object res = fut.get(); assert (Integer)res == SPLIT_COUNT : "Invalid result [num=" + num + ", fut=" + fut + ']'; }
/** {@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()); }
/** * @throws Exception If failed. */ @Test public void testSynchronousExecute() throws Exception { ComputeTaskFuture<?> fut = ignite.compute().executeAsync(GridTestTask.class, "testArg"); assert fut != null; info("Task result: " + fut.get()); }
/** * @throws Exception If test failed. */ @Test public void testContinuousJobsChain() throws Exception { try { Ignite ignite = startGrid(0); ComputeTaskFuture<Integer> fut1 = ignite.compute().executeAsync(TestJobsChainTask.class, true); ComputeTaskFuture<Integer> fut2 = ignite.compute().executeAsync(TestJobsChainTask.class, false); assert fut1.get() == 55; assert fut2.get() == 55; } finally { stopGrid(0); } }
@Override public void test(Factory factory, Ignite ignite) throws Exception { // Begin with negative to check 'null' value in the test. final int[] i = {-1}; ComputeTaskFuture<List<Object>> fut = ignite.compute().executeAsync( TestTask.class, new T2<>((Factory<ComputeJobAdapter>)factory, (Factory<Object>)new Factory<Object>() { @Override public Object create() { return value(i[0]++); } })); checkResultsClassCount(MAX_JOB_COUNT - 1, fut.get(), value(0).getClass()); assertCollectionsEquals("Results value mismatch", createGoldenResults(), fut.get()); } });
@Override public void test(Factory factory, Ignite ignite) throws Exception { // Begin with negative to check 'null' value in the test. final int[] i = {-1}; ComputeTaskFuture<List<Object>> fut = ignite.compute().executeAsync(new TestTask(), new T2<>((Factory<ComputeJobAdapter>)factory, (Factory<Object>)new Factory<Object>() { @Override public Object create() { return value(i[0]++); } })); checkResultsClassCount(MAX_JOB_COUNT - 1, fut.get(), value(0).getClass()); assertCollectionsEquals("Results value mismatch", createGoldenResults(), fut.get()); } });
/** */ private void checkExecuteAsyncException(IgniteException resE) throws Exception { try (Ignite ignite = startGrid()) { IgniteCompute compute = ignite.compute(); ComputeTaskFuture<Object> fut = compute.executeAsync(new ResultExceptionTask(resE), null); try { fut.get(); } catch (IgniteException e) { assertSame(resE, e); } } }
/** * Ensure that {@link org.apache.ignite.compute.ComputeJobMasterLeaveAware} callback is invoked when master node leaves topology normally. * * @throws Exception If failed. */ @Test public void testMasterStoppedNormally() throws Exception { // Start grids. for (int i = 0; i < GRID_CNT; i++) startGrid(i); int lastGridIdx = GRID_CNT - 1; compute(grid(lastGridIdx).cluster().forPredicate(excludeLastPredicate())) .executeAsync(new TestTask(GRID_CNT - 1), null); jobLatch.await(); stopGrid(lastGridIdx, true); latch.countDown(); assert invokeLatch.await(5000, MILLISECONDS); }
/** * @throws Exception If failed. */ @Test public void testJobCancel() throws Exception { Ignite server = startGrid("server"); server.services().deployNodeSingleton("my-service", new MyService()); Ignition.setClientMode(true); Ignite client = startGrid("client"); ComputeTaskFuture<Integer> fut = client.compute().executeAsync(new MyTask(), null); Thread.sleep(3000); server.close(); assertEquals(42, fut.get().intValue()); }
/** * @throws Exception If failed. */ @Test public void testSynchronousExecute() throws Exception { Ignite ignite = G.ignite(getTestIgniteInstanceName()); testState = 12345; GridStatefulTask task = new GridStatefulTask(testState); assert task.getState() != null; assert task.getState() == testState; ComputeTaskFuture<?> fut = ignite.compute().executeAsync(task, "testArg"); assert fut != null; info("Task result: " + fut.get()); }