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.42 by jsr166, Mon May 29 19:15:03 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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines