ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/SemaphoreTest.java
(Generate patch)

Comparing jsr166/src/test/tck/SemaphoreTest.java (file contents):
Revision 1.43 by jsr166, Tue Jan 23 20:44:11 2018 UTC vs.
Revision 1.45 by jsr166, Tue Aug 13 00:46:27 2019 UTC

# Line 11 | Line 11 | import static java.util.concurrent.TimeU
11   import java.util.Collection;
12   import java.util.concurrent.CountDownLatch;
13   import java.util.concurrent.Semaphore;
14 import java.util.concurrent.ThreadLocalRandom;
14  
15   import junit.framework.Test;
16   import junit.framework.TestSuite;
# Line 193 | Line 192 | public class SemaphoreTest extends JSR16
192      /**
193       * timed tryAcquire times out
194       */
195 <    public void testTryAcquire_timeout() {
196 <        final boolean fair = ThreadLocalRandom.current().nextBoolean();
195 >    public void testTryAcquire_timeout() throws InterruptedException {
196 >        final boolean fair = randomBoolean();
197          final Semaphore s = new Semaphore(0, fair);
198          final long startTime = System.nanoTime();
199 <        try { assertFalse(s.tryAcquire(timeoutMillis(), MILLISECONDS)); }
201 <        catch (InterruptedException e) { threadUnexpectedException(e); }
199 >        assertFalse(s.tryAcquire(timeoutMillis(), MILLISECONDS));
200          assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
201      }
202  
203      /**
204       * timed tryAcquire(N) times out
205       */
206 <    public void testTryAcquireN_timeout() {
207 <        final boolean fair = ThreadLocalRandom.current().nextBoolean();
206 >    public void testTryAcquireN_timeout() throws InterruptedException {
207 >        final boolean fair = randomBoolean();
208          final Semaphore s = new Semaphore(2, fair);
209          final long startTime = System.nanoTime();
210 <        try { assertFalse(s.tryAcquire(3, timeoutMillis(), MILLISECONDS)); }
213 <        catch (InterruptedException e) { threadUnexpectedException(e); }
210 >        assertFalse(s.tryAcquire(3, timeoutMillis(), MILLISECONDS));
211          assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
212      }
213  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines