Repository: reef
Updated Branches:
  refs/heads/master bc5e14dcc -> 298eaa934


[REEF-1076] VortexFuture get should throw CancellationException if Future is 
cancelled

This addressed the issue by
  * Throw CancellationException if Tasklet was cancelled.
  * Reduce duplicate code with get().
  * Add throws documentation for get().

JIRA:
  [REEF-1076](https://issues.apache.org/jira/browse/REEF-1076)

Pull Request:
  Closes #731


Project: http://git-wip-us.apache.org/repos/asf/reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/298eaa93
Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/298eaa93
Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/298eaa93

Branch: refs/heads/master
Commit: 298eaa9346c531c70a2c469b24aa0c892ee502f1
Parents: bc5e14d
Author: Andrew Chung <[email protected]>
Authored: Mon Dec 14 13:59:08 2015 -0800
Committer: Byung-Gon Chun <[email protected]>
Committed: Tue Dec 15 12:38:52 2015 +0900

----------------------------------------------------------------------
 .../apache/reef/vortex/api/VortexFuture.java    | 24 +++++++++-----------
 .../TaskletCancellationTestStart.java           |  5 ++--
 2 files changed, 14 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/reef/blob/298eaa93/lang/java/reef-applications/reef-vortex/src/main/java/org/apache/reef/vortex/api/VortexFuture.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-applications/reef-vortex/src/main/java/org/apache/reef/vortex/api/VortexFuture.java
 
b/lang/java/reef-applications/reef-vortex/src/main/java/org/apache/reef/vortex/api/VortexFuture.java
index 019eeb0..7f4fbb7 100644
--- 
a/lang/java/reef-applications/reef-vortex/src/main/java/org/apache/reef/vortex/api/VortexFuture.java
+++ 
b/lang/java/reef-applications/reef-vortex/src/main/java/org/apache/reef/vortex/api/VortexFuture.java
@@ -136,9 +136,12 @@ public final class VortexFuture<TOutput> implements 
Future<TOutput> {
 
   /**
    * Infinitely wait for the result of the task.
+   * @throws InterruptedException if the thread is interrupted.
+   * @throws ExecutionException if the Tasklet execution failed to complete.
+   * @throws CancellationException if the Tasklet was cancelled.
    */
   @Override
-  public TOutput get() throws InterruptedException, ExecutionException {
+  public TOutput get() throws InterruptedException, ExecutionException, 
CancellationException {
     countDownLatch.await();
     if (userResult != null) {
       return userResult.get();
@@ -148,30 +151,25 @@ public final class VortexFuture<TOutput> implements 
Future<TOutput> {
         throw new ExecutionException(userException);
       }
 
-      throw new ExecutionException(new InterruptedException("Task was 
cancelled."));
+      throw new CancellationException("Tasklet was cancelled.");
     }
   }
 
   /**
    * Wait a certain period of time for the result of the task.
+   * @throws TimeoutException if the timeout provided hits before the Tasklet 
is done.
+   * @throws InterruptedException if the thread is interrupted.
+   * @throws ExecutionException if the Tasklet execution failed to complete.
+   * @throws CancellationException if the Tasklet was cancelled.
    */
   @Override
   public TOutput get(final long timeout, final TimeUnit unit)
-      throws InterruptedException, ExecutionException, TimeoutException {
+      throws InterruptedException, ExecutionException, TimeoutException, 
CancellationException {
     if (!countDownLatch.await(timeout, unit)) {
       throw new TimeoutException();
     }
 
-    if (userResult != null) {
-      return userResult.get();
-    } else {
-      assert this.cancelled.get() || userException != null;
-      if (userException != null) {
-        throw new ExecutionException(userException);
-      }
-
-      throw new ExecutionException(new InterruptedException("Task was 
cancelled."));
-    }
+    return get();
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/reef/blob/298eaa93/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/cancellation/TaskletCancellationTestStart.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/cancellation/TaskletCancellationTestStart.java
 
b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/cancellation/TaskletCancellationTestStart.java
index d60e0b5..481bb5f 100644
--- 
a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/cancellation/TaskletCancellationTestStart.java
+++ 
b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/cancellation/TaskletCancellationTestStart.java
@@ -25,6 +25,7 @@ import org.apache.reef.vortex.api.VortexThreadPool;
 import org.junit.Assert;
 
 import javax.inject.Inject;
+import java.util.concurrent.CancellationException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
@@ -59,9 +60,9 @@ public final class TaskletCancellationTestStart implements 
VortexStart {
     try {
       future.get();
       Assert.fail();
-    } catch (final ExecutionException e) {
+    } catch (final CancellationException e) {
       // Expected.
-    } catch (InterruptedException e) {
+    } catch (final ExecutionException|InterruptedException e) {
       e.printStackTrace();
       Assert.fail();
     }

Reply via email to