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

Comparing jsr166/src/test/tck/AbstractExecutorServiceTest.java (file contents):
Revision 1.38 by jsr166, Mon Sep 14 03:14:43 2015 UTC vs.
Revision 1.42 by jsr166, Tue Oct 6 00:41:47 2015 UTC

# Line 192 | Line 192 | public class AbstractExecutorServiceTest
192      public void testInterruptedSubmit() throws InterruptedException {
193          final CountDownLatch submitted    = new CountDownLatch(1);
194          final CountDownLatch quittingTime = new CountDownLatch(1);
195        final ExecutorService p
196            = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS,
197                                     new ArrayBlockingQueue<Runnable>(10));
195          final Callable<Void> awaiter = new CheckedCallable<Void>() {
196              public Void realCall() throws InterruptedException {
197 <                quittingTime.await();
197 >                assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS));
198                  return null;
199              }};
200 <        try {
201 <            Thread t = new Thread(new CheckedInterruptedRunnable() {
200 >        final ExecutorService p
201 >            = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS,
202 >                                     new ArrayBlockingQueue<Runnable>(10));
203 >        try (PoolCleaner cleaner = cleaner(p, quittingTime)) {
204 >            Thread t = newStartedThread(new CheckedInterruptedRunnable() {
205                  public void realRun() throws Exception {
206                      Future<Void> future = p.submit(awaiter);
207                      submitted.countDown();
208                      future.get();
209                  }});
210 <            t.start();
211 <            submitted.await();
210 >
211 >            await(submitted);
212              t.interrupt();
213 <            t.join();
214 <        } finally {
215 <            quittingTime.countDown();
216 <            joinPool(p);
213 >            awaitTermination(t);
214          }
215      }
216  
# Line 222 | Line 219 | public class AbstractExecutorServiceTest
219       * throws exception
220       */
221      public void testSubmitEE() throws InterruptedException {
222 <        ThreadPoolExecutor p =
222 >        final ThreadPoolExecutor p =
223              new ThreadPoolExecutor(1, 1,
224                                     60, TimeUnit.SECONDS,
225                                     new ArrayBlockingQueue<Runnable>(10));
226 <
227 <        Callable c = new Callable() {
228 <            public Object call() { throw new ArithmeticException(); }};
229 <
230 <        try {
231 <            p.submit(c).get();
232 <            shouldThrow();
233 <        } catch (ExecutionException success) {
234 <            assertTrue(success.getCause() instanceof ArithmeticException);
226 >        try (PoolCleaner cleaner = cleaner(p)) {
227 >            Callable c = new Callable() {
228 >                public Object call() { throw new ArithmeticException(); }};
229 >            try {
230 >                p.submit(c).get();
231 >                shouldThrow();
232 >            } catch (ExecutionException success) {
233 >                assertTrue(success.getCause() instanceof ArithmeticException);
234 >            }
235          }
239        joinPool(p);
236      }
237  
238      /**
239       * invokeAny(null) throws NPE
240       */
241      public void testInvokeAny1() throws Exception {
242 <        ExecutorService e = new DirectExecutorService();
243 <        try {
244 <            e.invokeAny(null);
245 <            shouldThrow();
246 <        } catch (NullPointerException success) {
247 <        } finally {
252 <            joinPool(e);
242 >        final ExecutorService e = new DirectExecutorService();
243 >        try (PoolCleaner cleaner = cleaner(e)) {
244 >            try {
245 >                e.invokeAny(null);
246 >                shouldThrow();
247 >            } catch (NullPointerException success) {}
248          }
249      }
250  
# Line 257 | Line 252 | public class AbstractExecutorServiceTest
252       * invokeAny(empty collection) throws IAE
253       */
254      public void testInvokeAny2() throws Exception {
255 <        ExecutorService e = new DirectExecutorService();
256 <        try {
257 <            e.invokeAny(new ArrayList<Callable<String>>());
258 <            shouldThrow();
259 <        } catch (IllegalArgumentException success) {
260 <        } finally {
266 <            joinPool(e);
255 >        final ExecutorService e = new DirectExecutorService();
256 >        try (PoolCleaner cleaner = cleaner(e)) {
257 >            try {
258 >                e.invokeAny(new ArrayList<Callable<String>>());
259 >                shouldThrow();
260 >            } catch (IllegalArgumentException success) {}
261          }
262      }
263  
# Line 271 | Line 265 | public class AbstractExecutorServiceTest
265       * invokeAny(c) throws NPE if c has null elements
266       */
267      public void testInvokeAny3() throws Exception {
268 <        ExecutorService e = new DirectExecutorService();
269 <        List<Callable<Long>> l = new ArrayList<Callable<Long>>();
270 <        l.add(new Callable<Long>() {
271 <            public Long call() { throw new ArithmeticException(); }});
272 <        l.add(null);
273 <        try {
274 <            e.invokeAny(l);
275 <            shouldThrow();
276 <        } catch (NullPointerException success) {
277 <        } finally {
284 <            joinPool(e);
268 >        final ExecutorService e = new DirectExecutorService();
269 >        try (PoolCleaner cleaner = cleaner(e)) {
270 >            List<Callable<Long>> l = new ArrayList<Callable<Long>>();
271 >            l.add(new Callable<Long>() {
272 >                      public Long call() { throw new ArithmeticException(); }});
273 >            l.add(null);
274 >            try {
275 >                e.invokeAny(l);
276 >                shouldThrow();
277 >            } catch (NullPointerException success) {}
278          }
279      }
280  
# Line 289 | Line 282 | public class AbstractExecutorServiceTest
282       * invokeAny(c) throws ExecutionException if no task in c completes
283       */
284      public void testInvokeAny4() throws InterruptedException {
285 <        ExecutorService e = new DirectExecutorService();
286 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
287 <        l.add(new NPETask());
288 <        try {
289 <            e.invokeAny(l);
290 <            shouldThrow();
291 <        } catch (ExecutionException success) {
292 <            assertTrue(success.getCause() instanceof NullPointerException);
293 <        } finally {
294 <            joinPool(e);
285 >        final ExecutorService e = new DirectExecutorService();
286 >        try (PoolCleaner cleaner = cleaner(e)) {
287 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
288 >            l.add(new NPETask());
289 >            try {
290 >                e.invokeAny(l);
291 >                shouldThrow();
292 >            } catch (ExecutionException success) {
293 >                assertTrue(success.getCause() instanceof NullPointerException);
294 >            }
295          }
296      }
297  
# Line 306 | Line 299 | public class AbstractExecutorServiceTest
299       * invokeAny(c) returns result of some task in c if at least one completes
300       */
301      public void testInvokeAny5() throws Exception {
302 <        ExecutorService e = new DirectExecutorService();
303 <        try {
302 >        final ExecutorService e = new DirectExecutorService();
303 >        try (PoolCleaner cleaner = cleaner(e)) {
304              List<Callable<String>> l = new ArrayList<Callable<String>>();
305              l.add(new StringTask());
306              l.add(new StringTask());
307              String result = e.invokeAny(l);
308              assertSame(TEST_STRING, result);
316        } finally {
317            joinPool(e);
309          }
310      }
311  
# Line 322 | Line 313 | public class AbstractExecutorServiceTest
313       * invokeAll(null) throws NPE
314       */
315      public void testInvokeAll1() throws InterruptedException {
316 <        ExecutorService e = new DirectExecutorService();
317 <        try {
318 <            e.invokeAll(null);
319 <            shouldThrow();
320 <        } catch (NullPointerException success) {
321 <        } finally {
331 <            joinPool(e);
316 >        final ExecutorService e = new DirectExecutorService();
317 >        try (PoolCleaner cleaner = cleaner(e)) {
318 >            try {
319 >                e.invokeAll(null);
320 >                shouldThrow();
321 >            } catch (NullPointerException success) {}
322          }
323      }
324  
# Line 336 | Line 326 | public class AbstractExecutorServiceTest
326       * invokeAll(empty collection) returns empty collection
327       */
328      public void testInvokeAll2() throws InterruptedException {
329 <        ExecutorService e = new DirectExecutorService();
330 <        try {
329 >        final ExecutorService e = new DirectExecutorService();
330 >        try (PoolCleaner cleaner = cleaner(e)) {
331              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
332              assertTrue(r.isEmpty());
343        } finally {
344            joinPool(e);
333          }
334      }
335  
# Line 349 | Line 337 | public class AbstractExecutorServiceTest
337       * invokeAll(c) throws NPE if c has null elements
338       */
339      public void testInvokeAll3() throws InterruptedException {
340 <        ExecutorService e = new DirectExecutorService();
341 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
342 <        l.add(new StringTask());
343 <        l.add(null);
344 <        try {
345 <            e.invokeAll(l);
346 <            shouldThrow();
347 <        } catch (NullPointerException success) {
348 <        } finally {
361 <            joinPool(e);
340 >        final ExecutorService e = new DirectExecutorService();
341 >        try (PoolCleaner cleaner = cleaner(e)) {
342 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
343 >            l.add(new StringTask());
344 >            l.add(null);
345 >            try {
346 >                e.invokeAll(l);
347 >                shouldThrow();
348 >            } catch (NullPointerException success) {}
349          }
350      }
351  
# Line 366 | Line 353 | public class AbstractExecutorServiceTest
353       * get of returned element of invokeAll(c) throws exception on failed task
354       */
355      public void testInvokeAll4() throws Exception {
356 <        ExecutorService e = new DirectExecutorService();
357 <        try {
356 >        final ExecutorService e = new DirectExecutorService();
357 >        try (PoolCleaner cleaner = cleaner(e)) {
358              List<Callable<String>> l = new ArrayList<Callable<String>>();
359              l.add(new NPETask());
360              List<Future<String>> futures = e.invokeAll(l);
# Line 378 | Line 365 | public class AbstractExecutorServiceTest
365              } catch (ExecutionException success) {
366                  assertTrue(success.getCause() instanceof NullPointerException);
367              }
381        } finally {
382            joinPool(e);
368          }
369      }
370  
# Line 387 | Line 372 | public class AbstractExecutorServiceTest
372       * invokeAll(c) returns results of all completed tasks in c
373       */
374      public void testInvokeAll5() throws Exception {
375 <        ExecutorService e = new DirectExecutorService();
376 <        try {
375 >        final ExecutorService e = new DirectExecutorService();
376 >        try (PoolCleaner cleaner = cleaner(e)) {
377              List<Callable<String>> l = new ArrayList<Callable<String>>();
378              l.add(new StringTask());
379              l.add(new StringTask());
# Line 396 | Line 381 | public class AbstractExecutorServiceTest
381              assertEquals(2, futures.size());
382              for (Future<String> future : futures)
383                  assertSame(TEST_STRING, future.get());
399        } finally {
400            joinPool(e);
384          }
385      }
386  
# Line 405 | Line 388 | public class AbstractExecutorServiceTest
388       * timed invokeAny(null) throws NPE
389       */
390      public void testTimedInvokeAny1() throws Exception {
391 <        ExecutorService e = new DirectExecutorService();
392 <        try {
393 <            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
394 <            shouldThrow();
395 <        } catch (NullPointerException success) {
396 <        } finally {
414 <            joinPool(e);
391 >        final ExecutorService e = new DirectExecutorService();
392 >        try (PoolCleaner cleaner = cleaner(e)) {
393 >            try {
394 >                e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
395 >                shouldThrow();
396 >            } catch (NullPointerException success) {}
397          }
398      }
399  
# Line 419 | Line 401 | public class AbstractExecutorServiceTest
401       * timed invokeAny(null time unit) throws NPE
402       */
403      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
404 <        ExecutorService e = new DirectExecutorService();
405 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
406 <        l.add(new StringTask());
407 <        try {
408 <            e.invokeAny(l, MEDIUM_DELAY_MS, null);
409 <            shouldThrow();
410 <        } catch (NullPointerException success) {
411 <        } finally {
430 <            joinPool(e);
404 >        final ExecutorService e = new DirectExecutorService();
405 >        try (PoolCleaner cleaner = cleaner(e)) {
406 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
407 >            l.add(new StringTask());
408 >            try {
409 >                e.invokeAny(l, MEDIUM_DELAY_MS, null);
410 >                shouldThrow();
411 >            } catch (NullPointerException success) {}
412          }
413      }
414  
# Line 435 | Line 416 | public class AbstractExecutorServiceTest
416       * timed invokeAny(empty collection) throws IAE
417       */
418      public void testTimedInvokeAny2() throws Exception {
419 <        ExecutorService e = new DirectExecutorService();
420 <        try {
421 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
422 <            shouldThrow();
423 <        } catch (IllegalArgumentException success) {
424 <        } finally {
425 <            joinPool(e);
419 >        final ExecutorService e = new DirectExecutorService();
420 >        try (PoolCleaner cleaner = cleaner(e)) {
421 >            try {
422 >                e.invokeAny(new ArrayList<Callable<String>>(),
423 >                            MEDIUM_DELAY_MS, MILLISECONDS);
424 >                shouldThrow();
425 >            } catch (IllegalArgumentException success) {}
426          }
427      }
428  
# Line 449 | Line 430 | public class AbstractExecutorServiceTest
430       * timed invokeAny(c) throws NPE if c has null elements
431       */
432      public void testTimedInvokeAny3() throws Exception {
433 <        ExecutorService e = new DirectExecutorService();
434 <        List<Callable<Long>> l = new ArrayList<Callable<Long>>();
435 <        l.add(new Callable<Long>() {
436 <            public Long call() { throw new ArithmeticException(); }});
437 <        l.add(null);
438 <        try {
439 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
440 <            shouldThrow();
441 <        } catch (NullPointerException success) {
442 <        } finally {
462 <            joinPool(e);
433 >        final ExecutorService e = new DirectExecutorService();
434 >        try (PoolCleaner cleaner = cleaner(e)) {
435 >            List<Callable<Long>> l = new ArrayList<Callable<Long>>();
436 >            l.add(new Callable<Long>() {
437 >                      public Long call() { throw new ArithmeticException(); }});
438 >            l.add(null);
439 >            try {
440 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
441 >                shouldThrow();
442 >            } catch (NullPointerException success) {}
443          }
444      }
445  
# Line 467 | Line 447 | public class AbstractExecutorServiceTest
447       * timed invokeAny(c) throws ExecutionException if no task completes
448       */
449      public void testTimedInvokeAny4() throws Exception {
450 <        ExecutorService e = new DirectExecutorService();
451 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
452 <        l.add(new NPETask());
453 <        try {
454 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
455 <            shouldThrow();
456 <        } catch (ExecutionException success) {
457 <            assertTrue(success.getCause() instanceof NullPointerException);
458 <        } finally {
459 <            joinPool(e);
450 >        final ExecutorService e = new DirectExecutorService();
451 >        try (PoolCleaner cleaner = cleaner(e)) {
452 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
453 >            l.add(new NPETask());
454 >            try {
455 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
456 >                shouldThrow();
457 >            } catch (ExecutionException success) {
458 >                assertTrue(success.getCause() instanceof NullPointerException);
459 >            }
460          }
461      }
462  
# Line 484 | Line 464 | public class AbstractExecutorServiceTest
464       * timed invokeAny(c) returns result of some task in c
465       */
466      public void testTimedInvokeAny5() throws Exception {
467 <        ExecutorService e = new DirectExecutorService();
468 <        try {
467 >        final ExecutorService e = new DirectExecutorService();
468 >        try (PoolCleaner cleaner = cleaner(e)) {
469              List<Callable<String>> l = new ArrayList<Callable<String>>();
470              l.add(new StringTask());
471              l.add(new StringTask());
472              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
473              assertSame(TEST_STRING, result);
494        } finally {
495            joinPool(e);
474          }
475      }
476  
# Line 500 | Line 478 | public class AbstractExecutorServiceTest
478       * timed invokeAll(null) throws NPE
479       */
480      public void testTimedInvokeAll1() throws InterruptedException {
481 <        ExecutorService e = new DirectExecutorService();
482 <        try {
483 <            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
484 <            shouldThrow();
485 <        } catch (NullPointerException success) {
486 <        } finally {
509 <            joinPool(e);
481 >        final ExecutorService e = new DirectExecutorService();
482 >        try (PoolCleaner cleaner = cleaner(e)) {
483 >            try {
484 >                e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
485 >                shouldThrow();
486 >            } catch (NullPointerException success) {}
487          }
488      }
489  
# Line 514 | Line 491 | public class AbstractExecutorServiceTest
491       * timed invokeAll(null time unit) throws NPE
492       */
493      public void testTimedInvokeAllNullTimeUnit() throws InterruptedException {
494 <        ExecutorService e = new DirectExecutorService();
495 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
496 <        l.add(new StringTask());
497 <        try {
498 <            e.invokeAll(l, MEDIUM_DELAY_MS, null);
499 <            shouldThrow();
500 <        } catch (NullPointerException success) {
501 <        } finally {
525 <            joinPool(e);
494 >        final ExecutorService e = new DirectExecutorService();
495 >        try (PoolCleaner cleaner = cleaner(e)) {
496 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
497 >            l.add(new StringTask());
498 >            try {
499 >                e.invokeAll(l, MEDIUM_DELAY_MS, null);
500 >                shouldThrow();
501 >            } catch (NullPointerException success) {}
502          }
503      }
504  
# Line 530 | Line 506 | public class AbstractExecutorServiceTest
506       * timed invokeAll(empty collection) returns empty collection
507       */
508      public void testTimedInvokeAll2() throws InterruptedException {
509 <        ExecutorService e = new DirectExecutorService();
510 <        try {
509 >        final ExecutorService e = new DirectExecutorService();
510 >        try (PoolCleaner cleaner = cleaner(e)) {
511              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
512              assertTrue(r.isEmpty());
537        } finally {
538            joinPool(e);
513          }
514      }
515  
# Line 543 | Line 517 | public class AbstractExecutorServiceTest
517       * timed invokeAll(c) throws NPE if c has null elements
518       */
519      public void testTimedInvokeAll3() throws InterruptedException {
520 <        ExecutorService e = new DirectExecutorService();
521 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
522 <        l.add(new StringTask());
523 <        l.add(null);
524 <        try {
525 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
526 <            shouldThrow();
527 <        } catch (NullPointerException success) {
528 <        } finally {
555 <            joinPool(e);
520 >        final ExecutorService e = new DirectExecutorService();
521 >        try (PoolCleaner cleaner = cleaner(e)) {
522 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
523 >            l.add(new StringTask());
524 >            l.add(null);
525 >            try {
526 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
527 >                shouldThrow();
528 >            } catch (NullPointerException success) {}
529          }
530      }
531  
# Line 560 | Line 533 | public class AbstractExecutorServiceTest
533       * get of returned element of invokeAll(c) throws exception on failed task
534       */
535      public void testTimedInvokeAll4() throws Exception {
536 <        ExecutorService e = new DirectExecutorService();
537 <        try {
536 >        final ExecutorService e = new DirectExecutorService();
537 >        try (PoolCleaner cleaner = cleaner(e)) {
538              List<Callable<String>> l = new ArrayList<Callable<String>>();
539              l.add(new NPETask());
540              List<Future<String>> futures =
541 <                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
541 >                e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
542              assertEquals(1, futures.size());
543              try {
544                  futures.get(0).get();
# Line 573 | Line 546 | public class AbstractExecutorServiceTest
546              } catch (ExecutionException success) {
547                  assertTrue(success.getCause() instanceof NullPointerException);
548              }
576        } finally {
577            joinPool(e);
549          }
550      }
551  
# Line 582 | Line 553 | public class AbstractExecutorServiceTest
553       * timed invokeAll(c) returns results of all completed tasks in c
554       */
555      public void testTimedInvokeAll5() throws Exception {
556 <        ExecutorService e = new DirectExecutorService();
557 <        try {
556 >        final ExecutorService e = new DirectExecutorService();
557 >        try (PoolCleaner cleaner = cleaner(e)) {
558              List<Callable<String>> l = new ArrayList<Callable<String>>();
559              l.add(new StringTask());
560              l.add(new StringTask());
# Line 592 | Line 563 | public class AbstractExecutorServiceTest
563              assertEquals(2, futures.size());
564              for (Future<String> future : futures)
565                  assertSame(TEST_STRING, future.get());
595        } finally {
596            joinPool(e);
566          }
567      }
568  
# Line 601 | Line 570 | public class AbstractExecutorServiceTest
570       * timed invokeAll cancels tasks not completed by timeout
571       */
572      public void testTimedInvokeAll6() throws Exception {
573 <        ExecutorService e = new DirectExecutorService();
574 <        try {
575 <            long timeout = timeoutMillis();
576 <            List<Callable<String>> tasks = new ArrayList<>();
577 <            tasks.add(new StringTask("0"));
578 <            tasks.add(Executors.callable(possiblyInterruptedRunnable(timeout),
579 <                                         TEST_STRING));
580 <            tasks.add(new StringTask("2"));
581 <            long startTime = System.nanoTime();
582 <            List<Future<String>> futures =
583 <                e.invokeAll(tasks, timeout, MILLISECONDS);
584 <            assertEquals(tasks.size(), futures.size());
585 <            assertTrue(millisElapsedSince(startTime) >= timeout);
586 <            for (Future future : futures)
587 <                assertTrue(future.isDone());
588 <            assertEquals("0", futures.get(0).get());
589 <            assertEquals(TEST_STRING, futures.get(1).get());
590 <            assertTrue(futures.get(2).isCancelled());
591 <        } finally {
592 <            joinPool(e);
573 >        final ExecutorService e = new DirectExecutorService();
574 >        try (PoolCleaner cleaner = cleaner(e)) {
575 >            for (long timeout = timeoutMillis();;) {
576 >                List<Callable<String>> tasks = new ArrayList<>();
577 >                tasks.add(new StringTask("0"));
578 >                tasks.add(Executors.callable(possiblyInterruptedRunnable(timeout),
579 >                                             TEST_STRING));
580 >                tasks.add(new StringTask("2"));
581 >                long startTime = System.nanoTime();
582 >                List<Future<String>> futures =
583 >                    e.invokeAll(tasks, timeout, MILLISECONDS);
584 >                assertEquals(tasks.size(), futures.size());
585 >                assertTrue(millisElapsedSince(startTime) >= timeout);
586 >                for (Future future : futures)
587 >                    assertTrue(future.isDone());
588 >                try {
589 >                    assertEquals("0", futures.get(0).get());
590 >                    assertEquals(TEST_STRING, futures.get(1).get());
591 >                } catch (CancellationException retryWithLongerTimeout) {
592 >                    // unusual delay before starting second task
593 >                    timeout *= 2;
594 >                    if (timeout >= LONG_DELAY_MS / 2)
595 >                        fail("expected exactly one task to be cancelled");
596 >                    continue;
597 >                }
598 >                assertTrue(futures.get(2).isCancelled());
599 >                break;
600 >            }
601          }
602      }
603  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines