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.5 by jsr166, Fri Mar 22 16:10:19 2013 UTC vs.
Revision 1.16 by jsr166, Mon Sep 16 00:48:00 2013 UTC

# Line 185 | Line 185 | public class ForkJoinPool8Test extends J
185          final int number;
186          int result;
187          FibAction(int n) { number = n; }
188 <        public void realCompute() {
188 >        protected void realCompute() {
189              int n = number;
190              if (n <= 1)
191                  result = n;
# Line 223 | Line 223 | public class ForkJoinPool8Test extends J
223       */
224      public void testInvoke() {
225          RecursiveAction a = new CheckedRecursiveAction() {
226 <            public void realCompute() {
226 >            protected void realCompute() {
227                  FibAction f = new FibAction(8);
228                  assertNull(f.invoke());
229                  assertEquals(21, f.result);
# Line 239 | Line 239 | public class ForkJoinPool8Test extends J
239       */
240      public void testQuietlyInvoke() {
241          RecursiveAction a = new CheckedRecursiveAction() {
242 <            public void realCompute() {
242 >            protected void realCompute() {
243                  FibAction f = new FibAction(8);
244                  f.quietlyInvoke();
245                  assertEquals(21, f.result);
# Line 253 | Line 253 | public class ForkJoinPool8Test extends J
253       */
254      public void testForkJoin() {
255          RecursiveAction a = new CheckedRecursiveAction() {
256 <            public void realCompute() {
256 >            protected void realCompute() {
257                  FibAction f = new FibAction(8);
258                  assertSame(f, f.fork());
259                  assertNull(f.join());
# Line 268 | Line 268 | public class ForkJoinPool8Test extends J
268       */
269      public void testJoinIgnoresInterrupts() {
270          RecursiveAction a = new CheckedRecursiveAction() {
271 <            public void realCompute() {
271 >            protected void realCompute() {
272                  FibAction f = new FibAction(8);
273                  final Thread myself = Thread.currentThread();
274  
# Line 340 | Line 340 | public class ForkJoinPool8Test extends J
340          checkInvoke(a);
341      }
342  
343
343      /**
344       * get of a forked task returns when task completes
345       */
346      public void testForkGet() {
347          RecursiveAction a = new CheckedRecursiveAction() {
348 <            public void realCompute() throws Exception {
348 >            protected void realCompute() throws Exception {
349                  FibAction f = new FibAction(8);
350                  assertSame(f, f.fork());
351                  assertNull(f.get());
# Line 361 | Line 360 | public class ForkJoinPool8Test extends J
360       */
361      public void testForkTimedGet() {
362          RecursiveAction a = new CheckedRecursiveAction() {
363 <            public void realCompute() throws Exception {
363 >            protected void realCompute() throws Exception {
364                  FibAction f = new FibAction(8);
365                  assertSame(f, f.fork());
366                  assertNull(f.get(5L, SECONDS));
# Line 376 | Line 375 | public class ForkJoinPool8Test extends J
375       */
376      public void testForkTimedGetNPE() {
377          RecursiveAction a = new CheckedRecursiveAction() {
378 <            public void realCompute() throws Exception {
378 >            protected void realCompute() throws Exception {
379                  FibAction f = new FibAction(8);
380                  assertSame(f, f.fork());
381                  try {
# Line 392 | Line 391 | public class ForkJoinPool8Test extends J
391       */
392      public void testForkQuietlyJoin() {
393          RecursiveAction a = new CheckedRecursiveAction() {
394 <            public void realCompute() {
394 >            protected void realCompute() {
395                  FibAction f = new FibAction(8);
396                  assertSame(f, f.fork());
397                  f.quietlyJoin();
# Line 403 | Line 402 | public class ForkJoinPool8Test extends J
402      }
403  
404      /**
406     * helpQuiesce returns when tasks are complete.
407     * getQueuedTaskCount returns 0 when quiescent
408     */
409    public void testForkHelpQuiesce() {
410        RecursiveAction a = new CheckedRecursiveAction() {
411            public void realCompute() {
412                FibAction f = new FibAction(8);
413                assertSame(f, f.fork());
414                helpQuiesce();
415                assertEquals(21, f.result);
416                assertEquals(0, getQueuedTaskCount());
417                checkCompletedNormally(f);
418            }};
419        checkInvoke(a);
420    }
421
422    /**
405       * invoke task throws exception when task completes abnormally
406       */
407      public void testAbnormalInvoke() {
408          RecursiveAction a = new CheckedRecursiveAction() {
409 <            public void realCompute() {
409 >            protected void realCompute() {
410                  FailingFibAction f = new FailingFibAction(8);
411                  try {
412                      f.invoke();
# Line 441 | Line 423 | public class ForkJoinPool8Test extends J
423       */
424      public void testAbnormalQuietlyInvoke() {
425          RecursiveAction a = new CheckedRecursiveAction() {
426 <            public void realCompute() {
426 >            protected void realCompute() {
427                  FailingFibAction f = new FailingFibAction(8);
428                  f.quietlyInvoke();
429                  assertTrue(f.getException() instanceof FJException);
# Line 455 | Line 437 | public class ForkJoinPool8Test extends J
437       */
438      public void testAbnormalForkJoin() {
439          RecursiveAction a = new CheckedRecursiveAction() {
440 <            public void realCompute() {
440 >            protected void realCompute() {
441                  FailingFibAction f = new FailingFibAction(8);
442                  assertSame(f, f.fork());
443                  try {
# Line 473 | Line 455 | public class ForkJoinPool8Test extends J
455       */
456      public void testAbnormalForkGet() {
457          RecursiveAction a = new CheckedRecursiveAction() {
458 <            public void realCompute() throws Exception {
458 >            protected void realCompute() throws Exception {
459                  FailingFibAction f = new FailingFibAction(8);
460                  assertSame(f, f.fork());
461                  try {
# Line 493 | Line 475 | public class ForkJoinPool8Test extends J
475       */
476      public void testAbnormalForkTimedGet() {
477          RecursiveAction a = new CheckedRecursiveAction() {
478 <            public void realCompute() throws Exception {
478 >            protected void realCompute() throws Exception {
479                  FailingFibAction f = new FailingFibAction(8);
480                  assertSame(f, f.fork());
481                  try {
# Line 513 | Line 495 | public class ForkJoinPool8Test extends J
495       */
496      public void testAbnormalForkQuietlyJoin() {
497          RecursiveAction a = new CheckedRecursiveAction() {
498 <            public void realCompute() {
498 >            protected void realCompute() {
499                  FailingFibAction f = new FailingFibAction(8);
500                  assertSame(f, f.fork());
501                  f.quietlyJoin();
# Line 528 | Line 510 | public class ForkJoinPool8Test extends J
510       */
511      public void testCancelledInvoke() {
512          RecursiveAction a = new CheckedRecursiveAction() {
513 <            public void realCompute() {
513 >            protected void realCompute() {
514                  FibAction f = new FibAction(8);
515                  assertTrue(f.cancel(true));
516                  try {
# Line 546 | Line 528 | public class ForkJoinPool8Test extends J
528       */
529      public void testCancelledForkJoin() {
530          RecursiveAction a = new CheckedRecursiveAction() {
531 <            public void realCompute() {
531 >            protected void realCompute() {
532                  FibAction f = new FibAction(8);
533                  assertTrue(f.cancel(true));
534                  assertSame(f, f.fork());
# Line 565 | Line 547 | public class ForkJoinPool8Test extends J
547       */
548      public void testCancelledForkGet() {
549          RecursiveAction a = new CheckedRecursiveAction() {
550 <            public void realCompute() throws Exception {
550 >            protected void realCompute() throws Exception {
551                  FibAction f = new FibAction(8);
552                  assertTrue(f.cancel(true));
553                  assertSame(f, f.fork());
# Line 584 | Line 566 | public class ForkJoinPool8Test extends J
566       */
567      public void testCancelledForkTimedGet() {
568          RecursiveAction a = new CheckedRecursiveAction() {
569 <            public void realCompute() throws Exception {
569 >            protected void realCompute() throws Exception {
570                  FibAction f = new FibAction(8);
571                  assertTrue(f.cancel(true));
572                  assertSame(f, f.fork());
# Line 603 | Line 585 | public class ForkJoinPool8Test extends J
585       */
586      public void testCancelledForkQuietlyJoin() {
587          RecursiveAction a = new CheckedRecursiveAction() {
588 <            public void realCompute() {
588 >            protected void realCompute() {
589                  FibAction f = new FibAction(8);
590                  assertTrue(f.cancel(true));
591                  assertSame(f, f.fork());
# Line 618 | Line 600 | public class ForkJoinPool8Test extends J
600       */
601      public void testInForkJoinPool2() {
602          RecursiveAction a = new CheckedRecursiveAction() {
603 <            public void realCompute() {
603 >            protected void realCompute() {
604                  assertFalse(inForkJoinPool());
605              }};
606          assertNull(a.invoke());
# Line 629 | Line 611 | public class ForkJoinPool8Test extends J
611       */
612      public void testReinitialize() {
613          RecursiveAction a = new CheckedRecursiveAction() {
614 <            public void realCompute() {
614 >            protected void realCompute() {
615                  FibAction f = new FibAction(8);
616                  checkNotDone(f);
617  
# Line 649 | Line 631 | public class ForkJoinPool8Test extends J
631       */
632      public void testReinitializeAbnormal() {
633          RecursiveAction a = new CheckedRecursiveAction() {
634 <            public void realCompute() {
634 >            protected void realCompute() {
635                  FailingFibAction f = new FailingFibAction(8);
636                  checkNotDone(f);
637  
# Line 672 | Line 654 | public class ForkJoinPool8Test extends J
654       */
655      public void testCompleteExceptionally() {
656          RecursiveAction a = new CheckedRecursiveAction() {
657 <            public void realCompute() {
657 >            protected void realCompute() {
658                  FibAction f = new FibAction(8);
659                  f.completeExceptionally(new FJException());
660                  try {
# Line 690 | Line 672 | public class ForkJoinPool8Test extends J
672       */
673      public void testComplete() {
674          RecursiveAction a = new CheckedRecursiveAction() {
675 <            public void realCompute() {
675 >            protected void realCompute() {
676                  FibAction f = new FibAction(8);
677                  f.complete(null);
678                  assertNull(f.invoke());
# Line 705 | Line 687 | public class ForkJoinPool8Test extends J
687       */
688      public void testInvokeAll2() {
689          RecursiveAction a = new CheckedRecursiveAction() {
690 <            public void realCompute() {
690 >            protected void realCompute() {
691                  FibAction f = new FibAction(8);
692                  FibAction g = new FibAction(9);
693                  invokeAll(f, g);
# Line 722 | Line 704 | public class ForkJoinPool8Test extends J
704       */
705      public void testInvokeAll1() {
706          RecursiveAction a = new CheckedRecursiveAction() {
707 <            public void realCompute() {
707 >            protected void realCompute() {
708                  FibAction f = new FibAction(8);
709                  invokeAll(f);
710                  checkCompletedNormally(f);
# Line 736 | Line 718 | public class ForkJoinPool8Test extends J
718       */
719      public void testInvokeAll3() {
720          RecursiveAction a = new CheckedRecursiveAction() {
721 <            public void realCompute() {
721 >            protected void realCompute() {
722                  FibAction f = new FibAction(8);
723                  FibAction g = new FibAction(9);
724                  FibAction h = new FibAction(7);
# Line 759 | Line 741 | public class ForkJoinPool8Test extends J
741       */
742      public void testInvokeAllCollection() {
743          RecursiveAction a = new CheckedRecursiveAction() {
744 <            public void realCompute() {
744 >            protected void realCompute() {
745                  FibAction f = new FibAction(8);
746                  FibAction g = new FibAction(9);
747                  FibAction h = new FibAction(7);
# Line 786 | Line 768 | public class ForkJoinPool8Test extends J
768       */
769      public void testInvokeAllNPE() {
770          RecursiveAction a = new CheckedRecursiveAction() {
771 <            public void realCompute() {
771 >            protected void realCompute() {
772                  FibAction f = new FibAction(8);
773                  FibAction g = new FibAction(9);
774                  FibAction h = null;
# Line 803 | Line 785 | public class ForkJoinPool8Test extends J
785       */
786      public void testAbnormalInvokeAll2() {
787          RecursiveAction a = new CheckedRecursiveAction() {
788 <            public void realCompute() {
788 >            protected void realCompute() {
789                  FibAction f = new FibAction(8);
790                  FailingFibAction g = new FailingFibAction(9);
791                  try {
# Line 821 | Line 803 | public class ForkJoinPool8Test extends J
803       */
804      public void testAbnormalInvokeAll1() {
805          RecursiveAction a = new CheckedRecursiveAction() {
806 <            public void realCompute() {
806 >            protected void realCompute() {
807                  FailingFibAction g = new FailingFibAction(9);
808                  try {
809                      invokeAll(g);
# Line 838 | Line 820 | public class ForkJoinPool8Test extends J
820       */
821      public void testAbnormalInvokeAll3() {
822          RecursiveAction a = new CheckedRecursiveAction() {
823 <            public void realCompute() {
823 >            protected void realCompute() {
824                  FibAction f = new FibAction(8);
825                  FailingFibAction g = new FailingFibAction(9);
826                  FibAction h = new FibAction(7);
# Line 857 | Line 839 | public class ForkJoinPool8Test extends J
839       */
840      public void testAbnormalInvokeAllCollection() {
841          RecursiveAction a = new CheckedRecursiveAction() {
842 <            public void realCompute() {
842 >            protected void realCompute() {
843                  FailingFibAction f = new FailingFibAction(8);
844                  FibAction g = new FibAction(9);
845                  FibAction h = new FibAction(7);
# Line 877 | Line 859 | public class ForkJoinPool8Test extends J
859  
860      // CountedCompleter versions
861  
880    public abstract class CheckedFJTask extends RecursiveAction {
881        protected abstract void realCompute() throws Throwable;
882
883        public final void compute() {
884            try {
885                realCompute();
886            } catch (Throwable t) {
887                threadUnexpectedException(t);
888            }
889        }
890    }
891
862      abstract static class CCF extends CountedCompleter {
863          int number;
864          int rnumber;
# Line 997 | Line 967 | public class ForkJoinPool8Test extends J
967       * completed tasks; getRawResult returns null.
968       */
969      public void testInvokeCC() {
970 <       ForkJoinTask a =  new CheckedFJTask() {
971 <            public void realCompute() {
970 >        ForkJoinTask a = new CheckedRecursiveAction() {
971 >            protected void realCompute() {
972                  CCF f = new LCCF(null, 8);
973                  assertNull(f.invoke());
974                  assertEquals(21, f.number);
# Line 1013 | Line 983 | public class ForkJoinPool8Test extends J
983       * completed tasks
984       */
985      public void testQuietlyInvokeCC() {
986 <       ForkJoinTask a =  new CheckedFJTask() {
987 <            public void realCompute() {
986 >        ForkJoinTask a = new CheckedRecursiveAction() {
987 >            protected void realCompute() {
988                  CCF f = new LCCF(null, 8);
989                  f.quietlyInvoke();
990                  assertEquals(21, f.number);
# Line 1027 | Line 997 | public class ForkJoinPool8Test extends J
997       * join of a forked task returns when task completes
998       */
999      public void testForkJoinCC() {
1000 <       ForkJoinTask a =  new CheckedFJTask() {
1001 <            public void realCompute() {
1000 >        ForkJoinTask a = new CheckedRecursiveAction() {
1001 >            protected void realCompute() {
1002                  CCF f = new LCCF(null, 8);
1003                  assertSame(f, f.fork());
1004                  assertNull(f.join());
# Line 1042 | Line 1012 | public class ForkJoinPool8Test extends J
1012       * get of a forked task returns when task completes
1013       */
1014      public void testForkGetCC() {
1015 <       ForkJoinTask a =  new CheckedFJTask() {
1016 <            public void realCompute() throws Exception {
1015 >        ForkJoinTask a = new CheckedRecursiveAction() {
1016 >            protected void realCompute() throws Exception {
1017                  CCF f = new LCCF(null, 8);
1018                  assertSame(f, f.fork());
1019                  assertNull(f.get());
# Line 1057 | Line 1027 | public class ForkJoinPool8Test extends J
1027       * timed get of a forked task returns when task completes
1028       */
1029      public void testForkTimedGetCC() {
1030 <       ForkJoinTask a =  new CheckedFJTask() {
1031 <            public void realCompute() throws Exception {
1030 >        ForkJoinTask a = new CheckedRecursiveAction() {
1031 >            protected void realCompute() throws Exception {
1032                  CCF f = new LCCF(null, 8);
1033                  assertSame(f, f.fork());
1034                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
# Line 1072 | Line 1042 | public class ForkJoinPool8Test extends J
1042       * timed get with null time unit throws NPE
1043       */
1044      public void testForkTimedGetNPECC() {
1045 <       ForkJoinTask a =  new CheckedFJTask() {
1046 <            public void realCompute() throws Exception {
1045 >        ForkJoinTask a = new CheckedRecursiveAction() {
1046 >            protected void realCompute() throws Exception {
1047                  CCF f = new LCCF(null, 8);
1048                  assertSame(f, f.fork());
1049                  try {
# Line 1088 | Line 1058 | public class ForkJoinPool8Test extends J
1058       * quietlyJoin of a forked task returns when task completes
1059       */
1060      public void testForkQuietlyJoinCC() {
1061 <       ForkJoinTask a =  new CheckedFJTask() {
1062 <            public void realCompute() {
1061 >        ForkJoinTask a = new CheckedRecursiveAction() {
1062 >            protected void realCompute() {
1063                  CCF f = new LCCF(null, 8);
1064                  assertSame(f, f.fork());
1065                  f.quietlyJoin();
# Line 1100 | Line 1070 | public class ForkJoinPool8Test extends J
1070      }
1071  
1072      /**
1103     * helpQuiesce returns when tasks are complete.
1104     * getQueuedTaskCount returns 0 when quiescent
1105     */
1106    public void testForkHelpQuiesceCC() {
1107       ForkJoinTask a =  new CheckedFJTask() {
1108            public void realCompute() {
1109                CCF f = new LCCF(null, 8);
1110                assertSame(f, f.fork());
1111                helpQuiesce();
1112                assertEquals(21, f.number);
1113                assertEquals(0, getQueuedTaskCount());
1114                checkCompletedNormally(f);
1115            }};
1116        checkInvoke(a);
1117    }
1118
1119    /**
1073       * invoke task throws exception when task completes abnormally
1074       */
1075      public void testAbnormalInvokeCC() {
1076 <       ForkJoinTask a =  new CheckedFJTask() {
1077 <            public void realCompute() {
1076 >        ForkJoinTask a = new CheckedRecursiveAction() {
1077 >            protected void realCompute() {
1078                  FailingCCF f = new LFCCF(null, 8);
1079                  try {
1080                      f.invoke();
# Line 1137 | Line 1090 | public class ForkJoinPool8Test extends J
1090       * quietlyInvoke task returns when task completes abnormally
1091       */
1092      public void testAbnormalQuietlyInvokeCC() {
1093 <       ForkJoinTask a =  new CheckedFJTask() {
1094 <            public void realCompute() {
1093 >        ForkJoinTask a = new CheckedRecursiveAction() {
1094 >            protected void realCompute() {
1095                  FailingCCF f = new LFCCF(null, 8);
1096                  f.quietlyInvoke();
1097                  assertTrue(f.getException() instanceof FJException);
# Line 1151 | Line 1104 | public class ForkJoinPool8Test extends J
1104       * join of a forked task throws exception when task completes abnormally
1105       */
1106      public void testAbnormalForkJoinCC() {
1107 <       ForkJoinTask a =  new CheckedFJTask() {
1108 <            public void realCompute() {
1107 >        ForkJoinTask a = new CheckedRecursiveAction() {
1108 >            protected void realCompute() {
1109                  FailingCCF f = new LFCCF(null, 8);
1110                  assertSame(f, f.fork());
1111                  try {
# Line 1169 | Line 1122 | public class ForkJoinPool8Test extends J
1122       * get of a forked task throws exception when task completes abnormally
1123       */
1124      public void testAbnormalForkGetCC() {
1125 <       ForkJoinTask a =  new CheckedFJTask() {
1126 <            public void realCompute() throws Exception {
1125 >        ForkJoinTask a = new CheckedRecursiveAction() {
1126 >            protected void realCompute() throws Exception {
1127                  FailingCCF f = new LFCCF(null, 8);
1128                  assertSame(f, f.fork());
1129                  try {
# Line 1189 | Line 1142 | public class ForkJoinPool8Test extends J
1142       * timed get of a forked task throws exception when task completes abnormally
1143       */
1144      public void testAbnormalForkTimedGetCC() {
1145 <       ForkJoinTask a =  new CheckedFJTask() {
1146 <            public void realCompute() throws Exception {
1145 >        ForkJoinTask a = new CheckedRecursiveAction() {
1146 >            protected void realCompute() throws Exception {
1147                  FailingCCF f = new LFCCF(null, 8);
1148                  assertSame(f, f.fork());
1149                  try {
# Line 1209 | Line 1162 | public class ForkJoinPool8Test extends J
1162       * quietlyJoin of a forked task returns when task completes abnormally
1163       */
1164      public void testAbnormalForkQuietlyJoinCC() {
1165 <       ForkJoinTask a =  new CheckedFJTask() {
1166 <            public void realCompute() {
1165 >        ForkJoinTask a = new CheckedRecursiveAction() {
1166 >            protected void realCompute() {
1167                  FailingCCF f = new LFCCF(null, 8);
1168                  assertSame(f, f.fork());
1169                  f.quietlyJoin();
# Line 1224 | Line 1177 | public class ForkJoinPool8Test extends J
1177       * invoke task throws exception when task cancelled
1178       */
1179      public void testCancelledInvokeCC() {
1180 <       ForkJoinTask a =  new CheckedFJTask() {
1181 <            public void realCompute() {
1180 >        ForkJoinTask a = new CheckedRecursiveAction() {
1181 >            protected void realCompute() {
1182                  CCF f = new LCCF(null, 8);
1183                  assertTrue(f.cancel(true));
1184                  try {
# Line 1242 | Line 1195 | public class ForkJoinPool8Test extends J
1195       * join of a forked task throws exception when task cancelled
1196       */
1197      public void testCancelledForkJoinCC() {
1198 <       ForkJoinTask a =  new CheckedFJTask() {
1199 <            public void realCompute() {
1198 >        ForkJoinTask a = new CheckedRecursiveAction() {
1199 >            protected void realCompute() {
1200                  CCF f = new LCCF(null, 8);
1201                  assertTrue(f.cancel(true));
1202                  assertSame(f, f.fork());
# Line 1261 | Line 1214 | public class ForkJoinPool8Test extends J
1214       * get of a forked task throws exception when task cancelled
1215       */
1216      public void testCancelledForkGetCC() {
1217 <       ForkJoinTask a =  new CheckedFJTask() {
1218 <            public void realCompute() throws Exception {
1217 >        ForkJoinTask a = new CheckedRecursiveAction() {
1218 >            protected void realCompute() throws Exception {
1219                  CCF f = new LCCF(null, 8);
1220                  assertTrue(f.cancel(true));
1221                  assertSame(f, f.fork());
# Line 1280 | Line 1233 | public class ForkJoinPool8Test extends J
1233       * timed get of a forked task throws exception when task cancelled
1234       */
1235      public void testCancelledForkTimedGetCC() throws Exception {
1236 <       ForkJoinTask a =  new CheckedFJTask() {
1237 <            public void realCompute() throws Exception {
1236 >        ForkJoinTask a = new CheckedRecursiveAction() {
1237 >            protected void realCompute() throws Exception {
1238                  CCF f = new LCCF(null, 8);
1239                  assertTrue(f.cancel(true));
1240                  assertSame(f, f.fork());
# Line 1299 | Line 1252 | public class ForkJoinPool8Test extends J
1252       * quietlyJoin of a forked task returns when task cancelled
1253       */
1254      public void testCancelledForkQuietlyJoinCC() {
1255 <       ForkJoinTask a =  new CheckedFJTask() {
1256 <            public void realCompute() {
1255 >        ForkJoinTask a = new CheckedRecursiveAction() {
1256 >            protected void realCompute() {
1257                  CCF f = new LCCF(null, 8);
1258                  assertTrue(f.cancel(true));
1259                  assertSame(f, f.fork());
# Line 1314 | Line 1267 | public class ForkJoinPool8Test extends J
1267       * getPool of non-FJ task returns null
1268       */
1269      public void testGetPool2CC() {
1270 <       ForkJoinTask a =  new CheckedFJTask() {
1271 <            public void realCompute() {
1270 >        ForkJoinTask a = new CheckedRecursiveAction() {
1271 >            protected void realCompute() {
1272                  assertNull(getPool());
1273              }};
1274          assertNull(a.invoke());
# Line 1325 | Line 1278 | public class ForkJoinPool8Test extends J
1278       * inForkJoinPool of non-FJ task returns false
1279       */
1280      public void testInForkJoinPool2CC() {
1281 <       ForkJoinTask a =  new CheckedFJTask() {
1282 <            public void realCompute() {
1281 >        ForkJoinTask a = new CheckedRecursiveAction() {
1282 >            protected void realCompute() {
1283                  assertFalse(inForkJoinPool());
1284              }};
1285          assertNull(a.invoke());
# Line 1336 | Line 1289 | public class ForkJoinPool8Test extends J
1289       * setRawResult(null) succeeds
1290       */
1291      public void testSetRawResultCC() {
1292 <       ForkJoinTask a =  new CheckedFJTask() {
1293 <            public void realCompute() {
1292 >        ForkJoinTask a = new CheckedRecursiveAction() {
1293 >            protected void realCompute() {
1294                  setRawResult(null);
1295                  assertNull(getRawResult());
1296              }};
# Line 1348 | Line 1301 | public class ForkJoinPool8Test extends J
1301       * invoke task throws exception after invoking completeExceptionally
1302       */
1303      public void testCompleteExceptionally2CC() {
1304 <       ForkJoinTask a =  new CheckedFJTask() {
1305 <            public void realCompute() {
1304 >        ForkJoinTask a = new CheckedRecursiveAction() {
1305 >            protected void realCompute() {
1306                  CCF f = new LCCF(null, 8);
1307                  f.completeExceptionally(new FJException());
1308                  try {
# Line 1366 | Line 1319 | public class ForkJoinPool8Test extends J
1319       * invokeAll(t1, t2) invokes all task arguments
1320       */
1321      public void testInvokeAll2CC() {
1322 <       ForkJoinTask a =  new CheckedFJTask() {
1323 <            public void realCompute() {
1322 >        ForkJoinTask a = new CheckedRecursiveAction() {
1323 >            protected void realCompute() {
1324                  CCF f = new LCCF(null, 8);
1325                  CCF g = new LCCF(null, 9);
1326                  invokeAll(f, g);
# Line 1383 | Line 1336 | public class ForkJoinPool8Test extends J
1336       * invokeAll(tasks) with 1 argument invokes task
1337       */
1338      public void testInvokeAll1CC() {
1339 <       ForkJoinTask a =  new CheckedFJTask() {
1340 <            public void realCompute() {
1339 >        ForkJoinTask a = new CheckedRecursiveAction() {
1340 >            protected void realCompute() {
1341                  CCF f = new LCCF(null, 8);
1342                  invokeAll(f);
1343                  checkCompletedNormally(f);
# Line 1397 | Line 1350 | public class ForkJoinPool8Test extends J
1350       * invokeAll(tasks) with > 2 argument invokes tasks
1351       */
1352      public void testInvokeAll3CC() {
1353 <       ForkJoinTask a =  new CheckedFJTask() {
1354 <            public void realCompute() {
1353 >        ForkJoinTask a = new CheckedRecursiveAction() {
1354 >            protected void realCompute() {
1355                  CCF f = new LCCF(null, 8);
1356                  CCF g = new LCCF(null, 9);
1357                  CCF h = new LCCF(null, 7);
# Line 1417 | Line 1370 | public class ForkJoinPool8Test extends J
1370       * invokeAll(collection) invokes all tasks in the collection
1371       */
1372      public void testInvokeAllCollectionCC() {
1373 <       ForkJoinTask a =  new CheckedFJTask() {
1374 <            public void realCompute() {
1373 >        ForkJoinTask a = new CheckedRecursiveAction() {
1374 >            protected void realCompute() {
1375                  CCF f = new LCCF(null, 8);
1376                  CCF g = new LCCF(null, 9);
1377                  CCF h = new LCCF(null, 7);
# Line 1441 | Line 1394 | public class ForkJoinPool8Test extends J
1394       * invokeAll(tasks) with any null task throws NPE
1395       */
1396      public void testInvokeAllNPECC() {
1397 <       ForkJoinTask a =  new CheckedFJTask() {
1398 <            public void realCompute() {
1397 >        ForkJoinTask a = new CheckedRecursiveAction() {
1398 >            protected void realCompute() {
1399                  CCF f = new LCCF(null, 8);
1400                  CCF g = new LCCF(null, 9);
1401                  CCF h = null;
# Line 1458 | Line 1411 | public class ForkJoinPool8Test extends J
1411       * invokeAll(t1, t2) throw exception if any task does
1412       */
1413      public void testAbnormalInvokeAll2CC() {
1414 <       ForkJoinTask a =  new CheckedFJTask() {
1415 <            public void realCompute() {
1414 >        ForkJoinTask a = new CheckedRecursiveAction() {
1415 >            protected void realCompute() {
1416                  CCF f = new LCCF(null, 8);
1417                  FailingCCF g = new LFCCF(null, 9);
1418                  try {
# Line 1476 | Line 1429 | public class ForkJoinPool8Test extends J
1429       * invokeAll(tasks) with 1 argument throws exception if task does
1430       */
1431      public void testAbnormalInvokeAll1CC() {
1432 <       ForkJoinTask a =  new CheckedFJTask() {
1433 <            public void realCompute() {
1432 >        ForkJoinTask a = new CheckedRecursiveAction() {
1433 >            protected void realCompute() {
1434                  FailingCCF g = new LFCCF(null, 9);
1435                  try {
1436                      invokeAll(g);
# Line 1493 | Line 1446 | public class ForkJoinPool8Test extends J
1446       * invokeAll(tasks) with > 2 argument throws exception if any task does
1447       */
1448      public void testAbnormalInvokeAll3CC() {
1449 <       ForkJoinTask a =  new CheckedFJTask() {
1450 <            public void realCompute() {
1449 >        ForkJoinTask a = new CheckedRecursiveAction() {
1450 >            protected void realCompute() {
1451                  CCF f = new LCCF(null, 8);
1452                  FailingCCF g = new LFCCF(null, 9);
1453                  CCF h = new LCCF(null, 7);
# Line 1509 | Line 1462 | public class ForkJoinPool8Test extends J
1462      }
1463  
1464      /**
1465 <     * invokeAll(collection)  throws exception if any task does
1465 >     * invokeAll(collection) throws exception if any task does
1466       */
1467      public void testAbnormalInvokeAllCollectionCC() {
1468 <       ForkJoinTask a =  new CheckedFJTask() {
1469 <            public void realCompute() {
1468 >        ForkJoinTask a = new CheckedRecursiveAction() {
1469 >            protected void realCompute() {
1470                  FailingCCF f = new LFCCF(null, 8);
1471                  CCF g = new LCCF(null, 9);
1472                  CCF h = new LCCF(null, 7);
# Line 1531 | Line 1484 | public class ForkJoinPool8Test extends J
1484          checkInvoke(a);
1485      }
1486  
1487 +    /**
1488 +     * awaitQuiescent by a worker is equivalent in effect to
1489 +     * ForkJoinTask.helpQuiesce()
1490 +     */
1491 +    public void testAwaitQuiescent1() throws Exception {
1492 +        final ForkJoinPool p = new ForkJoinPool();
1493 +        try {
1494 +            final long startTime = System.nanoTime();
1495 +            assertTrue(p.isQuiescent());
1496 +            ForkJoinTask a = new CheckedRecursiveAction() {
1497 +                protected void realCompute() {
1498 +                    FibAction f = new FibAction(8);
1499 +                    assertSame(f, f.fork());
1500 +                    boolean t = ForkJoinTask.getPool().awaitQuiescence(MEDIUM_DELAY_MS, TimeUnit.SECONDS);
1501 +                    assertTrue(t);
1502 +                    while (!f.isDone()) {
1503 +                        if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1504 +                            threadFail("timed out");
1505 +                        assertFalse(p.getAsyncMode());
1506 +                        assertFalse(p.isShutdown());
1507 +                        assertFalse(p.isTerminating());
1508 +                        assertFalse(p.isTerminated());
1509 +                        Thread.yield();
1510 +                    }
1511 +                    assertFalse(p.isQuiescent());
1512 +                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1513 +                    try {
1514 +                        assertEquals(21, f.result);
1515 +                    } catch (Throwable fail) {
1516 +                        threadFail(fail.getMessage());
1517 +                    }
1518 +                }};
1519 +            p.execute(a);
1520 +            while (!a.isDone() || !p.isQuiescent()) {
1521 +                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1522 +                    throw new AssertionFailedError("timed out");
1523 +                assertFalse(p.getAsyncMode());
1524 +                assertFalse(p.isShutdown());
1525 +                assertFalse(p.isTerminating());
1526 +                assertFalse(p.isTerminated());
1527 +                Thread.yield();
1528 +            }
1529 +            assertEquals(0, p.getQueuedTaskCount());
1530 +            assertFalse(p.getAsyncMode());
1531 +            assertEquals(0, p.getActiveThreadCount());
1532 +            assertEquals(0, p.getQueuedTaskCount());
1533 +            assertEquals(0, p.getQueuedSubmissionCount());
1534 +            assertFalse(p.hasQueuedSubmissions());
1535 +            assertFalse(p.isShutdown());
1536 +            assertFalse(p.isTerminating());
1537 +            assertFalse(p.isTerminated());
1538 +        } finally {
1539 +            joinPool(p);
1540 +        }
1541 +    }
1542 +
1543 +    /**
1544 +     * awaitQuiescent returns when pool isQuiescent() or the indicated
1545 +     * timeout elapse
1546 +     */
1547 +    public void testAwaitQuiescent2() throws Exception {
1548 +        final ForkJoinPool p = new ForkJoinPool();
1549 +        try {
1550 +            assertTrue(p.isQuiescent());
1551 +            for (;;) {
1552 +                final long startTime = System.nanoTime();
1553 +                ForkJoinTask a = new CheckedRecursiveAction() {
1554 +                        protected void realCompute() {
1555 +                            FibAction f = new FibAction(8);
1556 +                            assertSame(f, f.fork());
1557 +                            ForkJoinTask.helpQuiesce();
1558 +                            while (!f.isDone()) {
1559 +                                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1560 +                                    threadFail("timed out");
1561 +                                assertFalse(p.getAsyncMode());
1562 +                                assertFalse(p.isShutdown());
1563 +                                assertFalse(p.isTerminating());
1564 +                                assertFalse(p.isTerminated());
1565 +                                Thread.yield();
1566 +                            }
1567 +                            assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1568 +                            try {
1569 +                                assertEquals(21, f.result);
1570 +                            } catch (Throwable fail) { System.out.println("fail " + fail.getMessage()); }
1571 +                        }
1572 +                    };
1573 +                p.execute(a);
1574 +                if (a.isDone() || p.isQuiescent())
1575 +                    continue; // Already done so cannot test; retry
1576 +                while (!p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) {
1577 +                    if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1578 +                        threadFail("timed out");
1579 +                    assertFalse(p.getAsyncMode());
1580 +                    assertFalse(p.isShutdown());
1581 +                    assertFalse(p.isTerminating());
1582 +                    assertFalse(p.isTerminated());
1583 +                    Thread.yield();
1584 +                }
1585 +                assertTrue(p.isQuiescent());
1586 +                assertTrue(a.isDone());
1587 +                assertEquals(0, p.getQueuedTaskCount());
1588 +                assertFalse(p.getAsyncMode());
1589 +                assertEquals(0, p.getActiveThreadCount());
1590 +                assertEquals(0, p.getQueuedTaskCount());
1591 +                assertEquals(0, p.getQueuedSubmissionCount());
1592 +                assertFalse(p.hasQueuedSubmissions());
1593 +                assertFalse(p.isShutdown());
1594 +                assertFalse(p.isTerminating());
1595 +                assertFalse(p.isTerminated());
1596 +                break;
1597 +            }
1598 +        } finally {
1599 +            joinPool(p);
1600 +        }
1601 +    }
1602 +
1603   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines