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.38 by jsr166, Sun May 14 00:38:16 2017 UTC vs.
Revision 1.41 by jsr166, Sun May 14 04:18:31 2017 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;
15  
16   import junit.framework.AssertionFailedError;
17   import junit.framework.Test;
# Line 193 | Line 194 | public class SemaphoreTest extends JSR16
194      /**
195       * timed tryAcquire times out
196       */
197 <    public void testTryAcquire_timeout()      { testTryAcquire_timeout(false); }
198 <    public void testTryAcquire_timeout_fair() { testTryAcquire_timeout(true); }
199 <    public void testTryAcquire_timeout(boolean fair) {
200 <        Semaphore s = new Semaphore(0, fair);
200 <        long startTime = System.nanoTime();
197 >    public void testTryAcquire_timeout() {
198 >        final boolean fair = ThreadLocalRandom.current().nextBoolean();
199 >        final Semaphore s = new Semaphore(0, fair);
200 >        final long startTime = System.nanoTime();
201          try { assertFalse(s.tryAcquire(timeoutMillis(), MILLISECONDS)); }
202          catch (InterruptedException e) { threadUnexpectedException(e); }
203          assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
# Line 206 | Line 206 | public class SemaphoreTest extends JSR16
206      /**
207       * timed tryAcquire(N) times out
208       */
209 <    public void testTryAcquireN_timeout()      { testTryAcquireN_timeout(false); }
210 <    public void testTryAcquireN_timeout_fair() { testTryAcquireN_timeout(true); }
211 <    public void testTryAcquireN_timeout(boolean fair) {
212 <        Semaphore s = new Semaphore(2, fair);
213 <        long startTime = System.nanoTime();
209 >    public void testTryAcquireN_timeout() {
210 >        final boolean fair = ThreadLocalRandom.current().nextBoolean();
211 >        final Semaphore s = new Semaphore(2, fair);
212 >        final long startTime = System.nanoTime();
213          try { assertFalse(s.tryAcquire(3, timeoutMillis(), MILLISECONDS)); }
214          catch (InterruptedException e) { threadUnexpectedException(e); }
215          assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
# Line 272 | Line 271 | public class SemaphoreTest extends JSR16
271              assertThreadBlocks(t, acquirer.parkedState());
272              t.interrupt();
273          }
274 <        
274 >
275          awaitTermination(t);
276      }
277  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines