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