13 |
|
import java.util.concurrent.Semaphore; |
14 |
|
import java.util.concurrent.ThreadLocalRandom; |
15 |
|
|
16 |
– |
import junit.framework.AssertionFailedError; |
16 |
|
import junit.framework.Test; |
17 |
|
import junit.framework.TestSuite; |
18 |
|
|
73 |
|
long startTime = System.nanoTime(); |
74 |
|
while (!s.hasQueuedThread(t)) { |
75 |
|
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
76 |
< |
throw new AssertionFailedError("timed out"); |
76 |
> |
throw new AssertionError("timed out"); |
77 |
|
Thread.yield(); |
78 |
|
} |
79 |
|
assertTrue(s.hasQueuedThreads()); |
87 |
|
long startTime = System.nanoTime(); |
88 |
|
while (!s.hasQueuedThreads()) { |
89 |
|
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
90 |
< |
throw new AssertionFailedError("timed out"); |
90 |
> |
throw new AssertionError("timed out"); |
91 |
|
Thread.yield(); |
92 |
|
} |
93 |
|
} |
607 |
|
Thread t2 = newStartedThread(new CheckedRunnable() { |
608 |
|
public void realRun() throws InterruptedException { |
609 |
|
// Will fail, even though 1 permit is available |
610 |
< |
assertFalse(s.tryAcquire(0L, MILLISECONDS)); |
611 |
< |
assertFalse(s.tryAcquire(1, 0L, MILLISECONDS)); |
610 |
> |
assertFalse( |
611 |
> |
s.tryAcquire(randomExpiredTimeout(), randomTimeUnit())); |
612 |
> |
assertFalse( |
613 |
> |
s.tryAcquire(1, randomExpiredTimeout(), randomTimeUnit())); |
614 |
|
|
615 |
|
// untimed tryAcquire will barge and succeed |
616 |
|
assertTrue(s.tryAcquire()); |