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.26 by jsr166, Tue Oct 19 00:41:14 2010 UTC vs.
Revision 1.29 by jsr166, Thu Oct 28 19:05:04 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 305 | Line 292 | public class LinkedTransferQueueTest ext
292          t.start();
293          Thread.sleep(SHORT_DELAY_MS);
294          t.interrupt();
295 <        t.join();
295 >        awaitTermination(t, MEDIUM_DELAY_MS);
296          checkEmpty(q);
297      }
298  
# 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 370 | Line 355 | public class LinkedTransferQueueTest ext
355  
356          Thread.sleep(SMALL_DELAY_MS);
357          t.interrupt();
358 <        t.join();
358 >        awaitTermination(t, MEDIUM_DELAY_MS);
359          checkEmpty(q);
360      }
361  
# Line 780 | Line 765 | public class LinkedTransferQueueTest ext
765          for (int i = 0; i < SIZE; ++i) {
766              assertEquals(l.get(i), i);
767          }
768 <        t.join();
768 >        awaitTermination(t, MEDIUM_DELAY_MS);
769          assertTrue(q.size() + l.size() >= SIZE);
770      }
771  
# Line 850 | Line 835 | public class LinkedTransferQueueTest ext
835          assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
836          assertEquals(q.getWaitingConsumerCount(), 0);
837          assertFalse(q.hasWaitingConsumer());
838 <        t.join();
838 >        awaitTermination(t, MEDIUM_DELAY_MS);
839      }
840  
841      /**
# Line 882 | Line 867 | public class LinkedTransferQueueTest ext
867          assertEquals(1, q.size());
868          assertEquals(SIZE, (int) q.poll());
869          assertTrue(q.isEmpty());
870 <        t.join();
870 >        awaitTermination(t, MEDIUM_DELAY_MS);
871      }
872  
873      /**
# Line 937 | Line 922 | public class LinkedTransferQueueTest ext
922          Thread.sleep(SHORT_DELAY_MS);
923          assertTrue(q.offer(three));
924          assertSame(four, q.poll());
925 <        t.join();
925 >        awaitTermination(t, MEDIUM_DELAY_MS);
926      }
927  
928      /**
# Line 957 | Line 942 | public class LinkedTransferQueueTest ext
942          Thread.sleep(SHORT_DELAY_MS);
943          assertEquals(SIZE, (int) q.take());
944          checkEmpty(q);
945 <        t.join();
945 >        awaitTermination(t, MEDIUM_DELAY_MS);
946      }
947  
948      /**
# Line 1002 | Line 987 | public class LinkedTransferQueueTest ext
987  
988          assertSame(hotPotato, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
989          checkEmpty(q);
990 <        t.join();
990 >        awaitTermination(t, MEDIUM_DELAY_MS);
991      }
992  
993      /**
# Line 1025 | Line 1010 | public class LinkedTransferQueueTest ext
1010  
1011          assertSame(q.take(), hotPotato);
1012          checkEmpty(q);
1013 <        t.join();
1013 >        awaitTermination(t, MEDIUM_DELAY_MS);
1014      }
1015  
1016      /**
# 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      /**
# Line 1081 | Line 1068 | public class LinkedTransferQueueTest ext
1068          assertSame(four, q.poll());
1069          assertSame(five, q.poll());
1070          checkEmpty(q);
1071 <        t.join();
1071 >        awaitTermination(t, MEDIUM_DELAY_MS);
1072      }
1073  
1074      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines