test/jdk/java/util/concurrent/tck/SemaphoreTest.java
changeset 48843 21efc1774302
parent 47216 71c04702a3d5
child 58138 1e4270f875ee
equal deleted inserted replaced
48842:a5a2e4770524 48843:21efc1774302
    38 import java.util.Collection;
    38 import java.util.Collection;
    39 import java.util.concurrent.CountDownLatch;
    39 import java.util.concurrent.CountDownLatch;
    40 import java.util.concurrent.Semaphore;
    40 import java.util.concurrent.Semaphore;
    41 import java.util.concurrent.ThreadLocalRandom;
    41 import java.util.concurrent.ThreadLocalRandom;
    42 
    42 
    43 import junit.framework.AssertionFailedError;
       
    44 import junit.framework.Test;
    43 import junit.framework.Test;
    45 import junit.framework.TestSuite;
    44 import junit.framework.TestSuite;
    46 
    45 
    47 public class SemaphoreTest extends JSR166TestCase {
    46 public class SemaphoreTest extends JSR166TestCase {
    48     public static void main(String[] args) {
    47     public static void main(String[] args) {
    99      */
    98      */
   100     void waitForQueuedThread(PublicSemaphore s, Thread t) {
    99     void waitForQueuedThread(PublicSemaphore s, Thread t) {
   101         long startTime = System.nanoTime();
   100         long startTime = System.nanoTime();
   102         while (!s.hasQueuedThread(t)) {
   101         while (!s.hasQueuedThread(t)) {
   103             if (millisElapsedSince(startTime) > LONG_DELAY_MS)
   102             if (millisElapsedSince(startTime) > LONG_DELAY_MS)
   104                 throw new AssertionFailedError("timed out");
   103                 throw new AssertionError("timed out");
   105             Thread.yield();
   104             Thread.yield();
   106         }
   105         }
   107         assertTrue(s.hasQueuedThreads());
   106         assertTrue(s.hasQueuedThreads());
   108         assertTrue(t.isAlive());
   107         assertTrue(t.isAlive());
   109     }
   108     }
   113      */
   112      */
   114     void waitForQueuedThreads(Semaphore s) {
   113     void waitForQueuedThreads(Semaphore s) {
   115         long startTime = System.nanoTime();
   114         long startTime = System.nanoTime();
   116         while (!s.hasQueuedThreads()) {
   115         while (!s.hasQueuedThreads()) {
   117             if (millisElapsedSince(startTime) > LONG_DELAY_MS)
   116             if (millisElapsedSince(startTime) > LONG_DELAY_MS)
   118                 throw new AssertionFailedError("timed out");
   117                 throw new AssertionError("timed out");
   119             Thread.yield();
   118             Thread.yield();
   120         }
   119         }
   121     }
   120     }
   122 
   121 
   123     enum AcquireMethod {
   122     enum AcquireMethod {