/** {@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 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; } }
@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()); } });
/** {@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(); }
@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()); } });
/** * @param num Number. * @throws IgniteCheckedException if failed. */ private void checkTask(int num) throws IgniteCheckedException { Ignite ignite = G.ignite(getTestIgniteInstanceName()); ComputeTaskFuture<?> fut = executeAsync(ignite.compute(), GridTaskSessionTestTask.class.getName(), null); int exp = SPLIT_COUNT - 1; Object res = fut.get(); assert (Integer)res == exp : "Invalid result [expected=" + exp + ", actual=" + res + ", iter=" + 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 + ']'; }
/** * @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()); }
/** * Test 2 jobs on 1 node with null predicate using string task name. * * @throws IgniteCheckedException If test failed. */ @Test public void testTwoJobsTaskNameNullPredicate() throws IgniteCheckedException { executeAsync(ignite1.compute(), JobStealingSingleNodeTask.class.getName(), null).get(TASK_EXEC_TIMEOUT_MS); // Verify that 1 job was stolen by second node. assertEquals(2, jobDistrMap.keySet().size()); assertEquals(1, jobDistrMap.get(ignite1.cluster().localNode().id()).size()); assertEquals(1, jobDistrMap.get(ignite2.cluster().localNode().id()).size()); }
/** * Test 2 jobs on 1 node. * * @throws IgniteCheckedException If test failed. */ @Test public void testTwoJobs() throws IgniteCheckedException { executeAsync(ignite1.compute(), new JobStealingSingleNodeTask(2), null).get(TASK_EXEC_TIMEOUT_MS); // Verify that 1 job was stolen by second node. assertEquals(2, jobDistrMap.keySet().size()); assertEquals(1, jobDistrMap.get(ignite1.cluster().localNode().id()).size()); assertEquals(1, jobDistrMap.get(ignite2.cluster().localNode().id()).size()); }
/** * Test 2 jobs on 1 node with null predicate. * * @throws IgniteCheckedException If test failed. */ @Test public void testTwoJobsNullPredicate() throws IgniteCheckedException { executeAsync(ignite1.compute(), new JobStealingSingleNodeTask(2), null).get(TASK_EXEC_TIMEOUT_MS); // Verify that 1 job was stolen by second node. assertEquals(2, jobDistrMap.keySet().size()); assertEquals(1, jobDistrMap.get(ignite1.cluster().localNode().id()).size()); assertEquals(1, jobDistrMap.get(ignite2.cluster().localNode().id()).size()); }
/** * @param num Number. * @throws IgniteCheckedException if failed. */ private void checkTask(int num) throws IgniteCheckedException { Ignite ignite = G.ignite(getTestIgniteInstanceName()); ComputeTaskFuture<?> fut = executeAsync(ignite.compute(), GridTaskSessionTestTask.class, num); Object res = fut.get(); assert (Integer)res == SPLIT_COUNT - 1 : "Invalid result [num=" + num + ", fut=" + fut + ']'; }
/** * @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); } }
/** * Tests that a job is not cancelled if there are no * available thief nodes in projection. * * @throws Exception If failed. */ @Test public void testSingleNodeProjection() throws Exception { ClusterGroup prj = ignite1.cluster().forNodeIds(Collections.singleton(ignite1.cluster().localNode().id())); executeAsync(compute(prj), new JobStealingSpreadTask(2), null).get(TASK_EXEC_TIMEOUT_MS); assertEquals(1, jobDistrMap.keySet().size()); assertEquals(2, jobDistrMap.get(ignite1.cluster().localNode().id()).size()); }
/** */ 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); } } }
/** * Tests that a job is not cancelled if there are no * available thief nodes in projection. Uses null predicate. * * @throws Exception If failed. */ @Test public void testSingleNodeProjectionNullPredicate() throws Exception { ClusterGroup prj = ignite1.cluster().forNodeIds(Collections.singleton(ignite1.cluster().localNode().id())); executeAsync(compute(prj).withTimeout(TASK_EXEC_TIMEOUT_MS), new JobStealingSpreadTask(2), null). get(TASK_EXEC_TIMEOUT_MS); assertEquals(1, jobDistrMap.keySet().size()); assertEquals(2, jobDistrMap.get(ignite1.cluster().localNode().id()).size()); }
/** * @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()); }