ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CompletableFutureTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CompletableFutureTest.java (file contents):
Revision 1.94 by jsr166, Wed Jun 18 02:37:38 2014 UTC vs.
Revision 1.95 by jsr166, Wed Jun 25 15:32:10 2014 UTC

# Line 57 | Line 57 | public class CompletableFutureTest exten
57      }
58  
59      <T> void checkCompletedNormally(CompletableFuture<T> f, T value) {
60 <        try {
61 <            assertEquals(value, f.get(LONG_DELAY_MS, MILLISECONDS));
62 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
60 >        checkTimedGet(f, value);
61 >
62          try {
63              assertEquals(value, f.join());
64          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 76 | Line 75 | public class CompletableFutureTest exten
75      }
76  
77      void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
78 +        long startTime = System.nanoTime();
79 +        long timeoutMillis = LONG_DELAY_MS;
80          try {
81 <            f.get(LONG_DELAY_MS, MILLISECONDS);
81 >            f.get(timeoutMillis, MILLISECONDS);
82              shouldThrow();
83          } catch (ExecutionException success) {
84              assertTrue(success.getCause() instanceof CFException);
85          } catch (Throwable fail) { threadUnexpectedException(fail); }
86 +        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
87 +
88          try {
89              f.join();
90              shouldThrow();
# Line 107 | Line 110 | public class CompletableFutureTest exten
110  
111      <U> void checkCompletedExceptionallyWithRootCause(CompletableFuture<U> f,
112                                                        Throwable ex) {
113 +        long startTime = System.nanoTime();
114 +        long timeoutMillis = LONG_DELAY_MS;
115          try {
116 <            f.get(LONG_DELAY_MS, MILLISECONDS);
116 >            f.get(timeoutMillis, MILLISECONDS);
117              shouldThrow();
118          } catch (ExecutionException success) {
119              assertSame(ex, success.getCause());
120          } catch (Throwable fail) { threadUnexpectedException(fail); }
121 +        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
122 +
123          try {
124              f.join();
125              shouldThrow();
# Line 158 | Line 165 | public class CompletableFutureTest exten
165      }
166  
167      void checkCancelled(CompletableFuture<?> f) {
168 +        long startTime = System.nanoTime();
169 +        long timeoutMillis = LONG_DELAY_MS;
170          try {
171 <            f.get(LONG_DELAY_MS, MILLISECONDS);
171 >            f.get(timeoutMillis, MILLISECONDS);
172              shouldThrow();
173          } catch (CancellationException success) {
174          } catch (Throwable fail) { threadUnexpectedException(fail); }
175 +        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
176 +
177          try {
178              f.join();
179              shouldThrow();
# Line 183 | Line 194 | public class CompletableFutureTest exten
194      }
195  
196      void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) {
197 +        long startTime = System.nanoTime();
198 +        long timeoutMillis = LONG_DELAY_MS;
199          try {
200 <            f.get(LONG_DELAY_MS, MILLISECONDS);
200 >            f.get(timeoutMillis, MILLISECONDS);
201              shouldThrow();
202          } catch (ExecutionException success) {
203              assertTrue(success.getCause() instanceof CancellationException);
204          } catch (Throwable fail) { threadUnexpectedException(fail); }
205 +        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
206 +
207          try {
208              f.join();
209              shouldThrow();
# Line 574 | Line 589 | public class CompletableFutureTest exten
589       * execution modes without copy/pasting all the test methods.
590       */
591      enum ExecutionMode {
592 <        DEFAULT {
592 >        SYNC {
593              public void checkExecutionMode() {
594                  assertFalse(ThreadExecutor.startedCurrentThread());
595                  assertNull(ForkJoinTask.getPool());
# Line 875 | Line 890 | public class CompletableFutureTest exten
890          if (!createIncomplete) f.completeExceptionally(ex);
891          final CompletableFuture<Integer> g = f.exceptionally
892              ((Throwable t) -> {
893 <                ExecutionMode.DEFAULT.checkExecutionMode();
893 >                ExecutionMode.SYNC.checkExecutionMode();
894                  threadAssertSame(t, ex);
895                  a.getAndIncrement();
896                  return v1;
# Line 897 | Line 912 | public class CompletableFutureTest exten
912          if (!createIncomplete) f.completeExceptionally(ex1);
913          final CompletableFuture<Integer> g = f.exceptionally
914              ((Throwable t) -> {
915 <                ExecutionMode.DEFAULT.checkExecutionMode();
915 >                ExecutionMode.SYNC.checkExecutionMode();
916                  threadAssertSame(t, ex1);
917                  a.getAndIncrement();
918                  throw ex2;
# Line 3148 | Line 3163 | public class CompletableFutureTest exten
3163          Runnable[] throwingActions = {
3164              () -> CompletableFuture.supplyAsync(null),
3165              () -> CompletableFuture.supplyAsync(null, exec),
3166 <            () -> CompletableFuture.supplyAsync(new IntegerSupplier(ExecutionMode.DEFAULT, 42), null),
3166 >            () -> CompletableFuture.supplyAsync(new IntegerSupplier(ExecutionMode.SYNC, 42), null),
3167  
3168              () -> CompletableFuture.runAsync(null),
3169              () -> CompletableFuture.runAsync(null, exec),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines