ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/LinkedTransferQueueTest.java
(Generate patch)

Comparing jsr166/src/test/tck/LinkedTransferQueueTest.java (file contents):
Revision 1.25 by jsr166, Wed Oct 6 07:49:22 2010 UTC vs.
Revision 1.28 by jsr166, Thu Oct 28 17:57:26 2010 UTC

# Line 18 | Line 18 | import java.util.List;
18   import java.util.NoSuchElementException;
19   import java.util.concurrent.*;
20   import static java.util.concurrent.TimeUnit.MILLISECONDS;
21 + import static java.util.concurrent.TimeUnit.NANOSECONDS;
22   import junit.framework.Test;
23   import junit.framework.TestSuite;
24  
# Line 273 | Line 274 | public class LinkedTransferQueueTest ext
274      }
275  
276      /**
277 <     * take blocks interruptibly when empty
277 <     */
278 <    public void testTakeFromEmpty() throws InterruptedException {
279 <        final LinkedTransferQueue q = new LinkedTransferQueue();
280 <        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
281 <            public void realRun() throws InterruptedException {
282 <                q.take();
283 <            }});
284 <        Thread.sleep(SHORT_DELAY_MS);
285 <        t.interrupt();
286 <        t.join();
287 <    }
288 <
289 <    /**
290 <     * Take removes existing elements until empty, then blocks interruptibly
277 >     * take removes existing elements until empty, then blocks interruptibly
278       */
279      public void testBlockingTake() throws InterruptedException {
280          final LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
# Line 341 | Line 328 | public class LinkedTransferQueueTest ext
328          for (int i = 0; i < SIZE; ++i) {
329              long t0 = System.nanoTime();
330              assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
331 <            long millisElapsed = (System.nanoTime() - t0)/(1024 * 1024);
345 <            assertTrue(millisElapsed < SMALL_DELAY_MS);
331 >            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
332          }
333          assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
334          checkEmpty(q);
# Line 359 | Line 345 | public class LinkedTransferQueueTest ext
345                  for (int i = 0; i < SIZE; ++i) {
346                      long t0 = System.nanoTime();
347                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
348 <                    long millisElapsed = (System.nanoTime() - t0)/(1024 * 1024);
363 <                    assertTrue(millisElapsed < SMALL_DELAY_MS);
348 >                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
349                  }
350                  try {
351                      q.poll(LONG_DELAY_MS, MILLISECONDS);
# Line 807 | Line 792 | public class LinkedTransferQueueTest ext
792      }
793  
794      /**
795 <     * drainTo(c, n) empties first max {n, size} elements of queue into c
795 >     * drainTo(c, n) empties first min(n, size) elements of queue into c
796       */
797      public void testDrainToN() {
798          LinkedTransferQueue q = new LinkedTransferQueue();
# Line 1053 | Line 1038 | public class LinkedTransferQueueTest ext
1038  
1039          Thread t = newStartedThread(new CheckedRunnable() {
1040              public void realRun() throws InterruptedException {
1041 +                long t0 = System.nanoTime();
1042                  assertFalse(q.tryTransfer(new Object(),
1043                                            SHORT_DELAY_MS, MILLISECONDS));
1044 +                assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
1045              }});
1046  
1060        Thread.sleep(SMALL_DELAY_MS);
1047          checkEmpty(q);
1048 <        t.join();
1048 >        awaitTermination(t, MEDIUM_DELAY_MS);
1049 >        checkEmpty(q);
1050      }
1051  
1052      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines