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.34 by jsr166, Tue Aug 16 23:17:13 2016 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import junit.framework.*;
7 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 > import static java.util.concurrent.TimeUnit.SECONDS;
9 >
10 > import java.util.HashSet;
11   import java.util.concurrent.CancellationException;
12 + import java.util.concurrent.CountedCompleter;
13   import java.util.concurrent.ExecutionException;
14   import java.util.concurrent.ForkJoinPool;
15   import java.util.concurrent.ForkJoinTask;
12 import java.util.concurrent.ForkJoinWorkerThread;
16   import java.util.concurrent.RecursiveAction;
14 import java.util.concurrent.CountedCompleter;
15 import java.util.concurrent.ThreadLocalRandom;
16 import java.util.concurrent.TimeUnit;
17   import java.util.concurrent.TimeoutException;
18 < import static java.util.concurrent.TimeUnit.SECONDS;
19 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
20 < import java.util.Arrays;
21 < import java.util.HashSet;
18 >
19 > import junit.framework.Test;
20 > import junit.framework.TestSuite;
21  
22   public class ForkJoinPool8Test extends JSR166TestCase {
23      public static void main(String[] args) {
24 <        junit.textui.TestRunner.run(suite());
24 >        main(suite(), args);
25      }
26  
27      public static Test suite() {
# Line 185 | Line 184 | public class ForkJoinPool8Test extends J
184          final int number;
185          int result;
186          FibAction(int n) { number = n; }
187 <        public void realCompute() {
187 >        protected void realCompute() {
188              int n = number;
189              if (n <= 1)
190                  result = n;
# Line 223 | Line 222 | public class ForkJoinPool8Test extends J
222       */
223      public void testInvoke() {
224          RecursiveAction a = new CheckedRecursiveAction() {
225 <            public void realCompute() {
225 >            protected void realCompute() {
226                  FibAction f = new FibAction(8);
227                  assertNull(f.invoke());
228                  assertEquals(21, f.result);
# Line 239 | Line 238 | public class ForkJoinPool8Test extends J
238       */
239      public void testQuietlyInvoke() {
240          RecursiveAction a = new CheckedRecursiveAction() {
241 <            public void realCompute() {
241 >            protected void realCompute() {
242                  FibAction f = new FibAction(8);
243                  f.quietlyInvoke();
244                  assertEquals(21, f.result);
# Line 253 | Line 252 | public class ForkJoinPool8Test extends J
252       */
253      public void testForkJoin() {
254          RecursiveAction a = new CheckedRecursiveAction() {
255 <            public void realCompute() {
255 >            protected void realCompute() {
256                  FibAction f = new FibAction(8);
257                  assertSame(f, f.fork());
258                  assertNull(f.join());
# Line 268 | Line 267 | public class ForkJoinPool8Test extends J
267       */
268      public void testJoinIgnoresInterrupts() {
269          RecursiveAction a = new CheckedRecursiveAction() {
270 <            public void realCompute() {
270 >            protected void realCompute() {
271                  FibAction f = new FibAction(8);
272 <                final Thread myself = Thread.currentThread();
272 >                final Thread currentThread = Thread.currentThread();
273  
274                  // test join()
275                  assertSame(f, f.fork());
276 <                myself.interrupt();
278 <                assertTrue(myself.isInterrupted());
276 >                currentThread.interrupt();
277                  assertNull(f.join());
278                  Thread.interrupted();
279                  assertEquals(21, f.result);
# Line 284 | Line 282 | public class ForkJoinPool8Test extends J
282                  f = new FibAction(8);
283                  f.cancel(true);
284                  assertSame(f, f.fork());
285 <                myself.interrupt();
288 <                assertTrue(myself.isInterrupted());
285 >                currentThread.interrupt();
286                  try {
287                      f.join();
288                      shouldThrow();
# Line 297 | Line 294 | public class ForkJoinPool8Test extends J
294                  f = new FibAction(8);
295                  f.completeExceptionally(new FJException());
296                  assertSame(f, f.fork());
297 <                myself.interrupt();
301 <                assertTrue(myself.isInterrupted());
297 >                currentThread.interrupt();
298                  try {
299                      f.join();
300                      shouldThrow();
# Line 310 | Line 306 | public class ForkJoinPool8Test extends J
306                  // test quietlyJoin()
307                  f = new FibAction(8);
308                  assertSame(f, f.fork());
309 <                myself.interrupt();
314 <                assertTrue(myself.isInterrupted());
309 >                currentThread.interrupt();
310                  f.quietlyJoin();
311                  Thread.interrupted();
312                  assertEquals(21, f.result);
# Line 320 | Line 315 | public class ForkJoinPool8Test extends J
315                  f = new FibAction(8);
316                  f.cancel(true);
317                  assertSame(f, f.fork());
318 <                myself.interrupt();
324 <                assertTrue(myself.isInterrupted());
318 >                currentThread.interrupt();
319                  f.quietlyJoin();
320                  Thread.interrupted();
321                  checkCancelled(f);
# Line 329 | Line 323 | public class ForkJoinPool8Test extends J
323                  f = new FibAction(8);
324                  f.completeExceptionally(new FJException());
325                  assertSame(f, f.fork());
326 <                myself.interrupt();
333 <                assertTrue(myself.isInterrupted());
326 >                currentThread.interrupt();
327                  f.quietlyJoin();
328                  Thread.interrupted();
329                  checkCompletedAbnormally(f, f.getException());
# Line 340 | Line 333 | public class ForkJoinPool8Test extends J
333          checkInvoke(a);
334      }
335  
343
336      /**
337       * get of a forked task returns when task completes
338       */
339      public void testForkGet() {
340          RecursiveAction a = new CheckedRecursiveAction() {
341 <            public void realCompute() throws Exception {
341 >            protected void realCompute() throws Exception {
342                  FibAction f = new FibAction(8);
343                  assertSame(f, f.fork());
344                  assertNull(f.get());
# Line 361 | Line 353 | public class ForkJoinPool8Test extends J
353       */
354      public void testForkTimedGet() {
355          RecursiveAction a = new CheckedRecursiveAction() {
356 <            public void realCompute() throws Exception {
356 >            protected void realCompute() throws Exception {
357                  FibAction f = new FibAction(8);
358                  assertSame(f, f.fork());
359                  assertNull(f.get(5L, SECONDS));
# Line 376 | Line 368 | public class ForkJoinPool8Test extends J
368       */
369      public void testForkTimedGetNPE() {
370          RecursiveAction a = new CheckedRecursiveAction() {
371 <            public void realCompute() throws Exception {
371 >            protected void realCompute() throws Exception {
372                  FibAction f = new FibAction(8);
373                  assertSame(f, f.fork());
374                  try {
# Line 392 | Line 384 | public class ForkJoinPool8Test extends J
384       */
385      public void testForkQuietlyJoin() {
386          RecursiveAction a = new CheckedRecursiveAction() {
387 <            public void realCompute() {
387 >            protected void realCompute() {
388                  FibAction f = new FibAction(8);
389                  assertSame(f, f.fork());
390                  f.quietlyJoin();
# Line 407 | Line 399 | public class ForkJoinPool8Test extends J
399       */
400      public void testAbnormalInvoke() {
401          RecursiveAction a = new CheckedRecursiveAction() {
402 <            public void realCompute() {
402 >            protected void realCompute() {
403                  FailingFibAction f = new FailingFibAction(8);
404                  try {
405                      f.invoke();
# Line 424 | Line 416 | public class ForkJoinPool8Test extends J
416       */
417      public void testAbnormalQuietlyInvoke() {
418          RecursiveAction a = new CheckedRecursiveAction() {
419 <            public void realCompute() {
419 >            protected void realCompute() {
420                  FailingFibAction f = new FailingFibAction(8);
421                  f.quietlyInvoke();
422                  assertTrue(f.getException() instanceof FJException);
# Line 438 | Line 430 | public class ForkJoinPool8Test extends J
430       */
431      public void testAbnormalForkJoin() {
432          RecursiveAction a = new CheckedRecursiveAction() {
433 <            public void realCompute() {
433 >            protected void realCompute() {
434                  FailingFibAction f = new FailingFibAction(8);
435                  assertSame(f, f.fork());
436                  try {
# Line 456 | Line 448 | public class ForkJoinPool8Test extends J
448       */
449      public void testAbnormalForkGet() {
450          RecursiveAction a = new CheckedRecursiveAction() {
451 <            public void realCompute() throws Exception {
451 >            protected void realCompute() throws Exception {
452                  FailingFibAction f = new FailingFibAction(8);
453                  assertSame(f, f.fork());
454                  try {
# Line 476 | Line 468 | public class ForkJoinPool8Test extends J
468       */
469      public void testAbnormalForkTimedGet() {
470          RecursiveAction a = new CheckedRecursiveAction() {
471 <            public void realCompute() throws Exception {
471 >            protected void realCompute() throws Exception {
472                  FailingFibAction f = new FailingFibAction(8);
473                  assertSame(f, f.fork());
474                  try {
475 <                    f.get(5L, TimeUnit.SECONDS);
475 >                    f.get(5L, SECONDS);
476                      shouldThrow();
477                  } catch (ExecutionException success) {
478                      Throwable cause = success.getCause();
# Line 496 | Line 488 | public class ForkJoinPool8Test extends J
488       */
489      public void testAbnormalForkQuietlyJoin() {
490          RecursiveAction a = new CheckedRecursiveAction() {
491 <            public void realCompute() {
491 >            protected void realCompute() {
492                  FailingFibAction f = new FailingFibAction(8);
493                  assertSame(f, f.fork());
494                  f.quietlyJoin();
# Line 511 | Line 503 | public class ForkJoinPool8Test extends J
503       */
504      public void testCancelledInvoke() {
505          RecursiveAction a = new CheckedRecursiveAction() {
506 <            public void realCompute() {
506 >            protected void realCompute() {
507                  FibAction f = new FibAction(8);
508                  assertTrue(f.cancel(true));
509                  try {
# Line 529 | Line 521 | public class ForkJoinPool8Test extends J
521       */
522      public void testCancelledForkJoin() {
523          RecursiveAction a = new CheckedRecursiveAction() {
524 <            public void realCompute() {
524 >            protected void realCompute() {
525                  FibAction f = new FibAction(8);
526                  assertTrue(f.cancel(true));
527                  assertSame(f, f.fork());
# Line 548 | Line 540 | public class ForkJoinPool8Test extends J
540       */
541      public void testCancelledForkGet() {
542          RecursiveAction a = new CheckedRecursiveAction() {
543 <            public void realCompute() throws Exception {
543 >            protected void realCompute() throws Exception {
544                  FibAction f = new FibAction(8);
545                  assertTrue(f.cancel(true));
546                  assertSame(f, f.fork());
# Line 567 | Line 559 | public class ForkJoinPool8Test extends J
559       */
560      public void testCancelledForkTimedGet() {
561          RecursiveAction a = new CheckedRecursiveAction() {
562 <            public void realCompute() throws Exception {
562 >            protected void realCompute() throws Exception {
563                  FibAction f = new FibAction(8);
564                  assertTrue(f.cancel(true));
565                  assertSame(f, f.fork());
# Line 586 | Line 578 | public class ForkJoinPool8Test extends J
578       */
579      public void testCancelledForkQuietlyJoin() {
580          RecursiveAction a = new CheckedRecursiveAction() {
581 <            public void realCompute() {
581 >            protected void realCompute() {
582                  FibAction f = new FibAction(8);
583                  assertTrue(f.cancel(true));
584                  assertSame(f, f.fork());
# Line 601 | Line 593 | public class ForkJoinPool8Test extends J
593       */
594      public void testInForkJoinPool2() {
595          RecursiveAction a = new CheckedRecursiveAction() {
596 <            public void realCompute() {
596 >            protected void realCompute() {
597                  assertFalse(inForkJoinPool());
598              }};
599          assertNull(a.invoke());
# Line 612 | Line 604 | public class ForkJoinPool8Test extends J
604       */
605      public void testReinitialize() {
606          RecursiveAction a = new CheckedRecursiveAction() {
607 <            public void realCompute() {
607 >            protected void realCompute() {
608                  FibAction f = new FibAction(8);
609                  checkNotDone(f);
610  
# Line 632 | Line 624 | public class ForkJoinPool8Test extends J
624       */
625      public void testReinitializeAbnormal() {
626          RecursiveAction a = new CheckedRecursiveAction() {
627 <            public void realCompute() {
627 >            protected void realCompute() {
628                  FailingFibAction f = new FailingFibAction(8);
629                  checkNotDone(f);
630  
# Line 655 | Line 647 | public class ForkJoinPool8Test extends J
647       */
648      public void testCompleteExceptionally() {
649          RecursiveAction a = new CheckedRecursiveAction() {
650 <            public void realCompute() {
650 >            protected void realCompute() {
651                  FibAction f = new FibAction(8);
652                  f.completeExceptionally(new FJException());
653                  try {
# Line 673 | Line 665 | public class ForkJoinPool8Test extends J
665       */
666      public void testComplete() {
667          RecursiveAction a = new CheckedRecursiveAction() {
668 <            public void realCompute() {
668 >            protected void realCompute() {
669                  FibAction f = new FibAction(8);
670                  f.complete(null);
671                  assertNull(f.invoke());
# Line 688 | Line 680 | public class ForkJoinPool8Test extends J
680       */
681      public void testInvokeAll2() {
682          RecursiveAction a = new CheckedRecursiveAction() {
683 <            public void realCompute() {
683 >            protected void realCompute() {
684                  FibAction f = new FibAction(8);
685                  FibAction g = new FibAction(9);
686                  invokeAll(f, g);
# Line 705 | Line 697 | public class ForkJoinPool8Test extends J
697       */
698      public void testInvokeAll1() {
699          RecursiveAction a = new CheckedRecursiveAction() {
700 <            public void realCompute() {
700 >            protected void realCompute() {
701                  FibAction f = new FibAction(8);
702                  invokeAll(f);
703                  checkCompletedNormally(f);
# Line 719 | Line 711 | public class ForkJoinPool8Test extends J
711       */
712      public void testInvokeAll3() {
713          RecursiveAction a = new CheckedRecursiveAction() {
714 <            public void realCompute() {
714 >            protected void realCompute() {
715                  FibAction f = new FibAction(8);
716                  FibAction g = new FibAction(9);
717                  FibAction h = new FibAction(7);
# Line 742 | Line 734 | public class ForkJoinPool8Test extends J
734       */
735      public void testInvokeAllCollection() {
736          RecursiveAction a = new CheckedRecursiveAction() {
737 <            public void realCompute() {
737 >            protected void realCompute() {
738                  FibAction f = new FibAction(8);
739                  FibAction g = new FibAction(9);
740                  FibAction h = new FibAction(7);
# Line 769 | Line 761 | public class ForkJoinPool8Test extends J
761       */
762      public void testInvokeAllNPE() {
763          RecursiveAction a = new CheckedRecursiveAction() {
764 <            public void realCompute() {
764 >            protected void realCompute() {
765                  FibAction f = new FibAction(8);
766                  FibAction g = new FibAction(9);
767                  FibAction h = null;
# Line 786 | Line 778 | public class ForkJoinPool8Test extends J
778       */
779      public void testAbnormalInvokeAll2() {
780          RecursiveAction a = new CheckedRecursiveAction() {
781 <            public void realCompute() {
781 >            protected void realCompute() {
782                  FibAction f = new FibAction(8);
783                  FailingFibAction g = new FailingFibAction(9);
784                  try {
# Line 804 | Line 796 | public class ForkJoinPool8Test extends J
796       */
797      public void testAbnormalInvokeAll1() {
798          RecursiveAction a = new CheckedRecursiveAction() {
799 <            public void realCompute() {
799 >            protected void realCompute() {
800                  FailingFibAction g = new FailingFibAction(9);
801                  try {
802                      invokeAll(g);
# Line 821 | Line 813 | public class ForkJoinPool8Test extends J
813       */
814      public void testAbnormalInvokeAll3() {
815          RecursiveAction a = new CheckedRecursiveAction() {
816 <            public void realCompute() {
816 >            protected void realCompute() {
817                  FibAction f = new FibAction(8);
818                  FailingFibAction g = new FailingFibAction(9);
819                  FibAction h = new FibAction(7);
# Line 840 | Line 832 | public class ForkJoinPool8Test extends J
832       */
833      public void testAbnormalInvokeAllCollection() {
834          RecursiveAction a = new CheckedRecursiveAction() {
835 <            public void realCompute() {
835 >            protected void realCompute() {
836                  FailingFibAction f = new FailingFibAction(8);
837                  FibAction g = new FibAction(9);
838                  FibAction h = new FibAction(7);
# Line 860 | Line 852 | public class ForkJoinPool8Test extends J
852  
853      // CountedCompleter versions
854  
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
855      abstract static class CCF extends CountedCompleter {
856          int number;
857          int rnumber;
# Line 980 | Line 960 | public class ForkJoinPool8Test extends J
960       * completed tasks; getRawResult returns null.
961       */
962      public void testInvokeCC() {
963 <       ForkJoinTask a = new CheckedFJTask() {
964 <            public void realCompute() {
963 >        ForkJoinTask a = new CheckedRecursiveAction() {
964 >            protected void realCompute() {
965                  CCF f = new LCCF(null, 8);
966                  assertNull(f.invoke());
967                  assertEquals(21, f.number);
# Line 996 | Line 976 | public class ForkJoinPool8Test extends J
976       * completed tasks
977       */
978      public void testQuietlyInvokeCC() {
979 <       ForkJoinTask a = new CheckedFJTask() {
980 <            public void realCompute() {
979 >        ForkJoinTask a = new CheckedRecursiveAction() {
980 >            protected void realCompute() {
981                  CCF f = new LCCF(null, 8);
982                  f.quietlyInvoke();
983                  assertEquals(21, f.number);
# Line 1010 | Line 990 | public class ForkJoinPool8Test extends J
990       * join of a forked task returns when task completes
991       */
992      public void testForkJoinCC() {
993 <       ForkJoinTask a = new CheckedFJTask() {
994 <            public void realCompute() {
993 >        ForkJoinTask a = new CheckedRecursiveAction() {
994 >            protected void realCompute() {
995                  CCF f = new LCCF(null, 8);
996                  assertSame(f, f.fork());
997                  assertNull(f.join());
# Line 1025 | Line 1005 | public class ForkJoinPool8Test extends J
1005       * get of a forked task returns when task completes
1006       */
1007      public void testForkGetCC() {
1008 <       ForkJoinTask a = new CheckedFJTask() {
1009 <            public void realCompute() throws Exception {
1008 >        ForkJoinTask a = new CheckedRecursiveAction() {
1009 >            protected void realCompute() throws Exception {
1010                  CCF f = new LCCF(null, 8);
1011                  assertSame(f, f.fork());
1012                  assertNull(f.get());
# Line 1040 | Line 1020 | public class ForkJoinPool8Test extends J
1020       * timed get of a forked task returns when task completes
1021       */
1022      public void testForkTimedGetCC() {
1023 <       ForkJoinTask a = new CheckedFJTask() {
1024 <            public void realCompute() throws Exception {
1023 >        ForkJoinTask a = new CheckedRecursiveAction() {
1024 >            protected void realCompute() throws Exception {
1025                  CCF f = new LCCF(null, 8);
1026                  assertSame(f, f.fork());
1027                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
# Line 1055 | Line 1035 | public class ForkJoinPool8Test extends J
1035       * timed get with null time unit throws NPE
1036       */
1037      public void testForkTimedGetNPECC() {
1038 <       ForkJoinTask a = new CheckedFJTask() {
1039 <            public void realCompute() throws Exception {
1038 >        ForkJoinTask a = new CheckedRecursiveAction() {
1039 >            protected void realCompute() throws Exception {
1040                  CCF f = new LCCF(null, 8);
1041                  assertSame(f, f.fork());
1042                  try {
# Line 1071 | Line 1051 | public class ForkJoinPool8Test extends J
1051       * quietlyJoin of a forked task returns when task completes
1052       */
1053      public void testForkQuietlyJoinCC() {
1054 <       ForkJoinTask a = new CheckedFJTask() {
1055 <            public void realCompute() {
1054 >        ForkJoinTask a = new CheckedRecursiveAction() {
1055 >            protected void realCompute() {
1056                  CCF f = new LCCF(null, 8);
1057                  assertSame(f, f.fork());
1058                  f.quietlyJoin();
# Line 1086 | Line 1066 | public class ForkJoinPool8Test extends J
1066       * invoke task throws exception when task completes abnormally
1067       */
1068      public void testAbnormalInvokeCC() {
1069 <       ForkJoinTask a = new CheckedFJTask() {
1070 <            public void realCompute() {
1069 >        ForkJoinTask a = new CheckedRecursiveAction() {
1070 >            protected void realCompute() {
1071                  FailingCCF f = new LFCCF(null, 8);
1072                  try {
1073                      f.invoke();
# Line 1103 | Line 1083 | public class ForkJoinPool8Test extends J
1083       * quietlyInvoke task returns when task completes abnormally
1084       */
1085      public void testAbnormalQuietlyInvokeCC() {
1086 <       ForkJoinTask a = new CheckedFJTask() {
1087 <            public void realCompute() {
1086 >        ForkJoinTask a = new CheckedRecursiveAction() {
1087 >            protected void realCompute() {
1088                  FailingCCF f = new LFCCF(null, 8);
1089                  f.quietlyInvoke();
1090                  assertTrue(f.getException() instanceof FJException);
# Line 1117 | Line 1097 | public class ForkJoinPool8Test extends J
1097       * join of a forked task throws exception when task completes abnormally
1098       */
1099      public void testAbnormalForkJoinCC() {
1100 <       ForkJoinTask a = new CheckedFJTask() {
1101 <            public void realCompute() {
1100 >        ForkJoinTask a = new CheckedRecursiveAction() {
1101 >            protected void realCompute() {
1102                  FailingCCF f = new LFCCF(null, 8);
1103                  assertSame(f, f.fork());
1104                  try {
# Line 1135 | Line 1115 | public class ForkJoinPool8Test extends J
1115       * get of a forked task throws exception when task completes abnormally
1116       */
1117      public void testAbnormalForkGetCC() {
1118 <       ForkJoinTask a = new CheckedFJTask() {
1119 <            public void realCompute() throws Exception {
1118 >        ForkJoinTask a = new CheckedRecursiveAction() {
1119 >            protected void realCompute() throws Exception {
1120                  FailingCCF f = new LFCCF(null, 8);
1121                  assertSame(f, f.fork());
1122                  try {
# Line 1155 | Line 1135 | public class ForkJoinPool8Test extends J
1135       * timed get of a forked task throws exception when task completes abnormally
1136       */
1137      public void testAbnormalForkTimedGetCC() {
1138 <       ForkJoinTask a = new CheckedFJTask() {
1139 <            public void realCompute() throws Exception {
1138 >        ForkJoinTask a = new CheckedRecursiveAction() {
1139 >            protected void realCompute() throws Exception {
1140                  FailingCCF f = new LFCCF(null, 8);
1141                  assertSame(f, f.fork());
1142                  try {
# Line 1175 | Line 1155 | public class ForkJoinPool8Test extends J
1155       * quietlyJoin of a forked task returns when task completes abnormally
1156       */
1157      public void testAbnormalForkQuietlyJoinCC() {
1158 <       ForkJoinTask a = new CheckedFJTask() {
1159 <            public void realCompute() {
1158 >        ForkJoinTask a = new CheckedRecursiveAction() {
1159 >            protected void realCompute() {
1160                  FailingCCF f = new LFCCF(null, 8);
1161                  assertSame(f, f.fork());
1162                  f.quietlyJoin();
# Line 1190 | Line 1170 | public class ForkJoinPool8Test extends J
1170       * invoke task throws exception when task cancelled
1171       */
1172      public void testCancelledInvokeCC() {
1173 <       ForkJoinTask a = new CheckedFJTask() {
1174 <            public void realCompute() {
1173 >        ForkJoinTask a = new CheckedRecursiveAction() {
1174 >            protected void realCompute() {
1175                  CCF f = new LCCF(null, 8);
1176                  assertTrue(f.cancel(true));
1177                  try {
# Line 1208 | Line 1188 | public class ForkJoinPool8Test extends J
1188       * join of a forked task throws exception when task cancelled
1189       */
1190      public void testCancelledForkJoinCC() {
1191 <       ForkJoinTask a = new CheckedFJTask() {
1192 <            public void realCompute() {
1191 >        ForkJoinTask a = new CheckedRecursiveAction() {
1192 >            protected void realCompute() {
1193                  CCF f = new LCCF(null, 8);
1194                  assertTrue(f.cancel(true));
1195                  assertSame(f, f.fork());
# Line 1227 | Line 1207 | public class ForkJoinPool8Test extends J
1207       * get of a forked task throws exception when task cancelled
1208       */
1209      public void testCancelledForkGetCC() {
1210 <       ForkJoinTask a = new CheckedFJTask() {
1211 <            public void realCompute() throws Exception {
1210 >        ForkJoinTask a = new CheckedRecursiveAction() {
1211 >            protected void realCompute() throws Exception {
1212                  CCF f = new LCCF(null, 8);
1213                  assertTrue(f.cancel(true));
1214                  assertSame(f, f.fork());
# Line 1246 | Line 1226 | public class ForkJoinPool8Test extends J
1226       * timed get of a forked task throws exception when task cancelled
1227       */
1228      public void testCancelledForkTimedGetCC() throws Exception {
1229 <       ForkJoinTask a = new CheckedFJTask() {
1230 <            public void realCompute() throws Exception {
1229 >        ForkJoinTask a = new CheckedRecursiveAction() {
1230 >            protected void realCompute() throws Exception {
1231                  CCF f = new LCCF(null, 8);
1232                  assertTrue(f.cancel(true));
1233                  assertSame(f, f.fork());
# Line 1265 | Line 1245 | public class ForkJoinPool8Test extends J
1245       * quietlyJoin of a forked task returns when task cancelled
1246       */
1247      public void testCancelledForkQuietlyJoinCC() {
1248 <       ForkJoinTask a = new CheckedFJTask() {
1249 <            public void realCompute() {
1248 >        ForkJoinTask a = new CheckedRecursiveAction() {
1249 >            protected void realCompute() {
1250                  CCF f = new LCCF(null, 8);
1251                  assertTrue(f.cancel(true));
1252                  assertSame(f, f.fork());
# Line 1280 | Line 1260 | public class ForkJoinPool8Test extends J
1260       * getPool of non-FJ task returns null
1261       */
1262      public void testGetPool2CC() {
1263 <       ForkJoinTask a = new CheckedFJTask() {
1264 <            public void realCompute() {
1263 >        ForkJoinTask a = new CheckedRecursiveAction() {
1264 >            protected void realCompute() {
1265                  assertNull(getPool());
1266              }};
1267          assertNull(a.invoke());
# Line 1291 | Line 1271 | public class ForkJoinPool8Test extends J
1271       * inForkJoinPool of non-FJ task returns false
1272       */
1273      public void testInForkJoinPool2CC() {
1274 <       ForkJoinTask a = new CheckedFJTask() {
1275 <            public void realCompute() {
1274 >        ForkJoinTask a = new CheckedRecursiveAction() {
1275 >            protected void realCompute() {
1276                  assertFalse(inForkJoinPool());
1277              }};
1278          assertNull(a.invoke());
# Line 1302 | Line 1282 | public class ForkJoinPool8Test extends J
1282       * setRawResult(null) succeeds
1283       */
1284      public void testSetRawResultCC() {
1285 <       ForkJoinTask a = new CheckedFJTask() {
1286 <            public void realCompute() {
1285 >        ForkJoinTask a = new CheckedRecursiveAction() {
1286 >            protected void realCompute() {
1287                  setRawResult(null);
1288                  assertNull(getRawResult());
1289              }};
# Line 1314 | Line 1294 | public class ForkJoinPool8Test extends J
1294       * invoke task throws exception after invoking completeExceptionally
1295       */
1296      public void testCompleteExceptionally2CC() {
1297 <       ForkJoinTask a = new CheckedFJTask() {
1298 <            public void realCompute() {
1297 >        ForkJoinTask a = new CheckedRecursiveAction() {
1298 >            protected void realCompute() {
1299                  CCF f = new LCCF(null, 8);
1300                  f.completeExceptionally(new FJException());
1301                  try {
# Line 1332 | Line 1312 | public class ForkJoinPool8Test extends J
1312       * invokeAll(t1, t2) invokes all task arguments
1313       */
1314      public void testInvokeAll2CC() {
1315 <       ForkJoinTask a = new CheckedFJTask() {
1316 <            public void realCompute() {
1315 >        ForkJoinTask a = new CheckedRecursiveAction() {
1316 >            protected void realCompute() {
1317                  CCF f = new LCCF(null, 8);
1318                  CCF g = new LCCF(null, 9);
1319                  invokeAll(f, g);
# Line 1349 | Line 1329 | public class ForkJoinPool8Test extends J
1329       * invokeAll(tasks) with 1 argument invokes task
1330       */
1331      public void testInvokeAll1CC() {
1332 <       ForkJoinTask a = new CheckedFJTask() {
1333 <            public void realCompute() {
1332 >        ForkJoinTask a = new CheckedRecursiveAction() {
1333 >            protected void realCompute() {
1334                  CCF f = new LCCF(null, 8);
1335                  invokeAll(f);
1336                  checkCompletedNormally(f);
# Line 1363 | Line 1343 | public class ForkJoinPool8Test extends J
1343       * invokeAll(tasks) with > 2 argument invokes tasks
1344       */
1345      public void testInvokeAll3CC() {
1346 <       ForkJoinTask a = new CheckedFJTask() {
1347 <            public void realCompute() {
1346 >        ForkJoinTask a = new CheckedRecursiveAction() {
1347 >            protected void realCompute() {
1348                  CCF f = new LCCF(null, 8);
1349                  CCF g = new LCCF(null, 9);
1350                  CCF h = new LCCF(null, 7);
# Line 1383 | Line 1363 | public class ForkJoinPool8Test extends J
1363       * invokeAll(collection) invokes all tasks in the collection
1364       */
1365      public void testInvokeAllCollectionCC() {
1366 <       ForkJoinTask a = new CheckedFJTask() {
1367 <            public void realCompute() {
1366 >        ForkJoinTask a = new CheckedRecursiveAction() {
1367 >            protected void realCompute() {
1368                  CCF f = new LCCF(null, 8);
1369                  CCF g = new LCCF(null, 9);
1370                  CCF h = new LCCF(null, 7);
# Line 1407 | Line 1387 | public class ForkJoinPool8Test extends J
1387       * invokeAll(tasks) with any null task throws NPE
1388       */
1389      public void testInvokeAllNPECC() {
1390 <       ForkJoinTask a = new CheckedFJTask() {
1391 <            public void realCompute() {
1390 >        ForkJoinTask a = new CheckedRecursiveAction() {
1391 >            protected void realCompute() {
1392                  CCF f = new LCCF(null, 8);
1393                  CCF g = new LCCF(null, 9);
1394                  CCF h = null;
# Line 1424 | Line 1404 | public class ForkJoinPool8Test extends J
1404       * invokeAll(t1, t2) throw exception if any task does
1405       */
1406      public void testAbnormalInvokeAll2CC() {
1407 <       ForkJoinTask a = new CheckedFJTask() {
1408 <            public void realCompute() {
1407 >        ForkJoinTask a = new CheckedRecursiveAction() {
1408 >            protected void realCompute() {
1409                  CCF f = new LCCF(null, 8);
1410                  FailingCCF g = new LFCCF(null, 9);
1411                  try {
# Line 1442 | Line 1422 | public class ForkJoinPool8Test extends J
1422       * invokeAll(tasks) with 1 argument throws exception if task does
1423       */
1424      public void testAbnormalInvokeAll1CC() {
1425 <       ForkJoinTask a = new CheckedFJTask() {
1426 <            public void realCompute() {
1425 >        ForkJoinTask a = new CheckedRecursiveAction() {
1426 >            protected void realCompute() {
1427                  FailingCCF g = new LFCCF(null, 9);
1428                  try {
1429                      invokeAll(g);
# Line 1459 | Line 1439 | public class ForkJoinPool8Test extends J
1439       * invokeAll(tasks) with > 2 argument throws exception if any task does
1440       */
1441      public void testAbnormalInvokeAll3CC() {
1442 <       ForkJoinTask a = new CheckedFJTask() {
1443 <            public void realCompute() {
1442 >        ForkJoinTask a = new CheckedRecursiveAction() {
1443 >            protected void realCompute() {
1444                  CCF f = new LCCF(null, 8);
1445                  FailingCCF g = new LFCCF(null, 9);
1446                  CCF h = new LCCF(null, 7);
# Line 1475 | Line 1455 | public class ForkJoinPool8Test extends J
1455      }
1456  
1457      /**
1458 <     * invokeAll(collection)  throws exception if any task does
1458 >     * invokeAll(collection) throws exception if any task does
1459       */
1460      public void testAbnormalInvokeAllCollectionCC() {
1461 <       ForkJoinTask a = new CheckedFJTask() {
1462 <            public void realCompute() {
1461 >        ForkJoinTask a = new CheckedRecursiveAction() {
1462 >            protected void realCompute() {
1463                  FailingCCF f = new LFCCF(null, 8);
1464                  CCF g = new LCCF(null, 9);
1465                  CCF h = new LCCF(null, 7);
# Line 1497 | Line 1477 | public class ForkJoinPool8Test extends J
1477          checkInvoke(a);
1478      }
1479  
1480 +    /**
1481 +     * awaitQuiescence by a worker is equivalent in effect to
1482 +     * ForkJoinTask.helpQuiesce()
1483 +     */
1484 +    public void testAwaitQuiescence1() throws Exception {
1485 +        final ForkJoinPool p = new ForkJoinPool();
1486 +        try (PoolCleaner cleaner = cleaner(p)) {
1487 +            final long startTime = System.nanoTime();
1488 +            assertTrue(p.isQuiescent());
1489 +            ForkJoinTask a = new CheckedRecursiveAction() {
1490 +                protected void realCompute() {
1491 +                    FibAction f = new FibAction(8);
1492 +                    assertSame(f, f.fork());
1493 +                    assertSame(p, ForkJoinTask.getPool());
1494 +                    boolean quiescent = p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS);
1495 +                    assertTrue(quiescent);
1496 +                    assertFalse(p.isQuiescent());
1497 +                    while (!f.isDone()) {
1498 +                        assertFalse(p.getAsyncMode());
1499 +                        assertFalse(p.isShutdown());
1500 +                        assertFalse(p.isTerminating());
1501 +                        assertFalse(p.isTerminated());
1502 +                        Thread.yield();
1503 +                    }
1504 +                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1505 +                    assertFalse(p.isQuiescent());
1506 +                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1507 +                    assertEquals(21, f.result);
1508 +                }};
1509 +            p.execute(a);
1510 +            while (!a.isDone() || !p.isQuiescent()) {
1511 +                assertFalse(p.getAsyncMode());
1512 +                assertFalse(p.isShutdown());
1513 +                assertFalse(p.isTerminating());
1514 +                assertFalse(p.isTerminated());
1515 +                Thread.yield();
1516 +            }
1517 +            assertEquals(0, p.getQueuedTaskCount());
1518 +            assertFalse(p.getAsyncMode());
1519 +            assertEquals(0, p.getQueuedSubmissionCount());
1520 +            assertFalse(p.hasQueuedSubmissions());
1521 +            while (p.getActiveThreadCount() != 0
1522 +                   && millisElapsedSince(startTime) < LONG_DELAY_MS)
1523 +                Thread.yield();
1524 +            assertFalse(p.isShutdown());
1525 +            assertFalse(p.isTerminating());
1526 +            assertFalse(p.isTerminated());
1527 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1528 +        }
1529 +    }
1530 +
1531 +    /**
1532 +     * awaitQuiescence returns when pool isQuiescent() or the indicated
1533 +     * timeout elapsed
1534 +     */
1535 +    public void testAwaitQuiescence2() throws Exception {
1536 +        /**
1537 +         * """It is possible to disable or limit the use of threads in the
1538 +         * common pool by setting the parallelism property to zero. However
1539 +         * doing so may cause unjoined tasks to never be executed."""
1540 +         */
1541 +        if ("0".equals(System.getProperty(
1542 +             "java.util.concurrent.ForkJoinPool.common.parallelism")))
1543 +            return;
1544 +        final ForkJoinPool p = new ForkJoinPool();
1545 +        try (PoolCleaner cleaner = cleaner(p)) {
1546 +            assertTrue(p.isQuiescent());
1547 +            final long startTime = System.nanoTime();
1548 +            ForkJoinTask a = new CheckedRecursiveAction() {
1549 +                protected void realCompute() {
1550 +                    FibAction f = new FibAction(8);
1551 +                    assertSame(f, f.fork());
1552 +                    while (!f.isDone()
1553 +                           && millisElapsedSince(startTime) < LONG_DELAY_MS) {
1554 +                        assertFalse(p.getAsyncMode());
1555 +                        assertFalse(p.isShutdown());
1556 +                        assertFalse(p.isTerminating());
1557 +                        assertFalse(p.isTerminated());
1558 +                        Thread.yield();
1559 +                    }
1560 +                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1561 +                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1562 +                    assertEquals(21, f.result);
1563 +                }};
1564 +            p.execute(a);
1565 +            assertTrue(p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS));
1566 +            assertTrue(p.isQuiescent());
1567 +            assertTrue(a.isDone());
1568 +            assertEquals(0, p.getQueuedTaskCount());
1569 +            assertFalse(p.getAsyncMode());
1570 +            assertEquals(0, p.getQueuedSubmissionCount());
1571 +            assertFalse(p.hasQueuedSubmissions());
1572 +            while (p.getActiveThreadCount() != 0
1573 +                   && millisElapsedSince(startTime) < LONG_DELAY_MS)
1574 +                Thread.yield();
1575 +            assertFalse(p.isShutdown());
1576 +            assertFalse(p.isTerminating());
1577 +            assertFalse(p.isTerminated());
1578 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1579 +        }
1580 +    }
1581 +
1582   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines