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

Comparing jsr166/src/test/tck/LinkedBlockingQueueTest.java (file contents):
Revision 1.16 by jsr166, Sat Nov 21 02:33:20 2009 UTC vs.
Revision 1.20 by jsr166, Sat Nov 21 21:00:34 2009 UTC

# Line 48 | Line 48 | public class LinkedBlockingQueueTest ext
48      }
49  
50      /**
51 <     * Constructor throws IAE if  capacity argument nonpositive
51 >     * Constructor throws IAE if capacity argument nonpositive
52       */
53      public void testConstructor2() {
54          try {
55              LinkedBlockingQueue q = new LinkedBlockingQueue(0);
56              shouldThrow();
57 <        }
58 <        catch (IllegalArgumentException success) {}
57 >        } catch (IllegalArgumentException success) {}
58      }
59  
60      /**
# Line 65 | Line 64 | public class LinkedBlockingQueueTest ext
64          try {
65              LinkedBlockingQueue q = new LinkedBlockingQueue(null);
66              shouldThrow();
67 <        }
69 <        catch (NullPointerException success) {}
67 >        } catch (NullPointerException success) {}
68      }
69  
70      /**
# Line 77 | Line 75 | public class LinkedBlockingQueueTest ext
75              Integer[] ints = new Integer[SIZE];
76              LinkedBlockingQueue q = new LinkedBlockingQueue(Arrays.asList(ints));
77              shouldThrow();
78 <        }
81 <        catch (NullPointerException success) {}
78 >        } catch (NullPointerException success) {}
79      }
80  
81      /**
# Line 91 | Line 88 | public class LinkedBlockingQueueTest ext
88                  ints[i] = new Integer(i);
89              LinkedBlockingQueue q = new LinkedBlockingQueue(Arrays.asList(ints));
90              shouldThrow();
91 <        }
95 <        catch (NullPointerException success) {}
91 >        } catch (NullPointerException success) {}
92      }
93  
94      /**
95       * Queue contains all elements of collection used to initialize
96       */
97      public void testConstructor6() {
98 <        try {
99 <            Integer[] ints = new Integer[SIZE];
100 <            for (int i = 0; i < SIZE; ++i)
101 <                ints[i] = new Integer(i);
102 <            LinkedBlockingQueue q = new LinkedBlockingQueue(Arrays.asList(ints));
103 <            for (int i = 0; i < SIZE; ++i)
108 <                assertEquals(ints[i], q.poll());
109 <        }
110 <        finally {}
98 >        Integer[] ints = new Integer[SIZE];
99 >        for (int i = 0; i < SIZE; ++i)
100 >            ints[i] = new Integer(i);
101 >        LinkedBlockingQueue q = new LinkedBlockingQueue(Arrays.asList(ints));
102 >        for (int i = 0; i < SIZE; ++i)
103 >            assertEquals(ints[i], q.poll());
104      }
105  
106      /**
# Line 150 | Line 143 | public class LinkedBlockingQueueTest ext
143              LinkedBlockingQueue q = new LinkedBlockingQueue(1);
144              q.offer(null);
145              shouldThrow();
146 <        } catch (NullPointerException success) { }
146 >        } catch (NullPointerException success) {}
147      }
148  
149      /**
# Line 161 | Line 154 | public class LinkedBlockingQueueTest ext
154              LinkedBlockingQueue q = new LinkedBlockingQueue(1);
155              q.add(null);
156              shouldThrow();
157 <        } catch (NullPointerException success) { }
157 >        } catch (NullPointerException success) {}
158      }
159  
160      /**
# Line 184 | Line 177 | public class LinkedBlockingQueueTest ext
177              }
178              assertEquals(0, q.remainingCapacity());
179              q.add(new Integer(SIZE));
180 <        } catch (IllegalStateException success) {
181 <        }
180 >            shouldThrow();
181 >        } catch (IllegalStateException success) {}
182      }
183  
184      /**
# Line 196 | Line 189 | public class LinkedBlockingQueueTest ext
189              LinkedBlockingQueue q = new LinkedBlockingQueue(1);
190              q.addAll(null);
191              shouldThrow();
192 <        }
200 <        catch (NullPointerException success) {}
192 >        } catch (NullPointerException success) {}
193      }
194  
195      /**
# Line 208 | Line 200 | public class LinkedBlockingQueueTest ext
200              LinkedBlockingQueue q = populatedQueue(SIZE);
201              q.addAll(q);
202              shouldThrow();
203 <        }
212 <        catch (IllegalArgumentException success) {}
203 >        } catch (IllegalArgumentException success) {}
204      }
205  
206      /**
# Line 221 | Line 212 | public class LinkedBlockingQueueTest ext
212              Integer[] ints = new Integer[SIZE];
213              q.addAll(Arrays.asList(ints));
214              shouldThrow();
215 <        }
225 <        catch (NullPointerException success) {}
215 >        } catch (NullPointerException success) {}
216      }
217      /**
218       * addAll of a collection with any null elements throws NPE after
# Line 236 | Line 226 | public class LinkedBlockingQueueTest ext
226                  ints[i] = new Integer(i);
227              q.addAll(Arrays.asList(ints));
228              shouldThrow();
229 <        }
240 <        catch (NullPointerException success) {}
229 >        } catch (NullPointerException success) {}
230      }
231      /**
232       * addAll throws ISE if not enough room
# Line 250 | Line 239 | public class LinkedBlockingQueueTest ext
239                  ints[i] = new Integer(i);
240              q.addAll(Arrays.asList(ints));
241              shouldThrow();
242 <        }
254 <        catch (IllegalStateException success) {}
242 >        } catch (IllegalStateException success) {}
243      }
244      /**
245       * Queue contains all elements, in traversal order, of successful addAll
246       */
247      public void testAddAll5() {
248 <        try {
249 <            Integer[] empty = new Integer[0];
250 <            Integer[] ints = new Integer[SIZE];
251 <            for (int i = 0; i < SIZE; ++i)
252 <                ints[i] = new Integer(i);
253 <            LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
254 <            assertFalse(q.addAll(Arrays.asList(empty)));
255 <            assertTrue(q.addAll(Arrays.asList(ints)));
256 <            for (int i = 0; i < SIZE; ++i)
269 <                assertEquals(ints[i], q.poll());
270 <        }
271 <        finally {}
248 >        Integer[] empty = new Integer[0];
249 >        Integer[] ints = new Integer[SIZE];
250 >        for (int i = 0; i < SIZE; ++i)
251 >            ints[i] = new Integer(i);
252 >        LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
253 >        assertFalse(q.addAll(Arrays.asList(empty)));
254 >        assertTrue(q.addAll(Arrays.asList(ints)));
255 >        for (int i = 0; i < SIZE; ++i)
256 >            assertEquals(ints[i], q.poll());
257      }
258  
259      /**
260       * put(null) throws NPE
261       */
262 <     public void testPutNull() {
262 >     public void testPutNull() throws InterruptedException {
263          try {
264              LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
265              q.put(null);
266              shouldThrow();
267 <        }
283 <        catch (NullPointerException success) {
284 <        }
285 <        catch (InterruptedException ie) {
286 <            unexpectedException();
287 <        }
267 >        } catch (NullPointerException success) {}
268       }
269  
270      /**
271       * all elements successfully put are contained
272       */
273 <     public void testPut() {
274 <         try {
275 <             LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
276 <             for (int i = 0; i < SIZE; ++i) {
277 <                 Integer I = new Integer(i);
278 <                 q.put(I);
299 <                 assertTrue(q.contains(I));
300 <             }
301 <             assertEquals(0, q.remainingCapacity());
302 <         }
303 <        catch (InterruptedException ie) {
304 <            unexpectedException();
273 >    public void testPut() throws InterruptedException {
274 >        LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
275 >        for (int i = 0; i < SIZE; ++i) {
276 >            Integer I = new Integer(i);
277 >            q.put(I);
278 >            assertTrue(q.contains(I));
279          }
280 +        assertEquals(0, q.remainingCapacity());
281      }
282  
283      /**
284       * put blocks interruptibly if full
285       */
286 <    public void testBlockingPut() {
287 <        Thread t = new Thread(new Runnable() {
288 <                public void run() {
289 <                    int added = 0;
290 <                    try {
291 <                        LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
292 <                        for (int i = 0; i < SIZE; ++i) {
293 <                            q.put(new Integer(i));
294 <                            ++added;
320 <                        }
321 <                        q.put(new Integer(SIZE));
322 <                        threadShouldThrow();
323 <                    } catch (InterruptedException ie) {
324 <                        threadAssertEquals(added, SIZE);
286 >    public void testBlockingPut() throws InterruptedException {
287 >        Thread t = new Thread(new CheckedRunnable() {
288 >            public void realRun() {
289 >                int added = 0;
290 >                try {
291 >                    LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
292 >                    for (int i = 0; i < SIZE; ++i) {
293 >                        q.put(new Integer(i));
294 >                        ++added;
295                      }
296 <                }});
296 >                    q.put(new Integer(SIZE));
297 >                    threadShouldThrow();
298 >                } catch (InterruptedException success) {
299 >                    threadAssertEquals(added, SIZE);
300 >                }
301 >            }});
302 >
303          t.start();
304 <        try {
305 <           Thread.sleep(SHORT_DELAY_MS);
306 <           t.interrupt();
331 <           t.join();
332 <        }
333 <        catch (InterruptedException ie) {
334 <            unexpectedException();
335 <        }
304 >        Thread.sleep(SHORT_DELAY_MS);
305 >        t.interrupt();
306 >        t.join();
307      }
308  
309      /**
310       * put blocks waiting for take when full
311       */
312 <    public void testPutWithTake() {
312 >    public void testPutWithTake() throws InterruptedException {
313          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
314 <        Thread t = new Thread(new Runnable() {
315 <                public void run() {
316 <                    int added = 0;
317 <                    try {
318 <                        q.put(new Object());
319 <                        ++added;
320 <                        q.put(new Object());
321 <                        ++added;
322 <                        q.put(new Object());
323 <                        ++added;
324 <                        q.put(new Object());
325 <                        ++added;
326 <                        threadShouldThrow();
327 <                    } catch (InterruptedException e) {
328 <                        threadAssertTrue(added >= 2);
358 <                    }
314 >        Thread t = new Thread(new CheckedRunnable() {
315 >            public void realRun() {
316 >                int added = 0;
317 >                try {
318 >                    q.put(new Object());
319 >                    ++added;
320 >                    q.put(new Object());
321 >                    ++added;
322 >                    q.put(new Object());
323 >                    ++added;
324 >                    q.put(new Object());
325 >                    ++added;
326 >                    threadShouldThrow();
327 >                } catch (InterruptedException success) {
328 >                    threadAssertTrue(added >= 2);
329                  }
330 <            });
331 <        try {
332 <            t.start();
333 <            Thread.sleep(SHORT_DELAY_MS);
334 <            q.take();
335 <            t.interrupt();
336 <            t.join();
367 <        } catch (Exception e) {
368 <            unexpectedException();
369 <        }
330 >            }});
331 >
332 >        t.start();
333 >        Thread.sleep(SHORT_DELAY_MS);
334 >        q.take();
335 >        t.interrupt();
336 >        t.join();
337      }
338  
339      /**
340       * timed offer times out if full and elements not taken
341       */
342 <    public void testTimedOffer() {
342 >    public void testTimedOffer() throws InterruptedException {
343          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
344 <        Thread t = new Thread(new Runnable() {
345 <                public void run() {
346 <                    try {
347 <                        q.put(new Object());
348 <                        q.put(new Object());
349 <                        threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
350 <                        q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
384 <                        threadShouldThrow();
385 <                    } catch (InterruptedException success) {}
386 <                }
387 <            });
344 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
345 >            public void realRun() throws InterruptedException {
346 >                q.put(new Object());
347 >                q.put(new Object());
348 >                threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
349 >                q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
350 >            }};
351  
352 <        try {
353 <            t.start();
354 <            Thread.sleep(SMALL_DELAY_MS);
355 <            t.interrupt();
393 <            t.join();
394 <        } catch (Exception e) {
395 <            unexpectedException();
396 <        }
352 >        t.start();
353 >        Thread.sleep(SMALL_DELAY_MS);
354 >        t.interrupt();
355 >        t.join();
356      }
357  
358      /**
359       * take retrieves elements in FIFO order
360       */
361 <    public void testTake() {
362 <        try {
363 <            LinkedBlockingQueue q = populatedQueue(SIZE);
364 <            for (int i = 0; i < SIZE; ++i) {
406 <                assertEquals(i, ((Integer)q.take()).intValue());
407 <            }
408 <        } catch (InterruptedException e) {
409 <            unexpectedException();
361 >    public void testTake() throws InterruptedException {
362 >        LinkedBlockingQueue q = populatedQueue(SIZE);
363 >        for (int i = 0; i < SIZE; ++i) {
364 >            assertEquals(i, ((Integer)q.take()).intValue());
365          }
366      }
367  
368      /**
369       * take blocks interruptibly when empty
370       */
371 <    public void testTakeFromEmpty() {
371 >    public void testTakeFromEmpty() throws InterruptedException {
372          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
373 <        Thread t = new Thread(new Runnable() {
374 <                public void run() {
375 <                    try {
376 <                        q.take();
377 <                        threadShouldThrow();
378 <                    } catch (InterruptedException success) { }
379 <                }
380 <            });
381 <        try {
427 <            t.start();
428 <            Thread.sleep(SHORT_DELAY_MS);
429 <            t.interrupt();
430 <            t.join();
431 <        } catch (Exception e) {
432 <            unexpectedException();
433 <        }
373 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
374 >            public void realRun() throws InterruptedException {
375 >                q.take();
376 >            }};
377 >
378 >        t.start();
379 >        Thread.sleep(SHORT_DELAY_MS);
380 >        t.interrupt();
381 >        t.join();
382      }
383  
384      /**
385       * Take removes existing elements until empty, then blocks interruptibly
386       */
387 <    public void testBlockingTake() {
388 <        Thread t = new Thread(new Runnable() {
389 <                public void run() {
390 <                    try {
391 <                        LinkedBlockingQueue q = populatedQueue(SIZE);
392 <                        for (int i = 0; i < SIZE; ++i) {
393 <                            assertEquals(i, ((Integer)q.take()).intValue());
394 <                        }
395 <                        q.take();
396 <                        threadShouldThrow();
449 <                    } catch (InterruptedException success) {
450 <                    }
451 <                }});
387 >    public void testBlockingTake() throws InterruptedException {
388 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
389 >            public void realRun() throws InterruptedException {
390 >                LinkedBlockingQueue q = populatedQueue(SIZE);
391 >                for (int i = 0; i < SIZE; ++i) {
392 >                    assertEquals(i, ((Integer)q.take()).intValue());
393 >                }
394 >                q.take();
395 >            }};
396 >
397          t.start();
398 <        try {
399 <           Thread.sleep(SHORT_DELAY_MS);
400 <           t.interrupt();
456 <           t.join();
457 <        }
458 <        catch (InterruptedException ie) {
459 <            unexpectedException();
460 <        }
398 >        Thread.sleep(SHORT_DELAY_MS);
399 >        t.interrupt();
400 >        t.join();
401      }
402  
403  
# Line 475 | Line 415 | public class LinkedBlockingQueueTest ext
415      /**
416       * timed pool with zero timeout succeeds when non-empty, else times out
417       */
418 <    public void testTimedPoll0() {
419 <        try {
420 <            LinkedBlockingQueue q = populatedQueue(SIZE);
421 <            for (int i = 0; i < SIZE; ++i) {
482 <                assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
483 <            }
484 <            assertNull(q.poll(0, MILLISECONDS));
485 <        } catch (InterruptedException e) {
486 <            unexpectedException();
418 >    public void testTimedPoll0() throws InterruptedException {
419 >        LinkedBlockingQueue q = populatedQueue(SIZE);
420 >        for (int i = 0; i < SIZE; ++i) {
421 >            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
422          }
423 +        assertNull(q.poll(0, MILLISECONDS));
424      }
425  
426      /**
427       * timed pool with nonzero timeout succeeds when non-empty, else times out
428       */
429 <    public void testTimedPoll() {
430 <        try {
431 <            LinkedBlockingQueue q = populatedQueue(SIZE);
432 <            for (int i = 0; i < SIZE; ++i) {
497 <                assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
498 <            }
499 <            assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
500 <        } catch (InterruptedException e) {
501 <            unexpectedException();
429 >    public void testTimedPoll() throws InterruptedException {
430 >        LinkedBlockingQueue q = populatedQueue(SIZE);
431 >        for (int i = 0; i < SIZE; ++i) {
432 >            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
433          }
434 +        assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
435      }
436  
437      /**
438       * Interrupted timed poll throws InterruptedException instead of
439       * returning timeout status
440       */
441 <    public void testInterruptedTimedPoll() {
442 <        Thread t = new Thread(new Runnable() {
443 <                public void run() {
444 <                    try {
445 <                        LinkedBlockingQueue q = populatedQueue(SIZE);
446 <                        for (int i = 0; i < SIZE; ++i) {
447 <                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
448 <                        }
449 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
450 <                    } catch (InterruptedException success) {
451 <                    }
452 <                }});
441 >    public void testInterruptedTimedPoll() throws InterruptedException {
442 >        Thread t = new Thread(new CheckedRunnable() {
443 >            public void realRun() throws InterruptedException {
444 >                LinkedBlockingQueue q = populatedQueue(SIZE);
445 >                for (int i = 0; i < SIZE; ++i) {
446 >                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
447 >                }
448 >                try {
449 >                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
450 >                    shouldThrow();
451 >                } catch (InterruptedException success) {}
452 >            }});
453 >
454          t.start();
455 <        try {
456 <           Thread.sleep(SHORT_DELAY_MS);
457 <           t.interrupt();
525 <           t.join();
526 <        }
527 <        catch (InterruptedException ie) {
528 <            unexpectedException();
529 <        }
455 >        Thread.sleep(SHORT_DELAY_MS);
456 >        t.interrupt();
457 >        t.join();
458      }
459  
460      /**
461       *  timed poll before a delayed offer fails; after offer succeeds;
462       *  on interruption throws
463       */
464 <    public void testTimedPollWithOffer() {
464 >    public void testTimedPollWithOffer() throws InterruptedException {
465          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
466 <        Thread t = new Thread(new Runnable() {
467 <                public void run() {
468 <                    try {
469 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
470 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
471 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
472 <                        threadShouldThrow();
473 <                    } catch (InterruptedException success) { }
474 <                }
475 <            });
476 <        try {
477 <            t.start();
478 <            Thread.sleep(SMALL_DELAY_MS);
479 <            assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
480 <            t.interrupt();
553 <            t.join();
554 <        } catch (Exception e) {
555 <            unexpectedException();
556 <        }
466 >        Thread t = new Thread(new CheckedRunnable() {
467 >            public void realRun() throws InterruptedException {
468 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
469 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
470 >                try {
471 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
472 >                    shouldThrow();
473 >                } catch (InterruptedException success) {}
474 >            }});
475 >
476 >        t.start();
477 >        Thread.sleep(SMALL_DELAY_MS);
478 >        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
479 >        t.interrupt();
480 >        t.join();
481      }
482  
483      /**
# Line 582 | Line 506 | public class LinkedBlockingQueueTest ext
506          try {
507              q.element();
508              shouldThrow();
509 <        }
586 <        catch (NoSuchElementException success) {}
509 >        } catch (NoSuchElementException success) {}
510      }
511  
512      /**
# Line 597 | Line 520 | public class LinkedBlockingQueueTest ext
520          try {
521              q.remove();
522              shouldThrow();
523 <        } catch (NoSuchElementException success) {
601 <        }
523 >        } catch (NoSuchElementException success) {}
524      }
525  
526      /**
# Line 619 | Line 541 | public class LinkedBlockingQueueTest ext
541      /**
542       * An add following remove(x) succeeds
543       */
544 <    public void testRemoveElementAndAdd() {
545 <        try {
546 <            LinkedBlockingQueue q = new LinkedBlockingQueue();
547 <            assertTrue(q.add(new Integer(1)));
548 <            assertTrue(q.add(new Integer(2)));
549 <            assertTrue(q.remove(new Integer(1)));
550 <            assertTrue(q.remove(new Integer(2)));
551 <            assertTrue(q.add(new Integer(3)));
630 <            assertTrue(q.take() != null);
631 <        } catch (Exception e) {
632 <            unexpectedException();
633 <        }
544 >    public void testRemoveElementAndAdd() throws InterruptedException {
545 >        LinkedBlockingQueue q = new LinkedBlockingQueue();
546 >        assertTrue(q.add(new Integer(1)));
547 >        assertTrue(q.add(new Integer(2)));
548 >        assertTrue(q.remove(new Integer(1)));
549 >        assertTrue(q.remove(new Integer(2)));
550 >        assertTrue(q.add(new Integer(3)));
551 >        assertTrue(q.take() != null);
552      }
553  
554      /**
# Line 713 | Line 631 | public class LinkedBlockingQueueTest ext
631      /**
632       * toArray contains all elements
633       */
634 <    public void testToArray() {
634 >    public void testToArray() throws InterruptedException {
635          LinkedBlockingQueue q = populatedQueue(SIZE);
636          Object[] o = q.toArray();
719        try {
637          for (int i = 0; i < o.length; i++)
638              assertEquals(o[i], q.take());
722        } catch (InterruptedException e) {
723            unexpectedException();
724        }
639      }
640  
641      /**
642       * toArray(a) contains all elements
643       */
644 <    public void testToArray2() {
644 >    public void testToArray2() throws InterruptedException {
645          LinkedBlockingQueue q = populatedQueue(SIZE);
646          Integer[] ints = new Integer[SIZE];
647          ints = (Integer[])q.toArray(ints);
648 <        try {
649 <            for (int i = 0; i < ints.length; i++)
736 <                assertEquals(ints[i], q.take());
737 <        } catch (InterruptedException e) {
738 <            unexpectedException();
739 <        }
648 >        for (int i = 0; i < ints.length; i++)
649 >            assertEquals(ints[i], q.take());
650      }
651  
652      /**
# Line 758 | Line 668 | public class LinkedBlockingQueueTest ext
668              LinkedBlockingQueue q = populatedQueue(SIZE);
669              Object o[] = q.toArray(new String[10] );
670              shouldThrow();
671 <        } catch (ArrayStoreException  success) {}
671 >        } catch (ArrayStoreException success) {}
672      }
673  
674  
675      /**
676       * iterator iterates through all elements
677       */
678 <    public void testIterator() {
678 >    public void testIterator() throws InterruptedException {
679          LinkedBlockingQueue q = populatedQueue(SIZE);
680          Iterator it = q.iterator();
681 <        try {
682 <            while (it.hasNext()) {
773 <                assertEquals(it.next(), q.take());
774 <            }
775 <        } catch (InterruptedException e) {
776 <            unexpectedException();
681 >        while (it.hasNext()) {
682 >            assertEquals(it.next(), q.take());
683          }
684      }
685  
# Line 822 | Line 728 | public class LinkedBlockingQueueTest ext
728          q.add(one);
729          q.add(two);
730          q.add(three);
731 <        try {
732 <            for (Iterator it = q.iterator(); it.hasNext();) {
733 <                q.remove();
828 <                it.next();
829 <            }
830 <        }
831 <        catch (ConcurrentModificationException e) {
832 <            unexpectedException();
731 >        for (Iterator it = q.iterator(); it.hasNext();) {
732 >            q.remove();
733 >            it.next();
734          }
735          assertEquals(0, q.size());
736      }
# Line 855 | Line 756 | public class LinkedBlockingQueueTest ext
756          q.add(one);
757          q.add(two);
758          ExecutorService executor = Executors.newFixedThreadPool(2);
759 <        executor.execute(new Runnable() {
760 <            public void run() {
759 >        executor.execute(new CheckedRunnable() {
760 >            public void realRun() throws InterruptedException {
761                  threadAssertFalse(q.offer(three));
762 <                try {
763 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
764 <                    threadAssertEquals(0, q.remainingCapacity());
765 <                }
766 <                catch (InterruptedException e) {
767 <                    threadUnexpectedException();
768 <                }
769 <            }
770 <        });
870 <
871 <        executor.execute(new Runnable() {
872 <            public void run() {
873 <                try {
874 <                    Thread.sleep(SMALL_DELAY_MS);
875 <                    threadAssertEquals(one, q.take());
876 <                }
877 <                catch (InterruptedException e) {
878 <                    threadUnexpectedException();
879 <                }
880 <            }
881 <        });
762 >                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
763 >                threadAssertEquals(0, q.remainingCapacity());
764 >            }});
765 >
766 >        executor.execute(new CheckedRunnable() {
767 >            public void realRun() throws InterruptedException {
768 >                Thread.sleep(SMALL_DELAY_MS);
769 >                threadAssertEquals(one, q.take());
770 >            }});
771  
772          joinPool(executor);
773      }
# Line 889 | Line 778 | public class LinkedBlockingQueueTest ext
778      public void testPollInExecutor() {
779          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
780          ExecutorService executor = Executors.newFixedThreadPool(2);
781 <        executor.execute(new Runnable() {
782 <            public void run() {
781 >        executor.execute(new CheckedRunnable() {
782 >            public void realRun() throws InterruptedException {
783                  threadAssertNull(q.poll());
784 <                try {
785 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
786 <                    threadAssertTrue(q.isEmpty());
787 <                }
788 <                catch (InterruptedException e) {
789 <                    threadUnexpectedException();
790 <                }
791 <            }
792 <        });
904 <
905 <        executor.execute(new Runnable() {
906 <            public void run() {
907 <                try {
908 <                    Thread.sleep(SMALL_DELAY_MS);
909 <                    q.put(one);
910 <                }
911 <                catch (InterruptedException e) {
912 <                    threadUnexpectedException();
913 <                }
914 <            }
915 <        });
784 >                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
785 >                threadAssertTrue(q.isEmpty());
786 >            }});
787 >
788 >        executor.execute(new CheckedRunnable() {
789 >            public void realRun() throws InterruptedException {
790 >                Thread.sleep(SMALL_DELAY_MS);
791 >                q.put(one);
792 >            }});
793  
794          joinPool(executor);
795      }
# Line 920 | Line 797 | public class LinkedBlockingQueueTest ext
797      /**
798       * A deserialized serialized queue has same elements in same order
799       */
800 <    public void testSerialization() {
800 >    public void testSerialization() throws Exception {
801          LinkedBlockingQueue q = populatedQueue(SIZE);
802  
803 <        try {
804 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
805 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
806 <            out.writeObject(q);
807 <            out.close();
808 <
809 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
810 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
811 <            LinkedBlockingQueue r = (LinkedBlockingQueue)in.readObject();
812 <            assertEquals(q.size(), r.size());
813 <            while (!q.isEmpty())
937 <                assertEquals(q.remove(), r.remove());
938 <        } catch (Exception e) {
939 <            unexpectedException();
940 <        }
803 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
804 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
805 >        out.writeObject(q);
806 >        out.close();
807 >
808 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
809 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
810 >        LinkedBlockingQueue r = (LinkedBlockingQueue)in.readObject();
811 >        assertEquals(q.size(), r.size());
812 >        while (!q.isEmpty())
813 >            assertEquals(q.remove(), r.remove());
814      }
815  
816      /**
# Line 948 | Line 821 | public class LinkedBlockingQueueTest ext
821          try {
822              q.drainTo(null);
823              shouldThrow();
824 <        } catch (NullPointerException success) {
952 <        }
824 >        } catch (NullPointerException success) {}
825      }
826  
827      /**
# Line 960 | Line 832 | public class LinkedBlockingQueueTest ext
832          try {
833              q.drainTo(q);
834              shouldThrow();
835 <        } catch (IllegalArgumentException success) {
964 <        }
835 >        } catch (IllegalArgumentException success) {}
836      }
837  
838      /**
# Line 991 | Line 862 | public class LinkedBlockingQueueTest ext
862      /**
863       * drainTo empties full queue, unblocking a waiting put.
864       */
865 <    public void testDrainToWithActivePut() {
865 >    public void testDrainToWithActivePut() throws InterruptedException {
866          final LinkedBlockingQueue q = populatedQueue(SIZE);
867 <        Thread t = new Thread(new Runnable() {
868 <                public void run() {
869 <                    try {
870 <                        q.put(new Integer(SIZE+1));
871 <                    } catch (InterruptedException ie) {
872 <                        threadUnexpectedException();
873 <                    }
874 <                }
875 <            });
876 <        try {
877 <            t.start();
878 <            ArrayList l = new ArrayList();
879 <            q.drainTo(l);
1009 <            assertTrue(l.size() >= SIZE);
1010 <            for (int i = 0; i < SIZE; ++i)
1011 <                assertEquals(l.get(i), new Integer(i));
1012 <            t.join();
1013 <            assertTrue(q.size() + l.size() >= SIZE);
1014 <        } catch (Exception e) {
1015 <            unexpectedException();
1016 <        }
867 >        Thread t = new Thread(new CheckedRunnable() {
868 >            public void realRun() throws InterruptedException {
869 >                q.put(new Integer(SIZE+1));
870 >            }});
871 >
872 >        t.start();
873 >        ArrayList l = new ArrayList();
874 >        q.drainTo(l);
875 >        assertTrue(l.size() >= SIZE);
876 >        for (int i = 0; i < SIZE; ++i)
877 >            assertEquals(l.get(i), new Integer(i));
878 >        t.join();
879 >        assertTrue(q.size() + l.size() >= SIZE);
880      }
881  
882      /**
# Line 1024 | Line 887 | public class LinkedBlockingQueueTest ext
887          try {
888              q.drainTo(null, 0);
889              shouldThrow();
890 <        } catch (NullPointerException success) {
1028 <        }
890 >        } catch (NullPointerException success) {}
891      }
892  
893      /**
# Line 1036 | Line 898 | public class LinkedBlockingQueueTest ext
898          try {
899              q.drainTo(q, 0);
900              shouldThrow();
901 <        } catch (IllegalArgumentException success) {
1040 <        }
901 >        } catch (IllegalArgumentException success) {}
902      }
903  
904      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines