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

Comparing jsr166/src/test/tck/LinkedBlockingDequeTest.java (file contents):
Revision 1.22 by jsr166, Wed Aug 25 01:44:48 2010 UTC vs.
Revision 1.28 by jsr166, Thu Oct 28 17:57:26 2010 UTC

# Line 11 | Line 11 | import static java.util.concurrent.TimeU
11   import java.io.*;
12  
13   public class LinkedBlockingDequeTest extends JSR166TestCase {
14 +
15 +    public static class Unbounded extends BlockingQueueTest {
16 +        protected BlockingQueue emptyCollection() {
17 +            return new LinkedBlockingDeque();
18 +        }
19 +    }
20 +
21 +    public static class Bounded extends BlockingQueueTest {
22 +        protected BlockingQueue emptyCollection() {
23 +            return new LinkedBlockingDeque(20);
24 +        }
25 +    }
26 +
27      public static void main(String[] args) {
28          junit.textui.TestRunner.run(suite());
29      }
30  
31      public static Test suite() {
32 <        return new TestSuite(LinkedBlockingDequeTest.class);
32 >        return newTestSuite(LinkedBlockingDequeTest.class,
33 >                            new Unbounded().testSuite(),
34 >                            new Bounded().testSuite());
35      }
36  
37      /**
# Line 93 | Line 108 | public class LinkedBlockingDequeTest ext
108      }
109  
110      /**
111 <     *  pollFirst succeeds unless empty
111 >     * pollFirst succeeds unless empty
112       */
113      public void testPollFirst() {
114          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 104 | Line 119 | public class LinkedBlockingDequeTest ext
119      }
120  
121      /**
122 <     *  pollLast succeeds unless empty
122 >     * pollLast succeeds unless empty
123       */
124      public void testPollLast() {
125          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 115 | Line 130 | public class LinkedBlockingDequeTest ext
130      }
131  
132      /**
133 <     *  peekFirst returns next element, or null if empty
133 >     * peekFirst returns next element, or null if empty
134       */
135      public void testPeekFirst() {
136          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 129 | Line 144 | public class LinkedBlockingDequeTest ext
144      }
145  
146      /**
147 <     *  peek returns next element, or null if empty
147 >     * peek returns next element, or null if empty
148       */
149      public void testPeek() {
150          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 143 | Line 158 | public class LinkedBlockingDequeTest ext
158      }
159  
160      /**
161 <     *  peekLast returns next element, or null if empty
161 >     * peekLast returns next element, or null if empty
162       */
163      public void testPeekLast() {
164          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 173 | Line 188 | public class LinkedBlockingDequeTest ext
188      }
189  
190      /**
191 <     *  getLast() returns last element, or throws NSEE if empty
191 >     * getLast() returns last element, or throws NSEE if empty
192       */
193      public void testLastElement() {
194          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 219 | Line 234 | public class LinkedBlockingDequeTest ext
234      }
235  
236      /**
237 <     *  remove removes next element, or throws NSEE if empty
237 >     * remove removes next element, or throws NSEE if empty
238       */
239      public void testRemove() {
240          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 442 | Line 457 | public class LinkedBlockingDequeTest ext
457  
458  
459      /**
460 <     *  pop removes next element, or throws NSEE if empty
460 >     * pop removes next element, or throws NSEE if empty
461       */
462      public void testPop() {
463          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 667 | Line 682 | public class LinkedBlockingDequeTest ext
682      }
683  
684      /**
670     * take blocks interruptibly when empty
671     */
672    public void testTakeFromEmpty() throws InterruptedException {
673        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
674        Thread t = new ThreadShouldThrow(InterruptedException.class) {
675            public void realRun() throws InterruptedException {
676                q.take();
677            }};
678
679        t.start();
680        Thread.sleep(SHORT_DELAY_MS);
681        t.interrupt();
682        t.join();
683    }
684
685    /**
685       * Take removes existing elements until empty, then blocks interruptibly
686       */
687      public void testBlockingTake() throws InterruptedException {
# Line 762 | Line 761 | public class LinkedBlockingDequeTest ext
761      }
762  
763      /**
765     *  timed poll before a delayed offer fails; after offer succeeds;
766     *  on interruption throws
767     */
768    public void testTimedPollWithOffer() throws InterruptedException {
769        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
770        Thread t = new Thread(new CheckedRunnable() {
771            public void realRun() throws InterruptedException {
772                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
773                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
774                try {
775                    q.poll(LONG_DELAY_MS, MILLISECONDS);
776                    shouldThrow();
777                } catch (InterruptedException success) {}
778            }});
779
780        t.start();
781        Thread.sleep(SMALL_DELAY_MS);
782        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
783        t.interrupt();
784        t.join();
785    }
786
787
788    /**
764       * putFirst(null) throws NPE
765       */
766       public void testPutFirstNull() throws InterruptedException {
# Line 976 | Line 951 | public class LinkedBlockingDequeTest ext
951      }
952  
953      /**
954 <     *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
955 <     *  on interruption throws
954 >     * timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
955 >     * on interruption throws
956       */
957      public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
958          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
# Line 1188 | Line 1163 | public class LinkedBlockingDequeTest ext
1163      }
1164  
1165      /**
1166 <     *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1167 <     *  on interruption throws
1166 >     * timed poll before a delayed offerLast fails; after offerLast succeeds;
1167 >     * on interruption throws
1168       */
1169      public void testTimedPollWithOfferLast() throws InterruptedException {
1170          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
# Line 1426 | Line 1401 | public class LinkedBlockingDequeTest ext
1401  
1402  
1403      /**
1404 <     *  Descending iterator iterates through all elements
1404 >     * Descending iterator iterates through all elements
1405       */
1406      public void testDescendingIterator() {
1407          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 1445 | Line 1420 | public class LinkedBlockingDequeTest ext
1420      }
1421  
1422      /**
1423 <     *  Descending iterator ordering is reverse FIFO
1423 >     * Descending iterator ordering is reverse FIFO
1424       */
1425      public void testDescendingIteratorOrdering() {
1426          final LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 1654 | Line 1629 | public class LinkedBlockingDequeTest ext
1629      }
1630  
1631      /**
1632 <     * drainTo(c, n) empties first max {n, size} elements of deque into c
1632 >     * drainTo(c, n) empties first min(n, size) elements of queue into c
1633       */
1634      public void testDrainToN() {
1635          LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 1663 | Line 1638 | public class LinkedBlockingDequeTest ext
1638                  assertTrue(q.offer(new Integer(j)));
1639              ArrayList l = new ArrayList();
1640              q.drainTo(l, i);
1641 <            int k = (i < SIZE)? i : SIZE;
1641 >            int k = (i < SIZE) ? i : SIZE;
1642              assertEquals(l.size(), k);
1643              assertEquals(q.size(), SIZE-k);
1644              for (int j = 0; j < k; ++j)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines