author | dl |
Fri, 03 Feb 2017 13:24:59 -0800 | |
changeset 43522 | f9c6f543c4db |
parent 42318 | 35806bea1e90 |
child 45288 | 58be10a068c2 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
34516
3bcd03288484
8144880: Instrument intermittently failing test ConfigChanges.java
darcy
parents:
34347
diff
changeset
|
2 |
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6450200 |
|
27 |
* @summary Test proper handling of pool state changes |
|
34516
3bcd03288484
8144880: Instrument intermittently failing test ConfigChanges.java
darcy
parents:
34347
diff
changeset
|
28 |
* @library /lib/testlibrary/ |
3bcd03288484
8144880: Instrument intermittently failing test ConfigChanges.java
darcy
parents:
34347
diff
changeset
|
29 |
* @build jdk.testlibrary.RandomFactory |
2 | 30 |
* @run main/othervm ConfigChanges |
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
31 |
* @key randomness |
2 | 32 |
* @author Martin Buchholz |
33 |
*/ |
|
34 |
||
34347 | 35 |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
36 |
import static java.util.concurrent.TimeUnit.MINUTES; |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
37 |
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
34347 | 38 |
|
39 |
import java.security.Permission; |
|
40 |
import java.util.Random; |
|
41 |
import java.util.concurrent.ArrayBlockingQueue; |
|
42 |
import java.util.concurrent.CyclicBarrier; |
|
43 |
import java.util.concurrent.ExecutorService; |
|
44 |
import java.util.concurrent.RejectedExecutionException; |
|
45 |
import java.util.concurrent.ThreadFactory; |
|
46 |
import java.util.concurrent.ThreadPoolExecutor; |
|
43522
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
47 |
import java.util.function.Supplier; |
34516
3bcd03288484
8144880: Instrument intermittently failing test ConfigChanges.java
darcy
parents:
34347
diff
changeset
|
48 |
import jdk.testlibrary.RandomFactory; |
2 | 49 |
|
50 |
public class ConfigChanges { |
|
7518 | 51 |
static final ThreadGroup tg = new ThreadGroup("pool"); |
2 | 52 |
|
34516
3bcd03288484
8144880: Instrument intermittently failing test ConfigChanges.java
darcy
parents:
34347
diff
changeset
|
53 |
static final Random rnd = RandomFactory.getRandom(); |
2 | 54 |
|
55 |
static void report(ThreadPoolExecutor tpe) { |
|
56 |
try { |
|
57 |
System.out.printf( |
|
58 |
"active=%d submitted=%d completed=%d queued=%d sizes=%d/%d/%d%n", |
|
59 |
tg.activeCount(), |
|
60 |
tpe.getTaskCount(), |
|
61 |
tpe.getCompletedTaskCount(), |
|
62 |
tpe.getQueue().size(), |
|
63 |
tpe.getPoolSize(), |
|
64 |
tpe.getCorePoolSize(), |
|
65 |
tpe.getMaximumPoolSize()); |
|
66 |
} catch (Throwable t) { unexpected(t); } |
|
67 |
} |
|
68 |
||
69 |
static void report(String label, ThreadPoolExecutor tpe) { |
|
70 |
System.out.printf("%10s ", label); |
|
71 |
report(tpe); |
|
72 |
} |
|
73 |
||
74 |
static class PermissiveSecurityManger extends SecurityManager { |
|
75 |
public void checkPermission(Permission p) { /* bien sur, Monsieur */ } |
|
76 |
} |
|
77 |
||
78 |
static void checkShutdown(final ExecutorService es) { |
|
79 |
final Runnable nop = new Runnable() {public void run() {}}; |
|
80 |
try { |
|
81 |
if (new Random().nextBoolean()) { |
|
82 |
check(es.isShutdown()); |
|
83 |
if (es instanceof ThreadPoolExecutor) |
|
84 |
check(((ThreadPoolExecutor) es).isTerminating() |
|
85 |
|| es.isTerminated()); |
|
86 |
THROWS(RejectedExecutionException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
7668
diff
changeset
|
87 |
() -> es.execute(nop)); |
2 | 88 |
} |
89 |
} catch (Throwable t) { unexpected(t); } |
|
90 |
} |
|
91 |
||
92 |
static void checkTerminated(final ThreadPoolExecutor tpe) { |
|
93 |
try { |
|
94 |
checkShutdown(tpe); |
|
95 |
check(tpe.getQueue().isEmpty()); |
|
96 |
check(tpe.isTerminated()); |
|
97 |
check(! tpe.isTerminating()); |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
98 |
equal(0, tpe.getActiveCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
99 |
equal(0, tpe.getPoolSize()); |
2 | 100 |
equal(tpe.getTaskCount(), tpe.getCompletedTaskCount()); |
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
101 |
check(tpe.awaitTermination(0L, MINUTES)); |
2 | 102 |
} catch (Throwable t) { unexpected(t); } |
103 |
} |
|
104 |
||
105 |
static Runnable waiter(final CyclicBarrier barrier) { |
|
106 |
return new Runnable() { public void run() { |
|
107 |
try { barrier.await(); barrier.await(); } |
|
108 |
catch (Throwable t) { unexpected(t); }}}; |
|
109 |
} |
|
110 |
||
111 |
static volatile Runnable runnableDuJour; |
|
112 |
||
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
113 |
static void awaitIdleness(ThreadPoolExecutor tpe, long taskCount) { |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
114 |
restart: for (;;) { |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
115 |
// check twice to make chance of race vanishingly small |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
116 |
for (int i = 0; i < 2; i++) { |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
117 |
if (tpe.getQueue().size() != 0 || |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
118 |
tpe.getActiveCount() != 0 || |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
119 |
tpe.getCompletedTaskCount() != taskCount) { |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
120 |
Thread.yield(); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
121 |
continue restart; |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
122 |
} |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
123 |
} |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
124 |
return; |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
125 |
} |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
126 |
} |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
127 |
|
43522
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
128 |
/** |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
129 |
* Waits for condition to become true, first spin-polling, then sleep-polling. |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
130 |
*/ |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
131 |
static void spinAwait(Supplier<Boolean> waitingForGodot) { |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
132 |
for (int spins = 0; !waitingForGodot.get(); ) { |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
133 |
if ((spins = (spins + 1) & 3) > 0) { |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
134 |
Thread.yield(); |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
135 |
} else { |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
136 |
try { Thread.sleep(4); } |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
137 |
catch (InterruptedException unexpected) { |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
138 |
throw new AssertionError(unexpected); |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
139 |
} |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
140 |
} |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
141 |
} |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
142 |
} |
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
143 |
|
2 | 144 |
private static void realMain(String[] args) throws Throwable { |
145 |
if (rnd.nextBoolean()) |
|
146 |
System.setSecurityManager(new PermissiveSecurityManger()); |
|
147 |
||
148 |
final boolean prestart = rnd.nextBoolean(); |
|
149 |
||
150 |
final Thread.UncaughtExceptionHandler handler |
|
151 |
= new Thread.UncaughtExceptionHandler() { |
|
152 |
public void uncaughtException(Thread t, Throwable e) { |
|
153 |
check(! Thread.currentThread().isInterrupted()); |
|
154 |
unexpected(e); |
|
155 |
}}; |
|
156 |
||
157 |
final int n = 3; |
|
158 |
final ThreadPoolExecutor tpe |
|
159 |
= new ThreadPoolExecutor(n, 3*n, |
|
160 |
3L, MINUTES, |
|
161 |
new ArrayBlockingQueue<Runnable>(3*n)); |
|
162 |
tpe.setThreadFactory(new ThreadFactory() { |
|
163 |
public Thread newThread(Runnable r) { |
|
164 |
Thread t = new Thread(tg, r); |
|
165 |
t.setUncaughtExceptionHandler(handler); |
|
166 |
return t; |
|
167 |
}}); |
|
168 |
||
169 |
if (prestart) { |
|
170 |
tpe.prestartAllCoreThreads(); |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
171 |
equal(n, tg.activeCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
172 |
equal(n, tpe.getCorePoolSize()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
173 |
equal(n, tpe.getLargestPoolSize()); |
2 | 174 |
} |
175 |
||
176 |
final Runnable runRunnableDuJour = |
|
177 |
new Runnable() { public void run() { |
|
178 |
// Delay choice of action till last possible moment. |
|
179 |
runnableDuJour.run(); }}; |
|
180 |
final CyclicBarrier pumpedUp = new CyclicBarrier(3*n + 1); |
|
181 |
runnableDuJour = waiter(pumpedUp); |
|
182 |
||
183 |
if (prestart) { |
|
184 |
for (int i = 0; i < 1*n; i++) |
|
185 |
tpe.execute(runRunnableDuJour); |
|
186 |
// Wait for prestarted threads to dequeue their initial tasks. |
|
187 |
while (! tpe.getQueue().isEmpty()) |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
188 |
Thread.sleep(1); |
2 | 189 |
for (int i = 0; i < 5*n; i++) |
190 |
tpe.execute(runRunnableDuJour); |
|
191 |
} else { |
|
192 |
for (int i = 0; i < 6*n; i++) |
|
193 |
tpe.execute(runRunnableDuJour); |
|
194 |
} |
|
195 |
||
196 |
//report("submitted", tpe); |
|
197 |
pumpedUp.await(); |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
198 |
equal(3*n, tg.activeCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
199 |
equal(3*n, tpe.getMaximumPoolSize()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
200 |
equal(3*n, tpe.getLargestPoolSize()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
201 |
equal(n, tpe.getCorePoolSize()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
202 |
equal(3*n, tpe.getActiveCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
203 |
equal(6L*n, tpe.getTaskCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
204 |
equal(0L, tpe.getCompletedTaskCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
205 |
|
2 | 206 |
//report("pumped up", tpe); |
207 |
tpe.setMaximumPoolSize(4*n); |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
208 |
equal(4*n, tpe.getMaximumPoolSize()); |
2 | 209 |
//report("pumped up2", tpe); |
210 |
final CyclicBarrier pumpedUp2 = new CyclicBarrier(n + 1); |
|
211 |
runnableDuJour = waiter(pumpedUp2); |
|
212 |
for (int i = 0; i < 1*n; i++) |
|
213 |
tpe.execute(runRunnableDuJour); |
|
214 |
pumpedUp2.await(); |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
215 |
equal(4*n, tg.activeCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
216 |
equal(4*n, tpe.getMaximumPoolSize()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
217 |
equal(4*n, tpe.getLargestPoolSize()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
218 |
equal(4*n, tpe.getActiveCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
219 |
equal(7L*n, tpe.getTaskCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
220 |
equal(0L, tpe.getCompletedTaskCount()); |
2 | 221 |
//report("pumped up2", tpe); |
222 |
runnableDuJour = new Runnable() { public void run() {}}; |
|
223 |
||
224 |
tpe.setMaximumPoolSize(2*n); |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
225 |
//report("after setMaximumPoolSize", tpe); |
2 | 226 |
|
227 |
pumpedUp2.await(); |
|
228 |
pumpedUp.await(); |
|
229 |
||
43522
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
230 |
spinAwait(() -> tg.activeCount() == 2*n); |
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
231 |
equal(2*n, tpe.getMaximumPoolSize()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
232 |
equal(4*n, tpe.getLargestPoolSize()); |
2 | 233 |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
234 |
//report("draining", tpe); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
235 |
awaitIdleness(tpe, 7L*n); |
2 | 236 |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
237 |
equal(2*n, tg.activeCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
238 |
equal(2*n, tpe.getMaximumPoolSize()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
239 |
equal(4*n, tpe.getLargestPoolSize()); |
2 | 240 |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
241 |
equal(7L*n, tpe.getTaskCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
242 |
equal(7L*n, tpe.getCompletedTaskCount()); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
243 |
equal(0, tpe.getActiveCount()); |
2 | 244 |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
245 |
equal(3L, tpe.getKeepAliveTime(MINUTES)); |
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
246 |
long t0 = System.nanoTime(); |
2 | 247 |
tpe.setKeepAliveTime(7L, MILLISECONDS); |
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
248 |
equal(7L, tpe.getKeepAliveTime(MILLISECONDS)); |
43522
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
249 |
spinAwait(() -> tg.activeCount() == n); |
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
250 |
check(System.nanoTime() - t0 >= tpe.getKeepAliveTime(NANOSECONDS)); |
2 | 251 |
|
252 |
//report("idle", tpe); |
|
253 |
check(! tpe.allowsCoreThreadTimeOut()); |
|
40816
9756dfcba32e
8139237: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java fails intermittently
dl
parents:
34516
diff
changeset
|
254 |
t0 = System.nanoTime(); |
2 | 255 |
tpe.allowCoreThreadTimeOut(true); |
256 |
check(tpe.allowsCoreThreadTimeOut()); |
|
43522
f9c6f543c4db
8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents:
42318
diff
changeset
|
257 |
spinAwait(() -> tg.activeCount() == 0); |
42318
35806bea1e90
8169243: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java still fails intermittently
dl
parents:
40816
diff
changeset
|
258 |
|
35806bea1e90
8169243: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java still fails intermittently
dl
parents:
40816
diff
changeset
|
259 |
// The following assertion is almost always true, but may |
35806bea1e90
8169243: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java still fails intermittently
dl
parents:
40816
diff
changeset
|
260 |
// exceptionally not be during a transition from core count |
35806bea1e90
8169243: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java still fails intermittently
dl
parents:
40816
diff
changeset
|
261 |
// too high to allowCoreThreadTimeOut. Users will never |
35806bea1e90
8169243: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java still fails intermittently
dl
parents:
40816
diff
changeset
|
262 |
// notice, and we accept the small loss of testability. |
35806bea1e90
8169243: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java still fails intermittently
dl
parents:
40816
diff
changeset
|
263 |
// |
35806bea1e90
8169243: java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java still fails intermittently
dl
parents:
40816
diff
changeset
|
264 |
// check(System.nanoTime() - t0 >= tpe.getKeepAliveTime(NANOSECONDS)); |
2 | 265 |
|
266 |
//report("idle", tpe); |
|
267 |
||
268 |
tpe.shutdown(); |
|
269 |
checkShutdown(tpe); |
|
270 |
check(tpe.awaitTermination(3L, MINUTES)); |
|
271 |
checkTerminated(tpe); |
|
272 |
} |
|
273 |
||
274 |
//--------------------- Infrastructure --------------------------- |
|
275 |
static volatile int passed = 0, failed = 0; |
|
276 |
static void pass() {passed++;} |
|
277 |
static void fail() {failed++; Thread.dumpStack();} |
|
278 |
static void fail(String msg) {System.out.println(msg); fail();} |
|
279 |
static void unexpected(Throwable t) {failed++; t.printStackTrace();} |
|
280 |
static void check(boolean cond) {if (cond) pass(); else fail();} |
|
281 |
static void equal(Object x, Object y) { |
|
282 |
if (x == null ? y == null : x.equals(y)) pass(); |
|
283 |
else fail(x + " not equal to " + y);} |
|
284 |
public static void main(String[] args) throws Throwable { |
|
285 |
try {realMain(args);} catch (Throwable t) {unexpected(t);} |
|
286 |
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); |
|
287 |
if (failed > 0) throw new AssertionError("Some tests failed");} |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
7668
diff
changeset
|
288 |
interface Fun {void f() throws Throwable;} |
2 | 289 |
static void THROWS(Class<? extends Throwable> k, Fun... fs) { |
290 |
for (Fun f : fs) |
|
291 |
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } |
|
292 |
catch (Throwable t) { |
|
293 |
if (k.isAssignableFrom(t.getClass())) pass(); |
|
294 |
else unexpected(t);}} |
|
295 |
} |