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

Comparing jsr166/src/test/tck/ForkJoinPool8Test.java (file contents):
Revision 1.7 by jsr166, Tue Apr 16 05:49:18 2013 UTC vs.
Revision 1.28 by jsr166, Wed Dec 31 16:44:01 2014 UTC

# Line 9 | Line 9 | import java.util.concurrent.Cancellation
9   import java.util.concurrent.ExecutionException;
10   import java.util.concurrent.ForkJoinPool;
11   import java.util.concurrent.ForkJoinTask;
12 import java.util.concurrent.ForkJoinWorkerThread;
12   import java.util.concurrent.RecursiveAction;
13   import java.util.concurrent.CountedCompleter;
15 import java.util.concurrent.ThreadLocalRandom;
16 import java.util.concurrent.TimeUnit;
14   import java.util.concurrent.TimeoutException;
15   import static java.util.concurrent.TimeUnit.SECONDS;
16   import static java.util.concurrent.TimeUnit.MILLISECONDS;
20 import java.util.Arrays;
17   import java.util.HashSet;
18  
19   public class ForkJoinPool8Test extends JSR166TestCase {
# Line 185 | Line 181 | public class ForkJoinPool8Test extends J
181          final int number;
182          int result;
183          FibAction(int n) { number = n; }
184 <        public void realCompute() {
184 >        protected void realCompute() {
185              int n = number;
186              if (n <= 1)
187                  result = n;
# Line 223 | Line 219 | public class ForkJoinPool8Test extends J
219       */
220      public void testInvoke() {
221          RecursiveAction a = new CheckedRecursiveAction() {
222 <            public void realCompute() {
222 >            protected void realCompute() {
223                  FibAction f = new FibAction(8);
224                  assertNull(f.invoke());
225                  assertEquals(21, f.result);
# Line 239 | Line 235 | public class ForkJoinPool8Test extends J
235       */
236      public void testQuietlyInvoke() {
237          RecursiveAction a = new CheckedRecursiveAction() {
238 <            public void realCompute() {
238 >            protected void realCompute() {
239                  FibAction f = new FibAction(8);
240                  f.quietlyInvoke();
241                  assertEquals(21, f.result);
# Line 253 | Line 249 | public class ForkJoinPool8Test extends J
249       */
250      public void testForkJoin() {
251          RecursiveAction a = new CheckedRecursiveAction() {
252 <            public void realCompute() {
252 >            protected void realCompute() {
253                  FibAction f = new FibAction(8);
254                  assertSame(f, f.fork());
255                  assertNull(f.join());
# Line 268 | Line 264 | public class ForkJoinPool8Test extends J
264       */
265      public void testJoinIgnoresInterrupts() {
266          RecursiveAction a = new CheckedRecursiveAction() {
267 <            public void realCompute() {
267 >            protected void realCompute() {
268                  FibAction f = new FibAction(8);
269                  final Thread myself = Thread.currentThread();
270  
# Line 340 | Line 336 | public class ForkJoinPool8Test extends J
336          checkInvoke(a);
337      }
338  
343
339      /**
340       * get of a forked task returns when task completes
341       */
342      public void testForkGet() {
343          RecursiveAction a = new CheckedRecursiveAction() {
344 <            public void realCompute() throws Exception {
344 >            protected void realCompute() throws Exception {
345                  FibAction f = new FibAction(8);
346                  assertSame(f, f.fork());
347                  assertNull(f.get());
# Line 361 | Line 356 | public class ForkJoinPool8Test extends J
356       */
357      public void testForkTimedGet() {
358          RecursiveAction a = new CheckedRecursiveAction() {
359 <            public void realCompute() throws Exception {
359 >            protected void realCompute() throws Exception {
360                  FibAction f = new FibAction(8);
361                  assertSame(f, f.fork());
362                  assertNull(f.get(5L, SECONDS));
# Line 376 | Line 371 | public class ForkJoinPool8Test extends J
371       */
372      public void testForkTimedGetNPE() {
373          RecursiveAction a = new CheckedRecursiveAction() {
374 <            public void realCompute() throws Exception {
374 >            protected void realCompute() throws Exception {
375                  FibAction f = new FibAction(8);
376                  assertSame(f, f.fork());
377                  try {
# Line 392 | Line 387 | public class ForkJoinPool8Test extends J
387       */
388      public void testForkQuietlyJoin() {
389          RecursiveAction a = new CheckedRecursiveAction() {
390 <            public void realCompute() {
390 >            protected void realCompute() {
391                  FibAction f = new FibAction(8);
392                  assertSame(f, f.fork());
393                  f.quietlyJoin();
# Line 407 | Line 402 | public class ForkJoinPool8Test extends J
402       */
403      public void testAbnormalInvoke() {
404          RecursiveAction a = new CheckedRecursiveAction() {
405 <            public void realCompute() {
405 >            protected void realCompute() {
406                  FailingFibAction f = new FailingFibAction(8);
407                  try {
408                      f.invoke();
# Line 424 | Line 419 | public class ForkJoinPool8Test extends J
419       */
420      public void testAbnormalQuietlyInvoke() {
421          RecursiveAction a = new CheckedRecursiveAction() {
422 <            public void realCompute() {
422 >            protected void realCompute() {
423                  FailingFibAction f = new FailingFibAction(8);
424                  f.quietlyInvoke();
425                  assertTrue(f.getException() instanceof FJException);
# Line 438 | Line 433 | public class ForkJoinPool8Test extends J
433       */
434      public void testAbnormalForkJoin() {
435          RecursiveAction a = new CheckedRecursiveAction() {
436 <            public void realCompute() {
436 >            protected void realCompute() {
437                  FailingFibAction f = new FailingFibAction(8);
438                  assertSame(f, f.fork());
439                  try {
# Line 456 | Line 451 | public class ForkJoinPool8Test extends J
451       */
452      public void testAbnormalForkGet() {
453          RecursiveAction a = new CheckedRecursiveAction() {
454 <            public void realCompute() throws Exception {
454 >            protected void realCompute() throws Exception {
455                  FailingFibAction f = new FailingFibAction(8);
456                  assertSame(f, f.fork());
457                  try {
# Line 476 | Line 471 | public class ForkJoinPool8Test extends J
471       */
472      public void testAbnormalForkTimedGet() {
473          RecursiveAction a = new CheckedRecursiveAction() {
474 <            public void realCompute() throws Exception {
474 >            protected void realCompute() throws Exception {
475                  FailingFibAction f = new FailingFibAction(8);
476                  assertSame(f, f.fork());
477                  try {
478 <                    f.get(5L, TimeUnit.SECONDS);
478 >                    f.get(5L, SECONDS);
479                      shouldThrow();
480                  } catch (ExecutionException success) {
481                      Throwable cause = success.getCause();
# Line 496 | Line 491 | public class ForkJoinPool8Test extends J
491       */
492      public void testAbnormalForkQuietlyJoin() {
493          RecursiveAction a = new CheckedRecursiveAction() {
494 <            public void realCompute() {
494 >            protected void realCompute() {
495                  FailingFibAction f = new FailingFibAction(8);
496                  assertSame(f, f.fork());
497                  f.quietlyJoin();
# Line 511 | Line 506 | public class ForkJoinPool8Test extends J
506       */
507      public void testCancelledInvoke() {
508          RecursiveAction a = new CheckedRecursiveAction() {
509 <            public void realCompute() {
509 >            protected void realCompute() {
510                  FibAction f = new FibAction(8);
511                  assertTrue(f.cancel(true));
512                  try {
# Line 529 | Line 524 | public class ForkJoinPool8Test extends J
524       */
525      public void testCancelledForkJoin() {
526          RecursiveAction a = new CheckedRecursiveAction() {
527 <            public void realCompute() {
527 >            protected void realCompute() {
528                  FibAction f = new FibAction(8);
529                  assertTrue(f.cancel(true));
530                  assertSame(f, f.fork());
# Line 548 | Line 543 | public class ForkJoinPool8Test extends J
543       */
544      public void testCancelledForkGet() {
545          RecursiveAction a = new CheckedRecursiveAction() {
546 <            public void realCompute() throws Exception {
546 >            protected void realCompute() throws Exception {
547                  FibAction f = new FibAction(8);
548                  assertTrue(f.cancel(true));
549                  assertSame(f, f.fork());
# Line 567 | Line 562 | public class ForkJoinPool8Test extends J
562       */
563      public void testCancelledForkTimedGet() {
564          RecursiveAction a = new CheckedRecursiveAction() {
565 <            public void realCompute() throws Exception {
565 >            protected void realCompute() throws Exception {
566                  FibAction f = new FibAction(8);
567                  assertTrue(f.cancel(true));
568                  assertSame(f, f.fork());
# Line 586 | Line 581 | public class ForkJoinPool8Test extends J
581       */
582      public void testCancelledForkQuietlyJoin() {
583          RecursiveAction a = new CheckedRecursiveAction() {
584 <            public void realCompute() {
584 >            protected void realCompute() {
585                  FibAction f = new FibAction(8);
586                  assertTrue(f.cancel(true));
587                  assertSame(f, f.fork());
# Line 601 | Line 596 | public class ForkJoinPool8Test extends J
596       */
597      public void testInForkJoinPool2() {
598          RecursiveAction a = new CheckedRecursiveAction() {
599 <            public void realCompute() {
599 >            protected void realCompute() {
600                  assertFalse(inForkJoinPool());
601              }};
602          assertNull(a.invoke());
# Line 612 | Line 607 | public class ForkJoinPool8Test extends J
607       */
608      public void testReinitialize() {
609          RecursiveAction a = new CheckedRecursiveAction() {
610 <            public void realCompute() {
610 >            protected void realCompute() {
611                  FibAction f = new FibAction(8);
612                  checkNotDone(f);
613  
# Line 632 | Line 627 | public class ForkJoinPool8Test extends J
627       */
628      public void testReinitializeAbnormal() {
629          RecursiveAction a = new CheckedRecursiveAction() {
630 <            public void realCompute() {
630 >            protected void realCompute() {
631                  FailingFibAction f = new FailingFibAction(8);
632                  checkNotDone(f);
633  
# Line 655 | Line 650 | public class ForkJoinPool8Test extends J
650       */
651      public void testCompleteExceptionally() {
652          RecursiveAction a = new CheckedRecursiveAction() {
653 <            public void realCompute() {
653 >            protected void realCompute() {
654                  FibAction f = new FibAction(8);
655                  f.completeExceptionally(new FJException());
656                  try {
# Line 673 | Line 668 | public class ForkJoinPool8Test extends J
668       */
669      public void testComplete() {
670          RecursiveAction a = new CheckedRecursiveAction() {
671 <            public void realCompute() {
671 >            protected void realCompute() {
672                  FibAction f = new FibAction(8);
673                  f.complete(null);
674                  assertNull(f.invoke());
# Line 688 | Line 683 | public class ForkJoinPool8Test extends J
683       */
684      public void testInvokeAll2() {
685          RecursiveAction a = new CheckedRecursiveAction() {
686 <            public void realCompute() {
686 >            protected void realCompute() {
687                  FibAction f = new FibAction(8);
688                  FibAction g = new FibAction(9);
689                  invokeAll(f, g);
# Line 705 | Line 700 | public class ForkJoinPool8Test extends J
700       */
701      public void testInvokeAll1() {
702          RecursiveAction a = new CheckedRecursiveAction() {
703 <            public void realCompute() {
703 >            protected void realCompute() {
704                  FibAction f = new FibAction(8);
705                  invokeAll(f);
706                  checkCompletedNormally(f);
# Line 719 | Line 714 | public class ForkJoinPool8Test extends J
714       */
715      public void testInvokeAll3() {
716          RecursiveAction a = new CheckedRecursiveAction() {
717 <            public void realCompute() {
717 >            protected void realCompute() {
718                  FibAction f = new FibAction(8);
719                  FibAction g = new FibAction(9);
720                  FibAction h = new FibAction(7);
# Line 742 | Line 737 | public class ForkJoinPool8Test extends J
737       */
738      public void testInvokeAllCollection() {
739          RecursiveAction a = new CheckedRecursiveAction() {
740 <            public void realCompute() {
740 >            protected void realCompute() {
741                  FibAction f = new FibAction(8);
742                  FibAction g = new FibAction(9);
743                  FibAction h = new FibAction(7);
# Line 769 | Line 764 | public class ForkJoinPool8Test extends J
764       */
765      public void testInvokeAllNPE() {
766          RecursiveAction a = new CheckedRecursiveAction() {
767 <            public void realCompute() {
767 >            protected void realCompute() {
768                  FibAction f = new FibAction(8);
769                  FibAction g = new FibAction(9);
770                  FibAction h = null;
# Line 786 | Line 781 | public class ForkJoinPool8Test extends J
781       */
782      public void testAbnormalInvokeAll2() {
783          RecursiveAction a = new CheckedRecursiveAction() {
784 <            public void realCompute() {
784 >            protected void realCompute() {
785                  FibAction f = new FibAction(8);
786                  FailingFibAction g = new FailingFibAction(9);
787                  try {
# Line 804 | Line 799 | public class ForkJoinPool8Test extends J
799       */
800      public void testAbnormalInvokeAll1() {
801          RecursiveAction a = new CheckedRecursiveAction() {
802 <            public void realCompute() {
802 >            protected void realCompute() {
803                  FailingFibAction g = new FailingFibAction(9);
804                  try {
805                      invokeAll(g);
# Line 821 | Line 816 | public class ForkJoinPool8Test extends J
816       */
817      public void testAbnormalInvokeAll3() {
818          RecursiveAction a = new CheckedRecursiveAction() {
819 <            public void realCompute() {
819 >            protected void realCompute() {
820                  FibAction f = new FibAction(8);
821                  FailingFibAction g = new FailingFibAction(9);
822                  FibAction h = new FibAction(7);
# Line 840 | Line 835 | public class ForkJoinPool8Test extends J
835       */
836      public void testAbnormalInvokeAllCollection() {
837          RecursiveAction a = new CheckedRecursiveAction() {
838 <            public void realCompute() {
838 >            protected void realCompute() {
839                  FailingFibAction f = new FailingFibAction(8);
840                  FibAction g = new FibAction(9);
841                  FibAction h = new FibAction(7);
# Line 860 | Line 855 | public class ForkJoinPool8Test extends J
855  
856      // CountedCompleter versions
857  
863    public abstract class CheckedFJTask extends RecursiveAction {
864        protected abstract void realCompute() throws Throwable;
865
866        public final void compute() {
867            try {
868                realCompute();
869            } catch (Throwable t) {
870                threadUnexpectedException(t);
871            }
872        }
873    }
874
858      abstract static class CCF extends CountedCompleter {
859          int number;
860          int rnumber;
# Line 980 | Line 963 | public class ForkJoinPool8Test extends J
963       * completed tasks; getRawResult returns null.
964       */
965      public void testInvokeCC() {
966 <       ForkJoinTask a = new CheckedFJTask() {
967 <            public void realCompute() {
966 >        ForkJoinTask a = new CheckedRecursiveAction() {
967 >            protected void realCompute() {
968                  CCF f = new LCCF(null, 8);
969                  assertNull(f.invoke());
970                  assertEquals(21, f.number);
# Line 996 | Line 979 | public class ForkJoinPool8Test extends J
979       * completed tasks
980       */
981      public void testQuietlyInvokeCC() {
982 <       ForkJoinTask a = new CheckedFJTask() {
983 <            public void realCompute() {
982 >        ForkJoinTask a = new CheckedRecursiveAction() {
983 >            protected void realCompute() {
984                  CCF f = new LCCF(null, 8);
985                  f.quietlyInvoke();
986                  assertEquals(21, f.number);
# Line 1010 | Line 993 | public class ForkJoinPool8Test extends J
993       * join of a forked task returns when task completes
994       */
995      public void testForkJoinCC() {
996 <       ForkJoinTask a = new CheckedFJTask() {
997 <            public void realCompute() {
996 >        ForkJoinTask a = new CheckedRecursiveAction() {
997 >            protected void realCompute() {
998                  CCF f = new LCCF(null, 8);
999                  assertSame(f, f.fork());
1000                  assertNull(f.join());
# Line 1025 | Line 1008 | public class ForkJoinPool8Test extends J
1008       * get of a forked task returns when task completes
1009       */
1010      public void testForkGetCC() {
1011 <       ForkJoinTask a = new CheckedFJTask() {
1012 <            public void realCompute() throws Exception {
1011 >        ForkJoinTask a = new CheckedRecursiveAction() {
1012 >            protected void realCompute() throws Exception {
1013                  CCF f = new LCCF(null, 8);
1014                  assertSame(f, f.fork());
1015                  assertNull(f.get());
# Line 1040 | Line 1023 | public class ForkJoinPool8Test extends J
1023       * timed get of a forked task returns when task completes
1024       */
1025      public void testForkTimedGetCC() {
1026 <       ForkJoinTask a = new CheckedFJTask() {
1027 <            public void realCompute() throws Exception {
1026 >        ForkJoinTask a = new CheckedRecursiveAction() {
1027 >            protected void realCompute() throws Exception {
1028                  CCF f = new LCCF(null, 8);
1029                  assertSame(f, f.fork());
1030                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
# Line 1055 | Line 1038 | public class ForkJoinPool8Test extends J
1038       * timed get with null time unit throws NPE
1039       */
1040      public void testForkTimedGetNPECC() {
1041 <       ForkJoinTask a = new CheckedFJTask() {
1042 <            public void realCompute() throws Exception {
1041 >        ForkJoinTask a = new CheckedRecursiveAction() {
1042 >            protected void realCompute() throws Exception {
1043                  CCF f = new LCCF(null, 8);
1044                  assertSame(f, f.fork());
1045                  try {
# Line 1071 | Line 1054 | public class ForkJoinPool8Test extends J
1054       * quietlyJoin of a forked task returns when task completes
1055       */
1056      public void testForkQuietlyJoinCC() {
1057 <       ForkJoinTask a = new CheckedFJTask() {
1058 <            public void realCompute() {
1057 >        ForkJoinTask a = new CheckedRecursiveAction() {
1058 >            protected void realCompute() {
1059                  CCF f = new LCCF(null, 8);
1060                  assertSame(f, f.fork());
1061                  f.quietlyJoin();
# Line 1086 | Line 1069 | public class ForkJoinPool8Test extends J
1069       * invoke task throws exception when task completes abnormally
1070       */
1071      public void testAbnormalInvokeCC() {
1072 <       ForkJoinTask a = new CheckedFJTask() {
1073 <            public void realCompute() {
1072 >        ForkJoinTask a = new CheckedRecursiveAction() {
1073 >            protected void realCompute() {
1074                  FailingCCF f = new LFCCF(null, 8);
1075                  try {
1076                      f.invoke();
# Line 1103 | Line 1086 | public class ForkJoinPool8Test extends J
1086       * quietlyInvoke task returns when task completes abnormally
1087       */
1088      public void testAbnormalQuietlyInvokeCC() {
1089 <       ForkJoinTask a = new CheckedFJTask() {
1090 <            public void realCompute() {
1089 >        ForkJoinTask a = new CheckedRecursiveAction() {
1090 >            protected void realCompute() {
1091                  FailingCCF f = new LFCCF(null, 8);
1092                  f.quietlyInvoke();
1093                  assertTrue(f.getException() instanceof FJException);
# Line 1117 | Line 1100 | public class ForkJoinPool8Test extends J
1100       * join of a forked task throws exception when task completes abnormally
1101       */
1102      public void testAbnormalForkJoinCC() {
1103 <       ForkJoinTask a = new CheckedFJTask() {
1104 <            public void realCompute() {
1103 >        ForkJoinTask a = new CheckedRecursiveAction() {
1104 >            protected void realCompute() {
1105                  FailingCCF f = new LFCCF(null, 8);
1106                  assertSame(f, f.fork());
1107                  try {
# Line 1135 | Line 1118 | public class ForkJoinPool8Test extends J
1118       * get of a forked task throws exception when task completes abnormally
1119       */
1120      public void testAbnormalForkGetCC() {
1121 <       ForkJoinTask a = new CheckedFJTask() {
1122 <            public void realCompute() throws Exception {
1121 >        ForkJoinTask a = new CheckedRecursiveAction() {
1122 >            protected void realCompute() throws Exception {
1123                  FailingCCF f = new LFCCF(null, 8);
1124                  assertSame(f, f.fork());
1125                  try {
# Line 1155 | Line 1138 | public class ForkJoinPool8Test extends J
1138       * timed get of a forked task throws exception when task completes abnormally
1139       */
1140      public void testAbnormalForkTimedGetCC() {
1141 <       ForkJoinTask a = new CheckedFJTask() {
1142 <            public void realCompute() throws Exception {
1141 >        ForkJoinTask a = new CheckedRecursiveAction() {
1142 >            protected void realCompute() throws Exception {
1143                  FailingCCF f = new LFCCF(null, 8);
1144                  assertSame(f, f.fork());
1145                  try {
# Line 1175 | Line 1158 | public class ForkJoinPool8Test extends J
1158       * quietlyJoin of a forked task returns when task completes abnormally
1159       */
1160      public void testAbnormalForkQuietlyJoinCC() {
1161 <       ForkJoinTask a = new CheckedFJTask() {
1162 <            public void realCompute() {
1161 >        ForkJoinTask a = new CheckedRecursiveAction() {
1162 >            protected void realCompute() {
1163                  FailingCCF f = new LFCCF(null, 8);
1164                  assertSame(f, f.fork());
1165                  f.quietlyJoin();
# Line 1190 | Line 1173 | public class ForkJoinPool8Test extends J
1173       * invoke task throws exception when task cancelled
1174       */
1175      public void testCancelledInvokeCC() {
1176 <       ForkJoinTask a = new CheckedFJTask() {
1177 <            public void realCompute() {
1176 >        ForkJoinTask a = new CheckedRecursiveAction() {
1177 >            protected void realCompute() {
1178                  CCF f = new LCCF(null, 8);
1179                  assertTrue(f.cancel(true));
1180                  try {
# Line 1208 | Line 1191 | public class ForkJoinPool8Test extends J
1191       * join of a forked task throws exception when task cancelled
1192       */
1193      public void testCancelledForkJoinCC() {
1194 <       ForkJoinTask a = new CheckedFJTask() {
1195 <            public void realCompute() {
1194 >        ForkJoinTask a = new CheckedRecursiveAction() {
1195 >            protected void realCompute() {
1196                  CCF f = new LCCF(null, 8);
1197                  assertTrue(f.cancel(true));
1198                  assertSame(f, f.fork());
# Line 1227 | Line 1210 | public class ForkJoinPool8Test extends J
1210       * get of a forked task throws exception when task cancelled
1211       */
1212      public void testCancelledForkGetCC() {
1213 <       ForkJoinTask a = new CheckedFJTask() {
1214 <            public void realCompute() throws Exception {
1213 >        ForkJoinTask a = new CheckedRecursiveAction() {
1214 >            protected void realCompute() throws Exception {
1215                  CCF f = new LCCF(null, 8);
1216                  assertTrue(f.cancel(true));
1217                  assertSame(f, f.fork());
# Line 1246 | Line 1229 | public class ForkJoinPool8Test extends J
1229       * timed get of a forked task throws exception when task cancelled
1230       */
1231      public void testCancelledForkTimedGetCC() throws Exception {
1232 <       ForkJoinTask a = new CheckedFJTask() {
1233 <            public void realCompute() throws Exception {
1232 >        ForkJoinTask a = new CheckedRecursiveAction() {
1233 >            protected void realCompute() throws Exception {
1234                  CCF f = new LCCF(null, 8);
1235                  assertTrue(f.cancel(true));
1236                  assertSame(f, f.fork());
# Line 1265 | Line 1248 | public class ForkJoinPool8Test extends J
1248       * quietlyJoin of a forked task returns when task cancelled
1249       */
1250      public void testCancelledForkQuietlyJoinCC() {
1251 <       ForkJoinTask a = new CheckedFJTask() {
1252 <            public void realCompute() {
1251 >        ForkJoinTask a = new CheckedRecursiveAction() {
1252 >            protected void realCompute() {
1253                  CCF f = new LCCF(null, 8);
1254                  assertTrue(f.cancel(true));
1255                  assertSame(f, f.fork());
# Line 1280 | Line 1263 | public class ForkJoinPool8Test extends J
1263       * getPool of non-FJ task returns null
1264       */
1265      public void testGetPool2CC() {
1266 <       ForkJoinTask a = new CheckedFJTask() {
1267 <            public void realCompute() {
1266 >        ForkJoinTask a = new CheckedRecursiveAction() {
1267 >            protected void realCompute() {
1268                  assertNull(getPool());
1269              }};
1270          assertNull(a.invoke());
# Line 1291 | Line 1274 | public class ForkJoinPool8Test extends J
1274       * inForkJoinPool of non-FJ task returns false
1275       */
1276      public void testInForkJoinPool2CC() {
1277 <       ForkJoinTask a = new CheckedFJTask() {
1278 <            public void realCompute() {
1277 >        ForkJoinTask a = new CheckedRecursiveAction() {
1278 >            protected void realCompute() {
1279                  assertFalse(inForkJoinPool());
1280              }};
1281          assertNull(a.invoke());
# Line 1302 | Line 1285 | public class ForkJoinPool8Test extends J
1285       * setRawResult(null) succeeds
1286       */
1287      public void testSetRawResultCC() {
1288 <       ForkJoinTask a = new CheckedFJTask() {
1289 <            public void realCompute() {
1288 >        ForkJoinTask a = new CheckedRecursiveAction() {
1289 >            protected void realCompute() {
1290                  setRawResult(null);
1291                  assertNull(getRawResult());
1292              }};
# Line 1314 | Line 1297 | public class ForkJoinPool8Test extends J
1297       * invoke task throws exception after invoking completeExceptionally
1298       */
1299      public void testCompleteExceptionally2CC() {
1300 <       ForkJoinTask a = new CheckedFJTask() {
1301 <            public void realCompute() {
1300 >        ForkJoinTask a = new CheckedRecursiveAction() {
1301 >            protected void realCompute() {
1302                  CCF f = new LCCF(null, 8);
1303                  f.completeExceptionally(new FJException());
1304                  try {
# Line 1332 | Line 1315 | public class ForkJoinPool8Test extends J
1315       * invokeAll(t1, t2) invokes all task arguments
1316       */
1317      public void testInvokeAll2CC() {
1318 <       ForkJoinTask a = new CheckedFJTask() {
1319 <            public void realCompute() {
1318 >        ForkJoinTask a = new CheckedRecursiveAction() {
1319 >            protected void realCompute() {
1320                  CCF f = new LCCF(null, 8);
1321                  CCF g = new LCCF(null, 9);
1322                  invokeAll(f, g);
# Line 1349 | Line 1332 | public class ForkJoinPool8Test extends J
1332       * invokeAll(tasks) with 1 argument invokes task
1333       */
1334      public void testInvokeAll1CC() {
1335 <       ForkJoinTask a = new CheckedFJTask() {
1336 <            public void realCompute() {
1335 >        ForkJoinTask a = new CheckedRecursiveAction() {
1336 >            protected void realCompute() {
1337                  CCF f = new LCCF(null, 8);
1338                  invokeAll(f);
1339                  checkCompletedNormally(f);
# Line 1363 | Line 1346 | public class ForkJoinPool8Test extends J
1346       * invokeAll(tasks) with > 2 argument invokes tasks
1347       */
1348      public void testInvokeAll3CC() {
1349 <       ForkJoinTask a = new CheckedFJTask() {
1350 <            public void realCompute() {
1349 >        ForkJoinTask a = new CheckedRecursiveAction() {
1350 >            protected void realCompute() {
1351                  CCF f = new LCCF(null, 8);
1352                  CCF g = new LCCF(null, 9);
1353                  CCF h = new LCCF(null, 7);
# Line 1383 | Line 1366 | public class ForkJoinPool8Test extends J
1366       * invokeAll(collection) invokes all tasks in the collection
1367       */
1368      public void testInvokeAllCollectionCC() {
1369 <       ForkJoinTask a = new CheckedFJTask() {
1370 <            public void realCompute() {
1369 >        ForkJoinTask a = new CheckedRecursiveAction() {
1370 >            protected void realCompute() {
1371                  CCF f = new LCCF(null, 8);
1372                  CCF g = new LCCF(null, 9);
1373                  CCF h = new LCCF(null, 7);
# Line 1407 | Line 1390 | public class ForkJoinPool8Test extends J
1390       * invokeAll(tasks) with any null task throws NPE
1391       */
1392      public void testInvokeAllNPECC() {
1393 <       ForkJoinTask a = new CheckedFJTask() {
1394 <            public void realCompute() {
1393 >        ForkJoinTask a = new CheckedRecursiveAction() {
1394 >            protected void realCompute() {
1395                  CCF f = new LCCF(null, 8);
1396                  CCF g = new LCCF(null, 9);
1397                  CCF h = null;
# Line 1424 | Line 1407 | public class ForkJoinPool8Test extends J
1407       * invokeAll(t1, t2) throw exception if any task does
1408       */
1409      public void testAbnormalInvokeAll2CC() {
1410 <       ForkJoinTask a = new CheckedFJTask() {
1411 <            public void realCompute() {
1410 >        ForkJoinTask a = new CheckedRecursiveAction() {
1411 >            protected void realCompute() {
1412                  CCF f = new LCCF(null, 8);
1413                  FailingCCF g = new LFCCF(null, 9);
1414                  try {
# Line 1442 | Line 1425 | public class ForkJoinPool8Test extends J
1425       * invokeAll(tasks) with 1 argument throws exception if task does
1426       */
1427      public void testAbnormalInvokeAll1CC() {
1428 <       ForkJoinTask a = new CheckedFJTask() {
1429 <            public void realCompute() {
1428 >        ForkJoinTask a = new CheckedRecursiveAction() {
1429 >            protected void realCompute() {
1430                  FailingCCF g = new LFCCF(null, 9);
1431                  try {
1432                      invokeAll(g);
# Line 1459 | Line 1442 | public class ForkJoinPool8Test extends J
1442       * invokeAll(tasks) with > 2 argument throws exception if any task does
1443       */
1444      public void testAbnormalInvokeAll3CC() {
1445 <       ForkJoinTask a = new CheckedFJTask() {
1446 <            public void realCompute() {
1445 >        ForkJoinTask a = new CheckedRecursiveAction() {
1446 >            protected void realCompute() {
1447                  CCF f = new LCCF(null, 8);
1448                  FailingCCF g = new LFCCF(null, 9);
1449                  CCF h = new LCCF(null, 7);
# Line 1475 | Line 1458 | public class ForkJoinPool8Test extends J
1458      }
1459  
1460      /**
1461 <     * invokeAll(collection)  throws exception if any task does
1461 >     * invokeAll(collection) throws exception if any task does
1462       */
1463      public void testAbnormalInvokeAllCollectionCC() {
1464 <       ForkJoinTask a = new CheckedFJTask() {
1465 <            public void realCompute() {
1464 >        ForkJoinTask a = new CheckedRecursiveAction() {
1465 >            protected void realCompute() {
1466                  FailingCCF f = new LFCCF(null, 8);
1467                  CCF g = new LCCF(null, 9);
1468                  CCF h = new LCCF(null, 7);
# Line 1497 | Line 1480 | public class ForkJoinPool8Test extends J
1480          checkInvoke(a);
1481      }
1482  
1483 +    /**
1484 +     * awaitQuiescence by a worker is equivalent in effect to
1485 +     * ForkJoinTask.helpQuiesce()
1486 +     */
1487 +    public void testAwaitQuiescence1() throws Exception {
1488 +        final ForkJoinPool p = new ForkJoinPool();
1489 +        try {
1490 +            final long startTime = System.nanoTime();
1491 +            assertTrue(p.isQuiescent());
1492 +            ForkJoinTask a = new CheckedRecursiveAction() {
1493 +                protected void realCompute() {
1494 +                    FibAction f = new FibAction(8);
1495 +                    assertSame(f, f.fork());
1496 +                    assertSame(p, ForkJoinTask.getPool());
1497 +                    boolean quiescent = p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS);
1498 +                    assertTrue(quiescent);
1499 +                    assertFalse(p.isQuiescent());
1500 +                    while (!f.isDone()) {
1501 +                        assertFalse(p.getAsyncMode());
1502 +                        assertFalse(p.isShutdown());
1503 +                        assertFalse(p.isTerminating());
1504 +                        assertFalse(p.isTerminated());
1505 +                        Thread.yield();
1506 +                    }
1507 +                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1508 +                    assertFalse(p.isQuiescent());
1509 +                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1510 +                    assertEquals(21, f.result);
1511 +                }};
1512 +            p.execute(a);
1513 +            while (!a.isDone() || !p.isQuiescent()) {
1514 +                assertFalse(p.getAsyncMode());
1515 +                assertFalse(p.isShutdown());
1516 +                assertFalse(p.isTerminating());
1517 +                assertFalse(p.isTerminated());
1518 +                Thread.yield();
1519 +            }
1520 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1521 +            assertEquals(0, p.getQueuedTaskCount());
1522 +            assertFalse(p.getAsyncMode());
1523 +            assertEquals(0, p.getActiveThreadCount());
1524 +            assertEquals(0, p.getQueuedTaskCount());
1525 +            assertEquals(0, p.getQueuedSubmissionCount());
1526 +            assertFalse(p.hasQueuedSubmissions());
1527 +            assertFalse(p.isShutdown());
1528 +            assertFalse(p.isTerminating());
1529 +            assertFalse(p.isTerminated());
1530 +        } finally {
1531 +            joinPool(p);
1532 +        }
1533 +    }
1534 +
1535 +    /**
1536 +     * awaitQuiescence returns when pool isQuiescent() or the indicated
1537 +     * timeout elapsed
1538 +     */
1539 +    public void testAwaitQuiescence2() throws Exception {
1540 +        /**
1541 +         * """It is possible to disable or limit the use of threads in the
1542 +         * common pool by setting the parallelism property to zero. However
1543 +         * doing so may cause unjoined tasks to never be executed."""
1544 +         */
1545 +        if ("0".equals(System.getProperty(
1546 +             "java.util.concurrent.ForkJoinPool.common.parallelism")))
1547 +            return;
1548 +        final ForkJoinPool p = new ForkJoinPool();
1549 +        try {
1550 +            assertTrue(p.isQuiescent());
1551 +            final long startTime = System.nanoTime();
1552 +            ForkJoinTask a = new CheckedRecursiveAction() {
1553 +                protected void realCompute() {
1554 +                    FibAction f = new FibAction(8);
1555 +                    assertSame(f, f.fork());
1556 +                    while (!f.isDone()
1557 +                           && millisElapsedSince(startTime) < LONG_DELAY_MS) {
1558 +                        assertFalse(p.getAsyncMode());
1559 +                        assertFalse(p.isShutdown());
1560 +                        assertFalse(p.isTerminating());
1561 +                        assertFalse(p.isTerminated());
1562 +                        Thread.yield();
1563 +                    }
1564 +                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1565 +                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1566 +                    assertEquals(21, f.result);
1567 +                }};
1568 +            p.execute(a);
1569 +            assertTrue(p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS));
1570 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1571 +            assertTrue(p.isQuiescent());
1572 +            assertTrue(a.isDone());
1573 +            assertEquals(0, p.getQueuedTaskCount());
1574 +            assertFalse(p.getAsyncMode());
1575 +            assertEquals(0, p.getActiveThreadCount());
1576 +            assertEquals(0, p.getQueuedTaskCount());
1577 +            assertEquals(0, p.getQueuedSubmissionCount());
1578 +            assertFalse(p.hasQueuedSubmissions());
1579 +            assertFalse(p.isShutdown());
1580 +            assertFalse(p.isTerminating());
1581 +            assertFalse(p.isTerminated());
1582 +        } finally {
1583 +            joinPool(p);
1584 +        }
1585 +    }
1586 +
1587   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines