12 |
|
|
13 |
|
public class LinkedBlockingDequeTest extends JSR166TestCase { |
14 |
|
public static void main(String[] args) { |
15 |
< |
junit.textui.TestRunner.run (suite()); |
15 |
> |
junit.textui.TestRunner.run(suite()); |
16 |
|
} |
17 |
|
|
18 |
|
public static Test suite() { |
157 |
|
} |
158 |
|
|
159 |
|
/** |
160 |
< |
* getFirst returns next getFirst, or throws NSEE if empty |
160 |
> |
* getFirst() returns first element, or throws NSEE if empty |
161 |
|
*/ |
162 |
|
public void testFirstElement() { |
163 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
173 |
|
} |
174 |
|
|
175 |
|
/** |
176 |
< |
* getLast returns next element, or throws NSEE if empty |
176 |
> |
* getLast() returns last element, or throws NSEE if empty |
177 |
|
*/ |
178 |
|
public void testLastElement() { |
179 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
189 |
|
} |
190 |
|
|
191 |
|
/** |
192 |
< |
* removeFirst removes next element, or throws NSEE if empty |
192 |
> |
* removeFirst() removes first element, or throws NSEE if empty |
193 |
|
*/ |
194 |
|
public void testRemoveFirst() { |
195 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
204 |
|
} |
205 |
|
|
206 |
|
/** |
207 |
< |
* removeLast removes last element, or throws NSEE if empty |
207 |
> |
* removeLast() removes last element, or throws NSEE if empty |
208 |
|
*/ |
209 |
|
public void testRemoveLast() { |
210 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
269 |
|
LinkedBlockingDeque q = populatedDeque(3); |
270 |
|
q.pollLast(); |
271 |
|
q.addFirst(four); |
272 |
< |
assertEquals(four,q.peekFirst()); |
272 |
> |
assertSame(four, q.peekFirst()); |
273 |
|
} |
274 |
|
|
275 |
|
/** |
279 |
|
LinkedBlockingDeque q = populatedDeque(3); |
280 |
|
q.pollLast(); |
281 |
|
q.addLast(four); |
282 |
< |
assertEquals(four,q.peekLast()); |
282 |
> |
assertSame(four, q.peekLast()); |
283 |
|
} |
284 |
|
|
285 |
|
|
437 |
|
LinkedBlockingDeque q = populatedDeque(3); |
438 |
|
q.pollLast(); |
439 |
|
q.push(four); |
440 |
< |
assertEquals(four,q.peekFirst()); |
440 |
> |
assertSame(four, q.peekFirst()); |
441 |
|
} |
442 |
|
|
443 |
|
|
513 |
|
shouldThrow(); |
514 |
|
} catch (NullPointerException success) {} |
515 |
|
} |
516 |
+ |
|
517 |
|
/** |
518 |
|
* addAll of a collection with any null elements throws NPE after |
519 |
|
* possibly adding some elements |
528 |
|
shouldThrow(); |
529 |
|
} catch (NullPointerException success) {} |
530 |
|
} |
531 |
+ |
|
532 |
|
/** |
533 |
|
* addAll throws ISE if not enough room |
534 |
|
*/ |
769 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
770 |
|
Thread t = new Thread(new CheckedRunnable() { |
771 |
|
public void realRun() throws InterruptedException { |
770 |
– |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
771 |
– |
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
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) {} |
1376 |
|
/** |
1377 |
|
* iterator.remove removes current element |
1378 |
|
*/ |
1379 |
< |
public void testIteratorRemove () { |
1379 |
> |
public void testIteratorRemove() { |
1380 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(3); |
1381 |
|
q.add(two); |
1382 |
|
q.add(one); |
1387 |
|
it.remove(); |
1388 |
|
|
1389 |
|
it = q.iterator(); |
1390 |
< |
assertEquals(it.next(), one); |
1391 |
< |
assertEquals(it.next(), three); |
1390 |
> |
assertSame(it.next(), one); |
1391 |
> |
assertSame(it.next(), three); |
1392 |
|
assertFalse(it.hasNext()); |
1393 |
|
} |
1394 |
|
|
1412 |
|
/** |
1413 |
|
* Modifications do not cause iterators to fail |
1414 |
|
*/ |
1415 |
< |
public void testWeaklyConsistentIteration () { |
1415 |
> |
public void testWeaklyConsistentIteration() { |
1416 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(3); |
1417 |
|
q.add(one); |
1418 |
|
q.add(two); |
1468 |
|
/** |
1469 |
|
* descendingIterator.remove removes current element |
1470 |
|
*/ |
1471 |
< |
public void testDescendingIteratorRemove () { |
1471 |
> |
public void testDescendingIteratorRemove() { |
1472 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(); |
1473 |
|
for (int iters = 0; iters < 100; ++iters) { |
1474 |
|
q.add(new Integer(3)); |
1510 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
1511 |
|
executor.execute(new CheckedRunnable() { |
1512 |
|
public void realRun() throws InterruptedException { |
1513 |
< |
threadAssertFalse(q.offer(three)); |
1514 |
< |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
1515 |
< |
threadAssertEquals(0, q.remainingCapacity()); |
1513 |
> |
assertFalse(q.offer(three)); |
1514 |
> |
assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
1515 |
> |
assertEquals(0, q.remainingCapacity()); |
1516 |
|
}}); |
1517 |
|
|
1518 |
|
executor.execute(new CheckedRunnable() { |
1519 |
|
public void realRun() throws InterruptedException { |
1520 |
|
Thread.sleep(SMALL_DELAY_MS); |
1521 |
< |
threadAssertEquals(one, q.take()); |
1521 |
> |
assertSame(one, q.take()); |
1522 |
|
}}); |
1523 |
|
|
1524 |
|
joinPool(executor); |
1532 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
1533 |
|
executor.execute(new CheckedRunnable() { |
1534 |
|
public void realRun() throws InterruptedException { |
1535 |
< |
threadAssertNull(q.poll()); |
1536 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
1537 |
< |
threadAssertTrue(q.isEmpty()); |
1535 |
> |
assertNull(q.poll()); |
1536 |
> |
assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
1537 |
> |
assertTrue(q.isEmpty()); |
1538 |
|
}}); |
1539 |
|
|
1540 |
|
executor.execute(new CheckedRunnable() { |