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.39 by jsr166, Sun May 14 03:31:53 2017 UTC vs.
Revision 1.43 by jsr166, Tue Jan 23 20:44:11 2018 UTC

# Line 13 | Line 13 | import java.util.concurrent.CountDownLat
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  
# Line 74 | Line 73 | public class SemaphoreTest extends JSR16
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());
# Line 88 | Line 87 | public class SemaphoreTest extends JSR16
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      }
# Line 195 | Line 194 | public class SemaphoreTest extends JSR16
194       * timed tryAcquire times out
195       */
196      public void testTryAcquire_timeout() {
197 <        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
199 <        final boolean fair = rnd.nextBoolean();
197 >        final boolean fair = ThreadLocalRandom.current().nextBoolean();
198          final Semaphore s = new Semaphore(0, fair);
199          final long startTime = System.nanoTime();
200          try { assertFalse(s.tryAcquire(timeoutMillis(), MILLISECONDS)); }
# Line 208 | Line 206 | public class SemaphoreTest extends JSR16
206       * timed tryAcquire(N) times out
207       */
208      public void testTryAcquireN_timeout() {
209 <        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
212 <        final boolean fair = rnd.nextBoolean();
209 >        final boolean fair = ThreadLocalRandom.current().nextBoolean();
210          final Semaphore s = new Semaphore(2, fair);
211          final long startTime = System.nanoTime();
212          try { assertFalse(s.tryAcquire(3, timeoutMillis(), MILLISECONDS)); }
# Line 273 | Line 270 | public class SemaphoreTest extends JSR16
270              assertThreadBlocks(t, acquirer.parkedState());
271              t.interrupt();
272          }
273 <        
273 >
274          awaitTermination(t);
275      }
276  
# Line 610 | Line 607 | public class SemaphoreTest extends JSR16
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());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines