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

    https://github.com/apache/spark/pull/2760#discussion_r18854718
  
    --- 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);
    --- End diff --
    
    This looks racy. There's no guarantee that the test won't have finished 
when this sleep wakes up, and then cancellation will fail.
    
    What exactly is the behavior you're trying to test? I'm pretty sure job 
cancellation is covered elsewhere, so if you want to test the wrapper's 
behavior, it might be worth it to use Mockito instead of running real jobs.


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