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.27 by jsr166, Thu Oct 28 17:22:13 2010 UTC vs.
Revision 1.29 by jsr166, Thu Oct 28 19:05:04 2010 UTC

# Line 274 | Line 274 | public class LinkedTransferQueueTest ext
274      }
275  
276      /**
277 <     * take blocks interruptibly when empty
278 <     */
279 <    public void testTakeFromEmpty() throws InterruptedException {
280 <        final LinkedTransferQueue q = new LinkedTransferQueue();
281 <        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
282 <            public void realRun() throws InterruptedException {
283 <                q.take();
284 <            }});
285 <        Thread.sleep(SHORT_DELAY_MS);
286 <        t.interrupt();
287 <        t.join();
288 <    }
289 <
290 <    /**
291 <     * 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 306 | 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 342 | 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);
346 <            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 360 | 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);
364 <                    assertTrue(millisElapsed < SMALL_DELAY_MS);
348 >                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
349                  }
350                  try {
351                      q.poll(LONG_DELAY_MS, MILLISECONDS);
# Line 371 | 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 781 | 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 851 | 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 883 | 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 938 | 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 958 | 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 1003 | 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 1026 | 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 1057 | Line 1041 | public class LinkedTransferQueueTest ext
1041                  long t0 = System.nanoTime();
1042                  assertFalse(q.tryTransfer(new Object(),
1043                                            SHORT_DELAY_MS, MILLISECONDS));
1044 <                long elapsed = NANOSECONDS.toMillis(System.nanoTime() - t0);
1061 <                assertTrue(elapsed >= SHORT_DELAY_MS);
1044 >                assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
1045              }});
1046  
1047          checkEmpty(q);
# Line 1085 | 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