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.40 by jsr166, Sun May 14 03:48:35 2017 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  
16 import junit.framework.AssertionFailedError;
15   import junit.framework.Test;
16   import junit.framework.TestSuite;
17  
# Line 74 | Line 72 | public class SemaphoreTest extends JSR16
72          long startTime = System.nanoTime();
73          while (!s.hasQueuedThread(t)) {
74              if (millisElapsedSince(startTime) > LONG_DELAY_MS)
75 <                throw new AssertionFailedError("timed out");
75 >                throw new AssertionError("timed out");
76              Thread.yield();
77          }
78          assertTrue(s.hasQueuedThreads());
# Line 88 | Line 86 | public class SemaphoreTest extends JSR16
86          long startTime = System.nanoTime();
87          while (!s.hasQueuedThreads()) {
88              if (millisElapsedSince(startTime) > LONG_DELAY_MS)
89 <                throw new AssertionFailedError("timed out");
89 >                throw new AssertionError("timed out");
90              Thread.yield();
91          }
92      }
# Line 194 | 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)); }
202 <        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)); }
214 <        catch (InterruptedException e) { threadUnexpectedException(e); }
210 >        assertFalse(s.tryAcquire(3, timeoutMillis(), MILLISECONDS));
211          assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
212      }
213  
# Line 271 | Line 267 | public class SemaphoreTest extends JSR16
267              assertThreadBlocks(t, acquirer.parkedState());
268              t.interrupt();
269          }
270 <        
270 >
271          awaitTermination(t);
272      }
273  
# Line 608 | Line 604 | public class SemaphoreTest extends JSR16
604          Thread t2 = newStartedThread(new CheckedRunnable() {
605              public void realRun() throws InterruptedException {
606                  // Will fail, even though 1 permit is available
607 <                assertFalse(s.tryAcquire(0L, MILLISECONDS));
608 <                assertFalse(s.tryAcquire(1, 0L, MILLISECONDS));
607 >                assertFalse(
608 >                    s.tryAcquire(randomExpiredTimeout(), randomTimeUnit()));
609 >                assertFalse(
610 >                    s.tryAcquire(1, randomExpiredTimeout(), randomTimeUnit()));
611  
612                  // untimed tryAcquire will barge and succeed
613                  assertTrue(s.tryAcquire());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines