49 |
|
} |
50 |
|
|
51 |
|
private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) { |
52 |
< |
try { |
52 |
> |
try (PoolCleaner cleaner = cleaner(pool)) { |
53 |
|
assertFalse(a.isDone()); |
54 |
|
assertFalse(a.isCompletedNormally()); |
55 |
|
assertFalse(a.isCompletedAbnormally()); |
65 |
|
assertFalse(a.isCancelled()); |
66 |
|
assertNull(a.getException()); |
67 |
|
assertNull(a.getRawResult()); |
68 |
– |
} finally { |
69 |
– |
joinPool(pool); |
68 |
|
} |
69 |
|
} |
70 |
|
|
93 |
|
|
94 |
|
{ |
95 |
|
Thread.currentThread().interrupt(); |
96 |
< |
long t0 = System.nanoTime(); |
96 |
> |
long startTime = System.nanoTime(); |
97 |
|
assertNull(a.join()); |
98 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
98 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
99 |
|
Thread.interrupted(); |
100 |
|
} |
101 |
|
|
102 |
|
{ |
103 |
|
Thread.currentThread().interrupt(); |
104 |
< |
long t0 = System.nanoTime(); |
104 |
> |
long startTime = System.nanoTime(); |
105 |
|
a.quietlyJoin(); // should be no-op |
106 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
106 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
107 |
|
Thread.interrupted(); |
108 |
|
} |
109 |
|
|
136 |
|
Thread.interrupted(); |
137 |
|
|
138 |
|
{ |
139 |
< |
long t0 = System.nanoTime(); |
139 |
> |
long startTime = System.nanoTime(); |
140 |
|
a.quietlyJoin(); // should be no-op |
141 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
141 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
142 |
|
} |
143 |
|
|
144 |
|
try { |
174 |
|
Thread.interrupted(); |
175 |
|
|
176 |
|
{ |
177 |
< |
long t0 = System.nanoTime(); |
177 |
> |
long startTime = System.nanoTime(); |
178 |
|
a.quietlyJoin(); // should be no-op |
179 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
179 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
180 |
|
} |
181 |
|
|
182 |
|
try { |
278 |
|
final class NoopCC extends CheckedCC { |
279 |
|
NoopCC() { super(); } |
280 |
|
NoopCC(CountedCompleter p) { super(p); } |
281 |
+ |
NoopCC(CountedCompleter p, int initialPendingCount) { |
282 |
+ |
super(p, initialPendingCount); |
283 |
+ |
} |
284 |
|
protected void realCompute() {} |
285 |
|
} |
286 |
|
|
299 |
|
void testComplete(NoopCC cc, Object x, int pendingCount) { |
300 |
|
cc.setPendingCount(pendingCount); |
301 |
|
cc.checkCompletes(x); |
302 |
+ |
assertEquals(pendingCount, cc.getPendingCount()); |
303 |
|
} |
304 |
|
|
305 |
|
/** |
313 |
|
} |
314 |
|
|
315 |
|
/** |
316 |
< |
* completeExceptionally(null) throws NullPointerException |
316 |
> |
* completeExceptionally(null) surprisingly has the same effect as |
317 |
> |
* completeExceptionally(new RuntimeException()) |
318 |
|
*/ |
319 |
|
public void testCompleteExceptionally_null() { |
320 |
+ |
NoopCC a = new NoopCC(); |
321 |
+ |
a.completeExceptionally(null); |
322 |
|
try { |
323 |
< |
new NoopCC() |
319 |
< |
.checkCompletesExceptionally(null); |
323 |
> |
a.invoke(); |
324 |
|
shouldThrow(); |
325 |
< |
} catch (NullPointerException success) {} |
325 |
> |
} catch (RuntimeException success) { |
326 |
> |
assertSame(success.getClass(), RuntimeException.class); |
327 |
> |
assertNull(success.getCause()); |
328 |
> |
a.checkCompletedExceptionally(success); |
329 |
> |
} |
330 |
|
} |
331 |
|
|
332 |
|
/** |
335 |
|
public void testSetPendingCount() { |
336 |
|
NoopCC a = new NoopCC(); |
337 |
|
assertEquals(0, a.getPendingCount()); |
338 |
< |
a.setPendingCount(1); |
339 |
< |
assertEquals(1, a.getPendingCount()); |
340 |
< |
a.setPendingCount(27); |
341 |
< |
assertEquals(27, a.getPendingCount()); |
338 |
> |
int[] vals = { |
339 |
> |
-1, 0, 1, |
340 |
> |
Integer.MIN_VALUE, |
341 |
> |
Integer.MAX_VALUE, |
342 |
> |
}; |
343 |
> |
for (int val : vals) { |
344 |
> |
a.setPendingCount(val); |
345 |
> |
assertEquals(val, a.getPendingCount()); |
346 |
> |
} |
347 |
|
} |
348 |
|
|
349 |
|
/** |
356 |
|
assertEquals(1, a.getPendingCount()); |
357 |
|
a.addToPendingCount(27); |
358 |
|
assertEquals(28, a.getPendingCount()); |
359 |
+ |
a.addToPendingCount(-28); |
360 |
+ |
assertEquals(0, a.getPendingCount()); |
361 |
|
} |
362 |
|
|
363 |
|
/** |
364 |
|
* decrementPendingCountUnlessZero decrements reported pending |
365 |
|
* count unless zero |
366 |
|
*/ |
367 |
< |
public void testDecrementPendingCount() { |
368 |
< |
NoopCC a = new NoopCC(); |
369 |
< |
assertEquals(0, a.getPendingCount()); |
370 |
< |
a.addToPendingCount(1); |
367 |
> |
public void testDecrementPendingCountUnlessZero() { |
368 |
> |
NoopCC a = new NoopCC(null, 2); |
369 |
> |
assertEquals(2, a.getPendingCount()); |
370 |
> |
assertEquals(2, a.decrementPendingCountUnlessZero()); |
371 |
|
assertEquals(1, a.getPendingCount()); |
372 |
< |
a.decrementPendingCountUnlessZero(); |
372 |
> |
assertEquals(1, a.decrementPendingCountUnlessZero()); |
373 |
|
assertEquals(0, a.getPendingCount()); |
374 |
< |
a.decrementPendingCountUnlessZero(); |
374 |
> |
assertEquals(0, a.decrementPendingCountUnlessZero()); |
375 |
|
assertEquals(0, a.getPendingCount()); |
376 |
+ |
a.setPendingCount(-1); |
377 |
+ |
assertEquals(-1, a.decrementPendingCountUnlessZero()); |
378 |
+ |
assertEquals(-2, a.getPendingCount()); |
379 |
|
} |
380 |
|
|
381 |
|
/** |