Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2760#discussion_r18854775
  
    --- Diff: core/src/test/java/org/apache/spark/JavaAPISuite.java ---
    @@ -1308,6 +1306,111 @@ public void collectUnderlyingScalaRDD() {
         Assert.assertEquals(data.size(), collected.length);
       }
     
    +  private static final class IdentityWithDelay<T> implements Function<T, 
T> {
    +
    +    final int delayMillis;
    +
    +    IdentityWithDelay(int delayMillis) {
    +      this.delayMillis = delayMillis;
    +    }
    +
    +    @Override
    +    public T call(T x) throws Exception {
    +      Thread.sleep(delayMillis);
    +      return x;
    +    }
    +  }
    +
    +  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.map(new IdentityWithDelay<Integer>(200)).collectAsync();
    +    Assert.assertFalse(future.isCancelled());
    +    Assert.assertFalse(future.isDone());
    +    List<Integer> result = future.get();
    +    Assert.assertEquals(result, data);
    +    Assert.assertFalse(future.isCancelled());
    +    Assert.assertTrue(future.isDone());
    +    Assert.assertEquals(future.jobIds().size(), 1);
    +  }
    +
    +  @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.map(new 
IdentityWithDelay<Integer>(200)).foreachAsync(
    +        new VoidFunction<Integer>() {
    +          @Override
    +          public void call(Integer integer) throws Exception {
    +            // intentionally left blank.
    +          }
    +        }
    +    );
    +    Assert.assertFalse(future.isCancelled());
    +    Assert.assertFalse(future.isDone());
    +    future.get();
    +    Assert.assertFalse(future.isCancelled());
    +    Assert.assertTrue(future.isDone());
    +    Assert.assertEquals(future.jobIds().size(), 1);
    +  }
    +
    +  @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.map(new 
IdentityWithDelay<Integer>(200)).countAsync();
    +    Assert.assertFalse(future.isCancelled());
    +    Assert.assertFalse(future.isDone());
    +    long count = future.get();
    +    Assert.assertEquals(count, data.size());
    +    Assert.assertFalse(future.isCancelled());
    +    Assert.assertTrue(future.isDone());
    +    Assert.assertEquals(future.jobIds().size(), 1);
    +  }
    +
    +  @Test
    +  public void testAsyncActionCancellation() 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 
IdentityWithDelay<Integer>(200)).countAsync();
    +    Thread.sleep(200);
    +    future.cancel(true);
    +    Assert.assertTrue(future.isCancelled());
    +    Assert.assertTrue(future.isDone());
    +    try {
    +      long count = 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();
    +    Thread.sleep(200);
    +    try {
    +      long count = future.get(2000, TimeUnit.MILLISECONDS);
    --- End diff --
    
    `(2, TimeUnit.SECONDS)`?


---
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]

Reply via email to