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

Comparing jsr166/src/test/tck/ForkJoinPoolTest.java (file contents):
Revision 1.71 by jsr166, Thu Sep 15 01:18:01 2016 UTC vs.
Revision 1.75 by jsr166, Mon May 29 22:44:27 2017 UTC

# Line 11 | Line 11 | import java.security.PrivilegedAction;
11   import java.security.PrivilegedExceptionAction;
12   import java.util.ArrayList;
13   import java.util.Collection;
14 + import java.util.Collections;
15   import java.util.List;
16   import java.util.concurrent.Callable;
17   import java.util.concurrent.CountDownLatch;
# Line 217 | Line 218 | public class ForkJoinPoolTest extends JS
218                      taskStarted.countDown();
219                      assertEquals(1, p.getPoolSize());
220                      assertEquals(1, p.getActiveThreadCount());
221 <                    done.await();
221 >                    await(done);
222                  }};
223              Future<?> future = p.submit(task);
224              await(taskStarted);
# Line 240 | Line 241 | public class ForkJoinPoolTest extends JS
241              assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS));
242              assertFalse(p.awaitTermination(-1L, NANOSECONDS));
243              assertFalse(p.awaitTermination(-1L, MILLISECONDS));
244 <            assertFalse(p.awaitTermination(0L, NANOSECONDS));
245 <            assertFalse(p.awaitTermination(0L, MILLISECONDS));
244 >            assertFalse(p.awaitTermination(randomExpiredTimeout(),
245 >                                           randomTimeUnit()));
246              long timeoutNanos = 999999L;
247              long startTime = System.nanoTime();
248              assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS));
# Line 422 | Line 423 | public class ForkJoinPoolTest extends JS
423                      done.set(true);
424                  }});
425              assertNull(future.get());
426 <            assertNull(future.get(0, MILLISECONDS));
426 >            assertNull(future.get(randomExpiredTimeout(), randomTimeUnit()));
427              assertTrue(done.get());
428              assertTrue(future.isDone());
429              assertFalse(future.isCancelled());
# Line 631 | Line 632 | public class ForkJoinPoolTest extends JS
632      public void testInvokeAny3() throws Throwable {
633          ExecutorService e = new ForkJoinPool(1);
634          try (PoolCleaner cleaner = cleaner(e)) {
635 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
635 >            List<Callable<String>> l = new ArrayList<>();
636              l.add(null);
637              try {
638                  e.invokeAny(l);
# Line 647 | Line 648 | public class ForkJoinPoolTest extends JS
648          CountDownLatch latch = new CountDownLatch(1);
649          ExecutorService e = new ForkJoinPool(1);
650          try (PoolCleaner cleaner = cleaner(e)) {
651 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
651 >            List<Callable<String>> l = new ArrayList<>();
652              l.add(latchAwaitingStringTask(latch));
653              l.add(null);
654              try {
# Line 664 | Line 665 | public class ForkJoinPoolTest extends JS
665      public void testInvokeAny5() throws Throwable {
666          ExecutorService e = new ForkJoinPool(1);
667          try (PoolCleaner cleaner = cleaner(e)) {
668 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
668 >            List<Callable<String>> l = new ArrayList<>();
669              l.add(new NPETask());
670              try {
671                  e.invokeAny(l);
# Line 681 | Line 682 | public class ForkJoinPoolTest extends JS
682      public void testInvokeAny6() throws Throwable {
683          ExecutorService e = new ForkJoinPool(1);
684          try (PoolCleaner cleaner = cleaner(e)) {
685 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
685 >            List<Callable<String>> l = new ArrayList<>();
686              l.add(new StringTask());
687              l.add(new StringTask());
688              String result = e.invokeAny(l);
# Line 703 | Line 704 | public class ForkJoinPoolTest extends JS
704      }
705  
706      /**
707 <     * invokeAll(empty collection) returns empty collection
707 >     * invokeAll(empty collection) returns empty list
708       */
709      public void testInvokeAll2() throws InterruptedException {
710          ExecutorService e = new ForkJoinPool(1);
711 +        final Collection<Callable<String>> emptyCollection
712 +            = Collections.emptyList();
713          try (PoolCleaner cleaner = cleaner(e)) {
714 <            List<Future<String>> r
712 <                = e.invokeAll(new ArrayList<Callable<String>>());
714 >            List<Future<String>> r = e.invokeAll(emptyCollection);
715              assertTrue(r.isEmpty());
716          }
717      }
# Line 720 | Line 722 | public class ForkJoinPoolTest extends JS
722      public void testInvokeAll3() throws InterruptedException {
723          ExecutorService e = new ForkJoinPool(1);
724          try (PoolCleaner cleaner = cleaner(e)) {
725 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
725 >            List<Callable<String>> l = new ArrayList<>();
726              l.add(new StringTask());
727              l.add(null);
728              try {
# Line 737 | Line 739 | public class ForkJoinPoolTest extends JS
739      public void testInvokeAll4() throws Throwable {
740          ExecutorService e = new ForkJoinPool(1);
741          try (PoolCleaner cleaner = cleaner(e)) {
742 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
742 >            List<Callable<String>> l = new ArrayList<>();
743              l.add(new NPETask());
744              List<Future<String>> futures = e.invokeAll(l);
745              assertEquals(1, futures.size());
# Line 756 | Line 758 | public class ForkJoinPoolTest extends JS
758      public void testInvokeAll5() throws Throwable {
759          ExecutorService e = new ForkJoinPool(1);
760          try (PoolCleaner cleaner = cleaner(e)) {
761 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
761 >            List<Callable<String>> l = new ArrayList<>();
762              l.add(new StringTask());
763              l.add(new StringTask());
764              List<Future<String>> futures = e.invokeAll(l);
# Line 773 | Line 775 | public class ForkJoinPoolTest extends JS
775          ExecutorService e = new ForkJoinPool(1);
776          try (PoolCleaner cleaner = cleaner(e)) {
777              try {
778 <                e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
778 >                e.invokeAny(null, randomTimeout(), randomTimeUnit());
779                  shouldThrow();
780              } catch (NullPointerException success) {}
781          }
# Line 785 | Line 787 | public class ForkJoinPoolTest extends JS
787      public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
788          ExecutorService e = new ForkJoinPool(1);
789          try (PoolCleaner cleaner = cleaner(e)) {
790 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
790 >            List<Callable<String>> l = new ArrayList<>();
791              l.add(new StringTask());
792              try {
793 <                e.invokeAny(l, MEDIUM_DELAY_MS, null);
793 >                e.invokeAny(l, randomTimeout(), null);
794                  shouldThrow();
795              } catch (NullPointerException success) {}
796          }
# Line 802 | Line 804 | public class ForkJoinPoolTest extends JS
804          try (PoolCleaner cleaner = cleaner(e)) {
805              try {
806                  e.invokeAny(new ArrayList<Callable<String>>(),
807 <                            MEDIUM_DELAY_MS, MILLISECONDS);
807 >                            randomTimeout(), randomTimeUnit());
808                  shouldThrow();
809              } catch (IllegalArgumentException success) {}
810          }
# Line 815 | Line 817 | public class ForkJoinPoolTest extends JS
817          CountDownLatch latch = new CountDownLatch(1);
818          ExecutorService e = new ForkJoinPool(1);
819          try (PoolCleaner cleaner = cleaner(e)) {
820 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
820 >            List<Callable<String>> l = new ArrayList<>();
821              l.add(latchAwaitingStringTask(latch));
822              l.add(null);
823              try {
824 <                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
824 >                e.invokeAny(l, randomTimeout(), randomTimeUnit());
825                  shouldThrow();
826              } catch (NullPointerException success) {}
827              latch.countDown();
# Line 833 | Line 835 | public class ForkJoinPoolTest extends JS
835          ExecutorService e = new ForkJoinPool(1);
836          try (PoolCleaner cleaner = cleaner(e)) {
837              long startTime = System.nanoTime();
838 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
838 >            List<Callable<String>> l = new ArrayList<>();
839              l.add(new NPETask());
840              try {
841                  e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
# Line 852 | Line 854 | public class ForkJoinPoolTest extends JS
854          ExecutorService e = new ForkJoinPool(1);
855          try (PoolCleaner cleaner = cleaner(e)) {
856              long startTime = System.nanoTime();
857 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
857 >            List<Callable<String>> l = new ArrayList<>();
858              l.add(new StringTask());
859              l.add(new StringTask());
860              String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
# Line 868 | Line 870 | public class ForkJoinPoolTest extends JS
870          ExecutorService e = new ForkJoinPool(1);
871          try (PoolCleaner cleaner = cleaner(e)) {
872              try {
873 <                e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
873 >                e.invokeAll(null, randomTimeout(), randomTimeUnit());
874                  shouldThrow();
875              } catch (NullPointerException success) {}
876          }
# Line 880 | Line 882 | public class ForkJoinPoolTest extends JS
882      public void testTimedInvokeAllNullTimeUnit() throws Throwable {
883          ExecutorService e = new ForkJoinPool(1);
884          try (PoolCleaner cleaner = cleaner(e)) {
885 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
885 >            List<Callable<String>> l = new ArrayList<>();
886              l.add(new StringTask());
887              try {
888 <                e.invokeAll(l, MEDIUM_DELAY_MS, null);
888 >                e.invokeAll(l, randomTimeout(), null);
889                  shouldThrow();
890              } catch (NullPointerException success) {}
891          }
892      }
893  
894      /**
895 <     * timed invokeAll(empty collection) returns empty collection
895 >     * timed invokeAll(empty collection) returns empty list
896       */
897      public void testTimedInvokeAll2() throws InterruptedException {
898          ExecutorService e = new ForkJoinPool(1);
899 +        final Collection<Callable<String>> emptyCollection
900 +            = Collections.emptyList();
901          try (PoolCleaner cleaner = cleaner(e)) {
902              List<Future<String>> r
903 <                = e.invokeAll(new ArrayList<Callable<String>>(),
904 <                              MEDIUM_DELAY_MS, MILLISECONDS);
903 >                = e.invokeAll(emptyCollection,
904 >                              randomTimeout(), randomTimeUnit());
905              assertTrue(r.isEmpty());
906          }
907      }
# Line 908 | Line 912 | public class ForkJoinPoolTest extends JS
912      public void testTimedInvokeAll3() throws InterruptedException {
913          ExecutorService e = new ForkJoinPool(1);
914          try (PoolCleaner cleaner = cleaner(e)) {
915 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
915 >            List<Callable<String>> l = new ArrayList<>();
916              l.add(new StringTask());
917              l.add(null);
918              try {
919 <                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
919 >                e.invokeAll(l, randomTimeout(), randomTimeUnit());
920                  shouldThrow();
921              } catch (NullPointerException success) {}
922          }
# Line 924 | Line 928 | public class ForkJoinPoolTest extends JS
928      public void testTimedInvokeAll4() throws Throwable {
929          ExecutorService e = new ForkJoinPool(1);
930          try (PoolCleaner cleaner = cleaner(e)) {
931 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
931 >            List<Callable<String>> l = new ArrayList<>();
932              l.add(new NPETask());
933              List<Future<String>> futures
934                  = e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
# Line 944 | Line 948 | public class ForkJoinPoolTest extends JS
948      public void testTimedInvokeAll5() throws Throwable {
949          ForkJoinPool e = new ForkJoinPool(1);
950          try (PoolCleaner cleaner = cleaner(e)) {
951 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
951 >            List<Callable<String>> l = new ArrayList<>();
952              l.add(new StringTask());
953              l.add(new StringTask());
954              List<Future<String>> futures

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines