/** * Example for start/stop node tasks. * * @param args Not used. */ public static void main(String[] args) { String nodeType = "tcp+ssl"; // Start initial node = 1 try (Ignite g = G.start(NODE_CFG.get(nodeType))) { // Change topology. changeTopology(g, 4, 1, nodeType); changeTopology(g, 1, 4, nodeType); // Stop node by id = 0 g.compute().execute(ClientStopNodeTask.class, g.cluster().localNode().id().toString()); // Wait for node stops. // U.sleep(1000); assert G.allGrids().isEmpty(); } catch (Exception e) { System.err.println("Uncaught exception: " + e.getMessage()); e.printStackTrace(System.err); } }
/** @throws Exception If failed. */ @SuppressWarnings({"AssignmentToCatchBlockParameter"}) public void testCancel() throws Exception { Ignite ignite = G.ignite(getTestGridName()); ignite .compute() .localDeployTask(GridCancelTestTask.class, GridCancelTestTask.class.getClassLoader()); ComputeTaskFuture<?> res0 = executeAsync( ignite.compute().withTimeout(maxJobExecTime * 2), GridCancelTestTask.class.getName(), null); try { Object res = res0.get(); info("Cancel test result: " + res); synchronized (mux) { // Every execute must be called. assert execCnt <= SPLIT_COUNT : "Invalid execute count: " + execCnt; // Job returns 1 if was cancelled. assert (Integer) res <= SPLIT_COUNT : "Invalid task result: " + res; // Should be exactly the same as Jobs number. assert cancelCnt <= SPLIT_COUNT : "Invalid cancel count: " + cancelCnt; // One per start and one per stop and some that come with heartbeats. assert colResolutionCnt > SPLIT_COUNT + 1 : "Invalid collision resolution count: " + colResolutionCnt; } } catch (ComputeTaskTimeoutException e) { error("Task execution got timed out.", e); } catch (Exception e) { assert e.getCause() != null; if (e.getCause() instanceof IgniteCheckedException) e = (Exception) e.getCause(); if (e.getCause() instanceof IOException) e = (Exception) e.getCause(); assert e.getCause() instanceof InterruptedException : "Invalid exception cause: " + e.getCause(); } }