author | dl |
Mon, 10 Apr 2017 13:46:19 -0700 | |
changeset 44589 | 64d9270bd24c |
parent 44039 | 058585425bb7 |
child 45936 | d564ef4bed8f |
permissions | -rw-r--r-- |
35394 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
6 |
* published by the Free Software Foundation. |
|
7 |
* |
|
8 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
9 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
10 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
11 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
12 |
* accompanied this code). |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License version |
|
15 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
16 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17 |
* |
|
18 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
19 |
* or visit www.oracle.com if you need additional information or have any |
|
20 |
* questions. |
|
21 |
*/ |
|
22 |
||
23 |
/* |
|
24 |
* This file is available under and governed by the GNU General Public |
|
25 |
* License version 2 only, as published by the Free Software Foundation. |
|
26 |
* However, the following notice accompanied the original version of this |
|
27 |
* file: |
|
28 |
* |
|
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
29 |
* Written by Doug Lea and Martin Buchholz with assistance from |
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
30 |
* members of JCP JSR-166 Expert Group and released to the public |
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
31 |
* domain, as explained at |
35394 | 32 |
* http://creativecommons.org/publicdomain/zero/1.0/ |
33 |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
|
34 |
* Pat Fisher, Mike Judd. |
|
35 |
*/ |
|
36 |
||
37 |
/* |
|
38 |
* @test |
|
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
39 |
* @summary JSR-166 tck tests, in a number of variations. |
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
40 |
* The first is the conformance testing variant, |
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
41 |
* while others also test implementation details. |
42927
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
42 |
* @build * |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
43 |
* @modules java.management |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
44 |
* @run junit/othervm/timeout=1000 JSR166TestCase |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
45 |
* @run junit/othervm/timeout=1000 |
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
46 |
* --add-opens java.base/java.util.concurrent=ALL-UNNAMED |
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
47 |
* --add-opens java.base/java.lang=ALL-UNNAMED |
42927
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
48 |
* -Djsr166.testImplementationDetails=true |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
49 |
* JSR166TestCase |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
50 |
* @run junit/othervm/timeout=1000 |
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
51 |
* --add-opens java.base/java.util.concurrent=ALL-UNNAMED |
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
52 |
* --add-opens java.base/java.lang=ALL-UNNAMED |
42927
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
53 |
* -Djsr166.testImplementationDetails=true |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
54 |
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
55 |
* JSR166TestCase |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
56 |
* @run junit/othervm/timeout=1000 |
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
57 |
* --add-opens java.base/java.util.concurrent=ALL-UNNAMED |
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
58 |
* --add-opens java.base/java.lang=ALL-UNNAMED |
42927
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
59 |
* -Djsr166.testImplementationDetails=true |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
60 |
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
61 |
* -Djava.util.secureRandomSeed=true |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
62 |
* JSR166TestCase |
43545
fdecd1d14d53
8172726: ForkJoin common pool retains a reference to the thread context class loader
dl
parents:
42927
diff
changeset
|
63 |
* @run junit/othervm/timeout=1000/policy=tck.policy |
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
64 |
* --add-opens java.base/java.util.concurrent=ALL-UNNAMED |
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
65 |
* --add-opens java.base/java.lang=ALL-UNNAMED |
43545
fdecd1d14d53
8172726: ForkJoin common pool retains a reference to the thread context class loader
dl
parents:
42927
diff
changeset
|
66 |
* -Djsr166.testImplementationDetails=true |
fdecd1d14d53
8172726: ForkJoin common pool retains a reference to the thread context class loader
dl
parents:
42927
diff
changeset
|
67 |
* JSR166TestCase |
35394 | 68 |
*/ |
69 |
||
70 |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
|
71 |
import static java.util.concurrent.TimeUnit.MINUTES; |
|
72 |
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
|
73 |
||
74 |
import java.io.ByteArrayInputStream; |
|
75 |
import java.io.ByteArrayOutputStream; |
|
76 |
import java.io.ObjectInputStream; |
|
77 |
import java.io.ObjectOutputStream; |
|
78 |
import java.lang.management.ManagementFactory; |
|
79 |
import java.lang.management.ThreadInfo; |
|
80 |
import java.lang.management.ThreadMXBean; |
|
81 |
import java.lang.reflect.Constructor; |
|
82 |
import java.lang.reflect.Method; |
|
83 |
import java.lang.reflect.Modifier; |
|
84 |
import java.security.CodeSource; |
|
85 |
import java.security.Permission; |
|
86 |
import java.security.PermissionCollection; |
|
87 |
import java.security.Permissions; |
|
88 |
import java.security.Policy; |
|
89 |
import java.security.ProtectionDomain; |
|
90 |
import java.security.SecurityPermission; |
|
91 |
import java.util.ArrayList; |
|
92 |
import java.util.Arrays; |
|
42319 | 93 |
import java.util.Collection; |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39879
diff
changeset
|
94 |
import java.util.Collections; |
35394 | 95 |
import java.util.Date; |
96 |
import java.util.Enumeration; |
|
97 |
import java.util.Iterator; |
|
98 |
import java.util.List; |
|
99 |
import java.util.NoSuchElementException; |
|
100 |
import java.util.PropertyPermission; |
|
101 |
import java.util.concurrent.BlockingQueue; |
|
102 |
import java.util.concurrent.Callable; |
|
103 |
import java.util.concurrent.CountDownLatch; |
|
104 |
import java.util.concurrent.CyclicBarrier; |
|
105 |
import java.util.concurrent.ExecutionException; |
|
106 |
import java.util.concurrent.Executors; |
|
107 |
import java.util.concurrent.ExecutorService; |
|
108 |
import java.util.concurrent.ForkJoinPool; |
|
109 |
import java.util.concurrent.Future; |
|
110 |
import java.util.concurrent.RecursiveAction; |
|
111 |
import java.util.concurrent.RecursiveTask; |
|
112 |
import java.util.concurrent.RejectedExecutionHandler; |
|
113 |
import java.util.concurrent.Semaphore; |
|
38551
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
114 |
import java.util.concurrent.SynchronousQueue; |
35394 | 115 |
import java.util.concurrent.ThreadFactory; |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39879
diff
changeset
|
116 |
import java.util.concurrent.ThreadLocalRandom; |
35394 | 117 |
import java.util.concurrent.ThreadPoolExecutor; |
118 |
import java.util.concurrent.TimeoutException; |
|
36231
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
119 |
import java.util.concurrent.atomic.AtomicBoolean; |
35394 | 120 |
import java.util.concurrent.atomic.AtomicReference; |
121 |
import java.util.regex.Pattern; |
|
122 |
||
123 |
import junit.framework.AssertionFailedError; |
|
124 |
import junit.framework.Test; |
|
125 |
import junit.framework.TestCase; |
|
126 |
import junit.framework.TestResult; |
|
127 |
import junit.framework.TestSuite; |
|
128 |
||
129 |
/** |
|
130 |
* Base class for JSR166 Junit TCK tests. Defines some constants, |
|
131 |
* utility methods and classes, as well as a simple framework for |
|
132 |
* helping to make sure that assertions failing in generated threads |
|
133 |
* cause the associated test that generated them to itself fail (which |
|
134 |
* JUnit does not otherwise arrange). The rules for creating such |
|
135 |
* tests are: |
|
136 |
* |
|
137 |
* <ol> |
|
138 |
* |
|
139 |
* <li>All assertions in code running in generated threads must use |
|
140 |
* the forms {@link #threadFail}, {@link #threadAssertTrue}, {@link |
|
141 |
* #threadAssertEquals}, or {@link #threadAssertNull}, (not |
|
142 |
* {@code fail}, {@code assertTrue}, etc.) It is OK (but not |
|
143 |
* particularly recommended) for other code to use these forms too. |
|
144 |
* Only the most typically used JUnit assertion methods are defined |
|
145 |
* this way, but enough to live with. |
|
146 |
* |
|
147 |
* <li>If you override {@link #setUp} or {@link #tearDown}, make sure |
|
148 |
* to invoke {@code super.setUp} and {@code super.tearDown} within |
|
149 |
* them. These methods are used to clear and check for thread |
|
150 |
* assertion failures. |
|
151 |
* |
|
152 |
* <li>All delays and timeouts must use one of the constants {@code |
|
153 |
* SHORT_DELAY_MS}, {@code SMALL_DELAY_MS}, {@code MEDIUM_DELAY_MS}, |
|
154 |
* {@code LONG_DELAY_MS}. The idea here is that a SHORT is always |
|
155 |
* discriminable from zero time, and always allows enough time for the |
|
156 |
* small amounts of computation (creating a thread, calling a few |
|
157 |
* methods, etc) needed to reach a timeout point. Similarly, a SMALL |
|
158 |
* is always discriminable as larger than SHORT and smaller than |
|
159 |
* MEDIUM. And so on. These constants are set to conservative values, |
|
160 |
* but even so, if there is ever any doubt, they can all be increased |
|
161 |
* in one spot to rerun tests on slower platforms. |
|
162 |
* |
|
163 |
* <li>All threads generated must be joined inside each test case |
|
164 |
* method (or {@code fail} to do so) before returning from the |
|
165 |
* method. The {@code joinPool} method can be used to do this when |
|
166 |
* using Executors. |
|
167 |
* |
|
168 |
* </ol> |
|
169 |
* |
|
170 |
* <p><b>Other notes</b> |
|
171 |
* <ul> |
|
172 |
* |
|
173 |
* <li>Usually, there is one testcase method per JSR166 method |
|
174 |
* covering "normal" operation, and then as many exception-testing |
|
175 |
* methods as there are exceptions the method can throw. Sometimes |
|
176 |
* there are multiple tests per JSR166 method when the different |
|
177 |
* "normal" behaviors differ significantly. And sometimes testcases |
|
178 |
* cover multiple methods when they cannot be tested in isolation. |
|
179 |
* |
|
180 |
* <li>The documentation style for testcases is to provide as javadoc |
|
181 |
* a simple sentence or two describing the property that the testcase |
|
182 |
* method purports to test. The javadocs do not say anything about how |
|
183 |
* the property is tested. To find out, read the code. |
|
184 |
* |
|
185 |
* <li>These tests are "conformance tests", and do not attempt to |
|
186 |
* test throughput, latency, scalability or other performance factors |
|
187 |
* (see the separate "jtreg" tests for a set intended to check these |
|
188 |
* for the most central aspects of functionality.) So, most tests use |
|
189 |
* the smallest sensible numbers of threads, collection sizes, etc |
|
190 |
* needed to check basic conformance. |
|
191 |
* |
|
192 |
* <li>The test classes currently do not declare inclusion in |
|
193 |
* any particular package to simplify things for people integrating |
|
194 |
* them in TCK test suites. |
|
195 |
* |
|
196 |
* <li>As a convenience, the {@code main} of this class (JSR166TestCase) |
|
197 |
* runs all JSR166 unit tests. |
|
198 |
* |
|
199 |
* </ul> |
|
200 |
*/ |
|
201 |
public class JSR166TestCase extends TestCase { |
|
202 |
private static final boolean useSecurityManager = |
|
203 |
Boolean.getBoolean("jsr166.useSecurityManager"); |
|
204 |
||
205 |
protected static final boolean expensiveTests = |
|
206 |
Boolean.getBoolean("jsr166.expensiveTests"); |
|
207 |
||
208 |
/** |
|
209 |
* If true, also run tests that are not part of the official tck |
|
210 |
* because they test unspecified implementation details. |
|
211 |
*/ |
|
212 |
protected static final boolean testImplementationDetails = |
|
213 |
Boolean.getBoolean("jsr166.testImplementationDetails"); |
|
214 |
||
215 |
/** |
|
216 |
* If true, report on stdout all "slow" tests, that is, ones that |
|
217 |
* take more than profileThreshold milliseconds to execute. |
|
218 |
*/ |
|
219 |
private static final boolean profileTests = |
|
220 |
Boolean.getBoolean("jsr166.profileTests"); |
|
221 |
||
222 |
/** |
|
223 |
* The number of milliseconds that tests are permitted for |
|
224 |
* execution without being reported, when profileTests is set. |
|
225 |
*/ |
|
226 |
private static final long profileThreshold = |
|
227 |
Long.getLong("jsr166.profileThreshold", 100); |
|
228 |
||
229 |
/** |
|
230 |
* The number of repetitions per test (for tickling rare bugs). |
|
231 |
*/ |
|
232 |
private static final int runsPerTest = |
|
233 |
Integer.getInteger("jsr166.runsPerTest", 1); |
|
234 |
||
235 |
/** |
|
236 |
* The number of repetitions of the test suite (for finding leaks?). |
|
237 |
*/ |
|
238 |
private static final int suiteRuns = |
|
239 |
Integer.getInteger("jsr166.suiteRuns", 1); |
|
240 |
||
36957
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
241 |
/** |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
242 |
* Returns the value of the system property, or NaN if not defined. |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
243 |
*/ |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
244 |
private static float systemPropertyValue(String name) { |
36231
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
245 |
String floatString = System.getProperty(name); |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
246 |
if (floatString == null) |
36957
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
247 |
return Float.NaN; |
36231
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
248 |
try { |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
249 |
return Float.parseFloat(floatString); |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
250 |
} catch (NumberFormatException ex) { |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
251 |
throw new IllegalArgumentException( |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
252 |
String.format("Bad float value in system property %s=%s", |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
253 |
name, floatString)); |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
254 |
} |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
255 |
} |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
256 |
|
35394 | 257 |
/** |
258 |
* The scaling factor to apply to standard delays used in tests. |
|
36957
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
259 |
* May be initialized from any of: |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
260 |
* - the "jsr166.delay.factor" system property |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
261 |
* - the "test.timeout.factor" system property (as used by jtreg) |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
262 |
* See: http://openjdk.java.net/jtreg/tag-spec.html |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
263 |
* - hard-coded fuzz factor when using a known slowpoke VM |
35394 | 264 |
*/ |
36957
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
265 |
private static final float delayFactor = delayFactor(); |
36231
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
266 |
|
36957
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
267 |
private static float delayFactor() { |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
268 |
float x; |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
269 |
if (!Float.isNaN(x = systemPropertyValue("jsr166.delay.factor"))) |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
270 |
return x; |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
271 |
if (!Float.isNaN(x = systemPropertyValue("test.timeout.factor"))) |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
272 |
return x; |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
273 |
String prop = System.getProperty("java.vm.version"); |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
274 |
if (prop != null && prop.matches(".*debug.*")) |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
275 |
return 4.0f; // How much slower is fastdebug than product?! |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
276 |
return 1.0f; |
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
277 |
} |
35394 | 278 |
|
279 |
public JSR166TestCase() { super(); } |
|
280 |
public JSR166TestCase(String name) { super(name); } |
|
281 |
||
282 |
/** |
|
283 |
* A filter for tests to run, matching strings of the form |
|
284 |
* methodName(className), e.g. "testInvokeAll5(ForkJoinPoolTest)" |
|
285 |
* Usefully combined with jsr166.runsPerTest. |
|
286 |
*/ |
|
287 |
private static final Pattern methodFilter = methodFilter(); |
|
288 |
||
289 |
private static Pattern methodFilter() { |
|
290 |
String regex = System.getProperty("jsr166.methodFilter"); |
|
291 |
return (regex == null) ? null : Pattern.compile(regex); |
|
292 |
} |
|
293 |
||
294 |
// Instrumentation to debug very rare, but very annoying hung test runs. |
|
295 |
static volatile TestCase currentTestCase; |
|
296 |
// static volatile int currentRun = 0; |
|
297 |
static { |
|
298 |
Runnable checkForWedgedTest = new Runnable() { public void run() { |
|
299 |
// Avoid spurious reports with enormous runsPerTest. |
|
300 |
// A single test case run should never take more than 1 second. |
|
301 |
// But let's cap it at the high end too ... |
|
302 |
final int timeoutMinutes = |
|
303 |
Math.min(15, Math.max(runsPerTest / 60, 1)); |
|
304 |
for (TestCase lastTestCase = currentTestCase;;) { |
|
305 |
try { MINUTES.sleep(timeoutMinutes); } |
|
306 |
catch (InterruptedException unexpected) { break; } |
|
307 |
if (lastTestCase == currentTestCase) { |
|
308 |
System.err.printf( |
|
309 |
"Looks like we're stuck running test: %s%n", |
|
310 |
lastTestCase); |
|
311 |
// System.err.printf( |
|
312 |
// "Looks like we're stuck running test: %s (%d/%d)%n", |
|
313 |
// lastTestCase, currentRun, runsPerTest); |
|
314 |
// System.err.println("availableProcessors=" + |
|
315 |
// Runtime.getRuntime().availableProcessors()); |
|
316 |
// System.err.printf("cpu model = %s%n", cpuModel()); |
|
317 |
dumpTestThreads(); |
|
318 |
// one stack dump is probably enough; more would be spam |
|
319 |
break; |
|
320 |
} |
|
321 |
lastTestCase = currentTestCase; |
|
322 |
}}}; |
|
323 |
Thread thread = new Thread(checkForWedgedTest, "checkForWedgedTest"); |
|
324 |
thread.setDaemon(true); |
|
325 |
thread.start(); |
|
326 |
} |
|
327 |
||
328 |
// public static String cpuModel() { |
|
329 |
// try { |
|
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
330 |
// java.util.regex.Matcher matcher |
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
331 |
// = Pattern.compile("model name\\s*: (.*)") |
35394 | 332 |
// .matcher(new String( |
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
333 |
// java.nio.file.Files.readAllBytes( |
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
334 |
// java.nio.file.Paths.get("/proc/cpuinfo")), "UTF-8")); |
35394 | 335 |
// matcher.find(); |
336 |
// return matcher.group(1); |
|
337 |
// } catch (Exception ex) { return null; } |
|
338 |
// } |
|
339 |
||
340 |
public void runBare() throws Throwable { |
|
341 |
currentTestCase = this; |
|
342 |
if (methodFilter == null |
|
343 |
|| methodFilter.matcher(toString()).find()) |
|
344 |
super.runBare(); |
|
345 |
} |
|
346 |
||
347 |
protected void runTest() throws Throwable { |
|
348 |
for (int i = 0; i < runsPerTest; i++) { |
|
349 |
// currentRun = i; |
|
350 |
if (profileTests) |
|
351 |
runTestProfiled(); |
|
352 |
else |
|
353 |
super.runTest(); |
|
354 |
} |
|
355 |
} |
|
356 |
||
357 |
protected void runTestProfiled() throws Throwable { |
|
358 |
for (int i = 0; i < 2; i++) { |
|
359 |
long startTime = System.nanoTime(); |
|
360 |
super.runTest(); |
|
361 |
long elapsedMillis = millisElapsedSince(startTime); |
|
362 |
if (elapsedMillis < profileThreshold) |
|
363 |
break; |
|
364 |
// Never report first run of any test; treat it as a |
|
365 |
// warmup run, notably to trigger all needed classloading, |
|
366 |
if (i > 0) |
|
367 |
System.out.printf("%n%s: %d%n", toString(), elapsedMillis); |
|
368 |
} |
|
369 |
} |
|
370 |
||
371 |
/** |
|
372 |
* Runs all JSR166 unit tests using junit.textui.TestRunner. |
|
373 |
*/ |
|
374 |
public static void main(String[] args) { |
|
375 |
main(suite(), args); |
|
376 |
} |
|
377 |
||
378 |
static class PithyResultPrinter extends junit.textui.ResultPrinter { |
|
379 |
PithyResultPrinter(java.io.PrintStream writer) { super(writer); } |
|
380 |
long runTime; |
|
381 |
public void startTest(Test test) {} |
|
382 |
protected void printHeader(long runTime) { |
|
383 |
this.runTime = runTime; // defer printing for later |
|
384 |
} |
|
385 |
protected void printFooter(TestResult result) { |
|
386 |
if (result.wasSuccessful()) { |
|
387 |
getWriter().println("OK (" + result.runCount() + " tests)" |
|
388 |
+ " Time: " + elapsedTimeAsString(runTime)); |
|
389 |
} else { |
|
390 |
getWriter().println("Time: " + elapsedTimeAsString(runTime)); |
|
391 |
super.printFooter(result); |
|
392 |
} |
|
393 |
} |
|
394 |
} |
|
395 |
||
396 |
/** |
|
397 |
* Returns a TestRunner that doesn't bother with unnecessary |
|
398 |
* fluff, like printing a "." for each test case. |
|
399 |
*/ |
|
400 |
static junit.textui.TestRunner newPithyTestRunner() { |
|
401 |
junit.textui.TestRunner runner = new junit.textui.TestRunner(); |
|
402 |
runner.setPrinter(new PithyResultPrinter(System.out)); |
|
403 |
return runner; |
|
404 |
} |
|
405 |
||
406 |
/** |
|
407 |
* Runs all unit tests in the given test suite. |
|
408 |
* Actual behavior influenced by jsr166.* system properties. |
|
409 |
*/ |
|
410 |
static void main(Test suite, String[] args) { |
|
411 |
if (useSecurityManager) { |
|
412 |
System.err.println("Setting a permissive security manager"); |
|
413 |
Policy.setPolicy(permissivePolicy()); |
|
414 |
System.setSecurityManager(new SecurityManager()); |
|
415 |
} |
|
416 |
for (int i = 0; i < suiteRuns; i++) { |
|
417 |
TestResult result = newPithyTestRunner().doRun(suite); |
|
418 |
if (!result.wasSuccessful()) |
|
419 |
System.exit(1); |
|
420 |
System.gc(); |
|
421 |
System.runFinalization(); |
|
422 |
} |
|
423 |
} |
|
424 |
||
425 |
public static TestSuite newTestSuite(Object... suiteOrClasses) { |
|
426 |
TestSuite suite = new TestSuite(); |
|
427 |
for (Object suiteOrClass : suiteOrClasses) { |
|
428 |
if (suiteOrClass instanceof TestSuite) |
|
429 |
suite.addTest((TestSuite) suiteOrClass); |
|
430 |
else if (suiteOrClass instanceof Class) |
|
431 |
suite.addTest(new TestSuite((Class<?>) suiteOrClass)); |
|
432 |
else |
|
433 |
throw new ClassCastException("not a test suite or class"); |
|
434 |
} |
|
435 |
return suite; |
|
436 |
} |
|
437 |
||
438 |
public static void addNamedTestClasses(TestSuite suite, |
|
439 |
String... testClassNames) { |
|
440 |
for (String testClassName : testClassNames) { |
|
441 |
try { |
|
442 |
Class<?> testClass = Class.forName(testClassName); |
|
443 |
Method m = testClass.getDeclaredMethod("suite", |
|
444 |
new Class<?>[0]); |
|
445 |
suite.addTest(newTestSuite((Test)m.invoke(null))); |
|
446 |
} catch (Exception e) { |
|
447 |
throw new Error("Missing test class", e); |
|
448 |
} |
|
449 |
} |
|
450 |
} |
|
451 |
||
452 |
public static final double JAVA_CLASS_VERSION; |
|
453 |
public static final String JAVA_SPECIFICATION_VERSION; |
|
454 |
static { |
|
455 |
try { |
|
456 |
JAVA_CLASS_VERSION = java.security.AccessController.doPrivileged( |
|
457 |
new java.security.PrivilegedAction<Double>() { |
|
458 |
public Double run() { |
|
459 |
return Double.valueOf(System.getProperty("java.class.version"));}}); |
|
460 |
JAVA_SPECIFICATION_VERSION = java.security.AccessController.doPrivileged( |
|
461 |
new java.security.PrivilegedAction<String>() { |
|
462 |
public String run() { |
|
463 |
return System.getProperty("java.specification.version");}}); |
|
464 |
} catch (Throwable t) { |
|
465 |
throw new Error(t); |
|
466 |
} |
|
467 |
} |
|
468 |
||
469 |
public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; } |
|
470 |
public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; } |
|
471 |
public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; } |
|
472 |
public static boolean atLeastJava9() { |
|
473 |
return JAVA_CLASS_VERSION >= 53.0 |
|
474 |
// As of 2015-09, java9 still uses 52.0 class file version |
|
475 |
|| JAVA_SPECIFICATION_VERSION.matches("^(1\\.)?(9|[0-9][0-9])$"); |
|
476 |
} |
|
477 |
public static boolean atLeastJava10() { |
|
478 |
return JAVA_CLASS_VERSION >= 54.0 |
|
479 |
|| JAVA_SPECIFICATION_VERSION.matches("^(1\\.)?[0-9][0-9]$"); |
|
480 |
} |
|
481 |
||
482 |
/** |
|
483 |
* Collects all JSR166 unit tests as one suite. |
|
484 |
*/ |
|
485 |
public static Test suite() { |
|
486 |
// Java7+ test classes |
|
487 |
TestSuite suite = newTestSuite( |
|
488 |
ForkJoinPoolTest.suite(), |
|
489 |
ForkJoinTaskTest.suite(), |
|
490 |
RecursiveActionTest.suite(), |
|
491 |
RecursiveTaskTest.suite(), |
|
492 |
LinkedTransferQueueTest.suite(), |
|
493 |
PhaserTest.suite(), |
|
494 |
ThreadLocalRandomTest.suite(), |
|
495 |
AbstractExecutorServiceTest.suite(), |
|
496 |
AbstractQueueTest.suite(), |
|
497 |
AbstractQueuedSynchronizerTest.suite(), |
|
498 |
AbstractQueuedLongSynchronizerTest.suite(), |
|
499 |
ArrayBlockingQueueTest.suite(), |
|
500 |
ArrayDequeTest.suite(), |
|
42319 | 501 |
ArrayListTest.suite(), |
35394 | 502 |
AtomicBooleanTest.suite(), |
503 |
AtomicIntegerArrayTest.suite(), |
|
504 |
AtomicIntegerFieldUpdaterTest.suite(), |
|
505 |
AtomicIntegerTest.suite(), |
|
506 |
AtomicLongArrayTest.suite(), |
|
507 |
AtomicLongFieldUpdaterTest.suite(), |
|
508 |
AtomicLongTest.suite(), |
|
509 |
AtomicMarkableReferenceTest.suite(), |
|
510 |
AtomicReferenceArrayTest.suite(), |
|
511 |
AtomicReferenceFieldUpdaterTest.suite(), |
|
512 |
AtomicReferenceTest.suite(), |
|
513 |
AtomicStampedReferenceTest.suite(), |
|
514 |
ConcurrentHashMapTest.suite(), |
|
515 |
ConcurrentLinkedDequeTest.suite(), |
|
516 |
ConcurrentLinkedQueueTest.suite(), |
|
517 |
ConcurrentSkipListMapTest.suite(), |
|
518 |
ConcurrentSkipListSubMapTest.suite(), |
|
519 |
ConcurrentSkipListSetTest.suite(), |
|
520 |
ConcurrentSkipListSubSetTest.suite(), |
|
521 |
CopyOnWriteArrayListTest.suite(), |
|
522 |
CopyOnWriteArraySetTest.suite(), |
|
523 |
CountDownLatchTest.suite(), |
|
42319 | 524 |
CountedCompleterTest.suite(), |
35394 | 525 |
CyclicBarrierTest.suite(), |
526 |
DelayQueueTest.suite(), |
|
527 |
EntryTest.suite(), |
|
528 |
ExchangerTest.suite(), |
|
529 |
ExecutorsTest.suite(), |
|
530 |
ExecutorCompletionServiceTest.suite(), |
|
531 |
FutureTaskTest.suite(), |
|
532 |
LinkedBlockingDequeTest.suite(), |
|
533 |
LinkedBlockingQueueTest.suite(), |
|
534 |
LinkedListTest.suite(), |
|
535 |
LockSupportTest.suite(), |
|
536 |
PriorityBlockingQueueTest.suite(), |
|
537 |
PriorityQueueTest.suite(), |
|
538 |
ReentrantLockTest.suite(), |
|
539 |
ReentrantReadWriteLockTest.suite(), |
|
540 |
ScheduledExecutorTest.suite(), |
|
541 |
ScheduledExecutorSubclassTest.suite(), |
|
542 |
SemaphoreTest.suite(), |
|
543 |
SynchronousQueueTest.suite(), |
|
544 |
SystemTest.suite(), |
|
545 |
ThreadLocalTest.suite(), |
|
546 |
ThreadPoolExecutorTest.suite(), |
|
547 |
ThreadPoolExecutorSubclassTest.suite(), |
|
548 |
ThreadTest.suite(), |
|
549 |
TimeUnitTest.suite(), |
|
550 |
TreeMapTest.suite(), |
|
551 |
TreeSetTest.suite(), |
|
552 |
TreeSubMapTest.suite(), |
|
42319 | 553 |
TreeSubSetTest.suite(), |
554 |
VectorTest.suite()); |
|
35394 | 555 |
|
556 |
// Java8+ test classes |
|
557 |
if (atLeastJava8()) { |
|
558 |
String[] java8TestClassNames = { |
|
42319 | 559 |
"ArrayDeque8Test", |
35394 | 560 |
"Atomic8Test", |
561 |
"CompletableFutureTest", |
|
562 |
"ConcurrentHashMap8Test", |
|
42319 | 563 |
"CountedCompleter8Test", |
35394 | 564 |
"DoubleAccumulatorTest", |
565 |
"DoubleAdderTest", |
|
566 |
"ForkJoinPool8Test", |
|
567 |
"ForkJoinTask8Test", |
|
42927
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
568 |
"LinkedBlockingDeque8Test", |
1d31e540bfcb
8170484: Miscellaneous changes imported from jsr166 CVS 2016-12
dl
parents:
42339
diff
changeset
|
569 |
"LinkedBlockingQueue8Test", |
35394 | 570 |
"LongAccumulatorTest", |
571 |
"LongAdderTest", |
|
572 |
"SplittableRandomTest", |
|
573 |
"StampedLockTest", |
|
574 |
"SubmissionPublisherTest", |
|
575 |
"ThreadLocalRandom8Test", |
|
36957
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
576 |
"TimeUnit8Test", |
35394 | 577 |
}; |
578 |
addNamedTestClasses(suite, java8TestClassNames); |
|
579 |
} |
|
580 |
||
581 |
// Java9+ test classes |
|
582 |
if (atLeastJava9()) { |
|
583 |
String[] java9TestClassNames = { |
|
39725
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
584 |
"AtomicBoolean9Test", |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
585 |
"AtomicInteger9Test", |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
586 |
"AtomicIntegerArray9Test", |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
587 |
"AtomicLong9Test", |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
588 |
"AtomicLongArray9Test", |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
589 |
"AtomicReference9Test", |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
590 |
"AtomicReferenceArray9Test", |
38551
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
591 |
"ExecutorCompletionService9Test", |
43545
fdecd1d14d53
8172726: ForkJoin common pool retains a reference to the thread context class loader
dl
parents:
42927
diff
changeset
|
592 |
"ForkJoinPool9Test", |
35394 | 593 |
}; |
594 |
addNamedTestClasses(suite, java9TestClassNames); |
|
595 |
} |
|
596 |
||
597 |
return suite; |
|
598 |
} |
|
599 |
||
600 |
/** Returns list of junit-style test method names in given class. */ |
|
601 |
public static ArrayList<String> testMethodNames(Class<?> testClass) { |
|
602 |
Method[] methods = testClass.getDeclaredMethods(); |
|
43545
fdecd1d14d53
8172726: ForkJoin common pool retains a reference to the thread context class loader
dl
parents:
42927
diff
changeset
|
603 |
ArrayList<String> names = new ArrayList<>(methods.length); |
35394 | 604 |
for (Method method : methods) { |
605 |
if (method.getName().startsWith("test") |
|
606 |
&& Modifier.isPublic(method.getModifiers()) |
|
607 |
// method.getParameterCount() requires jdk8+ |
|
608 |
&& method.getParameterTypes().length == 0) { |
|
609 |
names.add(method.getName()); |
|
610 |
} |
|
611 |
} |
|
612 |
return names; |
|
613 |
} |
|
614 |
||
615 |
/** |
|
616 |
* Returns junit-style testSuite for the given test class, but |
|
617 |
* parameterized by passing extra data to each test. |
|
618 |
*/ |
|
619 |
public static <ExtraData> Test parameterizedTestSuite |
|
620 |
(Class<? extends JSR166TestCase> testClass, |
|
621 |
Class<ExtraData> dataClass, |
|
622 |
ExtraData data) { |
|
623 |
try { |
|
624 |
TestSuite suite = new TestSuite(); |
|
625 |
Constructor c = |
|
626 |
testClass.getDeclaredConstructor(dataClass, String.class); |
|
627 |
for (String methodName : testMethodNames(testClass)) |
|
628 |
suite.addTest((Test) c.newInstance(data, methodName)); |
|
629 |
return suite; |
|
630 |
} catch (Exception e) { |
|
631 |
throw new Error(e); |
|
632 |
} |
|
633 |
} |
|
634 |
||
635 |
/** |
|
636 |
* Returns junit-style testSuite for the jdk8 extension of the |
|
637 |
* given test class, but parameterized by passing extra data to |
|
638 |
* each test. Uses reflection to allow compilation in jdk7. |
|
639 |
*/ |
|
640 |
public static <ExtraData> Test jdk8ParameterizedTestSuite |
|
641 |
(Class<? extends JSR166TestCase> testClass, |
|
642 |
Class<ExtraData> dataClass, |
|
643 |
ExtraData data) { |
|
644 |
if (atLeastJava8()) { |
|
645 |
String name = testClass.getName(); |
|
646 |
String name8 = name.replaceAll("Test$", "8Test"); |
|
647 |
if (name.equals(name8)) throw new Error(name); |
|
648 |
try { |
|
649 |
return (Test) |
|
650 |
Class.forName(name8) |
|
651 |
.getMethod("testSuite", new Class[] { dataClass }) |
|
652 |
.invoke(null, data); |
|
653 |
} catch (Exception e) { |
|
654 |
throw new Error(e); |
|
655 |
} |
|
656 |
} else { |
|
657 |
return new TestSuite(); |
|
658 |
} |
|
659 |
} |
|
660 |
||
661 |
// Delays for timing-dependent tests, in milliseconds. |
|
662 |
||
663 |
public static long SHORT_DELAY_MS; |
|
664 |
public static long SMALL_DELAY_MS; |
|
665 |
public static long MEDIUM_DELAY_MS; |
|
666 |
public static long LONG_DELAY_MS; |
|
667 |
||
668 |
/** |
|
669 |
* Returns the shortest timed delay. This can be scaled up for |
|
36231
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
670 |
* slow machines using the jsr166.delay.factor system property, |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
671 |
* or via jtreg's -timeoutFactor: flag. |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
672 |
* http://openjdk.java.net/jtreg/command-help.html |
35394 | 673 |
*/ |
674 |
protected long getShortDelay() { |
|
36957
96f46df4ac48
8151344: Improve timeout factor handling in tck/JSR166TestCase
dl
parents:
36231
diff
changeset
|
675 |
return (long) (50 * delayFactor); |
35394 | 676 |
} |
677 |
||
678 |
/** |
|
679 |
* Sets delays as multiples of SHORT_DELAY. |
|
680 |
*/ |
|
681 |
protected void setDelays() { |
|
682 |
SHORT_DELAY_MS = getShortDelay(); |
|
683 |
SMALL_DELAY_MS = SHORT_DELAY_MS * 5; |
|
684 |
MEDIUM_DELAY_MS = SHORT_DELAY_MS * 10; |
|
685 |
LONG_DELAY_MS = SHORT_DELAY_MS * 200; |
|
686 |
} |
|
687 |
||
688 |
/** |
|
689 |
* Returns a timeout in milliseconds to be used in tests that |
|
690 |
* verify that operations block or time out. |
|
691 |
*/ |
|
692 |
long timeoutMillis() { |
|
693 |
return SHORT_DELAY_MS / 4; |
|
694 |
} |
|
695 |
||
696 |
/** |
|
697 |
* Returns a new Date instance representing a time at least |
|
698 |
* delayMillis milliseconds in the future. |
|
699 |
*/ |
|
700 |
Date delayedDate(long delayMillis) { |
|
701 |
// Add 1 because currentTimeMillis is known to round into the past. |
|
702 |
return new Date(System.currentTimeMillis() + delayMillis + 1); |
|
703 |
} |
|
704 |
||
705 |
/** |
|
706 |
* The first exception encountered if any threadAssertXXX method fails. |
|
707 |
*/ |
|
708 |
private final AtomicReference<Throwable> threadFailure |
|
43545
fdecd1d14d53
8172726: ForkJoin common pool retains a reference to the thread context class loader
dl
parents:
42927
diff
changeset
|
709 |
= new AtomicReference<>(null); |
35394 | 710 |
|
711 |
/** |
|
712 |
* Records an exception so that it can be rethrown later in the test |
|
713 |
* harness thread, triggering a test case failure. Only the first |
|
714 |
* failure is recorded; subsequent calls to this method from within |
|
715 |
* the same test have no effect. |
|
716 |
*/ |
|
717 |
public void threadRecordFailure(Throwable t) { |
|
718 |
System.err.println(t); |
|
719 |
dumpTestThreads(); |
|
720 |
threadFailure.compareAndSet(null, t); |
|
721 |
} |
|
722 |
||
723 |
public void setUp() { |
|
724 |
setDelays(); |
|
725 |
} |
|
726 |
||
727 |
void tearDownFail(String format, Object... args) { |
|
728 |
String msg = toString() + ": " + String.format(format, args); |
|
729 |
System.err.println(msg); |
|
730 |
dumpTestThreads(); |
|
731 |
throw new AssertionFailedError(msg); |
|
732 |
} |
|
733 |
||
734 |
/** |
|
735 |
* Extra checks that get done for all test cases. |
|
736 |
* |
|
737 |
* Triggers test case failure if any thread assertions have failed, |
|
738 |
* by rethrowing, in the test harness thread, any exception recorded |
|
739 |
* earlier by threadRecordFailure. |
|
740 |
* |
|
741 |
* Triggers test case failure if interrupt status is set in the main thread. |
|
742 |
*/ |
|
743 |
public void tearDown() throws Exception { |
|
744 |
Throwable t = threadFailure.getAndSet(null); |
|
745 |
if (t != null) { |
|
746 |
if (t instanceof Error) |
|
747 |
throw (Error) t; |
|
748 |
else if (t instanceof RuntimeException) |
|
749 |
throw (RuntimeException) t; |
|
750 |
else if (t instanceof Exception) |
|
751 |
throw (Exception) t; |
|
752 |
else { |
|
753 |
AssertionFailedError afe = |
|
754 |
new AssertionFailedError(t.toString()); |
|
755 |
afe.initCause(t); |
|
756 |
throw afe; |
|
757 |
} |
|
758 |
} |
|
759 |
||
760 |
if (Thread.interrupted()) |
|
761 |
tearDownFail("interrupt status set in main thread"); |
|
762 |
||
763 |
checkForkJoinPoolThreadLeaks(); |
|
764 |
} |
|
765 |
||
766 |
/** |
|
767 |
* Finds missing PoolCleaners |
|
768 |
*/ |
|
769 |
void checkForkJoinPoolThreadLeaks() throws InterruptedException { |
|
770 |
Thread[] survivors = new Thread[7]; |
|
771 |
int count = Thread.enumerate(survivors); |
|
772 |
for (int i = 0; i < count; i++) { |
|
773 |
Thread thread = survivors[i]; |
|
774 |
String name = thread.getName(); |
|
775 |
if (name.startsWith("ForkJoinPool-")) { |
|
776 |
// give thread some time to terminate |
|
777 |
thread.join(LONG_DELAY_MS); |
|
778 |
if (thread.isAlive()) |
|
779 |
tearDownFail("Found leaked ForkJoinPool thread thread=%s", |
|
780 |
thread); |
|
781 |
} |
|
782 |
} |
|
783 |
||
784 |
if (!ForkJoinPool.commonPool() |
|
785 |
.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) |
|
786 |
tearDownFail("ForkJoin common pool thread stuck"); |
|
787 |
} |
|
788 |
||
789 |
/** |
|
790 |
* Just like fail(reason), but additionally recording (using |
|
791 |
* threadRecordFailure) any AssertionFailedError thrown, so that |
|
792 |
* the current testcase will fail. |
|
793 |
*/ |
|
794 |
public void threadFail(String reason) { |
|
795 |
try { |
|
796 |
fail(reason); |
|
797 |
} catch (AssertionFailedError t) { |
|
798 |
threadRecordFailure(t); |
|
799 |
throw t; |
|
800 |
} |
|
801 |
} |
|
802 |
||
803 |
/** |
|
804 |
* Just like assertTrue(b), but additionally recording (using |
|
805 |
* threadRecordFailure) any AssertionFailedError thrown, so that |
|
806 |
* the current testcase will fail. |
|
807 |
*/ |
|
808 |
public void threadAssertTrue(boolean b) { |
|
809 |
try { |
|
810 |
assertTrue(b); |
|
811 |
} catch (AssertionFailedError t) { |
|
812 |
threadRecordFailure(t); |
|
813 |
throw t; |
|
814 |
} |
|
815 |
} |
|
816 |
||
817 |
/** |
|
818 |
* Just like assertFalse(b), but additionally recording (using |
|
819 |
* threadRecordFailure) any AssertionFailedError thrown, so that |
|
820 |
* the current testcase will fail. |
|
821 |
*/ |
|
822 |
public void threadAssertFalse(boolean b) { |
|
823 |
try { |
|
824 |
assertFalse(b); |
|
825 |
} catch (AssertionFailedError t) { |
|
826 |
threadRecordFailure(t); |
|
827 |
throw t; |
|
828 |
} |
|
829 |
} |
|
830 |
||
831 |
/** |
|
832 |
* Just like assertNull(x), but additionally recording (using |
|
833 |
* threadRecordFailure) any AssertionFailedError thrown, so that |
|
834 |
* the current testcase will fail. |
|
835 |
*/ |
|
836 |
public void threadAssertNull(Object x) { |
|
837 |
try { |
|
838 |
assertNull(x); |
|
839 |
} catch (AssertionFailedError t) { |
|
840 |
threadRecordFailure(t); |
|
841 |
throw t; |
|
842 |
} |
|
843 |
} |
|
844 |
||
845 |
/** |
|
846 |
* Just like assertEquals(x, y), but additionally recording (using |
|
847 |
* threadRecordFailure) any AssertionFailedError thrown, so that |
|
848 |
* the current testcase will fail. |
|
849 |
*/ |
|
850 |
public void threadAssertEquals(long x, long y) { |
|
851 |
try { |
|
852 |
assertEquals(x, y); |
|
853 |
} catch (AssertionFailedError t) { |
|
854 |
threadRecordFailure(t); |
|
855 |
throw t; |
|
856 |
} |
|
857 |
} |
|
858 |
||
859 |
/** |
|
860 |
* Just like assertEquals(x, y), but additionally recording (using |
|
861 |
* threadRecordFailure) any AssertionFailedError thrown, so that |
|
862 |
* the current testcase will fail. |
|
863 |
*/ |
|
864 |
public void threadAssertEquals(Object x, Object y) { |
|
865 |
try { |
|
866 |
assertEquals(x, y); |
|
867 |
} catch (AssertionFailedError fail) { |
|
868 |
threadRecordFailure(fail); |
|
869 |
throw fail; |
|
870 |
} catch (Throwable fail) { |
|
871 |
threadUnexpectedException(fail); |
|
872 |
} |
|
873 |
} |
|
874 |
||
875 |
/** |
|
876 |
* Just like assertSame(x, y), but additionally recording (using |
|
877 |
* threadRecordFailure) any AssertionFailedError thrown, so that |
|
878 |
* the current testcase will fail. |
|
879 |
*/ |
|
880 |
public void threadAssertSame(Object x, Object y) { |
|
881 |
try { |
|
882 |
assertSame(x, y); |
|
883 |
} catch (AssertionFailedError fail) { |
|
884 |
threadRecordFailure(fail); |
|
885 |
throw fail; |
|
886 |
} |
|
887 |
} |
|
888 |
||
889 |
/** |
|
890 |
* Calls threadFail with message "should throw exception". |
|
891 |
*/ |
|
892 |
public void threadShouldThrow() { |
|
893 |
threadFail("should throw exception"); |
|
894 |
} |
|
895 |
||
896 |
/** |
|
897 |
* Calls threadFail with message "should throw" + exceptionName. |
|
898 |
*/ |
|
899 |
public void threadShouldThrow(String exceptionName) { |
|
900 |
threadFail("should throw " + exceptionName); |
|
901 |
} |
|
902 |
||
903 |
/** |
|
904 |
* Records the given exception using {@link #threadRecordFailure}, |
|
905 |
* then rethrows the exception, wrapping it in an |
|
906 |
* AssertionFailedError if necessary. |
|
907 |
*/ |
|
908 |
public void threadUnexpectedException(Throwable t) { |
|
909 |
threadRecordFailure(t); |
|
910 |
t.printStackTrace(); |
|
911 |
if (t instanceof RuntimeException) |
|
912 |
throw (RuntimeException) t; |
|
913 |
else if (t instanceof Error) |
|
914 |
throw (Error) t; |
|
915 |
else { |
|
916 |
AssertionFailedError afe = |
|
917 |
new AssertionFailedError("unexpected exception: " + t); |
|
918 |
afe.initCause(t); |
|
919 |
throw afe; |
|
920 |
} |
|
921 |
} |
|
922 |
||
923 |
/** |
|
924 |
* Delays, via Thread.sleep, for the given millisecond delay, but |
|
925 |
* if the sleep is shorter than specified, may re-sleep or yield |
|
926 |
* until time elapses. Ensures that the given time, as measured |
|
927 |
* by System.nanoTime(), has elapsed. |
|
928 |
*/ |
|
929 |
static void delay(long millis) throws InterruptedException { |
|
930 |
long nanos = millis * (1000 * 1000); |
|
931 |
final long wakeupTime = System.nanoTime() + nanos; |
|
932 |
do { |
|
933 |
if (millis > 0L) |
|
934 |
Thread.sleep(millis); |
|
935 |
else // too short to sleep |
|
936 |
Thread.yield(); |
|
937 |
nanos = wakeupTime - System.nanoTime(); |
|
938 |
millis = nanos / (1000 * 1000); |
|
939 |
} while (nanos >= 0L); |
|
940 |
} |
|
941 |
||
942 |
/** |
|
943 |
* Allows use of try-with-resources with per-test thread pools. |
|
944 |
*/ |
|
945 |
class PoolCleaner implements AutoCloseable { |
|
946 |
private final ExecutorService pool; |
|
947 |
public PoolCleaner(ExecutorService pool) { this.pool = pool; } |
|
948 |
public void close() { joinPool(pool); } |
|
949 |
} |
|
950 |
||
951 |
/** |
|
952 |
* An extension of PoolCleaner that has an action to release the pool. |
|
953 |
*/ |
|
954 |
class PoolCleanerWithReleaser extends PoolCleaner { |
|
955 |
private final Runnable releaser; |
|
956 |
public PoolCleanerWithReleaser(ExecutorService pool, Runnable releaser) { |
|
957 |
super(pool); |
|
958 |
this.releaser = releaser; |
|
959 |
} |
|
960 |
public void close() { |
|
961 |
try { |
|
962 |
releaser.run(); |
|
963 |
} finally { |
|
964 |
super.close(); |
|
965 |
} |
|
966 |
} |
|
967 |
} |
|
968 |
||
969 |
PoolCleaner cleaner(ExecutorService pool) { |
|
970 |
return new PoolCleaner(pool); |
|
971 |
} |
|
972 |
||
973 |
PoolCleaner cleaner(ExecutorService pool, Runnable releaser) { |
|
974 |
return new PoolCleanerWithReleaser(pool, releaser); |
|
975 |
} |
|
976 |
||
977 |
PoolCleaner cleaner(ExecutorService pool, CountDownLatch latch) { |
|
978 |
return new PoolCleanerWithReleaser(pool, releaser(latch)); |
|
979 |
} |
|
980 |
||
981 |
Runnable releaser(final CountDownLatch latch) { |
|
982 |
return new Runnable() { public void run() { |
|
983 |
do { latch.countDown(); } |
|
984 |
while (latch.getCount() > 0); |
|
985 |
}}; |
|
986 |
} |
|
987 |
||
36231
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
988 |
PoolCleaner cleaner(ExecutorService pool, AtomicBoolean flag) { |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
989 |
return new PoolCleanerWithReleaser(pool, releaser(flag)); |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
990 |
} |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
991 |
|
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
992 |
Runnable releaser(final AtomicBoolean flag) { |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
993 |
return new Runnable() { public void run() { flag.set(true); }}; |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
994 |
} |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
995 |
|
35394 | 996 |
/** |
997 |
* Waits out termination of a thread pool or fails doing so. |
|
998 |
*/ |
|
999 |
void joinPool(ExecutorService pool) { |
|
1000 |
try { |
|
1001 |
pool.shutdown(); |
|
1002 |
if (!pool.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS)) { |
|
1003 |
try { |
|
1004 |
threadFail("ExecutorService " + pool + |
|
1005 |
" did not terminate in a timely manner"); |
|
1006 |
} finally { |
|
1007 |
// last resort, for the benefit of subsequent tests |
|
1008 |
pool.shutdownNow(); |
|
1009 |
pool.awaitTermination(MEDIUM_DELAY_MS, MILLISECONDS); |
|
1010 |
} |
|
1011 |
} |
|
1012 |
} catch (SecurityException ok) { |
|
1013 |
// Allowed in case test doesn't have privs |
|
1014 |
} catch (InterruptedException fail) { |
|
1015 |
threadFail("Unexpected InterruptedException"); |
|
1016 |
} |
|
1017 |
} |
|
1018 |
||
39725
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1019 |
/** |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1020 |
* Like Runnable, but with the freedom to throw anything. |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1021 |
* junit folks had the same idea: |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1022 |
* http://junit.org/junit5/docs/snapshot/api/org/junit/gen5/api/Executable.html |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1023 |
*/ |
35394 | 1024 |
interface Action { public void run() throws Throwable; } |
1025 |
||
1026 |
/** |
|
1027 |
* Runs all the given actions in parallel, failing if any fail. |
|
1028 |
* Useful for running multiple variants of tests that are |
|
1029 |
* necessarily individually slow because they must block. |
|
1030 |
*/ |
|
1031 |
void testInParallel(Action ... actions) { |
|
1032 |
ExecutorService pool = Executors.newCachedThreadPool(); |
|
1033 |
try (PoolCleaner cleaner = cleaner(pool)) { |
|
1034 |
ArrayList<Future<?>> futures = new ArrayList<>(actions.length); |
|
1035 |
for (final Action action : actions) |
|
1036 |
futures.add(pool.submit(new CheckedRunnable() { |
|
1037 |
public void realRun() throws Throwable { action.run();}})); |
|
1038 |
for (Future<?> future : futures) |
|
1039 |
try { |
|
1040 |
assertNull(future.get(LONG_DELAY_MS, MILLISECONDS)); |
|
1041 |
} catch (ExecutionException ex) { |
|
1042 |
threadUnexpectedException(ex.getCause()); |
|
1043 |
} catch (Exception ex) { |
|
1044 |
threadUnexpectedException(ex); |
|
1045 |
} |
|
1046 |
} |
|
1047 |
} |
|
1048 |
||
1049 |
/** |
|
1050 |
* A debugging tool to print stack traces of most threads, as jstack does. |
|
1051 |
* Uninteresting threads are filtered out. |
|
1052 |
*/ |
|
1053 |
static void dumpTestThreads() { |
|
39725
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1054 |
SecurityManager sm = System.getSecurityManager(); |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1055 |
if (sm != null) { |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1056 |
try { |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1057 |
System.setSecurityManager(null); |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1058 |
} catch (SecurityException giveUp) { |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1059 |
return; |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1060 |
} |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1061 |
} |
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1062 |
|
35394 | 1063 |
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); |
1064 |
System.err.println("------ stacktrace dump start ------"); |
|
1065 |
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { |
|
41130
2004bf22423f
8166059: JSR166TestCase.java fails with NPE in dumpTestThreads on timeout
dl
parents:
40817
diff
changeset
|
1066 |
final String name = info.getThreadName(); |
2004bf22423f
8166059: JSR166TestCase.java fails with NPE in dumpTestThreads on timeout
dl
parents:
40817
diff
changeset
|
1067 |
String lockName; |
35394 | 1068 |
if ("Signal Dispatcher".equals(name)) |
1069 |
continue; |
|
1070 |
if ("Reference Handler".equals(name) |
|
41130
2004bf22423f
8166059: JSR166TestCase.java fails with NPE in dumpTestThreads on timeout
dl
parents:
40817
diff
changeset
|
1071 |
&& (lockName = info.getLockName()) != null |
2004bf22423f
8166059: JSR166TestCase.java fails with NPE in dumpTestThreads on timeout
dl
parents:
40817
diff
changeset
|
1072 |
&& lockName.startsWith("java.lang.ref.Reference$Lock")) |
35394 | 1073 |
continue; |
1074 |
if ("Finalizer".equals(name) |
|
41130
2004bf22423f
8166059: JSR166TestCase.java fails with NPE in dumpTestThreads on timeout
dl
parents:
40817
diff
changeset
|
1075 |
&& (lockName = info.getLockName()) != null |
2004bf22423f
8166059: JSR166TestCase.java fails with NPE in dumpTestThreads on timeout
dl
parents:
40817
diff
changeset
|
1076 |
&& lockName.startsWith("java.lang.ref.ReferenceQueue$Lock")) |
35394 | 1077 |
continue; |
1078 |
if ("checkForWedgedTest".equals(name)) |
|
1079 |
continue; |
|
1080 |
System.err.print(info); |
|
1081 |
} |
|
1082 |
System.err.println("------ stacktrace dump end ------"); |
|
39725
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1083 |
|
9548f8d846e9
8080603: Replace Unsafe with VarHandle in java.util.concurrent classes
dl
parents:
38551
diff
changeset
|
1084 |
if (sm != null) System.setSecurityManager(sm); |
35394 | 1085 |
} |
1086 |
||
1087 |
/** |
|
1088 |
* Checks that thread does not terminate within the default |
|
1089 |
* millisecond delay of {@code timeoutMillis()}. |
|
1090 |
*/ |
|
1091 |
void assertThreadStaysAlive(Thread thread) { |
|
1092 |
assertThreadStaysAlive(thread, timeoutMillis()); |
|
1093 |
} |
|
1094 |
||
1095 |
/** |
|
1096 |
* Checks that thread does not terminate within the given millisecond delay. |
|
1097 |
*/ |
|
1098 |
void assertThreadStaysAlive(Thread thread, long millis) { |
|
1099 |
try { |
|
1100 |
// No need to optimize the failing case via Thread.join. |
|
1101 |
delay(millis); |
|
1102 |
assertTrue(thread.isAlive()); |
|
1103 |
} catch (InterruptedException fail) { |
|
1104 |
threadFail("Unexpected InterruptedException"); |
|
1105 |
} |
|
1106 |
} |
|
1107 |
||
1108 |
/** |
|
1109 |
* Checks that the threads do not terminate within the default |
|
1110 |
* millisecond delay of {@code timeoutMillis()}. |
|
1111 |
*/ |
|
1112 |
void assertThreadsStayAlive(Thread... threads) { |
|
1113 |
assertThreadsStayAlive(timeoutMillis(), threads); |
|
1114 |
} |
|
1115 |
||
1116 |
/** |
|
1117 |
* Checks that the threads do not terminate within the given millisecond delay. |
|
1118 |
*/ |
|
1119 |
void assertThreadsStayAlive(long millis, Thread... threads) { |
|
1120 |
try { |
|
1121 |
// No need to optimize the failing case via Thread.join. |
|
1122 |
delay(millis); |
|
1123 |
for (Thread thread : threads) |
|
1124 |
assertTrue(thread.isAlive()); |
|
1125 |
} catch (InterruptedException fail) { |
|
1126 |
threadFail("Unexpected InterruptedException"); |
|
1127 |
} |
|
1128 |
} |
|
1129 |
||
1130 |
/** |
|
1131 |
* Checks that future.get times out, with the default timeout of |
|
1132 |
* {@code timeoutMillis()}. |
|
1133 |
*/ |
|
1134 |
void assertFutureTimesOut(Future future) { |
|
1135 |
assertFutureTimesOut(future, timeoutMillis()); |
|
1136 |
} |
|
1137 |
||
1138 |
/** |
|
1139 |
* Checks that future.get times out, with the given millisecond timeout. |
|
1140 |
*/ |
|
1141 |
void assertFutureTimesOut(Future future, long timeoutMillis) { |
|
1142 |
long startTime = System.nanoTime(); |
|
1143 |
try { |
|
1144 |
future.get(timeoutMillis, MILLISECONDS); |
|
1145 |
shouldThrow(); |
|
1146 |
} catch (TimeoutException success) { |
|
1147 |
} catch (Exception fail) { |
|
1148 |
threadUnexpectedException(fail); |
|
1149 |
} finally { future.cancel(true); } |
|
1150 |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
|
1151 |
} |
|
1152 |
||
1153 |
/** |
|
1154 |
* Fails with message "should throw exception". |
|
1155 |
*/ |
|
1156 |
public void shouldThrow() { |
|
1157 |
fail("Should throw exception"); |
|
1158 |
} |
|
1159 |
||
1160 |
/** |
|
1161 |
* Fails with message "should throw " + exceptionName. |
|
1162 |
*/ |
|
1163 |
public void shouldThrow(String exceptionName) { |
|
1164 |
fail("Should throw " + exceptionName); |
|
1165 |
} |
|
1166 |
||
1167 |
/** |
|
1168 |
* The number of elements to place in collections, arrays, etc. |
|
1169 |
*/ |
|
1170 |
public static final int SIZE = 20; |
|
1171 |
||
1172 |
// Some convenient Integer constants |
|
1173 |
||
1174 |
public static final Integer zero = new Integer(0); |
|
1175 |
public static final Integer one = new Integer(1); |
|
1176 |
public static final Integer two = new Integer(2); |
|
1177 |
public static final Integer three = new Integer(3); |
|
1178 |
public static final Integer four = new Integer(4); |
|
1179 |
public static final Integer five = new Integer(5); |
|
1180 |
public static final Integer six = new Integer(6); |
|
1181 |
public static final Integer seven = new Integer(7); |
|
1182 |
public static final Integer eight = new Integer(8); |
|
1183 |
public static final Integer nine = new Integer(9); |
|
1184 |
public static final Integer m1 = new Integer(-1); |
|
1185 |
public static final Integer m2 = new Integer(-2); |
|
1186 |
public static final Integer m3 = new Integer(-3); |
|
1187 |
public static final Integer m4 = new Integer(-4); |
|
1188 |
public static final Integer m5 = new Integer(-5); |
|
1189 |
public static final Integer m6 = new Integer(-6); |
|
1190 |
public static final Integer m10 = new Integer(-10); |
|
1191 |
||
1192 |
/** |
|
1193 |
* Runs Runnable r with a security policy that permits precisely |
|
1194 |
* the specified permissions. If there is no current security |
|
1195 |
* manager, the runnable is run twice, both with and without a |
|
1196 |
* security manager. We require that any security manager permit |
|
1197 |
* getPolicy/setPolicy. |
|
1198 |
*/ |
|
1199 |
public void runWithPermissions(Runnable r, Permission... permissions) { |
|
1200 |
SecurityManager sm = System.getSecurityManager(); |
|
1201 |
if (sm == null) { |
|
1202 |
r.run(); |
|
1203 |
} |
|
1204 |
runWithSecurityManagerWithPermissions(r, permissions); |
|
1205 |
} |
|
1206 |
||
1207 |
/** |
|
1208 |
* Runs Runnable r with a security policy that permits precisely |
|
1209 |
* the specified permissions. If there is no current security |
|
1210 |
* manager, a temporary one is set for the duration of the |
|
1211 |
* Runnable. We require that any security manager permit |
|
1212 |
* getPolicy/setPolicy. |
|
1213 |
*/ |
|
1214 |
public void runWithSecurityManagerWithPermissions(Runnable r, |
|
1215 |
Permission... permissions) { |
|
1216 |
SecurityManager sm = System.getSecurityManager(); |
|
1217 |
if (sm == null) { |
|
1218 |
Policy savedPolicy = Policy.getPolicy(); |
|
1219 |
try { |
|
1220 |
Policy.setPolicy(permissivePolicy()); |
|
1221 |
System.setSecurityManager(new SecurityManager()); |
|
1222 |
runWithSecurityManagerWithPermissions(r, permissions); |
|
1223 |
} finally { |
|
1224 |
System.setSecurityManager(null); |
|
1225 |
Policy.setPolicy(savedPolicy); |
|
1226 |
} |
|
1227 |
} else { |
|
1228 |
Policy savedPolicy = Policy.getPolicy(); |
|
1229 |
AdjustablePolicy policy = new AdjustablePolicy(permissions); |
|
1230 |
Policy.setPolicy(policy); |
|
1231 |
||
1232 |
try { |
|
1233 |
r.run(); |
|
1234 |
} finally { |
|
1235 |
policy.addPermission(new SecurityPermission("setPolicy")); |
|
1236 |
Policy.setPolicy(savedPolicy); |
|
1237 |
} |
|
1238 |
} |
|
1239 |
} |
|
1240 |
||
1241 |
/** |
|
1242 |
* Runs a runnable without any permissions. |
|
1243 |
*/ |
|
1244 |
public void runWithoutPermissions(Runnable r) { |
|
1245 |
runWithPermissions(r); |
|
1246 |
} |
|
1247 |
||
1248 |
/** |
|
1249 |
* A security policy where new permissions can be dynamically added |
|
1250 |
* or all cleared. |
|
1251 |
*/ |
|
1252 |
public static class AdjustablePolicy extends java.security.Policy { |
|
1253 |
Permissions perms = new Permissions(); |
|
1254 |
AdjustablePolicy(Permission... permissions) { |
|
1255 |
for (Permission permission : permissions) |
|
1256 |
perms.add(permission); |
|
1257 |
} |
|
1258 |
void addPermission(Permission perm) { perms.add(perm); } |
|
1259 |
void clearPermissions() { perms = new Permissions(); } |
|
1260 |
public PermissionCollection getPermissions(CodeSource cs) { |
|
1261 |
return perms; |
|
1262 |
} |
|
1263 |
public PermissionCollection getPermissions(ProtectionDomain pd) { |
|
1264 |
return perms; |
|
1265 |
} |
|
1266 |
public boolean implies(ProtectionDomain pd, Permission p) { |
|
1267 |
return perms.implies(p); |
|
1268 |
} |
|
1269 |
public void refresh() {} |
|
1270 |
public String toString() { |
|
43545
fdecd1d14d53
8172726: ForkJoin common pool retains a reference to the thread context class loader
dl
parents:
42927
diff
changeset
|
1271 |
List<Permission> ps = new ArrayList<>(); |
35394 | 1272 |
for (Enumeration<Permission> e = perms.elements(); e.hasMoreElements();) |
1273 |
ps.add(e.nextElement()); |
|
1274 |
return "AdjustablePolicy with permissions " + ps; |
|
1275 |
} |
|
1276 |
} |
|
1277 |
||
1278 |
/** |
|
1279 |
* Returns a policy containing all the permissions we ever need. |
|
1280 |
*/ |
|
1281 |
public static Policy permissivePolicy() { |
|
1282 |
return new AdjustablePolicy |
|
1283 |
// Permissions j.u.c. needs directly |
|
1284 |
(new RuntimePermission("modifyThread"), |
|
1285 |
new RuntimePermission("getClassLoader"), |
|
1286 |
new RuntimePermission("setContextClassLoader"), |
|
1287 |
// Permissions needed to change permissions! |
|
1288 |
new SecurityPermission("getPolicy"), |
|
1289 |
new SecurityPermission("setPolicy"), |
|
1290 |
new RuntimePermission("setSecurityManager"), |
|
1291 |
// Permissions needed by the junit test harness |
|
1292 |
new RuntimePermission("accessDeclaredMembers"), |
|
1293 |
new PropertyPermission("*", "read"), |
|
1294 |
new java.io.FilePermission("<<ALL FILES>>", "read")); |
|
1295 |
} |
|
1296 |
||
1297 |
/** |
|
1298 |
* Sleeps until the given time has elapsed. |
|
1299 |
* Throws AssertionFailedError if interrupted. |
|
1300 |
*/ |
|
40817
4f5fb115676d
8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents:
40278
diff
changeset
|
1301 |
static void sleep(long millis) { |
35394 | 1302 |
try { |
1303 |
delay(millis); |
|
1304 |
} catch (InterruptedException fail) { |
|
1305 |
AssertionFailedError afe = |
|
1306 |
new AssertionFailedError("Unexpected InterruptedException"); |
|
1307 |
afe.initCause(fail); |
|
1308 |
throw afe; |
|
1309 |
} |
|
1310 |
} |
|
1311 |
||
1312 |
/** |
|
1313 |
* Spin-waits up to the specified number of milliseconds for the given |
|
1314 |
* thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING. |
|
1315 |
*/ |
|
1316 |
void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) { |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39879
diff
changeset
|
1317 |
long startTime = 0L; |
35394 | 1318 |
for (;;) { |
1319 |
Thread.State s = thread.getState(); |
|
1320 |
if (s == Thread.State.BLOCKED || |
|
1321 |
s == Thread.State.WAITING || |
|
1322 |
s == Thread.State.TIMED_WAITING) |
|
1323 |
return; |
|
1324 |
else if (s == Thread.State.TERMINATED) |
|
1325 |
fail("Unexpected thread termination"); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39879
diff
changeset
|
1326 |
else if (startTime == 0L) |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39879
diff
changeset
|
1327 |
startTime = System.nanoTime(); |
35394 | 1328 |
else if (millisElapsedSince(startTime) > timeoutMillis) { |
1329 |
threadAssertTrue(thread.isAlive()); |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1330 |
fail("timed out waiting for thread to enter wait state"); |
35394 | 1331 |
} |
1332 |
Thread.yield(); |
|
1333 |
} |
|
1334 |
} |
|
1335 |
||
1336 |
/** |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1337 |
* Spin-waits up to the specified number of milliseconds for the given |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1338 |
* thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING, |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1339 |
* and additionally satisfy the given condition. |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1340 |
*/ |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1341 |
void waitForThreadToEnterWaitState( |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1342 |
Thread thread, long timeoutMillis, Callable<Boolean> waitingForGodot) { |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1343 |
long startTime = 0L; |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1344 |
for (;;) { |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1345 |
Thread.State s = thread.getState(); |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1346 |
if (s == Thread.State.BLOCKED || |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1347 |
s == Thread.State.WAITING || |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1348 |
s == Thread.State.TIMED_WAITING) { |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1349 |
try { |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1350 |
if (waitingForGodot.call()) |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1351 |
return; |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1352 |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1353 |
} |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1354 |
else if (s == Thread.State.TERMINATED) |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1355 |
fail("Unexpected thread termination"); |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1356 |
else if (startTime == 0L) |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1357 |
startTime = System.nanoTime(); |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1358 |
else if (millisElapsedSince(startTime) > timeoutMillis) { |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1359 |
threadAssertTrue(thread.isAlive()); |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1360 |
fail("timed out waiting for thread to enter wait state"); |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1361 |
} |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1362 |
Thread.yield(); |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1363 |
} |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1364 |
} |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1365 |
|
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1366 |
/** |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1367 |
* Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1368 |
* enter a wait state: BLOCKED, WAITING, or TIMED_WAITING. |
35394 | 1369 |
*/ |
1370 |
void waitForThreadToEnterWaitState(Thread thread) { |
|
1371 |
waitForThreadToEnterWaitState(thread, LONG_DELAY_MS); |
|
1372 |
} |
|
1373 |
||
1374 |
/** |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1375 |
* Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1376 |
* enter a wait state: BLOCKED, WAITING, or TIMED_WAITING, |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1377 |
* and additionally satisfy the given condition. |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1378 |
*/ |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1379 |
void waitForThreadToEnterWaitState( |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1380 |
Thread thread, Callable<Boolean> waitingForGodot) { |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1381 |
waitForThreadToEnterWaitState(thread, LONG_DELAY_MS, waitingForGodot); |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1382 |
} |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1383 |
|
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
43545
diff
changeset
|
1384 |
/** |
35394 | 1385 |
* Returns the number of milliseconds since time given by |
1386 |
* startNanoTime, which must have been previously returned from a |
|
1387 |
* call to {@link System#nanoTime()}. |
|
1388 |
*/ |
|
1389 |
static long millisElapsedSince(long startNanoTime) { |
|
1390 |
return NANOSECONDS.toMillis(System.nanoTime() - startNanoTime); |
|
1391 |
} |
|
1392 |
||
1393 |
// void assertTerminatesPromptly(long timeoutMillis, Runnable r) { |
|
1394 |
// long startTime = System.nanoTime(); |
|
1395 |
// try { |
|
1396 |
// r.run(); |
|
1397 |
// } catch (Throwable fail) { threadUnexpectedException(fail); } |
|
1398 |
// if (millisElapsedSince(startTime) > timeoutMillis/2) |
|
1399 |
// throw new AssertionFailedError("did not return promptly"); |
|
1400 |
// } |
|
1401 |
||
1402 |
// void assertTerminatesPromptly(Runnable r) { |
|
1403 |
// assertTerminatesPromptly(LONG_DELAY_MS/2, r); |
|
1404 |
// } |
|
1405 |
||
1406 |
/** |
|
1407 |
* Checks that timed f.get() returns the expected value, and does not |
|
1408 |
* wait for the timeout to elapse before returning. |
|
1409 |
*/ |
|
1410 |
<T> void checkTimedGet(Future<T> f, T expectedValue, long timeoutMillis) { |
|
1411 |
long startTime = System.nanoTime(); |
|
1412 |
try { |
|
1413 |
assertEquals(expectedValue, f.get(timeoutMillis, MILLISECONDS)); |
|
1414 |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
|
1415 |
if (millisElapsedSince(startTime) > timeoutMillis/2) |
|
1416 |
throw new AssertionFailedError("timed get did not return promptly"); |
|
1417 |
} |
|
1418 |
||
1419 |
<T> void checkTimedGet(Future<T> f, T expectedValue) { |
|
1420 |
checkTimedGet(f, expectedValue, LONG_DELAY_MS); |
|
1421 |
} |
|
1422 |
||
1423 |
/** |
|
1424 |
* Returns a new started daemon Thread running the given runnable. |
|
1425 |
*/ |
|
1426 |
Thread newStartedThread(Runnable runnable) { |
|
1427 |
Thread t = new Thread(runnable); |
|
1428 |
t.setDaemon(true); |
|
1429 |
t.start(); |
|
1430 |
return t; |
|
1431 |
} |
|
1432 |
||
1433 |
/** |
|
1434 |
* Waits for the specified time (in milliseconds) for the thread |
|
1435 |
* to terminate (using {@link Thread#join(long)}), else interrupts |
|
1436 |
* the thread (in the hope that it may terminate later) and fails. |
|
1437 |
*/ |
|
1438 |
void awaitTermination(Thread t, long timeoutMillis) { |
|
1439 |
try { |
|
1440 |
t.join(timeoutMillis); |
|
1441 |
} catch (InterruptedException fail) { |
|
1442 |
threadUnexpectedException(fail); |
|
1443 |
} finally { |
|
1444 |
if (t.getState() != Thread.State.TERMINATED) { |
|
1445 |
t.interrupt(); |
|
1446 |
threadFail("timed out waiting for thread to terminate"); |
|
1447 |
} |
|
1448 |
} |
|
1449 |
} |
|
1450 |
||
1451 |
/** |
|
1452 |
* Waits for LONG_DELAY_MS milliseconds for the thread to |
|
1453 |
* terminate (using {@link Thread#join(long)}), else interrupts |
|
1454 |
* the thread (in the hope that it may terminate later) and fails. |
|
1455 |
*/ |
|
1456 |
void awaitTermination(Thread t) { |
|
1457 |
awaitTermination(t, LONG_DELAY_MS); |
|
1458 |
} |
|
1459 |
||
1460 |
// Some convenient Runnable classes |
|
1461 |
||
1462 |
public abstract class CheckedRunnable implements Runnable { |
|
1463 |
protected abstract void realRun() throws Throwable; |
|
1464 |
||
1465 |
public final void run() { |
|
1466 |
try { |
|
1467 |
realRun(); |
|
1468 |
} catch (Throwable fail) { |
|
1469 |
threadUnexpectedException(fail); |
|
1470 |
} |
|
1471 |
} |
|
1472 |
} |
|
1473 |
||
1474 |
public abstract class RunnableShouldThrow implements Runnable { |
|
1475 |
protected abstract void realRun() throws Throwable; |
|
1476 |
||
1477 |
final Class<?> exceptionClass; |
|
1478 |
||
1479 |
<T extends Throwable> RunnableShouldThrow(Class<T> exceptionClass) { |
|
1480 |
this.exceptionClass = exceptionClass; |
|
1481 |
} |
|
1482 |
||
1483 |
public final void run() { |
|
1484 |
try { |
|
1485 |
realRun(); |
|
1486 |
threadShouldThrow(exceptionClass.getSimpleName()); |
|
1487 |
} catch (Throwable t) { |
|
1488 |
if (! exceptionClass.isInstance(t)) |
|
1489 |
threadUnexpectedException(t); |
|
1490 |
} |
|
1491 |
} |
|
1492 |
} |
|
1493 |
||
1494 |
public abstract class ThreadShouldThrow extends Thread { |
|
1495 |
protected abstract void realRun() throws Throwable; |
|
1496 |
||
1497 |
final Class<?> exceptionClass; |
|
1498 |
||
1499 |
<T extends Throwable> ThreadShouldThrow(Class<T> exceptionClass) { |
|
1500 |
this.exceptionClass = exceptionClass; |
|
1501 |
} |
|
1502 |
||
1503 |
public final void run() { |
|
1504 |
try { |
|
1505 |
realRun(); |
|
1506 |
threadShouldThrow(exceptionClass.getSimpleName()); |
|
1507 |
} catch (Throwable t) { |
|
1508 |
if (! exceptionClass.isInstance(t)) |
|
1509 |
threadUnexpectedException(t); |
|
1510 |
} |
|
1511 |
} |
|
1512 |
} |
|
1513 |
||
1514 |
public abstract class CheckedInterruptedRunnable implements Runnable { |
|
1515 |
protected abstract void realRun() throws Throwable; |
|
1516 |
||
1517 |
public final void run() { |
|
1518 |
try { |
|
1519 |
realRun(); |
|
1520 |
threadShouldThrow("InterruptedException"); |
|
1521 |
} catch (InterruptedException success) { |
|
1522 |
threadAssertFalse(Thread.interrupted()); |
|
1523 |
} catch (Throwable fail) { |
|
1524 |
threadUnexpectedException(fail); |
|
1525 |
} |
|
1526 |
} |
|
1527 |
} |
|
1528 |
||
1529 |
public abstract class CheckedCallable<T> implements Callable<T> { |
|
1530 |
protected abstract T realCall() throws Throwable; |
|
1531 |
||
1532 |
public final T call() { |
|
1533 |
try { |
|
1534 |
return realCall(); |
|
1535 |
} catch (Throwable fail) { |
|
1536 |
threadUnexpectedException(fail); |
|
1537 |
return null; |
|
1538 |
} |
|
1539 |
} |
|
1540 |
} |
|
1541 |
||
1542 |
public abstract class CheckedInterruptedCallable<T> |
|
1543 |
implements Callable<T> { |
|
1544 |
protected abstract T realCall() throws Throwable; |
|
1545 |
||
1546 |
public final T call() { |
|
1547 |
try { |
|
1548 |
T result = realCall(); |
|
1549 |
threadShouldThrow("InterruptedException"); |
|
1550 |
return result; |
|
1551 |
} catch (InterruptedException success) { |
|
1552 |
threadAssertFalse(Thread.interrupted()); |
|
1553 |
} catch (Throwable fail) { |
|
1554 |
threadUnexpectedException(fail); |
|
1555 |
} |
|
1556 |
return null; |
|
1557 |
} |
|
1558 |
} |
|
1559 |
||
1560 |
public static class NoOpRunnable implements Runnable { |
|
1561 |
public void run() {} |
|
1562 |
} |
|
1563 |
||
1564 |
public static class NoOpCallable implements Callable { |
|
1565 |
public Object call() { return Boolean.TRUE; } |
|
1566 |
} |
|
1567 |
||
1568 |
public static final String TEST_STRING = "a test string"; |
|
1569 |
||
1570 |
public static class StringTask implements Callable<String> { |
|
1571 |
final String value; |
|
1572 |
public StringTask() { this(TEST_STRING); } |
|
1573 |
public StringTask(String value) { this.value = value; } |
|
1574 |
public String call() { return value; } |
|
1575 |
} |
|
1576 |
||
1577 |
public Callable<String> latchAwaitingStringTask(final CountDownLatch latch) { |
|
1578 |
return new CheckedCallable<String>() { |
|
1579 |
protected String realCall() { |
|
1580 |
try { |
|
1581 |
latch.await(); |
|
1582 |
} catch (InterruptedException quittingTime) {} |
|
1583 |
return TEST_STRING; |
|
1584 |
}}; |
|
1585 |
} |
|
1586 |
||
1587 |
public Runnable countDowner(final CountDownLatch latch) { |
|
1588 |
return new CheckedRunnable() { |
|
1589 |
public void realRun() throws InterruptedException { |
|
1590 |
latch.countDown(); |
|
1591 |
}}; |
|
1592 |
} |
|
1593 |
||
1594 |
class LatchAwaiter extends CheckedRunnable { |
|
1595 |
static final int NEW = 0; |
|
1596 |
static final int RUNNING = 1; |
|
1597 |
static final int DONE = 2; |
|
1598 |
final CountDownLatch latch; |
|
1599 |
int state = NEW; |
|
1600 |
LatchAwaiter(CountDownLatch latch) { this.latch = latch; } |
|
1601 |
public void realRun() throws InterruptedException { |
|
1602 |
state = 1; |
|
1603 |
await(latch); |
|
1604 |
state = 2; |
|
1605 |
} |
|
1606 |
} |
|
1607 |
||
1608 |
public LatchAwaiter awaiter(CountDownLatch latch) { |
|
1609 |
return new LatchAwaiter(latch); |
|
1610 |
} |
|
1611 |
||
36231
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
1612 |
public void await(CountDownLatch latch, long timeoutMillis) { |
35394 | 1613 |
try { |
36231
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
1614 |
if (!latch.await(timeoutMillis, MILLISECONDS)) |
35394 | 1615 |
fail("timed out waiting for CountDownLatch for " |
36231
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
1616 |
+ (timeoutMillis/1000) + " sec"); |
35394 | 1617 |
} catch (Throwable fail) { |
1618 |
threadUnexpectedException(fail); |
|
1619 |
} |
|
1620 |
} |
|
1621 |
||
36231
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
1622 |
public void await(CountDownLatch latch) { |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
1623 |
await(latch, LONG_DELAY_MS); |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
1624 |
} |
52e0ee9847fb
8150319: ScheduledExecutorTest:testFixedDelaySequence timeout with slow VMs
dl
parents:
35768
diff
changeset
|
1625 |
|
35394 | 1626 |
public void await(Semaphore semaphore) { |
1627 |
try { |
|
1628 |
if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS)) |
|
1629 |
fail("timed out waiting for Semaphore for " |
|
1630 |
+ (LONG_DELAY_MS/1000) + " sec"); |
|
1631 |
} catch (Throwable fail) { |
|
1632 |
threadUnexpectedException(fail); |
|
1633 |
} |
|
1634 |
} |
|
1635 |
||
1636 |
// /** |
|
1637 |
// * Spin-waits up to LONG_DELAY_MS until flag becomes true. |
|
1638 |
// */ |
|
1639 |
// public void await(AtomicBoolean flag) { |
|
1640 |
// await(flag, LONG_DELAY_MS); |
|
1641 |
// } |
|
1642 |
||
1643 |
// /** |
|
1644 |
// * Spin-waits up to the specified timeout until flag becomes true. |
|
1645 |
// */ |
|
1646 |
// public void await(AtomicBoolean flag, long timeoutMillis) { |
|
1647 |
// long startTime = System.nanoTime(); |
|
1648 |
// while (!flag.get()) { |
|
1649 |
// if (millisElapsedSince(startTime) > timeoutMillis) |
|
1650 |
// throw new AssertionFailedError("timed out"); |
|
1651 |
// Thread.yield(); |
|
1652 |
// } |
|
1653 |
// } |
|
1654 |
||
1655 |
public static class NPETask implements Callable<String> { |
|
1656 |
public String call() { throw new NullPointerException(); } |
|
1657 |
} |
|
1658 |
||
1659 |
public static class CallableOne implements Callable<Integer> { |
|
1660 |
public Integer call() { return one; } |
|
1661 |
} |
|
1662 |
||
1663 |
public class ShortRunnable extends CheckedRunnable { |
|
1664 |
protected void realRun() throws Throwable { |
|
1665 |
delay(SHORT_DELAY_MS); |
|
1666 |
} |
|
1667 |
} |
|
1668 |
||
1669 |
public class ShortInterruptedRunnable extends CheckedInterruptedRunnable { |
|
1670 |
protected void realRun() throws InterruptedException { |
|
1671 |
delay(SHORT_DELAY_MS); |
|
1672 |
} |
|
1673 |
} |
|
1674 |
||
1675 |
public class SmallRunnable extends CheckedRunnable { |
|
1676 |
protected void realRun() throws Throwable { |
|
1677 |
delay(SMALL_DELAY_MS); |
|
1678 |
} |
|
1679 |
} |
|
1680 |
||
1681 |
public class SmallPossiblyInterruptedRunnable extends CheckedRunnable { |
|
1682 |
protected void realRun() { |
|
1683 |
try { |
|
1684 |
delay(SMALL_DELAY_MS); |
|
1685 |
} catch (InterruptedException ok) {} |
|
1686 |
} |
|
1687 |
} |
|
1688 |
||
1689 |
public class SmallCallable extends CheckedCallable { |
|
1690 |
protected Object realCall() throws InterruptedException { |
|
1691 |
delay(SMALL_DELAY_MS); |
|
1692 |
return Boolean.TRUE; |
|
1693 |
} |
|
1694 |
} |
|
1695 |
||
1696 |
public class MediumRunnable extends CheckedRunnable { |
|
1697 |
protected void realRun() throws Throwable { |
|
1698 |
delay(MEDIUM_DELAY_MS); |
|
1699 |
} |
|
1700 |
} |
|
1701 |
||
1702 |
public class MediumInterruptedRunnable extends CheckedInterruptedRunnable { |
|
1703 |
protected void realRun() throws InterruptedException { |
|
1704 |
delay(MEDIUM_DELAY_MS); |
|
1705 |
} |
|
1706 |
} |
|
1707 |
||
1708 |
public Runnable possiblyInterruptedRunnable(final long timeoutMillis) { |
|
1709 |
return new CheckedRunnable() { |
|
1710 |
protected void realRun() { |
|
1711 |
try { |
|
1712 |
delay(timeoutMillis); |
|
1713 |
} catch (InterruptedException ok) {} |
|
1714 |
}}; |
|
1715 |
} |
|
1716 |
||
1717 |
public class MediumPossiblyInterruptedRunnable extends CheckedRunnable { |
|
1718 |
protected void realRun() { |
|
1719 |
try { |
|
1720 |
delay(MEDIUM_DELAY_MS); |
|
1721 |
} catch (InterruptedException ok) {} |
|
1722 |
} |
|
1723 |
} |
|
1724 |
||
1725 |
public class LongPossiblyInterruptedRunnable extends CheckedRunnable { |
|
1726 |
protected void realRun() { |
|
1727 |
try { |
|
1728 |
delay(LONG_DELAY_MS); |
|
1729 |
} catch (InterruptedException ok) {} |
|
1730 |
} |
|
1731 |
} |
|
1732 |
||
1733 |
/** |
|
1734 |
* For use as ThreadFactory in constructors |
|
1735 |
*/ |
|
1736 |
public static class SimpleThreadFactory implements ThreadFactory { |
|
1737 |
public Thread newThread(Runnable r) { |
|
1738 |
return new Thread(r); |
|
1739 |
} |
|
1740 |
} |
|
1741 |
||
1742 |
public interface TrackedRunnable extends Runnable { |
|
1743 |
boolean isDone(); |
|
1744 |
} |
|
1745 |
||
1746 |
public static TrackedRunnable trackedRunnable(final long timeoutMillis) { |
|
1747 |
return new TrackedRunnable() { |
|
1748 |
private volatile boolean done = false; |
|
1749 |
public boolean isDone() { return done; } |
|
1750 |
public void run() { |
|
1751 |
try { |
|
1752 |
delay(timeoutMillis); |
|
1753 |
done = true; |
|
1754 |
} catch (InterruptedException ok) {} |
|
1755 |
} |
|
1756 |
}; |
|
1757 |
} |
|
1758 |
||
1759 |
public static class TrackedShortRunnable implements Runnable { |
|
1760 |
public volatile boolean done = false; |
|
1761 |
public void run() { |
|
1762 |
try { |
|
1763 |
delay(SHORT_DELAY_MS); |
|
1764 |
done = true; |
|
1765 |
} catch (InterruptedException ok) {} |
|
1766 |
} |
|
1767 |
} |
|
1768 |
||
1769 |
public static class TrackedSmallRunnable implements Runnable { |
|
1770 |
public volatile boolean done = false; |
|
1771 |
public void run() { |
|
1772 |
try { |
|
1773 |
delay(SMALL_DELAY_MS); |
|
1774 |
done = true; |
|
1775 |
} catch (InterruptedException ok) {} |
|
1776 |
} |
|
1777 |
} |
|
1778 |
||
1779 |
public static class TrackedMediumRunnable implements Runnable { |
|
1780 |
public volatile boolean done = false; |
|
1781 |
public void run() { |
|
1782 |
try { |
|
1783 |
delay(MEDIUM_DELAY_MS); |
|
1784 |
done = true; |
|
1785 |
} catch (InterruptedException ok) {} |
|
1786 |
} |
|
1787 |
} |
|
1788 |
||
1789 |
public static class TrackedLongRunnable implements Runnable { |
|
1790 |
public volatile boolean done = false; |
|
1791 |
public void run() { |
|
1792 |
try { |
|
1793 |
delay(LONG_DELAY_MS); |
|
1794 |
done = true; |
|
1795 |
} catch (InterruptedException ok) {} |
|
1796 |
} |
|
1797 |
} |
|
1798 |
||
1799 |
public static class TrackedNoOpRunnable implements Runnable { |
|
1800 |
public volatile boolean done = false; |
|
1801 |
public void run() { |
|
1802 |
done = true; |
|
1803 |
} |
|
1804 |
} |
|
1805 |
||
1806 |
public static class TrackedCallable implements Callable { |
|
1807 |
public volatile boolean done = false; |
|
1808 |
public Object call() { |
|
1809 |
try { |
|
1810 |
delay(SMALL_DELAY_MS); |
|
1811 |
done = true; |
|
1812 |
} catch (InterruptedException ok) {} |
|
1813 |
return Boolean.TRUE; |
|
1814 |
} |
|
1815 |
} |
|
1816 |
||
1817 |
/** |
|
1818 |
* Analog of CheckedRunnable for RecursiveAction |
|
1819 |
*/ |
|
1820 |
public abstract class CheckedRecursiveAction extends RecursiveAction { |
|
1821 |
protected abstract void realCompute() throws Throwable; |
|
1822 |
||
1823 |
@Override protected final void compute() { |
|
1824 |
try { |
|
1825 |
realCompute(); |
|
1826 |
} catch (Throwable fail) { |
|
1827 |
threadUnexpectedException(fail); |
|
1828 |
} |
|
1829 |
} |
|
1830 |
} |
|
1831 |
||
1832 |
/** |
|
1833 |
* Analog of CheckedCallable for RecursiveTask |
|
1834 |
*/ |
|
1835 |
public abstract class CheckedRecursiveTask<T> extends RecursiveTask<T> { |
|
1836 |
protected abstract T realCompute() throws Throwable; |
|
1837 |
||
1838 |
@Override protected final T compute() { |
|
1839 |
try { |
|
1840 |
return realCompute(); |
|
1841 |
} catch (Throwable fail) { |
|
1842 |
threadUnexpectedException(fail); |
|
1843 |
return null; |
|
1844 |
} |
|
1845 |
} |
|
1846 |
} |
|
1847 |
||
1848 |
/** |
|
1849 |
* For use as RejectedExecutionHandler in constructors |
|
1850 |
*/ |
|
1851 |
public static class NoOpREHandler implements RejectedExecutionHandler { |
|
1852 |
public void rejectedExecution(Runnable r, |
|
1853 |
ThreadPoolExecutor executor) {} |
|
1854 |
} |
|
1855 |
||
1856 |
/** |
|
1857 |
* A CyclicBarrier that uses timed await and fails with |
|
1858 |
* AssertionFailedErrors instead of throwing checked exceptions. |
|
1859 |
*/ |
|
41130
2004bf22423f
8166059: JSR166TestCase.java fails with NPE in dumpTestThreads on timeout
dl
parents:
40817
diff
changeset
|
1860 |
public static class CheckedBarrier extends CyclicBarrier { |
35394 | 1861 |
public CheckedBarrier(int parties) { super(parties); } |
1862 |
||
1863 |
public int await() { |
|
1864 |
try { |
|
1865 |
return super.await(2 * LONG_DELAY_MS, MILLISECONDS); |
|
1866 |
} catch (TimeoutException timedOut) { |
|
1867 |
throw new AssertionFailedError("timed out"); |
|
1868 |
} catch (Exception fail) { |
|
1869 |
AssertionFailedError afe = |
|
1870 |
new AssertionFailedError("Unexpected exception: " + fail); |
|
1871 |
afe.initCause(fail); |
|
1872 |
throw afe; |
|
1873 |
} |
|
1874 |
} |
|
1875 |
} |
|
1876 |
||
1877 |
void checkEmpty(BlockingQueue q) { |
|
1878 |
try { |
|
1879 |
assertTrue(q.isEmpty()); |
|
1880 |
assertEquals(0, q.size()); |
|
1881 |
assertNull(q.peek()); |
|
1882 |
assertNull(q.poll()); |
|
1883 |
assertNull(q.poll(0, MILLISECONDS)); |
|
1884 |
assertEquals(q.toString(), "[]"); |
|
1885 |
assertTrue(Arrays.equals(q.toArray(), new Object[0])); |
|
1886 |
assertFalse(q.iterator().hasNext()); |
|
1887 |
try { |
|
1888 |
q.element(); |
|
1889 |
shouldThrow(); |
|
1890 |
} catch (NoSuchElementException success) {} |
|
1891 |
try { |
|
1892 |
q.iterator().next(); |
|
1893 |
shouldThrow(); |
|
1894 |
} catch (NoSuchElementException success) {} |
|
1895 |
try { |
|
1896 |
q.remove(); |
|
1897 |
shouldThrow(); |
|
1898 |
} catch (NoSuchElementException success) {} |
|
1899 |
} catch (InterruptedException fail) { threadUnexpectedException(fail); } |
|
1900 |
} |
|
1901 |
||
1902 |
void assertSerialEquals(Object x, Object y) { |
|
1903 |
assertTrue(Arrays.equals(serialBytes(x), serialBytes(y))); |
|
1904 |
} |
|
1905 |
||
1906 |
void assertNotSerialEquals(Object x, Object y) { |
|
1907 |
assertFalse(Arrays.equals(serialBytes(x), serialBytes(y))); |
|
1908 |
} |
|
1909 |
||
1910 |
byte[] serialBytes(Object o) { |
|
1911 |
try { |
|
1912 |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
|
1913 |
ObjectOutputStream oos = new ObjectOutputStream(bos); |
|
1914 |
oos.writeObject(o); |
|
1915 |
oos.flush(); |
|
1916 |
oos.close(); |
|
1917 |
return bos.toByteArray(); |
|
1918 |
} catch (Throwable fail) { |
|
1919 |
threadUnexpectedException(fail); |
|
1920 |
return new byte[0]; |
|
1921 |
} |
|
1922 |
} |
|
1923 |
||
42319 | 1924 |
void assertImmutable(final Object o) { |
1925 |
if (o instanceof Collection) { |
|
1926 |
assertThrows( |
|
1927 |
UnsupportedOperationException.class, |
|
1928 |
new Runnable() { public void run() { |
|
1929 |
((Collection) o).add(null);}}); |
|
1930 |
} |
|
1931 |
} |
|
1932 |
||
35394 | 1933 |
@SuppressWarnings("unchecked") |
1934 |
<T> T serialClone(T o) { |
|
1935 |
try { |
|
1936 |
ObjectInputStream ois = new ObjectInputStream |
|
1937 |
(new ByteArrayInputStream(serialBytes(o))); |
|
1938 |
T clone = (T) ois.readObject(); |
|
42319 | 1939 |
if (o == clone) assertImmutable(o); |
35394 | 1940 |
assertSame(o.getClass(), clone.getClass()); |
1941 |
return clone; |
|
1942 |
} catch (Throwable fail) { |
|
1943 |
threadUnexpectedException(fail); |
|
1944 |
return null; |
|
1945 |
} |
|
1946 |
} |
|
1947 |
||
42319 | 1948 |
/** |
1949 |
* A version of serialClone that leaves error handling (for |
|
1950 |
* e.g. NotSerializableException) up to the caller. |
|
1951 |
*/ |
|
1952 |
@SuppressWarnings("unchecked") |
|
1953 |
<T> T serialClonePossiblyFailing(T o) |
|
1954 |
throws ReflectiveOperationException, java.io.IOException { |
|
1955 |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
|
1956 |
ObjectOutputStream oos = new ObjectOutputStream(bos); |
|
1957 |
oos.writeObject(o); |
|
1958 |
oos.flush(); |
|
1959 |
oos.close(); |
|
1960 |
ObjectInputStream ois = new ObjectInputStream |
|
1961 |
(new ByteArrayInputStream(bos.toByteArray())); |
|
1962 |
T clone = (T) ois.readObject(); |
|
1963 |
if (o == clone) assertImmutable(o); |
|
1964 |
assertSame(o.getClass(), clone.getClass()); |
|
1965 |
return clone; |
|
1966 |
} |
|
1967 |
||
1968 |
/** |
|
1969 |
* If o implements Cloneable and has a public clone method, |
|
1970 |
* returns a clone of o, else null. |
|
1971 |
*/ |
|
1972 |
@SuppressWarnings("unchecked") |
|
1973 |
<T> T cloneableClone(T o) { |
|
1974 |
if (!(o instanceof Cloneable)) return null; |
|
1975 |
final T clone; |
|
1976 |
try { |
|
1977 |
clone = (T) o.getClass().getMethod("clone").invoke(o); |
|
1978 |
} catch (NoSuchMethodException ok) { |
|
1979 |
return null; |
|
1980 |
} catch (ReflectiveOperationException unexpected) { |
|
1981 |
throw new Error(unexpected); |
|
1982 |
} |
|
1983 |
assertNotSame(o, clone); // not 100% guaranteed by spec |
|
1984 |
assertSame(o.getClass(), clone.getClass()); |
|
1985 |
return clone; |
|
1986 |
} |
|
1987 |
||
35394 | 1988 |
public void assertThrows(Class<? extends Throwable> expectedExceptionClass, |
1989 |
Runnable... throwingActions) { |
|
1990 |
for (Runnable throwingAction : throwingActions) { |
|
1991 |
boolean threw = false; |
|
1992 |
try { throwingAction.run(); } |
|
1993 |
catch (Throwable t) { |
|
1994 |
threw = true; |
|
1995 |
if (!expectedExceptionClass.isInstance(t)) { |
|
1996 |
AssertionFailedError afe = |
|
1997 |
new AssertionFailedError |
|
1998 |
("Expected " + expectedExceptionClass.getName() + |
|
1999 |
", got " + t.getClass().getName()); |
|
2000 |
afe.initCause(t); |
|
2001 |
threadUnexpectedException(afe); |
|
2002 |
} |
|
2003 |
} |
|
2004 |
if (!threw) |
|
2005 |
shouldThrow(expectedExceptionClass.getName()); |
|
2006 |
} |
|
2007 |
} |
|
2008 |
||
2009 |
public void assertIteratorExhausted(Iterator<?> it) { |
|
2010 |
try { |
|
2011 |
it.next(); |
|
2012 |
shouldThrow(); |
|
2013 |
} catch (NoSuchElementException success) {} |
|
2014 |
assertFalse(it.hasNext()); |
|
2015 |
} |
|
38551
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2016 |
|
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2017 |
public <T> Callable<T> callableThrowing(final Exception ex) { |
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2018 |
return new Callable<T>() { public T call() throws Exception { throw ex; }}; |
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2019 |
} |
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2020 |
|
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2021 |
public Runnable runnableThrowing(final RuntimeException ex) { |
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2022 |
return new Runnable() { public void run() { throw ex; }}; |
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2023 |
} |
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2024 |
|
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2025 |
/** A reusable thread pool to be shared by tests. */ |
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2026 |
static final ExecutorService cachedThreadPool = |
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2027 |
new ThreadPoolExecutor(0, Integer.MAX_VALUE, |
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2028 |
1000L, MILLISECONDS, |
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2029 |
new SynchronousQueue<Runnable>()); |
82c48058acc2
8153768: Miscellaneous changes imported from jsr166 CVS 2016-05
dl
parents:
36957
diff
changeset
|
2030 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39879
diff
changeset
|
2031 |
static <T> void shuffle(T[] array) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39879
diff
changeset
|
2032 |
Collections.shuffle(Arrays.asList(array), ThreadLocalRandom.current()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39879
diff
changeset
|
2033 |
} |
35394 | 2034 |
} |