private boolean cancelJob(JobWrapper<?> job) { boolean cancelled = false; for (JavaFutureAction<?> action : job.jobs) { cancelled |= action.cancel(true); } return cancelled | (job.future != null && job.future.cancel(true)); }
@Test public void testAsyncActionCancellation() throws Exception { List<Integer> data = Arrays.asList(1, 2, 3, 4, 5); JavaRDD<Integer> rdd = sc.parallelize(data, 1); JavaFutureAction<Void> future = rdd.foreachAsync(integer -> { Thread.sleep(10000); // To ensure that the job won't finish before it's cancelled. }); future.cancel(true); assertTrue(future.isCancelled()); assertTrue(future.isDone()); try { future.get(2000, TimeUnit.MILLISECONDS); fail("Expected future.get() for cancelled job to throw CancellationException"); } catch (CancellationException ignored) { // pass } }
@Test public void testAsyncActionCancellation() throws Exception { List<Integer> data = Arrays.asList(1, 2, 3, 4, 5); JavaRDD<Integer> rdd = sc.parallelize(data, 1); JavaFutureAction<Void> future = rdd.foreachAsync(integer -> { Thread.sleep(10000); // To ensure that the job won't finish before it's cancelled. }); future.cancel(true); assertTrue(future.isCancelled()); assertTrue(future.isDone()); try { future.get(2000, TimeUnit.MILLISECONDS); fail("Expected future.get() for cancelled job to throw CancellationException"); } catch (CancellationException ignored) { // pass } }
@Test public void testAsyncActionCancellation() throws Exception { List<Integer> data = Arrays.asList(1, 2, 3, 4, 5); JavaRDD<Integer> rdd = sc.parallelize(data, 1); JavaFutureAction<Void> future = rdd.foreachAsync(integer -> { Thread.sleep(10000); // To ensure that the job won't finish before it's cancelled. }); future.cancel(true); assertTrue(future.isCancelled()); assertTrue(future.isDone()); try { future.get(2000, TimeUnit.MILLISECONDS); fail("Expected future.get() for cancelled job to throw CancellationException"); } catch (CancellationException ignored) { // pass } }
private boolean cancelJob(JobWrapper<?> job) { boolean cancelled = false; for (JavaFutureAction<?> action : job.jobs) { cancelled |= action.cancel(true); } return cancelled | (job.future != null && job.future.cancel(true)); }
private boolean cancelJob(JobWrapper<?> job) { boolean cancelled = false; for (JavaFutureAction<?> action : job.jobs) { cancelled |= action.cancel(true); } return cancelled | (job.future != null && job.future.cancel(true)); }