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 |
|
/** |
108 |
|
} |
109 |
|
|
110 |
|
/** |
111 |
< |
* pollFirst succeeds unless empty |
111 |
> |
* pollFirst succeeds unless empty |
112 |
|
*/ |
113 |
|
public void testPollFirst() { |
114 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
119 |
|
} |
120 |
|
|
121 |
|
/** |
122 |
< |
* pollLast succeeds unless empty |
122 |
> |
* pollLast succeeds unless empty |
123 |
|
*/ |
124 |
|
public void testPollLast() { |
125 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
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); |
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); |
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); |
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); |
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); |
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); |
777 |
|
} |
778 |
|
|
779 |
|
/** |
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 |
– |
try { |
773 |
– |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
774 |
– |
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
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 |
– |
/** |
780 |
|
* putFirst(null) throws NPE |
781 |
|
*/ |
782 |
|
public void testPutFirstNull() throws InterruptedException { |
967 |
|
} |
968 |
|
|
969 |
|
/** |
970 |
< |
* timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds; |
971 |
< |
* on interruption throws |
970 |
> |
* timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds; |
971 |
> |
* on interruption throws |
972 |
|
*/ |
973 |
|
public void testTimedPollFirstWithOfferFirst() throws InterruptedException { |
974 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1179 |
|
} |
1180 |
|
|
1181 |
|
/** |
1182 |
< |
* timed poll before a delayed offerLast fails; after offerLast succeeds; |
1183 |
< |
* on interruption throws |
1182 |
> |
* timed poll before a delayed offerLast fails; after offerLast succeeds; |
1183 |
> |
* on interruption throws |
1184 |
|
*/ |
1185 |
|
public void testTimedPollWithOfferLast() throws InterruptedException { |
1186 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1417 |
|
|
1418 |
|
|
1419 |
|
/** |
1420 |
< |
* Descending iterator iterates through all elements |
1420 |
> |
* Descending iterator iterates through all elements |
1421 |
|
*/ |
1422 |
|
public void testDescendingIterator() { |
1423 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1436 |
|
} |
1437 |
|
|
1438 |
|
/** |
1439 |
< |
* Descending iterator ordering is reverse FIFO |
1439 |
> |
* Descending iterator ordering is reverse FIFO |
1440 |
|
*/ |
1441 |
|
public void testDescendingIteratorOrdering() { |
1442 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(); |