36 |
|
return q; |
37 |
|
} |
38 |
|
|
39 |
< |
public void testConstructor1(){ |
39 |
> |
/** |
40 |
> |
* |
41 |
> |
*/ |
42 |
> |
public void testConstructor1() { |
43 |
|
assertEquals(SIZE, new LinkedBlockingQueue(SIZE).remainingCapacity()); |
44 |
|
} |
45 |
|
|
46 |
< |
public void testConstructor2(){ |
46 |
> |
/** |
47 |
> |
* |
48 |
> |
*/ |
49 |
> |
public void testConstructor2() { |
50 |
|
try { |
51 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(0); |
52 |
< |
fail("Cannot make zero-sized"); |
52 |
> |
shouldThrow(); |
53 |
|
} |
54 |
|
catch (IllegalArgumentException success) {} |
55 |
|
} |
56 |
|
|
57 |
< |
public void testConstructor3(){ |
57 |
> |
/** |
58 |
> |
* |
59 |
> |
*/ |
60 |
> |
public void testConstructor3() { |
61 |
|
|
62 |
|
try { |
63 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(null); |
64 |
< |
fail("Cannot make from null collection"); |
64 |
> |
shouldThrow(); |
65 |
|
} |
66 |
|
catch (NullPointerException success) {} |
67 |
|
} |
68 |
|
|
69 |
< |
public void testConstructor4(){ |
69 |
> |
/** |
70 |
> |
* |
71 |
> |
*/ |
72 |
> |
public void testConstructor4() { |
73 |
|
try { |
74 |
|
Integer[] ints = new Integer[SIZE]; |
75 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(Arrays.asList(ints)); |
76 |
< |
fail("Cannot make with null elements"); |
76 |
> |
shouldThrow(); |
77 |
|
} |
78 |
|
catch (NullPointerException success) {} |
79 |
|
} |
80 |
|
|
81 |
< |
public void testConstructor5(){ |
81 |
> |
/** |
82 |
> |
* |
83 |
> |
*/ |
84 |
> |
public void testConstructor5() { |
85 |
|
try { |
86 |
|
Integer[] ints = new Integer[SIZE]; |
87 |
|
for (int i = 0; i < SIZE-1; ++i) |
88 |
|
ints[i] = new Integer(i); |
89 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(Arrays.asList(ints)); |
90 |
< |
fail("Cannot make with null elements"); |
90 |
> |
shouldThrow(); |
91 |
|
} |
92 |
|
catch (NullPointerException success) {} |
93 |
|
} |
94 |
|
|
95 |
< |
public void testConstructor6(){ |
95 |
> |
/** |
96 |
> |
* |
97 |
> |
*/ |
98 |
> |
public void testConstructor6() { |
99 |
|
try { |
100 |
|
Integer[] ints = new Integer[SIZE]; |
101 |
|
for (int i = 0; i < SIZE; ++i) |
107 |
|
finally {} |
108 |
|
} |
109 |
|
|
110 |
+ |
/** |
111 |
+ |
* |
112 |
+ |
*/ |
113 |
|
public void testEmptyFull() { |
114 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
115 |
|
assertTrue(q.isEmpty()); |
118 |
|
assertFalse(q.isEmpty()); |
119 |
|
q.add(two); |
120 |
|
assertFalse(q.isEmpty()); |
121 |
< |
assertEquals("queue should be full", 0, q.remainingCapacity()); |
122 |
< |
assertFalse("offer should be rejected", q.offer(three)); |
121 |
> |
assertEquals(0, q.remainingCapacity()); |
122 |
> |
assertFalse(q.offer(three)); |
123 |
|
} |
124 |
|
|
125 |
< |
public void testRemainingCapacity(){ |
125 |
> |
/** |
126 |
> |
* |
127 |
> |
*/ |
128 |
> |
public void testRemainingCapacity() { |
129 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
130 |
|
for (int i = 0; i < SIZE; ++i) { |
131 |
|
assertEquals(i, q.remainingCapacity()); |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
< |
public void testOfferNull(){ |
142 |
> |
/** |
143 |
> |
* |
144 |
> |
*/ |
145 |
> |
public void testOfferNull() { |
146 |
|
try { |
147 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(1); |
148 |
|
q.offer(null); |
149 |
< |
fail("should throw NPE"); |
149 |
> |
shouldThrow(); |
150 |
|
} catch (NullPointerException success) { } |
151 |
|
} |
152 |
|
|
153 |
< |
public void testOffer(){ |
153 |
> |
/** |
154 |
> |
* |
155 |
> |
*/ |
156 |
> |
public void testOffer() { |
157 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(1); |
158 |
|
assertTrue(q.offer(zero)); |
159 |
|
assertFalse(q.offer(one)); |
160 |
|
} |
161 |
|
|
162 |
< |
public void testAdd(){ |
162 |
> |
/** |
163 |
> |
* |
164 |
> |
*/ |
165 |
> |
public void testAdd() { |
166 |
|
try { |
167 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); |
168 |
|
for (int i = 0; i < SIZE; ++i) { |
174 |
|
} |
175 |
|
} |
176 |
|
|
177 |
< |
public void testAddAll1(){ |
177 |
> |
/** |
178 |
> |
* |
179 |
> |
*/ |
180 |
> |
public void testAddAll1() { |
181 |
|
try { |
182 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(1); |
183 |
|
q.addAll(null); |
184 |
< |
fail("Cannot add null collection"); |
184 |
> |
shouldThrow(); |
185 |
|
} |
186 |
|
catch (NullPointerException success) {} |
187 |
|
} |
188 |
< |
public void testAddAll2(){ |
188 |
> |
/** |
189 |
> |
* |
190 |
> |
*/ |
191 |
> |
public void testAddAll2() { |
192 |
|
try { |
193 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); |
194 |
|
Integer[] ints = new Integer[SIZE]; |
195 |
|
q.addAll(Arrays.asList(ints)); |
196 |
< |
fail("Cannot add null elements"); |
196 |
> |
shouldThrow(); |
197 |
|
} |
198 |
|
catch (NullPointerException success) {} |
199 |
|
} |
200 |
< |
public void testAddAll3(){ |
200 |
> |
/** |
201 |
> |
* |
202 |
> |
*/ |
203 |
> |
public void testAddAll3() { |
204 |
|
try { |
205 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); |
206 |
|
Integer[] ints = new Integer[SIZE]; |
207 |
|
for (int i = 0; i < SIZE-1; ++i) |
208 |
|
ints[i] = new Integer(i); |
209 |
|
q.addAll(Arrays.asList(ints)); |
210 |
< |
fail("Cannot add null elements"); |
210 |
> |
shouldThrow(); |
211 |
|
} |
212 |
|
catch (NullPointerException success) {} |
213 |
|
} |
214 |
< |
public void testAddAll4(){ |
214 |
> |
/** |
215 |
> |
* |
216 |
> |
*/ |
217 |
> |
public void testAddAll4() { |
218 |
|
try { |
219 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(1); |
220 |
|
Integer[] ints = new Integer[SIZE]; |
221 |
|
for (int i = 0; i < SIZE; ++i) |
222 |
|
ints[i] = new Integer(i); |
223 |
|
q.addAll(Arrays.asList(ints)); |
224 |
< |
fail("Cannot add with insufficient capacity"); |
224 |
> |
shouldThrow(); |
225 |
|
} |
226 |
|
catch (IllegalStateException success) {} |
227 |
|
} |
228 |
< |
public void testAddAll5(){ |
228 |
> |
/** |
229 |
> |
* |
230 |
> |
*/ |
231 |
> |
public void testAddAll5() { |
232 |
|
try { |
233 |
|
Integer[] empty = new Integer[0]; |
234 |
|
Integer[] ints = new Integer[SIZE]; |
243 |
|
finally {} |
244 |
|
} |
245 |
|
|
246 |
+ |
/** |
247 |
+ |
* |
248 |
+ |
*/ |
249 |
|
public void testPutNull() { |
250 |
|
try { |
251 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); |
252 |
|
q.put(null); |
253 |
< |
fail("put should throw NPE"); |
253 |
> |
shouldThrow(); |
254 |
|
} |
255 |
|
catch (NullPointerException success){ |
256 |
|
} |
257 |
|
catch (InterruptedException ie) { |
258 |
< |
fail("Unexpected exception"); |
258 |
> |
unexpectedException(); |
259 |
|
} |
260 |
|
} |
261 |
|
|
262 |
+ |
/** |
263 |
+ |
* |
264 |
+ |
*/ |
265 |
|
public void testPut() { |
266 |
|
try { |
267 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); |
273 |
|
assertEquals(0, q.remainingCapacity()); |
274 |
|
} |
275 |
|
catch (InterruptedException ie) { |
276 |
< |
fail("Unexpected exception"); |
276 |
> |
unexpectedException(); |
277 |
|
} |
278 |
|
} |
279 |
|
|
280 |
< |
public void testBlockingPut(){ |
280 |
> |
/** |
281 |
> |
* |
282 |
> |
*/ |
283 |
> |
public void testBlockingPut() { |
284 |
|
Thread t = new Thread(new Runnable() { |
285 |
|
public void run() { |
286 |
|
int added = 0; |
291 |
|
++added; |
292 |
|
} |
293 |
|
q.put(new Integer(SIZE)); |
294 |
< |
threadFail("put should block"); |
294 |
> |
threadShouldThrow(); |
295 |
|
} catch (InterruptedException ie){ |
296 |
|
threadAssertEquals(added, SIZE); |
297 |
|
} |
303 |
|
t.join(); |
304 |
|
} |
305 |
|
catch (InterruptedException ie) { |
306 |
< |
fail("Unexpected exception"); |
306 |
> |
unexpectedException(); |
307 |
|
} |
308 |
|
} |
309 |
|
|
310 |
+ |
/** |
311 |
+ |
* |
312 |
+ |
*/ |
313 |
|
public void testPutWithTake() { |
314 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
315 |
|
Thread t = new Thread(new Runnable() { |
316 |
< |
public void run(){ |
316 |
> |
public void run() { |
317 |
|
int added = 0; |
318 |
|
try { |
319 |
|
q.put(new Object()); |
324 |
|
++added; |
325 |
|
q.put(new Object()); |
326 |
|
++added; |
327 |
< |
threadFail("Should block"); |
327 |
> |
threadShouldThrow(); |
328 |
|
} catch (InterruptedException e){ |
329 |
|
threadAssertTrue(added >= 2); |
330 |
|
} |
337 |
|
t.interrupt(); |
338 |
|
t.join(); |
339 |
|
} catch (Exception e){ |
340 |
< |
fail("Unexpected exception"); |
340 |
> |
unexpectedException(); |
341 |
|
} |
342 |
|
} |
343 |
|
|
344 |
+ |
/** |
345 |
+ |
* |
346 |
+ |
*/ |
347 |
|
public void testTimedOffer() { |
348 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
349 |
|
Thread t = new Thread(new Runnable() { |
350 |
< |
public void run(){ |
350 |
> |
public void run() { |
351 |
|
try { |
352 |
|
q.put(new Object()); |
353 |
|
q.put(new Object()); |
354 |
|
threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
355 |
|
q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
356 |
< |
threadFail("Should block"); |
356 |
> |
threadShouldThrow(); |
357 |
|
} catch (InterruptedException success){} |
358 |
|
} |
359 |
|
}); |
364 |
|
t.interrupt(); |
365 |
|
t.join(); |
366 |
|
} catch (Exception e){ |
367 |
< |
fail("Unexpected exception"); |
367 |
> |
unexpectedException(); |
368 |
|
} |
369 |
|
} |
370 |
|
|
371 |
< |
public void testTake(){ |
371 |
> |
/** |
372 |
> |
* |
373 |
> |
*/ |
374 |
> |
public void testTake() { |
375 |
|
try { |
376 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
377 |
|
for (int i = 0; i < SIZE; ++i) { |
378 |
|
assertEquals(i, ((Integer)q.take()).intValue()); |
379 |
|
} |
380 |
|
} catch (InterruptedException e){ |
381 |
< |
fail("Unexpected exception"); |
381 |
> |
unexpectedException(); |
382 |
|
} |
383 |
|
} |
384 |
|
|
385 |
+ |
/** |
386 |
+ |
* |
387 |
+ |
*/ |
388 |
|
public void testTakeFromEmpty() { |
389 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
390 |
|
Thread t = new Thread(new Runnable() { |
391 |
< |
public void run(){ |
391 |
> |
public void run() { |
392 |
|
try { |
393 |
|
q.take(); |
394 |
< |
threadFail("Should block"); |
394 |
> |
threadShouldThrow(); |
395 |
|
} catch (InterruptedException success){ } |
396 |
|
} |
397 |
|
}); |
401 |
|
t.interrupt(); |
402 |
|
t.join(); |
403 |
|
} catch (Exception e){ |
404 |
< |
fail("Unexpected exception"); |
404 |
> |
unexpectedException(); |
405 |
|
} |
406 |
|
} |
407 |
|
|
408 |
< |
public void testBlockingTake(){ |
408 |
> |
/** |
409 |
> |
* |
410 |
> |
*/ |
411 |
> |
public void testBlockingTake() { |
412 |
|
Thread t = new Thread(new Runnable() { |
413 |
|
public void run() { |
414 |
|
try { |
417 |
|
assertEquals(i, ((Integer)q.take()).intValue()); |
418 |
|
} |
419 |
|
q.take(); |
420 |
< |
threadFail("take should block"); |
420 |
> |
threadShouldThrow(); |
421 |
|
} catch (InterruptedException success){ |
422 |
|
} |
423 |
|
}}); |
428 |
|
t.join(); |
429 |
|
} |
430 |
|
catch (InterruptedException ie) { |
431 |
< |
fail("Unexpected exception"); |
431 |
> |
unexpectedException(); |
432 |
|
} |
433 |
|
} |
434 |
|
|
435 |
|
|
436 |
< |
public void testPoll(){ |
436 |
> |
/** |
437 |
> |
* |
438 |
> |
*/ |
439 |
> |
public void testPoll() { |
440 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
441 |
|
for (int i = 0; i < SIZE; ++i) { |
442 |
|
assertEquals(i, ((Integer)q.poll()).intValue()); |
444 |
|
assertNull(q.poll()); |
445 |
|
} |
446 |
|
|
447 |
+ |
/** |
448 |
+ |
* |
449 |
+ |
*/ |
450 |
|
public void testTimedPoll0() { |
451 |
|
try { |
452 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
455 |
|
} |
456 |
|
assertNull(q.poll(0, TimeUnit.MILLISECONDS)); |
457 |
|
} catch (InterruptedException e){ |
458 |
< |
fail("Unexpected exception"); |
458 |
> |
unexpectedException(); |
459 |
|
} |
460 |
|
} |
461 |
|
|
462 |
+ |
/** |
463 |
+ |
* |
464 |
+ |
*/ |
465 |
|
public void testTimedPoll() { |
466 |
|
try { |
467 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
470 |
|
} |
471 |
|
assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
472 |
|
} catch (InterruptedException e){ |
473 |
< |
fail("Unexpected exception"); |
473 |
> |
unexpectedException(); |
474 |
|
} |
475 |
|
} |
476 |
|
|
477 |
< |
public void testInterruptedTimedPoll(){ |
477 |
> |
/** |
478 |
> |
* |
479 |
> |
*/ |
480 |
> |
public void testInterruptedTimedPoll() { |
481 |
|
Thread t = new Thread(new Runnable() { |
482 |
|
public void run() { |
483 |
|
try { |
496 |
|
t.join(); |
497 |
|
} |
498 |
|
catch (InterruptedException ie) { |
499 |
< |
fail("Unexpected exception"); |
499 |
> |
unexpectedException(); |
500 |
|
} |
501 |
|
} |
502 |
|
|
503 |
< |
public void testTimedPollWithOffer(){ |
503 |
> |
/** |
504 |
> |
* |
505 |
> |
*/ |
506 |
> |
public void testTimedPollWithOffer() { |
507 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
508 |
|
Thread t = new Thread(new Runnable() { |
509 |
< |
public void run(){ |
509 |
> |
public void run() { |
510 |
|
try { |
511 |
|
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
512 |
|
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
513 |
|
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
514 |
< |
threadFail("Should block"); |
514 |
> |
threadShouldThrow(); |
515 |
|
} catch (InterruptedException success) { } |
516 |
|
} |
517 |
|
}); |
522 |
|
t.interrupt(); |
523 |
|
t.join(); |
524 |
|
} catch (Exception e){ |
525 |
< |
fail("Unexpected exception"); |
525 |
> |
unexpectedException(); |
526 |
|
} |
527 |
|
} |
528 |
|
|
529 |
|
|
530 |
< |
public void testPeek(){ |
530 |
> |
/** |
531 |
> |
* |
532 |
> |
*/ |
533 |
> |
public void testPeek() { |
534 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
535 |
|
for (int i = 0; i < SIZE; ++i) { |
536 |
|
assertEquals(i, ((Integer)q.peek()).intValue()); |
541 |
|
assertNull(q.peek()); |
542 |
|
} |
543 |
|
|
544 |
< |
public void testElement(){ |
544 |
> |
/** |
545 |
> |
* |
546 |
> |
*/ |
547 |
> |
public void testElement() { |
548 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
549 |
|
for (int i = 0; i < SIZE; ++i) { |
550 |
|
assertEquals(i, ((Integer)q.element()).intValue()); |
552 |
|
} |
553 |
|
try { |
554 |
|
q.element(); |
555 |
< |
fail("no such element"); |
555 |
> |
shouldThrow(); |
556 |
|
} |
557 |
|
catch (NoSuchElementException success) {} |
558 |
|
} |
559 |
|
|
560 |
< |
public void testRemove(){ |
560 |
> |
/** |
561 |
> |
* |
562 |
> |
*/ |
563 |
> |
public void testRemove() { |
564 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
565 |
|
for (int i = 0; i < SIZE; ++i) { |
566 |
|
assertEquals(i, ((Integer)q.remove()).intValue()); |
567 |
|
} |
568 |
|
try { |
569 |
|
q.remove(); |
570 |
< |
fail("remove should throw"); |
570 |
> |
shouldThrow(); |
571 |
|
} catch (NoSuchElementException success){ |
572 |
|
} |
573 |
|
} |
574 |
|
|
575 |
< |
public void testRemoveElement(){ |
575 |
> |
/** |
576 |
> |
* |
577 |
> |
*/ |
578 |
> |
public void testRemoveElement() { |
579 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
580 |
|
for (int i = 1; i < SIZE; i+=2) { |
581 |
|
assertTrue(q.remove(new Integer(i))); |
587 |
|
assertTrue(q.isEmpty()); |
588 |
|
} |
589 |
|
|
590 |
< |
public void testContains(){ |
590 |
> |
/** |
591 |
> |
* |
592 |
> |
*/ |
593 |
> |
public void testContains() { |
594 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
595 |
|
for (int i = 0; i < SIZE; ++i) { |
596 |
|
assertTrue(q.contains(new Integer(i))); |
599 |
|
} |
600 |
|
} |
601 |
|
|
602 |
< |
public void testClear(){ |
602 |
> |
/** |
603 |
> |
* |
604 |
> |
*/ |
605 |
> |
public void testClear() { |
606 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
607 |
|
q.clear(); |
608 |
|
assertTrue(q.isEmpty()); |
614 |
|
assertTrue(q.isEmpty()); |
615 |
|
} |
616 |
|
|
617 |
< |
public void testContainsAll(){ |
617 |
> |
/** |
618 |
> |
* |
619 |
> |
*/ |
620 |
> |
public void testContainsAll() { |
621 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
622 |
|
LinkedBlockingQueue p = new LinkedBlockingQueue(SIZE); |
623 |
|
for (int i = 0; i < SIZE; ++i) { |
628 |
|
assertTrue(p.containsAll(q)); |
629 |
|
} |
630 |
|
|
631 |
< |
public void testRetainAll(){ |
631 |
> |
/** |
632 |
> |
* |
633 |
> |
*/ |
634 |
> |
public void testRetainAll() { |
635 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
636 |
|
LinkedBlockingQueue p = populatedQueue(SIZE); |
637 |
|
for (int i = 0; i < SIZE; ++i) { |
647 |
|
} |
648 |
|
} |
649 |
|
|
650 |
< |
public void testRemoveAll(){ |
650 |
> |
/** |
651 |
> |
* |
652 |
> |
*/ |
653 |
> |
public void testRemoveAll() { |
654 |
|
for (int i = 1; i < SIZE; ++i) { |
655 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
656 |
|
LinkedBlockingQueue p = populatedQueue(i); |
664 |
|
} |
665 |
|
|
666 |
|
|
667 |
< |
public void testToArray(){ |
667 |
> |
/** |
668 |
> |
* |
669 |
> |
*/ |
670 |
> |
public void testToArray() { |
671 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
672 |
|
Object[] o = q.toArray(); |
673 |
|
try { |
674 |
|
for(int i = 0; i < o.length; i++) |
675 |
|
assertEquals(o[i], q.take()); |
676 |
|
} catch (InterruptedException e){ |
677 |
< |
fail("Unexpected exception"); |
677 |
> |
unexpectedException(); |
678 |
|
} |
679 |
|
} |
680 |
|
|
681 |
< |
public void testToArray2(){ |
681 |
> |
/** |
682 |
> |
* |
683 |
> |
*/ |
684 |
> |
public void testToArray2() { |
685 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
686 |
|
Integer[] ints = new Integer[SIZE]; |
687 |
|
ints = (Integer[])q.toArray(ints); |
689 |
|
for(int i = 0; i < ints.length; i++) |
690 |
|
assertEquals(ints[i], q.take()); |
691 |
|
} catch (InterruptedException e){ |
692 |
< |
fail("Unexpected exception"); |
692 |
> |
unexpectedException(); |
693 |
|
} |
694 |
|
} |
695 |
|
|
696 |
< |
public void testIterator(){ |
696 |
> |
/** |
697 |
> |
* |
698 |
> |
*/ |
699 |
> |
public void testIterator() { |
700 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
701 |
|
Iterator it = q.iterator(); |
702 |
|
try { |
704 |
|
assertEquals(it.next(), q.take()); |
705 |
|
} |
706 |
|
} catch (InterruptedException e){ |
707 |
< |
fail("Unexpected exception"); |
707 |
> |
unexpectedException(); |
708 |
|
} |
709 |
|
} |
710 |
|
|
711 |
+ |
/** |
712 |
+ |
* |
713 |
+ |
*/ |
714 |
|
public void testIteratorOrdering() { |
715 |
|
|
716 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(3); |
719 |
|
q.add(two); |
720 |
|
q.add(three); |
721 |
|
|
722 |
< |
assertEquals("queue should be full", 0, q.remainingCapacity()); |
722 |
> |
assertEquals(0, q.remainingCapacity()); |
723 |
|
|
724 |
|
int k = 0; |
725 |
|
for (Iterator it = q.iterator(); it.hasNext();) { |
726 |
|
int i = ((Integer)(it.next())).intValue(); |
727 |
< |
assertEquals("items should come out in order", ++k, i); |
727 |
> |
assertEquals(++k, i); |
728 |
|
} |
729 |
|
|
730 |
< |
assertEquals("should go through 3 elements", 3, k); |
730 |
> |
assertEquals(3, k); |
731 |
|
} |
732 |
|
|
733 |
+ |
/** |
734 |
+ |
* |
735 |
+ |
*/ |
736 |
|
public void testWeaklyConsistentIteration () { |
737 |
|
|
738 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(3); |
748 |
|
} |
749 |
|
} |
750 |
|
catch (ConcurrentModificationException e) { |
751 |
< |
fail("weakly consistent iterator; should not get CME"); |
751 |
> |
unexpectedException(); |
752 |
|
} |
753 |
|
|
754 |
< |
assertEquals("queue should be empty again", 0, q.size()); |
754 |
> |
assertEquals(0, q.size()); |
755 |
|
} |
756 |
|
|
757 |
|
|
758 |
< |
public void testToString(){ |
758 |
> |
/** |
759 |
> |
* |
760 |
> |
*/ |
761 |
> |
public void testToString() { |
762 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
763 |
|
String s = q.toString(); |
764 |
|
for (int i = 0; i < SIZE; ++i) { |
767 |
|
} |
768 |
|
|
769 |
|
|
770 |
+ |
/** |
771 |
+ |
* |
772 |
+ |
*/ |
773 |
|
public void testOfferInExecutor() { |
774 |
|
|
775 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
787 |
|
threadAssertEquals(0, q.remainingCapacity()); |
788 |
|
} |
789 |
|
catch (InterruptedException e) { |
790 |
< |
threadFail("should not be interrupted"); |
790 |
> |
threadUnexpectedException(); |
791 |
|
} |
792 |
|
} |
793 |
|
}); |
799 |
|
threadAssertEquals(one, q.take()); |
800 |
|
} |
801 |
|
catch (InterruptedException e) { |
802 |
< |
threadFail("should not be interrupted"); |
802 |
> |
threadUnexpectedException(); |
803 |
|
} |
804 |
|
} |
805 |
|
}); |
808 |
|
|
809 |
|
} |
810 |
|
|
811 |
+ |
/** |
812 |
+ |
* |
813 |
+ |
*/ |
814 |
|
public void testPollInExecutor() { |
815 |
|
|
816 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
825 |
|
threadAssertTrue(q.isEmpty()); |
826 |
|
} |
827 |
|
catch (InterruptedException e) { |
828 |
< |
threadFail("should not be interrupted"); |
828 |
> |
threadUnexpectedException(); |
829 |
|
} |
830 |
|
} |
831 |
|
}); |
837 |
|
q.put(one); |
838 |
|
} |
839 |
|
catch (InterruptedException e) { |
840 |
< |
threadFail("should not be interrupted"); |
840 |
> |
threadUnexpectedException(); |
841 |
|
} |
842 |
|
} |
843 |
|
}); |
845 |
|
joinPool(executor); |
846 |
|
} |
847 |
|
|
848 |
+ |
/** |
849 |
+ |
* |
850 |
+ |
*/ |
851 |
|
public void testSerialization() { |
852 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
853 |
|
|
864 |
|
while (!q.isEmpty()) |
865 |
|
assertEquals(q.remove(), r.remove()); |
866 |
|
} catch(Exception e){ |
867 |
< |
e.printStackTrace(); |
727 |
< |
fail("unexpected exception"); |
867 |
> |
unexpectedException(); |
868 |
|
} |
869 |
|
} |
870 |
|
|