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); |
682 |
|
} |
683 |
|
|
684 |
|
/** |
685 |
– |
* take blocks interruptibly when empty |
686 |
– |
*/ |
687 |
– |
public void testTakeFromEmpty() throws InterruptedException { |
688 |
– |
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
689 |
– |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
690 |
– |
public void realRun() throws InterruptedException { |
691 |
– |
q.take(); |
692 |
– |
}}; |
693 |
– |
|
694 |
– |
t.start(); |
695 |
– |
Thread.sleep(SHORT_DELAY_MS); |
696 |
– |
t.interrupt(); |
697 |
– |
t.join(); |
698 |
– |
} |
699 |
– |
|
700 |
– |
/** |
685 |
|
* Take removes existing elements until empty, then blocks interruptibly |
686 |
|
*/ |
687 |
|
public void testBlockingTake() throws InterruptedException { |
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); |
1294 |
|
} |
1295 |
|
|
1296 |
|
/** |
1297 |
< |
* toArray contains all elements |
1297 |
> |
* toArray contains all elements in FIFO order |
1298 |
|
*/ |
1299 |
|
public void testToArray() throws InterruptedException{ |
1300 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1301 |
|
Object[] o = q.toArray(); |
1302 |
|
for (int i = 0; i < o.length; i++) |
1303 |
< |
assertEquals(o[i], q.take()); |
1303 |
> |
assertSame(o[i], q.poll()); |
1304 |
|
} |
1305 |
|
|
1306 |
|
/** |
1307 |
< |
* toArray(a) contains all elements |
1307 |
> |
* toArray(a) contains all elements in FIFO order |
1308 |
|
*/ |
1309 |
< |
public void testToArray2() throws InterruptedException { |
1309 |
> |
public void testToArray2() { |
1310 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1311 |
|
Integer[] ints = new Integer[SIZE]; |
1312 |
< |
ints = (Integer[])q.toArray(ints); |
1312 |
> |
assertSame(ints, q.toArray(ints)); |
1313 |
|
for (int i = 0; i < ints.length; i++) |
1314 |
< |
assertEquals(ints[i], q.take()); |
1314 |
> |
assertSame(ints[i], q.remove()); |
1315 |
|
} |
1316 |
|
|
1317 |
|
/** |
1318 |
< |
* toArray(null) throws NPE |
1318 |
> |
* toArray(null) throws NullPointerException |
1319 |
|
*/ |
1320 |
< |
public void testToArray_BadArg() { |
1320 |
> |
public void testToArray_NullArg() { |
1321 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1322 |
|
try { |
1323 |
< |
Object o[] = q.toArray(null); |
1323 |
> |
q.toArray(null); |
1324 |
|
shouldThrow(); |
1325 |
|
} catch (NullPointerException success) {} |
1326 |
|
} |
1327 |
|
|
1328 |
|
/** |
1329 |
< |
* toArray with incompatible array type throws CCE |
1329 |
> |
* toArray(incompatible array type) throws ArrayStoreException |
1330 |
|
*/ |
1331 |
|
public void testToArray1_BadArg() { |
1332 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1333 |
|
try { |
1334 |
< |
Object o[] = q.toArray(new String[10]); |
1334 |
> |
q.toArray(new String[10]); |
1335 |
|
shouldThrow(); |
1336 |
|
} catch (ArrayStoreException success) {} |
1337 |
|
} |
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); |
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(); |
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(); |
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) |