jdk/test/java/util/concurrent/tck/RecursiveActionTest.java
author dl
Wed, 09 Aug 2017 17:40:38 -0700
changeset 46146 b3e220a04d3f
parent 45937 646816090183
permissions -rw-r--r--
8185099: Miscellaneous changes imported from jsr166 CVS 2017-08 Reviewed-by: martin, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     1
/*
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     3
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     6
 * published by the Free Software Foundation.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     7
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    12
 * accompanied this code).
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    13
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    17
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    20
 * questions.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    21
 */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    22
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    23
/*
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    24
 * This file is available under and governed by the GNU General Public
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    25
 * License version 2 only, as published by the Free Software Foundation.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    26
 * However, the following notice accompanied the original version of this
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    27
 * file:
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    28
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    29
 * Written by Doug Lea with assistance from members of JCP JSR-166
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    30
 * Expert Group and released to the public domain, as explained at
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    31
 * http://creativecommons.org/publicdomain/zero/1.0/
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    32
 */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    33
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 44589
diff changeset
    34
import static java.util.concurrent.TimeUnit.MILLISECONDS;
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    35
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    36
import java.util.Arrays;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    37
import java.util.HashSet;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    38
import java.util.concurrent.CancellationException;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    39
import java.util.concurrent.ExecutionException;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    40
import java.util.concurrent.ForkJoinPool;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    41
import java.util.concurrent.ForkJoinTask;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    42
import java.util.concurrent.ForkJoinWorkerThread;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    43
import java.util.concurrent.RecursiveAction;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    44
import java.util.concurrent.SynchronousQueue;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    45
import java.util.concurrent.ThreadLocalRandom;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    46
import java.util.concurrent.TimeoutException;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    47
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    48
import junit.framework.Test;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    49
import junit.framework.TestSuite;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    50
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    51
public class RecursiveActionTest extends JSR166TestCase {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    52
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    53
    public static void main(String[] args) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    54
        main(suite(), args);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    55
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    56
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    57
    public static Test suite() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    58
        return new TestSuite(RecursiveActionTest.class);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    59
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    60
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    61
    private static ForkJoinPool mainPool() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    62
        return new ForkJoinPool();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    63
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    64
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    65
    private static ForkJoinPool singletonPool() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    66
        return new ForkJoinPool(1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    67
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    68
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    69
    private static ForkJoinPool asyncSingletonPool() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    70
        return new ForkJoinPool(1,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    71
                                ForkJoinPool.defaultForkJoinWorkerThreadFactory,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    72
                                null, true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    73
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    74
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    75
    private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    76
        try (PoolCleaner cleaner = cleaner(pool)) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    77
            checkNotDone(a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    78
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    79
            assertNull(pool.invoke(a));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    80
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    81
            checkCompletedNormally(a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    82
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    83
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    84
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    85
    void checkNotDone(RecursiveAction a) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    86
        assertFalse(a.isDone());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    87
        assertFalse(a.isCompletedNormally());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    88
        assertFalse(a.isCompletedAbnormally());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    89
        assertFalse(a.isCancelled());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    90
        assertNull(a.getException());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    91
        assertNull(a.getRawResult());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    92
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    93
        if (! ForkJoinTask.inForkJoinPool()) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    94
            Thread.currentThread().interrupt();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    95
            try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    96
                a.get();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    97
                shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    98
            } catch (InterruptedException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    99
            } catch (Throwable fail) { threadUnexpectedException(fail); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   100
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   101
            Thread.currentThread().interrupt();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   102
            try {
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 44589
diff changeset
   103
                a.get(randomTimeout(), randomTimeUnit());
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   104
                shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   105
            } catch (InterruptedException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   106
            } catch (Throwable fail) { threadUnexpectedException(fail); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   107
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   108
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   109
        try {
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 44589
diff changeset
   110
            a.get(randomExpiredTimeout(), randomTimeUnit());
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   111
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   112
        } catch (TimeoutException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   113
        } catch (Throwable fail) { threadUnexpectedException(fail); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   114
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   115
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   116
    void checkCompletedNormally(RecursiveAction a) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   117
        assertTrue(a.isDone());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   118
        assertFalse(a.isCancelled());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   119
        assertTrue(a.isCompletedNormally());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   120
        assertFalse(a.isCompletedAbnormally());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   121
        assertNull(a.getException());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   122
        assertNull(a.getRawResult());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   123
        assertNull(a.join());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   124
        assertFalse(a.cancel(false));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   125
        assertFalse(a.cancel(true));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   126
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   127
            assertNull(a.get());
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 44589
diff changeset
   128
            assertNull(a.get(randomTimeout(), randomTimeUnit()));
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   129
        } catch (Throwable fail) { threadUnexpectedException(fail); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   130
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   131
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   132
    void checkCancelled(RecursiveAction a) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   133
        assertTrue(a.isDone());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   134
        assertTrue(a.isCancelled());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   135
        assertFalse(a.isCompletedNormally());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   136
        assertTrue(a.isCompletedAbnormally());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   137
        assertTrue(a.getException() instanceof CancellationException);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   138
        assertNull(a.getRawResult());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   139
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   140
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   141
            a.join();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   142
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   143
        } catch (CancellationException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   144
        } catch (Throwable fail) { threadUnexpectedException(fail); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   145
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   146
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   147
            a.get();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   148
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   149
        } catch (CancellationException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   150
        } catch (Throwable fail) { threadUnexpectedException(fail); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   151
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   152
        try {
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 44589
diff changeset
   153
            a.get(randomTimeout(), randomTimeUnit());
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   154
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   155
        } catch (CancellationException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   156
        } catch (Throwable fail) { threadUnexpectedException(fail); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   157
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   158
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   159
    void checkCompletedAbnormally(RecursiveAction a, Throwable t) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   160
        assertTrue(a.isDone());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   161
        assertFalse(a.isCancelled());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   162
        assertFalse(a.isCompletedNormally());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   163
        assertTrue(a.isCompletedAbnormally());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   164
        assertSame(t.getClass(), a.getException().getClass());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   165
        assertNull(a.getRawResult());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   166
        assertFalse(a.cancel(false));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   167
        assertFalse(a.cancel(true));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   168
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   169
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   170
            a.join();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   171
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   172
        } catch (Throwable expected) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   173
            assertSame(expected.getClass(), t.getClass());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   174
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   175
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   176
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   177
            a.get();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   178
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   179
        } catch (ExecutionException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   180
            assertSame(t.getClass(), success.getCause().getClass());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   181
        } catch (Throwable fail) { threadUnexpectedException(fail); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   182
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   183
        try {
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 44589
diff changeset
   184
            a.get(randomTimeout(), randomTimeUnit());
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   185
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   186
        } catch (ExecutionException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   187
            assertSame(t.getClass(), success.getCause().getClass());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   188
        } catch (Throwable fail) { threadUnexpectedException(fail); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   189
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   190
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   191
    public static final class FJException extends RuntimeException {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   192
        public FJException() { super(); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   193
        public FJException(Throwable cause) { super(cause); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   194
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   195
44589
64d9270bd24c 8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents: 40817
diff changeset
   196
    /** A simple recursive action for testing. */
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   197
    final class FibAction extends CheckedRecursiveAction {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   198
        final int number;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   199
        int result;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   200
        FibAction(int n) { number = n; }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   201
        protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   202
            int n = number;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   203
            if (n <= 1)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   204
                result = n;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   205
            else {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   206
                FibAction f1 = new FibAction(n - 1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   207
                FibAction f2 = new FibAction(n - 2);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   208
                invokeAll(f1, f2);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   209
                result = f1.result + f2.result;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   210
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   211
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   212
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   213
44589
64d9270bd24c 8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents: 40817
diff changeset
   214
    /** A recursive action failing in base case. */
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   215
    static final class FailingFibAction extends RecursiveAction {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   216
        final int number;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   217
        int result;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   218
        FailingFibAction(int n) { number = n; }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   219
        public void compute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   220
            int n = number;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   221
            if (n <= 1)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   222
                throw new FJException();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   223
            else {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   224
                FailingFibAction f1 = new FailingFibAction(n - 1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   225
                FailingFibAction f2 = new FailingFibAction(n - 2);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   226
                invokeAll(f1, f2);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   227
                result = f1.result + f2.result;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   228
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   229
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   230
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   231
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   232
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   233
     * invoke returns when task completes normally.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   234
     * isCompletedAbnormally and isCancelled return false for normally
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   235
     * completed tasks. getRawResult of a RecursiveAction returns null;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   236
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   237
    public void testInvoke() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   238
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   239
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   240
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   241
                assertNull(f.invoke());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   242
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   243
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   244
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   245
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   246
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   247
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   248
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   249
     * quietlyInvoke task returns when task completes normally.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   250
     * isCompletedAbnormally and isCancelled return false for normally
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   251
     * completed tasks
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   252
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   253
    public void testQuietlyInvoke() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   254
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   255
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   256
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   257
                f.quietlyInvoke();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   258
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   259
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   260
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   261
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   262
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   263
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   264
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   265
     * join of a forked task returns when task completes
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   266
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   267
    public void testForkJoin() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   268
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   269
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   270
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   271
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   272
                assertNull(f.join());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   273
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   274
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   275
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   276
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   277
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   278
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   279
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   280
     * join/quietlyJoin of a forked task succeeds in the presence of interrupts
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   281
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   282
    public void testJoinIgnoresInterrupts() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   283
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   284
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   285
                FibAction f = new FibAction(8);
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   286
                final Thread currentThread = Thread.currentThread();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   287
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   288
                // test join()
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   289
                assertSame(f, f.fork());
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   290
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   291
                assertNull(f.join());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   292
                Thread.interrupted();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   293
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   294
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   295
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   296
                f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   297
                f.cancel(true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   298
                assertSame(f, f.fork());
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   299
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   300
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   301
                    f.join();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   302
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   303
                } catch (CancellationException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   304
                    Thread.interrupted();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   305
                    checkCancelled(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   306
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   307
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   308
                f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   309
                f.completeExceptionally(new FJException());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   310
                assertSame(f, f.fork());
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   311
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   312
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   313
                    f.join();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   314
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   315
                } catch (FJException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   316
                    Thread.interrupted();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   317
                    checkCompletedAbnormally(f, success);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   318
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   319
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   320
                // test quietlyJoin()
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   321
                f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   322
                assertSame(f, f.fork());
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   323
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   324
                f.quietlyJoin();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   325
                Thread.interrupted();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   326
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   327
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   328
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   329
                f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   330
                f.cancel(true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   331
                assertSame(f, f.fork());
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   332
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   333
                f.quietlyJoin();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   334
                Thread.interrupted();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   335
                checkCancelled(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   336
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   337
                f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   338
                f.completeExceptionally(new FJException());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   339
                assertSame(f, f.fork());
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   340
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   341
                f.quietlyJoin();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   342
                Thread.interrupted();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   343
                checkCompletedAbnormally(f, f.getException());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   344
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   345
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   346
        a.reinitialize();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   347
        testInvokeOnPool(singletonPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   348
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   349
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   350
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   351
     * join/quietlyJoin of a forked task when not in ForkJoinPool
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   352
     * succeeds in the presence of interrupts
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   353
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   354
    public void testJoinIgnoresInterruptsOutsideForkJoinPool() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   355
        final SynchronousQueue<FibAction[]> sq =
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   356
            new SynchronousQueue<FibAction[]>();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   357
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   358
            protected void realCompute() throws InterruptedException {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   359
                FibAction[] fibActions = new FibAction[6];
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   360
                for (int i = 0; i < fibActions.length; i++)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   361
                    fibActions[i] = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   362
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   363
                fibActions[1].cancel(false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   364
                fibActions[2].completeExceptionally(new FJException());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   365
                fibActions[4].cancel(true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   366
                fibActions[5].completeExceptionally(new FJException());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   367
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   368
                for (int i = 0; i < fibActions.length; i++)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   369
                    fibActions[i].fork();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   370
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   371
                sq.put(fibActions);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   372
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   373
                helpQuiesce();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   374
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   375
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   376
        Runnable r = new CheckedRunnable() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   377
            public void realRun() throws InterruptedException {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   378
                FibAction[] fibActions = sq.take();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   379
                FibAction f;
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   380
                final Thread currentThread = Thread.currentThread();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   381
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   382
                // test join() ------------
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   383
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   384
                f = fibActions[0];
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   385
                assertFalse(ForkJoinTask.inForkJoinPool());
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   386
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   387
                assertNull(f.join());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   388
                assertTrue(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   389
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   390
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   391
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   392
                f = fibActions[1];
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   393
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   394
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   395
                    f.join();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   396
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   397
                } catch (CancellationException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   398
                    assertTrue(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   399
                    checkCancelled(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   400
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   401
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   402
                f = fibActions[2];
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   403
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   404
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   405
                    f.join();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   406
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   407
                } catch (FJException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   408
                    assertTrue(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   409
                    checkCompletedAbnormally(f, success);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   410
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   411
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   412
                // test quietlyJoin() ---------
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   413
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   414
                f = fibActions[3];
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   415
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   416
                f.quietlyJoin();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   417
                assertTrue(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   418
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   419
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   420
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   421
                f = fibActions[4];
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   422
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   423
                f.quietlyJoin();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   424
                assertTrue(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   425
                checkCancelled(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   426
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   427
                f = fibActions[5];
40817
4f5fb115676d 8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents: 35394
diff changeset
   428
                currentThread.interrupt();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   429
                f.quietlyJoin();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   430
                assertTrue(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   431
                assertTrue(f.getException() instanceof FJException);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   432
                checkCompletedAbnormally(f, f.getException());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   433
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   434
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   435
        Thread t;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   436
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   437
        t = newStartedThread(r);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   438
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   439
        awaitTermination(t);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   440
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   441
        a.reinitialize();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   442
        t = newStartedThread(r);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   443
        testInvokeOnPool(singletonPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   444
        awaitTermination(t);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   445
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   446
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   447
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   448
     * get of a forked task returns when task completes
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   449
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   450
    public void testForkGet() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   451
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   452
            protected void realCompute() throws Exception {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   453
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   454
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   455
                assertNull(f.get());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   456
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   457
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   458
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   459
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   460
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   461
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   462
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   463
     * timed get of a forked task returns when task completes
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   464
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   465
    public void testForkTimedGet() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   466
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   467
            protected void realCompute() throws Exception {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   468
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   469
                assertSame(f, f.fork());
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 44589
diff changeset
   470
                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   471
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   472
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   473
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   474
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   475
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   476
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   477
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   478
     * timed get with null time unit throws NPE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   479
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   480
    public void testForkTimedGetNPE() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   481
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   482
            protected void realCompute() throws Exception {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   483
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   484
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   485
                try {
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 44589
diff changeset
   486
                    f.get(randomTimeout(), null);
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   487
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   488
                } catch (NullPointerException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   489
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   490
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   491
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   492
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   493
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   494
     * quietlyJoin of a forked task returns when task completes
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   495
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   496
    public void testForkQuietlyJoin() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   497
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   498
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   499
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   500
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   501
                f.quietlyJoin();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   502
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   503
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   504
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   505
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   506
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   507
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   508
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   509
     * helpQuiesce returns when tasks are complete.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   510
     * getQueuedTaskCount returns 0 when quiescent
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   511
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   512
    public void testForkHelpQuiesce() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   513
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   514
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   515
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   516
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   517
                helpQuiesce();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   518
                while (!f.isDone()) // wait out race
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   519
                    ;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   520
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   521
                assertEquals(0, getQueuedTaskCount());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   522
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   523
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   524
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   525
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   526
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   527
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   528
     * invoke task throws exception when task completes abnormally
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   529
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   530
    public void testAbnormalInvoke() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   531
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   532
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   533
                FailingFibAction f = new FailingFibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   534
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   535
                    f.invoke();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   536
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   537
                } catch (FJException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   538
                    checkCompletedAbnormally(f, success);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   539
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   540
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   541
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   542
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   543
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   544
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   545
     * quietlyInvoke task returns when task completes abnormally
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   546
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   547
    public void testAbnormalQuietlyInvoke() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   548
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   549
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   550
                FailingFibAction f = new FailingFibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   551
                f.quietlyInvoke();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   552
                assertTrue(f.getException() instanceof FJException);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   553
                checkCompletedAbnormally(f, f.getException());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   554
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   555
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   556
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   557
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   558
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   559
     * join of a forked task throws exception when task completes abnormally
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   560
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   561
    public void testAbnormalForkJoin() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   562
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   563
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   564
                FailingFibAction f = new FailingFibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   565
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   566
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   567
                    f.join();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   568
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   569
                } catch (FJException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   570
                    checkCompletedAbnormally(f, success);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   571
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   572
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   573
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   574
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   575
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   576
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   577
     * get of a forked task throws exception when task completes abnormally
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   578
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   579
    public void testAbnormalForkGet() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   580
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   581
            protected void realCompute() throws Exception {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   582
                FailingFibAction f = new FailingFibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   583
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   584
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   585
                    f.get();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   586
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   587
                } catch (ExecutionException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   588
                    Throwable cause = success.getCause();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   589
                    assertTrue(cause instanceof FJException);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   590
                    checkCompletedAbnormally(f, cause);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   591
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   592
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   593
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   594
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   595
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   596
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   597
     * timed get of a forked task throws exception when task completes abnormally
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   598
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   599
    public void testAbnormalForkTimedGet() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   600
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   601
            protected void realCompute() throws Exception {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   602
                FailingFibAction f = new FailingFibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   603
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   604
                try {
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 44589
diff changeset
   605
                    f.get(LONG_DELAY_MS, MILLISECONDS);
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   606
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   607
                } catch (ExecutionException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   608
                    Throwable cause = success.getCause();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   609
                    assertTrue(cause instanceof FJException);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   610
                    checkCompletedAbnormally(f, cause);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   611
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   612
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   613
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   614
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   615
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   616
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   617
     * quietlyJoin of a forked task returns when task completes abnormally
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   618
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   619
    public void testAbnormalForkQuietlyJoin() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   620
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   621
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   622
                FailingFibAction f = new FailingFibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   623
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   624
                f.quietlyJoin();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   625
                assertTrue(f.getException() instanceof FJException);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   626
                checkCompletedAbnormally(f, f.getException());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   627
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   628
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   629
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   630
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   631
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   632
     * invoke task throws exception when task cancelled
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   633
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   634
    public void testCancelledInvoke() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   635
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   636
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   637
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   638
                assertTrue(f.cancel(true));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   639
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   640
                    f.invoke();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   641
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   642
                } catch (CancellationException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   643
                    checkCancelled(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   644
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   645
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   646
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   647
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   648
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   649
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   650
     * join of a forked task throws exception when task cancelled
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   651
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   652
    public void testCancelledForkJoin() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   653
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   654
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   655
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   656
                assertTrue(f.cancel(true));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   657
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   658
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   659
                    f.join();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   660
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   661
                } catch (CancellationException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   662
                    checkCancelled(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   663
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   664
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   665
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   666
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   667
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   668
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   669
     * get of a forked task throws exception when task cancelled
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   670
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   671
    public void testCancelledForkGet() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   672
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   673
            protected void realCompute() throws Exception {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   674
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   675
                assertTrue(f.cancel(true));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   676
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   677
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   678
                    f.get();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   679
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   680
                } catch (CancellationException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   681
                    checkCancelled(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   682
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   683
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   684
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   685
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   686
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   687
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   688
     * timed get of a forked task throws exception when task cancelled
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   689
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   690
    public void testCancelledForkTimedGet() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   691
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   692
            protected void realCompute() throws Exception {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   693
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   694
                assertTrue(f.cancel(true));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   695
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   696
                try {
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 44589
diff changeset
   697
                    f.get(LONG_DELAY_MS, MILLISECONDS);
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   698
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   699
                } catch (CancellationException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   700
                    checkCancelled(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   701
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   702
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   703
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   704
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   705
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   706
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   707
     * quietlyJoin of a forked task returns when task cancelled
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   708
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   709
    public void testCancelledForkQuietlyJoin() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   710
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   711
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   712
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   713
                assertTrue(f.cancel(true));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   714
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   715
                f.quietlyJoin();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   716
                checkCancelled(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   717
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   718
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   719
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   720
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   721
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   722
     * getPool of executing task returns its pool
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   723
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   724
    public void testGetPool() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   725
        final ForkJoinPool mainPool = mainPool();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   726
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   727
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   728
                assertSame(mainPool, getPool());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   729
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   730
        testInvokeOnPool(mainPool, a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   731
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   732
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   733
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   734
     * getPool of non-FJ task returns null
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   735
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   736
    public void testGetPool2() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   737
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   738
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   739
                assertNull(getPool());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   740
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   741
        assertNull(a.invoke());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   742
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   743
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   744
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   745
     * inForkJoinPool of executing task returns true
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   746
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   747
    public void testInForkJoinPool() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   748
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   749
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   750
                assertTrue(inForkJoinPool());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   751
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   752
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   753
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   754
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   755
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   756
     * inForkJoinPool of non-FJ task returns false
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   757
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   758
    public void testInForkJoinPool2() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   759
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   760
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   761
                assertFalse(inForkJoinPool());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   762
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   763
        assertNull(a.invoke());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   764
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   765
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   766
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   767
     * getPool of current thread in pool returns its pool
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   768
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   769
    public void testWorkerGetPool() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   770
        final ForkJoinPool mainPool = mainPool();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   771
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   772
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   773
                ForkJoinWorkerThread w =
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   774
                    (ForkJoinWorkerThread) Thread.currentThread();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   775
                assertSame(mainPool, w.getPool());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   776
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   777
        testInvokeOnPool(mainPool, a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   778
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   779
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   780
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   781
     * getPoolIndex of current thread in pool returns 0 <= value < poolSize
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   782
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   783
    public void testWorkerGetPoolIndex() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   784
        final ForkJoinPool mainPool = mainPool();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   785
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   786
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   787
                ForkJoinWorkerThread w =
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   788
                    (ForkJoinWorkerThread) Thread.currentThread();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   789
                assertTrue(w.getPoolIndex() >= 0);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   790
                // pool size can shrink after assigning index, so cannot check
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   791
                // assertTrue(w.getPoolIndex() < mainPool.getPoolSize());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   792
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   793
        testInvokeOnPool(mainPool, a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   794
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   795
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   796
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   797
     * setRawResult(null) succeeds
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   798
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   799
    public void testSetRawResult() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   800
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   801
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   802
                setRawResult(null);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   803
                assertNull(getRawResult());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   804
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   805
        assertNull(a.invoke());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   806
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   807
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   808
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   809
     * A reinitialized normally completed task may be re-invoked
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   810
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   811
    public void testReinitialize() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   812
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   813
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   814
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   815
                checkNotDone(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   816
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   817
                for (int i = 0; i < 3; i++) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   818
                    assertNull(f.invoke());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   819
                    assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   820
                    checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   821
                    f.reinitialize();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   822
                    checkNotDone(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   823
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   824
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   825
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   826
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   827
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   828
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   829
     * A reinitialized abnormally completed task may be re-invoked
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   830
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   831
    public void testReinitializeAbnormal() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   832
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   833
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   834
                FailingFibAction f = new FailingFibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   835
                checkNotDone(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   836
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   837
                for (int i = 0; i < 3; i++) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   838
                    try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   839
                        f.invoke();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   840
                        shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   841
                    } catch (FJException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   842
                        checkCompletedAbnormally(f, success);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   843
                    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   844
                    f.reinitialize();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   845
                    checkNotDone(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   846
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   847
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   848
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   849
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   850
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   851
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   852
     * invoke task throws exception after invoking completeExceptionally
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   853
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   854
    public void testCompleteExceptionally() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   855
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   856
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   857
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   858
                f.completeExceptionally(new FJException());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   859
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   860
                    f.invoke();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   861
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   862
                } catch (FJException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   863
                    checkCompletedAbnormally(f, success);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   864
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   865
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   866
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   867
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   868
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   869
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   870
     * invoke task suppresses execution invoking complete
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   871
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   872
    public void testComplete() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   873
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   874
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   875
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   876
                f.complete(null);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   877
                assertNull(f.invoke());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   878
                assertEquals(0, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   879
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   880
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   881
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   882
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   883
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   884
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   885
     * invokeAll(t1, t2) invokes all task arguments
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   886
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   887
    public void testInvokeAll2() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   888
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   889
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   890
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   891
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   892
                invokeAll(f, g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   893
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   894
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   895
                checkCompletedNormally(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   896
                assertEquals(34, g.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   897
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   898
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   899
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   900
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   901
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   902
     * invokeAll(tasks) with 1 argument invokes task
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   903
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   904
    public void testInvokeAll1() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   905
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   906
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   907
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   908
                invokeAll(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   909
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   910
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   911
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   912
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   913
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   914
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   915
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   916
     * invokeAll(tasks) with > 2 argument invokes tasks
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   917
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   918
    public void testInvokeAll3() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   919
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   920
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   921
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   922
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   923
                FibAction h = new FibAction(7);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   924
                invokeAll(f, g, h);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   925
                assertTrue(f.isDone());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   926
                assertTrue(g.isDone());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   927
                assertTrue(h.isDone());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   928
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   929
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   930
                checkCompletedNormally(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   931
                assertEquals(34, g.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   932
                checkCompletedNormally(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   933
                assertEquals(13, h.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   934
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   935
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   936
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   937
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   938
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   939
     * invokeAll(collection) invokes all tasks in the collection
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   940
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   941
    public void testInvokeAllCollection() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   942
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   943
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   944
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   945
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   946
                FibAction h = new FibAction(7);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   947
                HashSet set = new HashSet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   948
                set.add(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   949
                set.add(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   950
                set.add(h);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   951
                invokeAll(set);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   952
                assertTrue(f.isDone());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   953
                assertTrue(g.isDone());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   954
                assertTrue(h.isDone());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   955
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   956
                assertEquals(21, f.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   957
                checkCompletedNormally(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   958
                assertEquals(34, g.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   959
                checkCompletedNormally(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   960
                assertEquals(13, h.result);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   961
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   962
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   963
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   964
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   965
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   966
     * invokeAll(tasks) with any null task throws NPE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   967
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   968
    public void testInvokeAllNPE() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   969
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   970
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   971
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   972
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   973
                FibAction h = null;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   974
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   975
                    invokeAll(f, g, h);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   976
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   977
                } catch (NullPointerException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   978
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   979
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   980
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   981
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   982
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   983
     * invokeAll(t1, t2) throw exception if any task does
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   984
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   985
    public void testAbnormalInvokeAll2() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   986
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   987
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   988
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   989
                FailingFibAction g = new FailingFibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   990
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   991
                    invokeAll(f, g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   992
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   993
                } catch (FJException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   994
                    checkCompletedAbnormally(g, success);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   995
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   996
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   997
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   998
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   999
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1000
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1001
     * invokeAll(tasks) with 1 argument throws exception if task does
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1002
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1003
    public void testAbnormalInvokeAll1() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1004
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1005
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1006
                FailingFibAction g = new FailingFibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1007
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1008
                    invokeAll(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1009
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1010
                } catch (FJException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1011
                    checkCompletedAbnormally(g, success);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1012
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1013
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1014
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1015
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1016
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1017
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1018
     * invokeAll(tasks) with > 2 argument throws exception if any task does
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1019
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1020
    public void testAbnormalInvokeAll3() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1021
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1022
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1023
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1024
                FailingFibAction g = new FailingFibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1025
                FibAction h = new FibAction(7);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1026
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1027
                    invokeAll(f, g, h);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1028
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1029
                } catch (FJException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1030
                    checkCompletedAbnormally(g, success);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1031
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1032
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1033
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1034
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1035
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1036
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1037
     * invokeAll(collection) throws exception if any task does
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1038
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1039
    public void testAbnormalInvokeAllCollection() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1040
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1041
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1042
                FailingFibAction f = new FailingFibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1043
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1044
                FibAction h = new FibAction(7);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1045
                HashSet set = new HashSet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1046
                set.add(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1047
                set.add(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1048
                set.add(h);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1049
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1050
                    invokeAll(set);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1051
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1052
                } catch (FJException success) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1053
                    checkCompletedAbnormally(f, success);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1054
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1055
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1056
        testInvokeOnPool(mainPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1057
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1058
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1059
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1060
     * tryUnfork returns true for most recent unexecuted task,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1061
     * and suppresses execution
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1062
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1063
    public void testTryUnfork() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1064
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1065
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1066
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1067
                assertSame(g, g.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1068
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1069
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1070
                assertTrue(f.tryUnfork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1071
                helpQuiesce();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1072
                checkNotDone(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1073
                checkCompletedNormally(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1074
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1075
        testInvokeOnPool(singletonPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1076
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1077
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1078
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1079
     * getSurplusQueuedTaskCount returns > 0 when
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1080
     * there are more tasks than threads
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1081
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1082
    public void testGetSurplusQueuedTaskCount() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1083
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1084
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1085
                FibAction h = new FibAction(7);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1086
                assertSame(h, h.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1087
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1088
                assertSame(g, g.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1089
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1090
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1091
                assertTrue(getSurplusQueuedTaskCount() > 0);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1092
                helpQuiesce();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1093
                assertEquals(0, getSurplusQueuedTaskCount());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1094
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1095
                checkCompletedNormally(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1096
                checkCompletedNormally(h);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1097
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1098
        testInvokeOnPool(singletonPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1099
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1100
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1101
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1102
     * peekNextLocalTask returns most recent unexecuted task.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1103
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1104
    public void testPeekNextLocalTask() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1105
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1106
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1107
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1108
                assertSame(g, g.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1109
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1110
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1111
                assertSame(f, peekNextLocalTask());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1112
                assertNull(f.join());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1113
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1114
                helpQuiesce();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1115
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1116
                checkCompletedNormally(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1117
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1118
        testInvokeOnPool(singletonPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1119
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1120
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1121
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1122
     * pollNextLocalTask returns most recent unexecuted task
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1123
     * without executing it
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1124
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1125
    public void testPollNextLocalTask() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1126
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1127
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1128
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1129
                assertSame(g, g.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1130
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1131
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1132
                assertSame(f, pollNextLocalTask());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1133
                helpQuiesce();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1134
                checkNotDone(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1135
                checkCompletedNormally(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1136
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1137
        testInvokeOnPool(singletonPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1138
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1139
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1140
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1141
     * pollTask returns an unexecuted task without executing it
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1142
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1143
    public void testPollTask() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1144
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1145
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1146
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1147
                assertSame(g, g.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1148
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1149
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1150
                assertSame(f, pollTask());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1151
                helpQuiesce();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1152
                checkNotDone(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1153
                checkCompletedNormally(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1154
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1155
        testInvokeOnPool(singletonPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1156
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1157
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1158
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1159
     * peekNextLocalTask returns least recent unexecuted task in async mode
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1160
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1161
    public void testPeekNextLocalTaskAsync() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1162
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1163
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1164
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1165
                assertSame(g, g.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1166
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1167
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1168
                assertSame(g, peekNextLocalTask());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1169
                assertNull(f.join());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1170
                helpQuiesce();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1171
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1172
                checkCompletedNormally(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1173
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1174
        testInvokeOnPool(asyncSingletonPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1175
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1176
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1177
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1178
     * pollNextLocalTask returns least recent unexecuted task without
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1179
     * executing it, in async mode
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1180
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1181
    public void testPollNextLocalTaskAsync() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1182
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1183
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1184
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1185
                assertSame(g, g.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1186
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1187
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1188
                assertSame(g, pollNextLocalTask());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1189
                helpQuiesce();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1190
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1191
                checkNotDone(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1192
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1193
        testInvokeOnPool(asyncSingletonPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1194
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1195
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1196
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1197
     * pollTask returns an unexecuted task without executing it, in
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1198
     * async mode
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1199
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1200
    public void testPollTaskAsync() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1201
        RecursiveAction a = new CheckedRecursiveAction() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1202
            protected void realCompute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1203
                FibAction g = new FibAction(9);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1204
                assertSame(g, g.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1205
                FibAction f = new FibAction(8);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1206
                assertSame(f, f.fork());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1207
                assertSame(g, pollTask());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1208
                helpQuiesce();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1209
                checkCompletedNormally(f);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1210
                checkNotDone(g);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1211
            }};
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1212
        testInvokeOnPool(asyncSingletonPool(), a);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1213
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1214
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1215
    /** Demo from RecursiveAction javadoc */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1216
    static class SortTask extends RecursiveAction {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1217
        final long[] array; final int lo, hi;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1218
        SortTask(long[] array, int lo, int hi) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1219
            this.array = array; this.lo = lo; this.hi = hi;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1220
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1221
        SortTask(long[] array) { this(array, 0, array.length); }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1222
        protected void compute() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1223
            if (hi - lo < THRESHOLD)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1224
                sortSequentially(lo, hi);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1225
            else {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1226
                int mid = (lo + hi) >>> 1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1227
                invokeAll(new SortTask(array, lo, mid),
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1228
                          new SortTask(array, mid, hi));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1229
                merge(lo, mid, hi);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1230
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1231
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1232
        // implementation details follow:
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1233
        static final int THRESHOLD = 100;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1234
        void sortSequentially(int lo, int hi) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1235
            Arrays.sort(array, lo, hi);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1236
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1237
        void merge(int lo, int mid, int hi) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1238
            long[] buf = Arrays.copyOfRange(array, lo, mid);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1239
            for (int i = 0, j = lo, k = mid; i < buf.length; j++)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1240
                array[j] = (k == hi || buf[i] < array[k]) ?
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1241
                    buf[i++] : array[k++];
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1242
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1243
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1244
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1245
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1246
     * SortTask demo works as advertised
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1247
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1248
    public void testSortTaskDemo() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1249
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1250
        long[] array = new long[1007];
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1251
        for (int i = 0; i < array.length; i++)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1252
            array[i] = rnd.nextLong();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1253
        long[] arrayClone = array.clone();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1254
        testInvokeOnPool(mainPool(), new SortTask(array));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1255
        Arrays.sort(arrayClone);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1256
        assertTrue(Arrays.equals(array, arrayClone));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1257
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1258
}