/** @throws Exception If failed. */ @SuppressWarnings("unchecked") public void testCancel() throws Exception { Grid grid = G.grid(getTestGridName()); grid.compute() .localDeployTask(GridCancelTestTask.class, U.detectClassLoader(GridCancelTestTask.class)); GridComputeTaskFuture<?> fut = grid.compute().execute(GridCancelTestTask.class.getName(), null); // Wait until jobs begin execution. boolean await = startSignal.await(WAIT_TIME, TimeUnit.MILLISECONDS); assert await : "Jobs did not start."; info("Test task result: " + fut); assert fut != null; // Only first job should successfully complete. Object res = fut.get(); assert (Integer) res == 1; // Wait for all jobs to finish. await = stopSignal.await(WAIT_TIME, TimeUnit.MILLISECONDS); assert await : "Jobs did not stop."; // One is definitely processed. But there might be some more processed or cancelled or processed // and cancelled. // Thus total number should be at least SPLIT_COUNT and at most (SPLIT_COUNT - 1) *2 +1 assert (cancelCnt + processedCnt) >= SPLIT_COUNT && (cancelCnt + processedCnt) <= (SPLIT_COUNT - 1) * 2 + 1 : "Invalid cancel count value: " + cancelCnt; }
/** * Tests that failover don't pick local node if it has been excluded from topology. * * @throws Exception If failed. */ @SuppressWarnings({"WaitNotInLoop", "UnconditionalWait", "unchecked"}) public void testFailoverTopology() throws Exception { try { Grid grid1 = startGrid(1); Grid grid2 = startGrid(2); assert grid1 != null; assert grid2 != null; grid1.compute().localDeployTask(JobTask.class, JobTask.class.getClassLoader()); try { GridComputeTaskFuture<String> fut; synchronized (mux) { fut = grid1.compute().execute(JobTask.class, null); mux.wait(); } stopAndCancelGrid(2); String res = fut.get(); info("Task result: " + res); } catch (GridException e) { info("Got unexpected grid exception: " + e); } info("Failed over: " + failCnt.get()); assert failCnt.get() == 1 : "Invalid fail over counter [expected=1, actual=" + failCnt.get() + ']'; } finally { stopGrid(1); // Stopping stopped instance just in case. stopGrid(2); } }