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.24 by jsr166, Tue Dec 1 09:56:28 2009 UTC vs.
Revision 1.27 by jsr166, Thu Oct 28 17:22:13 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  
25   @SuppressWarnings({"unchecked", "rawtypes"})
26   public class LinkedTransferQueueTest extends JSR166TestCase {
27  
28 +    public static class Generic extends BlockingQueueTest {
29 +        protected BlockingQueue emptyCollection() {
30 +            return new LinkedTransferQueue();
31 +        }
32 +    }
33 +
34      public static void main(String[] args) {
35          junit.textui.TestRunner.run(suite());
36      }
37  
38      public static Test suite() {
39 <        return new TestSuite(LinkedTransferQueueTest.class);
39 >        return newTestSuite(LinkedTransferQueueTest.class,
40 >                            new Generic().testSuite());
41      }
42  
43      void checkEmpty(LinkedTransferQueue q) throws InterruptedException {
# Line 368 | Line 376 | public class LinkedTransferQueueTest ext
376      }
377  
378      /**
371     * timed poll before a delayed offer fails; after offer succeeds;
372     * on interruption throws
373     */
374    public void testTimedPollWithOffer() throws InterruptedException {
375        final LinkedTransferQueue q = new LinkedTransferQueue();
376        Thread t = new Thread(new CheckedRunnable() {
377            public void realRun() throws InterruptedException {
378                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
379                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
380                try {
381                    q.poll(LONG_DELAY_MS, MILLISECONDS);
382                    shouldThrow();
383                } catch (InterruptedException success) {}
384            }});
385
386        t.start();
387        Thread.sleep(SMALL_DELAY_MS);
388        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
389        t.interrupt();
390        t.join();
391    }
392
393    /**
379       * peek returns next element, or null if empty
380       */
381      public void testPeek() throws InterruptedException {
# Line 823 | Line 808 | public class LinkedTransferQueueTest ext
808      }
809  
810      /**
811 <     * drainTo(c, n) empties first max {n, size} elements of queue into c
811 >     * drainTo(c, n) empties first min(n, size) elements of queue into c
812       */
813      public void testDrainToN() {
814          LinkedTransferQueue q = new LinkedTransferQueue();
# Line 1069 | Line 1054 | public class LinkedTransferQueueTest ext
1054  
1055          Thread t = newStartedThread(new CheckedRunnable() {
1056              public void realRun() throws InterruptedException {
1057 +                long t0 = System.nanoTime();
1058                  assertFalse(q.tryTransfer(new Object(),
1059                                            SHORT_DELAY_MS, MILLISECONDS));
1060 +                long elapsed = NANOSECONDS.toMillis(System.nanoTime() - t0);
1061 +                assertTrue(elapsed >= SHORT_DELAY_MS);
1062              }});
1063  
1076        Thread.sleep(SMALL_DELAY_MS);
1064          checkEmpty(q);
1065 <        t.join();
1065 >        awaitTermination(t, MEDIUM_DELAY_MS);
1066 >        checkEmpty(q);
1067      }
1068  
1069      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines