Github user vanzin commented on a diff in the pull request:
https://github.com/apache/spark/pull/2760#discussion_r18865362
--- Diff: core/src/test/java/org/apache/spark/JavaAPISuite.java ---
@@ -1308,6 +1307,92 @@ public void collectUnderlyingScalaRDD() {
Assert.assertEquals(data.size(), collected.length);
}
+ private static final class BuggyMapFunction<T> implements Function<T, T>
{
+
+ @Override
+ public T call(T x) throws Exception {
+ throw new IllegalStateException("Custom exception!");
+ }
+ }
+
+ @Test
+ public void collectAsync() throws Exception {
+ List<Integer> data = Arrays.asList(1, 2, 3, 4, 5);
+ JavaRDD<Integer> rdd = sc.parallelize(data, 1);
+ JavaFutureAction<List<Integer>> future = rdd.collectAsync();
+ List<Integer> result = future.get();
+ Assert.assertEquals(data, result);
+ Assert.assertFalse(future.isCancelled());
+ Assert.assertTrue(future.isDone());
+ Assert.assertEquals(1, future.jobIds().size());
+ }
+
+ @Test
+ public void foreachAsync() throws Exception {
+ List<Integer> data = Arrays.asList(1, 2, 3, 4, 5);
+ JavaRDD<Integer> rdd = sc.parallelize(data, 1);
+ JavaFutureAction<Void> future = rdd.foreachAsync(
+ new VoidFunction<Integer>() {
+ @Override
+ public void call(Integer integer) throws Exception {
+ // intentionally left blank.
+ }
+ }
+ );
+ future.get();
+ Assert.assertFalse(future.isCancelled());
+ Assert.assertTrue(future.isDone());
+ Assert.assertEquals(1, future.jobIds().size());
+ }
+
+ @Test
+ public void countAsync() throws Exception {
+ List<Integer> data = Arrays.asList(1, 2, 3, 4, 5);
+ JavaRDD<Integer> rdd = sc.parallelize(data, 1);
+ JavaFutureAction<Long> future = rdd.countAsync();
+ long count = future.get();
+ Assert.assertEquals(data.size(), count);
+ Assert.assertFalse(future.isCancelled());
+ Assert.assertTrue(future.isDone());
+ Assert.assertEquals(1, future.jobIds().size());
+ }
+
+ @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(new
VoidFunction<Integer>() {
+ @Override
+ public void call(Integer integer) throws Exception {
+ Thread.sleep(10000); // To ensure that the job won't finish
before it's cancelled.
+ }
+ });
+ future.cancel(true);
+ Assert.assertTrue(future.isCancelled());
+ Assert.assertTrue(future.isDone());
+ try {
+ future.get(2000, TimeUnit.MILLISECONDS);
+ Assert.fail("Expected future.get() for cancelled job to throw
CancellationException");
+ } catch (CancellationException ignored) {
+ // pass
+ }
+ }
+
+ @Test
+ public void testAsyncActionErrorWrapping() throws Exception {
+ List<Integer> data = Arrays.asList(1, 2, 3, 4, 5);
+ JavaRDD<Integer> rdd = sc.parallelize(data, 1);
+ JavaFutureAction<Long> future = rdd.map(new
BuggyMapFunction<Integer>()).countAsync();
+ try {
+ long count = future.get(2, TimeUnit.SECONDS);
--- End diff --
nit: variable is unused.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]