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

Comparing jsr166/src/test/tck/LinkedTransferQueueTest.java (file contents):
Revision 1.5 by jsr166, Sun Aug 2 08:17:31 2009 UTC vs.
Revision 1.31 by jsr166, Thu Oct 28 22:42:05 2010 UTC

# Line 13 | Line 13 | import java.io.ObjectInputStream;
13   import java.io.ObjectOutputStream;
14   import java.util.ArrayList;
15   import java.util.Arrays;
16 import java.util.ConcurrentModificationException;
16   import java.util.Iterator;
17 + import java.util.List;
18   import java.util.NoSuchElementException;
19   import java.util.concurrent.*;
20 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
21 + import static java.util.concurrent.TimeUnit.NANOSECONDS;
22   import junit.framework.Test;
23   import junit.framework.TestSuite;
24  
25 + @SuppressWarnings({"unchecked", "rawtypes"})
26   public class LinkedTransferQueueTest extends JSR166TestCase {
27  
28 +    public static class Generic extends BlockingQueueTest {
29 +        protected BlockingQueue emptyCollection() {
30 +            return new LinkedTransferQueue();
31 +        }
32 +    }
33 +
34      public static void main(String[] args) {
35          junit.textui.TestRunner.run(suite());
36      }
37  
38      public static Test suite() {
39 <        return new TestSuite(LinkedTransferQueueTest.class);
39 >        return newTestSuite(LinkedTransferQueueTest.class,
40 >                            new Generic().testSuite());
41 >    }
42 >
43 >    void checkEmpty(BlockingQueue q) {
44 >        try {
45 >            assertTrue(q.isEmpty());
46 >            assertEquals(0, q.size());
47 >            assertNull(q.peek());
48 >            assertNull(q.poll());
49 >            assertNull(q.poll(0, MILLISECONDS));
50 >            assertEquals(q.toString(), "[]");
51 >            assertTrue(Arrays.equals(q.toArray(), new Object[0]));
52 >            assertFalse(q.iterator().hasNext());
53 >            try {
54 >                q.element();
55 >                shouldThrow();
56 >            } catch (NoSuchElementException success) {}
57 >            try {
58 >                q.iterator().next();
59 >                shouldThrow();
60 >            } catch (NoSuchElementException success) {}
61 >            try {
62 >                q.remove();
63 >                shouldThrow();
64 >            } catch (NoSuchElementException success) {}
65 >        } catch (InterruptedException ie) {
66 >            threadUnexpectedException(ie);
67 >        }
68      }
69  
70      /**
71 <     * Constructor builds new queue with size being zero and empty being true
71 >     * Constructor builds new queue with size being zero and empty
72 >     * being true
73       */
74      public void testConstructor1() {
75          assertEquals(0, new LinkedTransferQueue().size());
# Line 39 | Line 77 | public class LinkedTransferQueueTest ext
77      }
78  
79      /**
80 <     * Initializing constructor with null collection throws NullPointerException
80 >     * Initializing constructor with null collection throws
81 >     * NullPointerException
82       */
83      public void testConstructor2() {
84          try {
85              new LinkedTransferQueue(null);
86              shouldThrow();
87 <        } catch (NullPointerException success) {
49 <        }
87 >        } catch (NullPointerException success) {}
88      }
89  
90      /**
91 <     * Initializing from Collection of null elements throws NullPointerException
91 >     * Initializing from Collection of null elements throws
92 >     * NullPointerException
93       */
94      public void testConstructor3() {
95          try {
96              Integer[] ints = new Integer[SIZE];
97 <            LinkedTransferQueue q = new LinkedTransferQueue(Arrays.asList(ints));
97 >            new LinkedTransferQueue(Arrays.asList(ints));
98              shouldThrow();
99 <        } catch (NullPointerException success) {
61 <        }
99 >        } catch (NullPointerException success) {}
100      }
101  
102      /**
# Line 71 | Line 109 | public class LinkedTransferQueueTest ext
109              for (int i = 0; i < SIZE - 1; ++i) {
110                  ints[i] = i;
111              }
112 <            LinkedTransferQueue q = new LinkedTransferQueue(Arrays.asList(ints));
112 >            new LinkedTransferQueue(Arrays.asList(ints));
113              shouldThrow();
114 <        } catch (NullPointerException success) {
77 <        }
114 >        } catch (NullPointerException success) {}
115      }
116  
117      /**
118       * Queue contains all elements of the collection it is initialized by
119       */
120      public void testConstructor5() {
121 <        try {
122 <            Integer[] ints = new Integer[SIZE];
123 <            for (int i = 0; i < SIZE; ++i) {
124 <                ints[i] = i;
125 <            }
126 <            LinkedTransferQueue q = new LinkedTransferQueue(Arrays.asList(ints));
127 <            for (int i = 0; i < SIZE; ++i) {
128 <                assertEquals(ints[i], q.poll());
129 <            }
130 <        } finally {
121 >        Integer[] ints = new Integer[SIZE];
122 >        for (int i = 0; i < SIZE; ++i) {
123 >            ints[i] = i;
124 >        }
125 >        List intList = Arrays.asList(ints);
126 >        LinkedTransferQueue q
127 >            = new LinkedTransferQueue(intList);
128 >        assertEquals(q.size(), intList.size());
129 >        assertEquals(q.toString(), intList.toString());
130 >        assertTrue(Arrays.equals(q.toArray(),
131 >                                     intList.toArray()));
132 >        assertTrue(Arrays.equals(q.toArray(new Object[0]),
133 >                                 intList.toArray(new Object[0])));
134 >        assertTrue(Arrays.equals(q.toArray(new Object[SIZE]),
135 >                                 intList.toArray(new Object[SIZE])));
136 >        for (int i = 0; i < SIZE; ++i) {
137 >            assertEquals(ints[i], q.poll());
138          }
139      }
140  
141      /**
142 <     * Remaining capacity never decrease nor increase on add or remove
142 >     * remainingCapacity() always returns Integer.MAX_VALUE
143       */
144      public void testRemainingCapacity() {
145          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
# Line 119 | Line 163 | public class LinkedTransferQueueTest ext
163              LinkedTransferQueue q = new LinkedTransferQueue();
164              q.offer(null);
165              shouldThrow();
166 <        } catch (NullPointerException success) {
123 <        }
166 >        } catch (NullPointerException success) {}
167      }
168  
169      /**
# Line 131 | Line 174 | public class LinkedTransferQueueTest ext
174              LinkedTransferQueue q = new LinkedTransferQueue();
175              q.add(null);
176              shouldThrow();
177 <        } catch (NullPointerException success) {
135 <        }
177 >        } catch (NullPointerException success) {}
178      }
179  
180      /**
# Line 143 | Line 185 | public class LinkedTransferQueueTest ext
185              LinkedTransferQueue q = new LinkedTransferQueue();
186              q.addAll(null);
187              shouldThrow();
188 <        } catch (NullPointerException success) {
147 <        }
188 >        } catch (NullPointerException success) {}
189      }
190  
191      /**
# Line 155 | Line 196 | public class LinkedTransferQueueTest ext
196              LinkedTransferQueue q = populatedQueue(SIZE);
197              q.addAll(q);
198              shouldThrow();
199 <        } catch (IllegalArgumentException success) {
159 <        }
199 >        } catch (IllegalArgumentException success) {}
200      }
201  
202      /**
# Line 168 | Line 208 | public class LinkedTransferQueueTest ext
208              Integer[] ints = new Integer[SIZE];
209              q.addAll(Arrays.asList(ints));
210              shouldThrow();
211 <        } catch (NullPointerException success) {
172 <        }
211 >        } catch (NullPointerException success) {}
212      }
213  
214      /**
215 <     * addAll of a collection with any null elements throws NullPointerException after
216 <     * possibly adding some elements
215 >     * addAll of a collection with any null elements throws
216 >     * NullPointerException after possibly adding some elements
217       */
218      public void testAddAll3() {
219          try {
# Line 185 | Line 224 | public class LinkedTransferQueueTest ext
224              }
225              q.addAll(Arrays.asList(ints));
226              shouldThrow();
227 <        } catch (NullPointerException success) {
189 <        }
227 >        } catch (NullPointerException success) {}
228      }
229  
230      /**
# Line 223 | Line 261 | public class LinkedTransferQueueTest ext
261      public void testPut() {
262          LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>();
263          for (int i = 0; i < SIZE; ++i) {
264 +            assertEquals(q.size(), i);
265              q.put(i);
266              assertTrue(q.contains(i));
267          }
229        assertEquals(q.size(), SIZE);
268      }
269  
270      /**
# Line 240 | Line 278 | public class LinkedTransferQueueTest ext
278      }
279  
280      /**
281 <     * take blocks interruptibly when empty
244 <     */
245 <    public void testTakeFromEmpty() throws InterruptedException {
246 <        final LinkedTransferQueue q = new LinkedTransferQueue();
247 <        Thread t = new Thread(new Runnable() {
248 <            public void run() {
249 <                try {
250 <                    q.take();
251 <                    threadShouldThrow();
252 <                } catch (InterruptedException success) {
253 <                } catch (Throwable ex) {
254 <                    threadUnexpectedException(ex);
255 <                }
256 <            }});
257 <        t.start();
258 <        Thread.sleep(SHORT_DELAY_MS);
259 <        t.interrupt();
260 <        t.join();
261 <    }
262 <
263 <    /**
264 <     * Take removes existing elements until empty, then blocks interruptibly
281 >     * take removes existing elements until empty, then blocks interruptibly
282       */
283      public void testBlockingTake() throws InterruptedException {
284 <        Thread t = new Thread(new Runnable() {
285 <            public void run() {
284 >        final BlockingQueue<Integer> q = populatedQueue(SIZE);
285 >        final CountDownLatch aboutToWait = new CountDownLatch(1);
286 >        Thread t = newStartedThread(new CheckedRunnable() {
287 >            public void realRun() throws InterruptedException {
288 >                for (int i = 0; i < SIZE; ++i) {
289 >                    assertEquals(i, (int) q.take());
290 >                }
291 >                aboutToWait.countDown();
292                  try {
270                    LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
271                    for (int i = 0; i < SIZE; ++i) {
272                        threadAssertEquals(i, (int) q.take());
273                    }
293                      q.take();
294 <                    threadShouldThrow();
295 <                } catch (InterruptedException success) {
277 <                } catch (Throwable ex) {
278 <                    threadUnexpectedException(ex);
279 <                }
294 >                    shouldThrow();
295 >                } catch (InterruptedException success) {}
296              }});
297 <        t.start();
298 <        Thread.sleep(SHORT_DELAY_MS);
297 >
298 >        aboutToWait.await();
299 >        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
300          t.interrupt();
301 <        t.join();
301 >        awaitTermination(t, MEDIUM_DELAY_MS);
302 >        checkEmpty(q);
303      }
304  
305      /**
306       * poll succeeds unless empty
307       */
308 <    public void testPoll() {
308 >    public void testPoll() throws InterruptedException {
309          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
310          for (int i = 0; i < SIZE; ++i) {
311              assertEquals(i, (int) q.poll());
312          }
313          assertNull(q.poll());
314 +        checkEmpty(q);
315      }
316  
317      /**
318 <     * timed pool with zero timeout succeeds when non-empty, else times out
318 >     * timed poll with zero timeout succeeds when non-empty, else times out
319       */
320      public void testTimedPoll0() throws InterruptedException {
321          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
322          for (int i = 0; i < SIZE; ++i) {
323 <            assertEquals(i, (int) q.poll(0, TimeUnit.MILLISECONDS));
323 >            assertEquals(i, (int) q.poll(0, MILLISECONDS));
324          }
325 <        assertNull(q.poll(0, TimeUnit.MILLISECONDS));
325 >        assertNull(q.poll(0, MILLISECONDS));
326 >        checkEmpty(q);
327      }
328  
329      /**
330 <     * timed pool with nonzero timeout succeeds when non-empty, else times out
330 >     * timed poll with nonzero timeout succeeds when non-empty, else times out
331       */
332      public void testTimedPoll() throws InterruptedException {
333          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
334          for (int i = 0; i < SIZE; ++i) {
335 <            assertEquals(i, (int) q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
336 <        }
337 <        assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
335 >            long t0 = System.nanoTime();
336 >            assertEquals(i, (int) q.poll(SMALL_DELAY_MS, MILLISECONDS));
337 >            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
338 >        }
339 >        long t0 = System.nanoTime();
340 >        assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
341 >        assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
342 >        checkEmpty(q);
343      }
344  
345      /**
# Line 322 | Line 347 | public class LinkedTransferQueueTest ext
347       * returning timeout status
348       */
349      public void testInterruptedTimedPoll() throws InterruptedException {
350 <        Thread t = new Thread(new Runnable() {
351 <            public void run() {
352 <                try {
353 <                    LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
354 <                    for (int i = 0; i < SIZE; ++i) {
355 <                        threadAssertEquals(i, (int) q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
356 <                    }
357 <                    threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
333 <                } catch (InterruptedException success) {
334 <                } catch (Throwable ex) {
335 <                    threadUnexpectedException(ex);
350 >        final BlockingQueue<Integer> q = populatedQueue(SIZE);
351 >        final CountDownLatch aboutToWait = new CountDownLatch(1);
352 >        Thread t = newStartedThread(new CheckedRunnable() {
353 >            public void realRun() throws InterruptedException {
354 >                for (int i = 0; i < SIZE; ++i) {
355 >                    long t0 = System.nanoTime();
356 >                    assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
357 >                    assertTrue(millisElapsedSince(t0) < SHORT_DELAY_MS);
358                  }
359 +                aboutToWait.countDown();
360 +                try {
361 +                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
362 +                    shouldThrow();
363 +                } catch (InterruptedException success) {}
364              }});
365 <        t.start();
366 <        Thread.sleep(SHORT_DELAY_MS);
365 >
366 >        aboutToWait.await();
367 >        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
368          t.interrupt();
369 <        t.join();
369 >        awaitTermination(t, MEDIUM_DELAY_MS);
370 >        checkEmpty(q);
371      }
372  
373      /**
374 <     * timed poll before a delayed offer fails; after offer succeeds;
375 <     * on interruption throws
374 >     * timed poll after thread interrupted throws InterruptedException
375 >     * instead of returning timeout status
376       */
377 <    public void testTimedPollWithOffer() throws InterruptedException {
378 <        final LinkedTransferQueue q = new LinkedTransferQueue();
379 <        Thread t = new Thread(new Runnable() {
380 <            public void run() {
381 <                try {
382 <                    threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
383 <                    q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
384 <                    q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
385 <                    threadShouldThrow();
357 <                } catch (InterruptedException success) {
358 <                } catch (Throwable ex) {
359 <                    threadUnexpectedException(ex);
377 >    public void testTimedPollAfterInterrupt() throws InterruptedException {
378 >        final BlockingQueue<Integer> q = populatedQueue(SIZE);
379 >        Thread t = newStartedThread(new CheckedRunnable() {
380 >            public void realRun() throws InterruptedException {
381 >                Thread.currentThread().interrupt();
382 >                for (int i = 0; i < SIZE; ++i) {
383 >                    long t0 = System.nanoTime();
384 >                    assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
385 >                    assertTrue(millisElapsedSince(t0) < SHORT_DELAY_MS);
386                  }
387 +                try {
388 +                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
389 +                    shouldThrow();
390 +                } catch (InterruptedException success) {}
391              }});
392 <        t.start();
393 <        Thread.sleep(SMALL_DELAY_MS);
394 <        assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
365 <        t.interrupt();
366 <        t.join();
392 >
393 >        awaitTermination(t, MEDIUM_DELAY_MS);
394 >        checkEmpty(q);
395      }
396  
397      /**
398       * peek returns next element, or null if empty
399       */
400 <    public void testPeek() {
400 >    public void testPeek() throws InterruptedException {
401          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
402          for (int i = 0; i < SIZE; ++i) {
403              assertEquals(i, (int) q.peek());
# Line 378 | Line 406 | public class LinkedTransferQueueTest ext
406                         i != (int) q.peek());
407          }
408          assertNull(q.peek());
409 +        checkEmpty(q);
410      }
411  
412      /**
413       * element returns next element, or throws NoSuchElementException if empty
414       */
415 <    public void testElement() {
415 >    public void testElement() throws InterruptedException {
416          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
417          for (int i = 0; i < SIZE; ++i) {
418              assertEquals(i, (int) q.element());
# Line 392 | Line 421 | public class LinkedTransferQueueTest ext
421          try {
422              q.element();
423              shouldThrow();
424 <        } catch (NoSuchElementException success) {
425 <        }
424 >        } catch (NoSuchElementException success) {}
425 >        checkEmpty(q);
426      }
427  
428      /**
429       * remove removes next element, or throws NoSuchElementException if empty
430       */
431 <    public void testRemove() {
431 >    public void testRemove() throws InterruptedException {
432          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
433          for (int i = 0; i < SIZE; ++i) {
434              assertEquals(i, (int) q.remove());
# Line 407 | Line 436 | public class LinkedTransferQueueTest ext
436          try {
437              q.remove();
438              shouldThrow();
439 <        } catch (NoSuchElementException success) {
440 <        }
439 >        } catch (NoSuchElementException success) {}
440 >        checkEmpty(q);
441      }
442  
443      /**
444       * remove(x) removes x and returns true if present
445       */
446 <    public void testRemoveElement() {
446 >    public void testRemoveElement() throws InterruptedException {
447          LinkedTransferQueue q = populatedQueue(SIZE);
448          for (int i = 1; i < SIZE; i += 2) {
449              assertTrue(q.remove(i));
# Line 423 | Line 452 | public class LinkedTransferQueueTest ext
452              assertTrue(q.remove(i));
453              assertFalse(q.remove(i + 1));
454          }
455 <        assertTrue(q.isEmpty());
455 >        checkEmpty(q);
456      }
457  
458      /**
# Line 436 | Line 465 | public class LinkedTransferQueueTest ext
465          assertTrue(q.remove(one));
466          assertTrue(q.remove(two));
467          assertTrue(q.add(three));
468 <        assertTrue(q.take() != null);
468 >        assertSame(q.take(), three);
469      }
470  
471      /**
# Line 454 | Line 483 | public class LinkedTransferQueueTest ext
483      /**
484       * clear removes all elements
485       */
486 <    public void testClear() {
486 >    public void testClear() throws InterruptedException {
487          LinkedTransferQueue q = populatedQueue(SIZE);
488          q.clear();
489 <        assertTrue(q.isEmpty());
461 <        assertEquals(0, q.size());
489 >        checkEmpty(q);
490          assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
491          q.add(one);
492          assertFalse(q.isEmpty());
493 +        assertEquals(1, q.size());
494          assertTrue(q.contains(one));
495          q.clear();
496 <        assertTrue(q.isEmpty());
496 >        checkEmpty(q);
497      }
498  
499      /**
# Line 482 | Line 511 | public class LinkedTransferQueueTest ext
511      }
512  
513      /**
514 <     * retainAll(c) retains only those elements of c and reports true if changed
514 >     * retainAll(c) retains only those elements of c and reports true
515 >     * if changed
516       */
517      public void testRetainAll() {
518          LinkedTransferQueue q = populatedQueue(SIZE);
# Line 501 | Line 531 | public class LinkedTransferQueueTest ext
531      }
532  
533      /**
534 <     * removeAll(c) removes only those elements of c and reports true if changed
534 >     * removeAll(c) removes only those elements of c and reports true
535 >     * if changed
536       */
537      public void testRemoveAll() {
538          for (int i = 1; i < SIZE; ++i) {
# Line 516 | Line 547 | public class LinkedTransferQueueTest ext
547      }
548  
549      /**
550 <     * toArray contains all elements
550 >     * toArray() contains all elements
551       */
552      public void testToArray() throws InterruptedException {
553          LinkedTransferQueue q = populatedQueue(SIZE);
# Line 542 | Line 573 | public class LinkedTransferQueueTest ext
573       * toArray(null) throws NullPointerException
574       */
575      public void testToArray_BadArg() {
576 +        LinkedTransferQueue q = populatedQueue(SIZE);
577          try {
546            LinkedTransferQueue q = populatedQueue(SIZE);
578              Object o[] = q.toArray(null);
579              shouldThrow();
580 <        } catch (NullPointerException success) {
550 <        }
580 >        } catch (NullPointerException success) {}
581      }
582  
583      /**
584 <     * toArray with incompatible array type throws CCE
584 >     * toArray(incompatible array type) throws CCE
585       */
586      public void testToArray1_BadArg() {
587 +        LinkedTransferQueue q = populatedQueue(SIZE);
588          try {
558            LinkedTransferQueue q = populatedQueue(SIZE);
589              Object o[] = q.toArray(new String[10]);
590              shouldThrow();
591 <        } catch (ArrayStoreException success) {
562 <        }
591 >        } catch (ArrayStoreException success) {}
592      }
593  
594      /**
# Line 568 | Line 597 | public class LinkedTransferQueueTest ext
597      public void testIterator() throws InterruptedException {
598          LinkedTransferQueue q = populatedQueue(SIZE);
599          Iterator it = q.iterator();
600 +        int i = 0;
601          while (it.hasNext()) {
602 <            assertEquals(it.next(), q.take());
602 >            assertEquals(it.next(), i++);
603          }
604 +        assertEquals(i, SIZE);
605      }
606  
607      /**
608 <     * iterator.remove removes current element
608 >     * iterator.remove() removes current element
609       */
610      public void testIteratorRemove() {
611          final LinkedTransferQueue q = new LinkedTransferQueue();
# Line 587 | Line 618 | public class LinkedTransferQueueTest ext
618          it.remove();
619  
620          it = q.iterator();
621 <        assertEquals(it.next(), one);
622 <        assertEquals(it.next(), three);
621 >        assertSame(it.next(), one);
622 >        assertSame(it.next(), three);
623          assertFalse(it.hasNext());
624      }
625  
# Line 596 | Line 627 | public class LinkedTransferQueueTest ext
627       * iterator ordering is FIFO
628       */
629      public void testIteratorOrdering() {
630 <        final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>();
630 >        final LinkedTransferQueue<Integer> q
631 >            = new LinkedTransferQueue<Integer>();
632          assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
633          q.add(one);
634          q.add(two);
# Line 640 | Line 672 | public class LinkedTransferQueueTest ext
672       */
673      public void testOfferInExecutor() {
674          final LinkedTransferQueue q = new LinkedTransferQueue();
675 <        q.add(one);
644 <        q.add(two);
675 >        final CountDownLatch threadsStarted = new CountDownLatch(2);
676          ExecutorService executor = Executors.newFixedThreadPool(2);
677 <        executor.execute(new Runnable() {
678 <            public void run() {
679 <                try {
680 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
681 <                } catch (Throwable ex) {
682 <                    threadUnexpectedException(ex);
652 <                }
677 >
678 >        executor.execute(new CheckedRunnable() {
679 >            public void realRun() throws InterruptedException {
680 >                threadsStarted.countDown();
681 >                threadsStarted.await();
682 >                assertTrue(q.offer(one, MEDIUM_DELAY_MS, MILLISECONDS));
683              }});
684  
685 <        executor.execute(new Runnable() {
686 <            public void run() {
687 <                try {
688 <                    Thread.sleep(SMALL_DELAY_MS);
689 <                    threadAssertEquals(one, q.take());
690 <                } catch (Throwable ex) {
661 <                    threadUnexpectedException(ex);
662 <                }
685 >        executor.execute(new CheckedRunnable() {
686 >            public void realRun() throws InterruptedException {
687 >                threadsStarted.countDown();
688 >                threadsStarted.await();
689 >                assertSame(one, q.take());
690 >                checkEmpty(q);
691              }});
692  
693          joinPool(executor);
694      }
695  
696      /**
697 <     * poll retrieves elements across Executor threads
697 >     * timed poll retrieves elements across Executor threads
698       */
699      public void testPollInExecutor() {
700          final LinkedTransferQueue q = new LinkedTransferQueue();
701 +        final CountDownLatch threadsStarted = new CountDownLatch(2);
702          ExecutorService executor = Executors.newFixedThreadPool(2);
703 <        executor.execute(new Runnable() {
704 <            public void run() {
705 <                try {
706 <                    threadAssertNull(q.poll());
707 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
708 <                    threadAssertTrue(q.isEmpty());
709 <                } catch (Throwable  ex) {
710 <                    threadUnexpectedException(ex);
682 <                }
703 >
704 >        executor.execute(new CheckedRunnable() {
705 >            public void realRun() throws InterruptedException {
706 >                assertNull(q.poll());
707 >                threadsStarted.countDown();
708 >                threadsStarted.await();
709 >                assertSame(one, q.poll(SMALL_DELAY_MS, MILLISECONDS));
710 >                checkEmpty(q);
711              }});
712  
713 <        executor.execute(new Runnable() {
714 <            public void run() {
715 <                try {
716 <                    Thread.sleep(SMALL_DELAY_MS);
717 <                    q.put(one);
690 <                } catch (Throwable ex) {
691 <                    threadUnexpectedException(ex);
692 <                }
713 >        executor.execute(new CheckedRunnable() {
714 >            public void realRun() throws InterruptedException {
715 >                threadsStarted.countDown();
716 >                threadsStarted.await();
717 >                q.put(one);
718              }});
719  
720          joinPool(executor);
# Line 702 | Line 727 | public class LinkedTransferQueueTest ext
727          LinkedTransferQueue q = populatedQueue(SIZE);
728  
729          ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
730 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
730 >        ObjectOutputStream out
731 >            = new ObjectOutputStream(new BufferedOutputStream(bout));
732          out.writeObject(q);
733          out.close();
734  
735 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
736 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
735 >        ByteArrayInputStream bin
736 >            = new ByteArrayInputStream(bout.toByteArray());
737 >        ObjectInputStream in
738 >            = new ObjectInputStream(new BufferedInputStream(bin));
739          LinkedTransferQueue r = (LinkedTransferQueue) in.readObject();
740  
741          assertEquals(q.size(), r.size());
# Line 724 | Line 752 | public class LinkedTransferQueueTest ext
752          try {
753              q.drainTo(null);
754              shouldThrow();
755 <        } catch (NullPointerException success) {
728 <        }
755 >        } catch (NullPointerException success) {}
756      }
757  
758      /**
# Line 736 | Line 763 | public class LinkedTransferQueueTest ext
763          try {
764              q.drainTo(q);
765              shouldThrow();
766 <        } catch (IllegalArgumentException success) {
740 <        }
766 >        } catch (IllegalArgumentException success) {}
767      }
768  
769      /**
# Line 767 | Line 793 | public class LinkedTransferQueueTest ext
793      }
794  
795      /**
796 <     * drainTo empties full queue, unblocking a waiting put.
796 >     * drainTo(c) empties full queue, unblocking a waiting put.
797       */
798      public void testDrainToWithActivePut() throws InterruptedException {
799          final LinkedTransferQueue q = populatedQueue(SIZE);
800 <        Thread t = new Thread(new Runnable() {
801 <            public void run() {
802 <                try {
777 <                    q.put(SIZE + 1);
778 <                } catch (Throwable ex) {
779 <                    threadUnexpectedException(ex);
780 <                }
800 >        Thread t = newStartedThread(new CheckedRunnable() {
801 >            public void realRun() {
802 >                q.put(SIZE + 1);
803              }});
782        t.start();
804          ArrayList l = new ArrayList();
805          q.drainTo(l);
806          assertTrue(l.size() >= SIZE);
807          for (int i = 0; i < SIZE; ++i) {
808              assertEquals(l.get(i), i);
809          }
810 <        t.join();
810 >        awaitTermination(t, MEDIUM_DELAY_MS);
811          assertTrue(q.size() + l.size() >= SIZE);
812      }
813  
# Line 796 | Line 817 | public class LinkedTransferQueueTest ext
817      public void testDrainToNullN() {
818          LinkedTransferQueue q = populatedQueue(SIZE);
819          try {
820 <            q.drainTo(null, 0);
820 >            q.drainTo(null, SIZE);
821              shouldThrow();
822 <        } catch (NullPointerException success) {
802 <        }
822 >        } catch (NullPointerException success) {}
823      }
824  
825      /**
# Line 808 | Line 828 | public class LinkedTransferQueueTest ext
828      public void testDrainToSelfN() {
829          LinkedTransferQueue q = populatedQueue(SIZE);
830          try {
831 <            q.drainTo(q, 0);
831 >            q.drainTo(q, SIZE);
832              shouldThrow();
833 <        } catch (IllegalArgumentException success) {
814 <        }
833 >        } catch (IllegalArgumentException success) {}
834      }
835  
836      /**
837 <     * drainTo(c, n) empties first max {n, size} elements of queue into c
837 >     * drainTo(c, n) empties first min(n, size) elements of queue into c
838       */
839      public void testDrainToN() {
840          LinkedTransferQueue q = new LinkedTransferQueue();
# Line 837 | Line 856 | public class LinkedTransferQueueTest ext
856      }
857  
858      /**
859 <     * poll and take should decrement the waiting consumer count
859 >     * timed poll() or take() increments the waiting consumer count;
860 >     * offer(e) decrements the waiting consumer count
861       */
862      public void testWaitingConsumer() throws InterruptedException {
863          final LinkedTransferQueue q = new LinkedTransferQueue();
864 <        final ConsumerObserver waiting = new ConsumerObserver();
865 <        new Thread(new Runnable() {
866 <            public void run() {
867 <                try {
868 <                    threadAssertTrue(q.hasWaitingConsumer());
869 <                    waiting.setWaitingConsumer(q.getWaitingConsumerCount());
870 <                    threadAssertTrue(q.offer(new Object()));
871 <                } catch (Throwable ex) {
872 <                    threadUnexpectedException(ex);
873 <                }
874 <            }}).start();
875 <        assertTrue(q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS) != null);
876 <        assertTrue(q.getWaitingConsumerCount() < waiting.getWaitingConsumers());
864 >        assertEquals(q.getWaitingConsumerCount(), 0);
865 >        assertFalse(q.hasWaitingConsumer());
866 >        final CountDownLatch threadStarted = new CountDownLatch(1);
867 >
868 >        Thread t = newStartedThread(new CheckedRunnable() {
869 >            public void realRun() throws InterruptedException {
870 >                threadStarted.countDown();
871 >                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
872 >                assertEquals(q.getWaitingConsumerCount(), 0);
873 >                assertFalse(q.hasWaitingConsumer());
874 >            }});
875 >
876 >        threadStarted.await();
877 >        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
878 >        assertEquals(q.getWaitingConsumerCount(), 1);
879 >        assertTrue(q.hasWaitingConsumer());
880 >
881 >        assertTrue(q.offer(one));
882 >        assertEquals(q.getWaitingConsumerCount(), 0);
883 >        assertFalse(q.hasWaitingConsumer());
884 >
885 >        awaitTermination(t, MEDIUM_DELAY_MS);
886      }
887  
888      /**
# Line 864 | Line 893 | public class LinkedTransferQueueTest ext
893              LinkedTransferQueue q = new LinkedTransferQueue();
894              q.transfer(null);
895              shouldThrow();
896 <        } catch (NullPointerException ex) {
868 <        }
896 >        } catch (NullPointerException success) {}
897      }
898  
899      /**
900 <     * transfer attempts to insert into the queue then wait until that
901 <     * object is removed via take or poll.
900 >     * transfer waits until a poll occurs. The transfered element
901 >     * is returned by this associated poll.
902       */
903      public void testTransfer2() throws InterruptedException {
904 <        final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>();
905 <
906 <        new Thread(new Runnable() {
907 <            public void run() {
908 <                try {
909 <                    q.transfer(SIZE);
910 <                    threadAssertTrue(q.isEmpty());
911 <                } catch (Throwable ex) {
912 <                    threadUnexpectedException(ex);
913 <                }
886 <            }}).start();
904 >        final LinkedTransferQueue<Integer> q
905 >            = new LinkedTransferQueue<Integer>();
906 >        final CountDownLatch threadStarted = new CountDownLatch(1);
907 >
908 >        Thread t = newStartedThread(new CheckedRunnable() {
909 >            public void realRun() throws InterruptedException {
910 >                threadStarted.countDown();
911 >                q.transfer(SIZE);
912 >                checkEmpty(q);
913 >            }});
914  
915 <        Thread.sleep(SHORT_DELAY_MS);
915 >        threadStarted.await();
916 >        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
917 >        assertTrue(t.isAlive());
918          assertEquals(1, q.size());
919          assertEquals(SIZE, (int) q.poll());
920 <        assertTrue(q.isEmpty());
920 >        checkEmpty(q);
921 >        awaitTermination(t, MEDIUM_DELAY_MS);
922      }
923  
924      /**
925 <     * transfer will attempt to transfer in fifo order and continue
896 <     * waiting if the element being transfered is not polled or taken
925 >     * transfer waits until a poll occurs, and then transfers in fifo order
926       */
927      public void testTransfer3() throws InterruptedException {
928 <        final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>();
928 >        final LinkedTransferQueue<Integer> q
929 >            = new LinkedTransferQueue<Integer>();
930  
931 <        Thread first =
932 <            new Thread(new Runnable() {
933 <                public void run() {
934 <                    try {
935 <                        Integer i = SIZE + 1;
936 <                        q.transfer(i);
937 <                        threadAssertTrue(!q.contains(i));
908 <                        threadAssertEquals(1, q.size());
909 <                    } catch (Throwable ex) {
910 <                        threadUnexpectedException(ex);
911 <                    }
912 <                }});
913 <        first.start();
931 >        Thread first = newStartedThread(new CheckedRunnable() {
932 >            public void realRun() throws InterruptedException {
933 >                Integer i = SIZE + 1;
934 >                q.transfer(i);
935 >                assertTrue(!q.contains(i));
936 >                assertEquals(1, q.size());
937 >            }});
938  
939 <        Thread interruptedThread =
940 <            new Thread(new Runnable() {
941 <                public void run() {
942 <                    try {
943 <                        while (q.size() == 0)
944 <                            Thread.yield();
921 <                        q.transfer(SIZE);
922 <                        threadShouldThrow();
923 <                    } catch (InterruptedException success) {
924 <                    } catch (Throwable ex) {
925 <                        threadUnexpectedException(ex);
926 <                    }
939 >        Thread interruptedThread = newStartedThread(
940 >            new CheckedInterruptedRunnable() {
941 >                public void realRun() throws InterruptedException {
942 >                    while (q.size() == 0)
943 >                        Thread.yield();
944 >                    q.transfer(SIZE);
945                  }});
928        interruptedThread.start();
946  
947          while (q.size() < 2)
948              Thread.yield();
# Line 935 | Line 952 | public class LinkedTransferQueueTest ext
952          assertEquals(1, q.size());
953          interruptedThread.interrupt();
954          interruptedThread.join();
955 <        assertEquals(0, q.size());
939 <        assertTrue(q.isEmpty());
955 >        checkEmpty(q);
956      }
957  
958      /**
959 <     * transfer will wait as long as a poll or take occurs if one does occur
960 <     * the waiting is finished and the thread that tries to poll/take
945 <     * wins in retrieving the element
959 >     * transfer waits until a poll occurs, at which point the polling
960 >     * thread returns the element
961       */
962      public void testTransfer4() throws InterruptedException {
963          final LinkedTransferQueue q = new LinkedTransferQueue();
964 <        new Thread(new Runnable() {
965 <            public void run() {
966 <                try {
967 <                    q.transfer(four);
968 <                    threadAssertFalse(q.contains(four));
969 <                    threadAssertEquals(three, q.poll());
970 <                } catch (Throwable ex) {
971 <                    threadUnexpectedException(ex);
972 <                }
973 <            }}).start();
974 <        Thread.sleep(MEDIUM_DELAY_MS);
964 >
965 >        Thread t = newStartedThread(new CheckedRunnable() {
966 >            public void realRun() throws InterruptedException {
967 >                q.transfer(four);
968 >                assertFalse(q.contains(four));
969 >                assertSame(three, q.poll());
970 >            }});
971 >
972 >        while (q.isEmpty())
973 >            Thread.yield();
974 >        assertFalse(q.isEmpty());
975 >        assertEquals(1, q.size());
976          assertTrue(q.offer(three));
977 <        assertEquals(four, q.poll());
977 >        assertSame(four, q.poll());
978 >        awaitTermination(t, MEDIUM_DELAY_MS);
979 >    }
980 >
981 >    /**
982 >     * transfer waits until a take occurs. The transfered element
983 >     * is returned by this associated take.
984 >     */
985 >    public void testTransfer5() throws InterruptedException {
986 >        final LinkedTransferQueue<Integer> q
987 >            = new LinkedTransferQueue<Integer>();
988 >
989 >        Thread t = newStartedThread(new CheckedRunnable() {
990 >            public void realRun() throws InterruptedException {
991 >                q.transfer(four);
992 >                checkEmpty(q);
993 >            }});
994 >
995 >        while (q.isEmpty())
996 >            Thread.yield();
997 >        assertFalse(q.isEmpty());
998 >        assertEquals(1, q.size());
999 >        assertSame(four, q.take());
1000 >        checkEmpty(q);
1001 >        awaitTermination(t, MEDIUM_DELAY_MS);
1002      }
1003  
1004      /**
# Line 968 | Line 1008 | public class LinkedTransferQueueTest ext
1008          try {
1009              final LinkedTransferQueue q = new LinkedTransferQueue();
1010              q.tryTransfer(null);
1011 <            this.shouldThrow();
1012 <        } catch (NullPointerException ex) {
973 <        }
1011 >            shouldThrow();
1012 >        } catch (NullPointerException success) {}
1013      }
1014  
1015      /**
1016       * tryTransfer returns false and does not enqueue if there are no
1017       * consumers waiting to poll or take.
1018       */
1019 <    public void testTryTransfer2() {
1019 >    public void testTryTransfer2() throws InterruptedException {
1020          final LinkedTransferQueue q = new LinkedTransferQueue();
1021          assertFalse(q.tryTransfer(new Object()));
1022          assertFalse(q.hasWaitingConsumer());
1023 <        assertTrue(q.isEmpty());
985 <        assertEquals(0, q.size());
1023 >        checkEmpty(q);
1024      }
1025  
1026      /**
# Line 992 | Line 1030 | public class LinkedTransferQueueTest ext
1030      public void testTryTransfer3() throws InterruptedException {
1031          final Object hotPotato = new Object();
1032          final LinkedTransferQueue q = new LinkedTransferQueue();
1033 <        new Thread(new Runnable() {
1034 <            public void run() {
1035 <                try {
1036 <                    while (! q.hasWaitingConsumer())
1037 <                        Thread.yield();
1038 <                    threadAssertTrue(q.hasWaitingConsumer());
1039 <                    threadAssertTrue(q.isEmpty());
1040 <                    threadAssertTrue(q.size() == 0);
1041 <                    threadAssertTrue(q.tryTransfer(hotPotato));
1042 <                } catch (Throwable ex) {
1043 <                    threadUnexpectedException(ex);
1044 <                }
1045 <            }}).start();
1008 <        assertTrue(q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS) == hotPotato);
1009 <        assertTrue(q.isEmpty());
1033 >
1034 >        Thread t = newStartedThread(new CheckedRunnable() {
1035 >            public void realRun() {
1036 >                while (! q.hasWaitingConsumer())
1037 >                    Thread.yield();
1038 >                assertTrue(q.hasWaitingConsumer());
1039 >                checkEmpty(q);
1040 >                assertTrue(q.tryTransfer(hotPotato));
1041 >            }});
1042 >
1043 >        assertSame(hotPotato, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1044 >        checkEmpty(q);
1045 >        awaitTermination(t, MEDIUM_DELAY_MS);
1046      }
1047  
1048      /**
# Line 1016 | Line 1052 | public class LinkedTransferQueueTest ext
1052      public void testTryTransfer4() throws InterruptedException {
1053          final Object hotPotato = new Object();
1054          final LinkedTransferQueue q = new LinkedTransferQueue();
1055 <        new Thread(new Runnable() {
1056 <            public void run() {
1057 <                try {
1058 <                    while (! q.hasWaitingConsumer())
1059 <                        Thread.yield();
1060 <                    threadAssertTrue(q.hasWaitingConsumer());
1061 <                    threadAssertTrue(q.isEmpty());
1062 <                    threadAssertTrue(q.size() == 0);
1063 <                    threadAssertTrue(q.tryTransfer(hotPotato));
1064 <                } catch (Throwable ex) {
1065 <                    threadUnexpectedException(ex);
1066 <                }
1067 <            }}).start();
1032 <        assertTrue(q.take() == hotPotato);
1033 <        assertTrue(q.isEmpty());
1055 >
1056 >        Thread t = newStartedThread(new CheckedRunnable() {
1057 >            public void realRun() {
1058 >                while (! q.hasWaitingConsumer())
1059 >                    Thread.yield();
1060 >                assertTrue(q.hasWaitingConsumer());
1061 >                checkEmpty(q);
1062 >                assertTrue(q.tryTransfer(hotPotato));
1063 >            }});
1064 >
1065 >        assertSame(q.take(), hotPotato);
1066 >        checkEmpty(q);
1067 >        awaitTermination(t, MEDIUM_DELAY_MS);
1068      }
1069  
1070      /**
1071 <     * tryTransfer waits the amount given if interrupted, show an
1072 <     * interrupted exception
1071 >     * tryTransfer waits the amount given if interrupted, and
1072 >     * throws interrupted exception
1073       */
1074      public void testTryTransfer5() throws InterruptedException {
1075          final LinkedTransferQueue q = new LinkedTransferQueue();
1076 <        Thread toInterrupt = new Thread(new Runnable() {
1077 <            public void run() {
1076 >        final CountDownLatch threadStarted = new CountDownLatch(1);
1077 >
1078 >        Thread t = newStartedThread(new CheckedRunnable() {
1079 >            public void realRun() throws InterruptedException {
1080 >                long t0 = System.nanoTime();
1081 >                threadStarted.countDown();
1082                  try {
1083 <                    q.tryTransfer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1084 <                    threadShouldThrow();
1085 <                } catch (InterruptedException success) {
1086 <                } catch (Throwable ex) {
1049 <                    threadUnexpectedException(ex);
1050 <                }
1083 >                    q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS);
1084 >                    shouldThrow();
1085 >                } catch (InterruptedException success) {}
1086 >                assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
1087              }});
1088 <        toInterrupt.start();
1089 <        Thread.sleep(SMALL_DELAY_MS);
1090 <        toInterrupt.interrupt();
1088 >
1089 >        threadStarted.await();
1090 >        Thread.sleep(SHORT_DELAY_MS);
1091 >        t.interrupt();
1092 >        awaitTermination(t, MEDIUM_DELAY_MS);
1093 >        checkEmpty(q);
1094      }
1095  
1096      /**
# Line 1059 | Line 1098 | public class LinkedTransferQueueTest ext
1098       */
1099      public void testTryTransfer6() throws InterruptedException {
1100          final LinkedTransferQueue q = new LinkedTransferQueue();
1101 <        new Thread(new Runnable() {
1102 <            public void run() {
1103 <                try {
1104 <                    threadAssertFalse(q.tryTransfer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1105 <                } catch (Throwable ex) {
1106 <                    threadUnexpectedException(ex);
1107 <                }
1108 <            }}).start();
1109 <        Thread.sleep(LONG_DELAY_MS);
1110 <        assertTrue(q.isEmpty());
1101 >
1102 >        Thread t = newStartedThread(new CheckedRunnable() {
1103 >            public void realRun() throws InterruptedException {
1104 >                long t0 = System.nanoTime();
1105 >                assertFalse(q.tryTransfer(new Object(),
1106 >                                          SHORT_DELAY_MS, MILLISECONDS));
1107 >                assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
1108 >            }});
1109 >
1110 >        checkEmpty(q);
1111 >        awaitTermination(t, MEDIUM_DELAY_MS);
1112 >        checkEmpty(q);
1113      }
1114  
1115      /**
# Line 1078 | Line 1119 | public class LinkedTransferQueueTest ext
1119      public void testTryTransfer7() throws InterruptedException {
1120          final LinkedTransferQueue q = new LinkedTransferQueue();
1121          assertTrue(q.offer(four));
1122 <        new Thread(new Runnable() {
1123 <            public void run() {
1124 <                try {
1125 <                    threadAssertTrue(q.tryTransfer(five, LONG_DELAY_MS, TimeUnit.MILLISECONDS));
1126 <                    threadAssertTrue(q.isEmpty());
1127 <                } catch (Throwable ex) {
1128 <                    threadUnexpectedException(ex);
1088 <                }
1089 <            }}).start();
1122 >
1123 >        Thread t = newStartedThread(new CheckedRunnable() {
1124 >            public void realRun() throws InterruptedException {
1125 >                assertTrue(q.tryTransfer(five, MEDIUM_DELAY_MS, MILLISECONDS));
1126 >                checkEmpty(q);
1127 >            }});
1128 >
1129          Thread.sleep(SHORT_DELAY_MS);
1130          assertEquals(2, q.size());
1131 <        assertEquals(four, q.poll());
1132 <        assertEquals(five, q.poll());
1133 <        assertTrue(q.isEmpty());
1131 >        assertSame(four, q.poll());
1132 >        assertSame(five, q.poll());
1133 >        checkEmpty(q);
1134 >        awaitTermination(t, MEDIUM_DELAY_MS);
1135      }
1136  
1137      /**
# Line 1102 | Line 1142 | public class LinkedTransferQueueTest ext
1142          final LinkedTransferQueue q = new LinkedTransferQueue();
1143          assertTrue(q.offer(four));
1144          assertEquals(1, q.size());
1145 <        assertFalse(q.tryTransfer(five, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1145 >        assertFalse(q.tryTransfer(five, SHORT_DELAY_MS, MILLISECONDS));
1146          assertEquals(1, q.size());
1147 <        assertEquals(four, q.poll());
1108 <        threadAssertTrue(q.isEmpty());
1147 >        assertSame(four, q.poll());
1148          assertNull(q.poll());
1149 +        checkEmpty(q);
1150      }
1151  
1152      private LinkedTransferQueue<Integer> populatedQueue(int n) {
1153          LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>();
1154 <        assertTrue(q.isEmpty());
1154 >        checkEmpty(q);
1155          for (int i = 0; i < n; i++) {
1156              assertEquals(i, q.size());
1157              assertTrue(q.offer(i));
# Line 1120 | Line 1160 | public class LinkedTransferQueueTest ext
1160          assertFalse(q.isEmpty());
1161          return q;
1162      }
1123
1124    private static class ConsumerObserver {
1125
1126        private int waitingConsumers;
1127
1128        private ConsumerObserver() {
1129        }
1130
1131        private void setWaitingConsumer(int i) {
1132            this.waitingConsumers = i;
1133        }
1134
1135        private int getWaitingConsumers() {
1136            return waitingConsumers;
1137        }
1138    }
1163   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines