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.50 by jsr166, Sat Nov 26 05:19:17 2011 UTC vs.
Revision 1.70 by jsr166, Sat Feb 18 16:37:49 2017 UTC

# Line 5 | Line 5
5   * Other contributors include John Vint
6   */
7  
8 < import junit.framework.*;
9 < import java.util.Arrays;
8 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
9 >
10   import java.util.ArrayList;
11 + import java.util.Arrays;
12   import java.util.Collection;
13   import java.util.Iterator;
14   import java.util.List;
15   import java.util.NoSuchElementException;
16   import java.util.Queue;
17   import java.util.concurrent.BlockingQueue;
18 + import java.util.concurrent.Callable;
19   import java.util.concurrent.CountDownLatch;
20   import java.util.concurrent.Executors;
21   import java.util.concurrent.ExecutorService;
22   import java.util.concurrent.LinkedTransferQueue;
23 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
24 < import static java.util.concurrent.TimeUnit.NANOSECONDS;
23 >
24 > import junit.framework.Test;
25  
26   @SuppressWarnings({"unchecked", "rawtypes"})
27   public class LinkedTransferQueueTest extends JSR166TestCase {
26
28      public static class Generic extends BlockingQueueTest {
29          protected BlockingQueue emptyCollection() {
30              return new LinkedTransferQueue();
# Line 31 | Line 32 | public class LinkedTransferQueueTest ext
32      }
33  
34      public static void main(String[] args) {
35 <        junit.textui.TestRunner.run(suite());
35 >        main(suite(), args);
36      }
37  
38      public static Test suite() {
39 +        class Implementation implements CollectionImplementation {
40 +            public Class<?> klazz() { return LinkedTransferQueue.class; }
41 +            public Collection emptyCollection() { return new LinkedTransferQueue(); }
42 +            public Object makeElement(int i) { return i; }
43 +            public boolean isConcurrent() { return true; }
44 +            public boolean permitsNulls() { return false; }
45 +        }
46          return newTestSuite(LinkedTransferQueueTest.class,
47 <                            new Generic().testSuite());
47 >                            new Generic().testSuite(),
48 >                            CollectionTest.testSuite(new Implementation()));
49      }
50  
51      /**
# Line 77 | Line 86 | public class LinkedTransferQueueTest ext
86       */
87      public void testConstructor4() {
88          Integer[] ints = new Integer[SIZE];
89 <        for (int i = 0; i < SIZE-1; ++i)
89 >        for (int i = 0; i < SIZE - 1; ++i)
90              ints[i] = i;
91          Collection<Integer> elements = Arrays.asList(ints);
92          try {
# Line 114 | Line 123 | public class LinkedTransferQueueTest ext
123       * remainingCapacity() always returns Integer.MAX_VALUE
124       */
125      public void testRemainingCapacity() {
126 <        LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
126 >        BlockingQueue q = populatedQueue(SIZE);
127          for (int i = 0; i < SIZE; ++i) {
128              assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
129              assertEquals(SIZE - i, q.size());
130 <            q.remove();
130 >            assertEquals(i, q.remove());
131          }
132          for (int i = 0; i < SIZE; ++i) {
133              assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
134              assertEquals(i, q.size());
135 <            q.add(i);
135 >            assertTrue(q.add(i));
136          }
137      }
138  
# Line 131 | Line 140 | public class LinkedTransferQueueTest ext
140       * addAll(this) throws IllegalArgumentException
141       */
142      public void testAddAllSelf() {
143 +        LinkedTransferQueue q = populatedQueue(SIZE);
144          try {
135            LinkedTransferQueue q = populatedQueue(SIZE);
145              q.addAll(q);
146              shouldThrow();
147          } catch (IllegalArgumentException success) {}
# Line 143 | Line 152 | public class LinkedTransferQueueTest ext
152       * NullPointerException after possibly adding some elements
153       */
154      public void testAddAll3() {
155 +        LinkedTransferQueue q = new LinkedTransferQueue();
156 +        Integer[] ints = new Integer[SIZE];
157 +        for (int i = 0; i < SIZE - 1; ++i)
158 +            ints[i] = i;
159          try {
147            LinkedTransferQueue q = new LinkedTransferQueue();
148            Integer[] ints = new Integer[SIZE];
149            for (int i = 0; i < SIZE - 1; ++i) {
150                ints[i] = i;
151            }
160              q.addAll(Arrays.asList(ints));
161              shouldThrow();
162          } catch (NullPointerException success) {}
# Line 175 | Line 183 | public class LinkedTransferQueueTest ext
183       * all elements successfully put are contained
184       */
185      public void testPut() {
186 <        LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>();
186 >        LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
187          for (int i = 0; i < SIZE; ++i) {
188 <            assertEquals(q.size(), i);
188 >            assertEquals(i, q.size());
189              q.put(i);
190              assertTrue(q.contains(i));
191          }
# Line 255 | Line 263 | public class LinkedTransferQueueTest ext
263       */
264      public void testTimedPoll() throws InterruptedException {
265          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
258        for (int i = 0; i < SIZE; ++i) {
259            long startTime = System.nanoTime();
260            assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
261            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
262        }
266          long startTime = System.nanoTime();
267 +        for (int i = 0; i < SIZE; ++i)
268 +            assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
269 +        assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
270 +
271 +        startTime = System.nanoTime();
272          assertNull(q.poll(timeoutMillis(), MILLISECONDS));
273          assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
274          checkEmpty(q);
# Line 275 | Line 283 | public class LinkedTransferQueueTest ext
283          final CountDownLatch aboutToWait = new CountDownLatch(1);
284          Thread t = newStartedThread(new CheckedRunnable() {
285              public void realRun() throws InterruptedException {
286 <                for (int i = 0; i < SIZE; ++i) {
287 <                    long t0 = System.nanoTime();
286 >                long startTime = System.nanoTime();
287 >                for (int i = 0; i < SIZE; ++i)
288                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
281                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
282                }
283                long t0 = System.nanoTime();
289                  aboutToWait.countDown();
290                  try {
291 <                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
291 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
292                      shouldThrow();
293 <                } catch (InterruptedException success) {
294 <                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
290 <                }
293 >                } catch (InterruptedException success) {}
294 >                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
295              }});
296  
297          aboutToWait.await();
298 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
298 >        waitForThreadToEnterWaitState(t);
299          t.interrupt();
300 <        awaitTermination(t, MEDIUM_DELAY_MS);
300 >        awaitTermination(t);
301          checkEmpty(q);
302      }
303  
# Line 305 | Line 309 | public class LinkedTransferQueueTest ext
309          final BlockingQueue<Integer> q = populatedQueue(SIZE);
310          Thread t = newStartedThread(new CheckedRunnable() {
311              public void realRun() throws InterruptedException {
312 +                long startTime = System.nanoTime();
313                  Thread.currentThread().interrupt();
314 <                for (int i = 0; i < SIZE; ++i) {
310 <                    long t0 = System.nanoTime();
314 >                for (int i = 0; i < SIZE; ++i)
315                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
312                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
313                }
316                  try {
317 <                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
317 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
318                      shouldThrow();
319                  } catch (InterruptedException success) {}
320 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
321              }});
322  
323 <        awaitTermination(t, MEDIUM_DELAY_MS);
323 >        awaitTermination(t);
324          checkEmpty(q);
325      }
326  
# Line 413 | Line 416 | public class LinkedTransferQueueTest ext
416       */
417      public void testContainsAll() {
418          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
419 <        LinkedTransferQueue<Integer> p = new LinkedTransferQueue<Integer>();
419 >        LinkedTransferQueue<Integer> p = new LinkedTransferQueue<>();
420          for (int i = 0; i < SIZE; ++i) {
421              assertTrue(q.containsAll(p));
422              assertFalse(p.containsAll(q));
# Line 499 | Line 502 | public class LinkedTransferQueueTest ext
502      public void testIterator() throws InterruptedException {
503          LinkedTransferQueue q = populatedQueue(SIZE);
504          Iterator it = q.iterator();
505 <        int i = 0;
506 <        while (it.hasNext()) {
507 <            assertEquals(it.next(), i++);
505 <        }
505 >        int i;
506 >        for (i = 0; it.hasNext(); i++)
507 >            assertTrue(q.contains(it.next()));
508          assertEquals(i, SIZE);
509 +        assertIteratorExhausted(it);
510 +
511 +        it = q.iterator();
512 +        for (i = 0; it.hasNext(); i++)
513 +            assertEquals(it.next(), q.take());
514 +        assertEquals(i, SIZE);
515 +        assertIteratorExhausted(it);
516 +    }
517 +
518 +    /**
519 +     * iterator of empty collection has no elements
520 +     */
521 +    public void testEmptyIterator() {
522 +        assertIteratorExhausted(new LinkedTransferQueue().iterator());
523      }
524  
525      /**
# Line 529 | Line 545 | public class LinkedTransferQueueTest ext
545       * iterator ordering is FIFO
546       */
547      public void testIteratorOrdering() {
548 <        final LinkedTransferQueue<Integer> q
533 <            = new LinkedTransferQueue<Integer>();
548 >        final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
549          assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
550          q.add(one);
551          q.add(two);
# Line 575 | Line 590 | public class LinkedTransferQueueTest ext
590      public void testOfferInExecutor() {
591          final LinkedTransferQueue q = new LinkedTransferQueue();
592          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
593 <        ExecutorService executor = Executors.newFixedThreadPool(2);
594 <
580 <        executor.execute(new CheckedRunnable() {
581 <            public void realRun() throws InterruptedException {
582 <                threadsStarted.await();
583 <                assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
584 <            }});
593 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
594 >        try (PoolCleaner cleaner = cleaner(executor)) {
595  
596 <        executor.execute(new CheckedRunnable() {
597 <            public void realRun() throws InterruptedException {
598 <                threadsStarted.await();
599 <                assertSame(one, q.take());
600 <                checkEmpty(q);
601 <            }});
596 >            executor.execute(new CheckedRunnable() {
597 >                public void realRun() throws InterruptedException {
598 >                    threadsStarted.await();
599 >                    long startTime = System.nanoTime();
600 >                    assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
601 >                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
602 >                }});
603  
604 <        joinPool(executor);
604 >            executor.execute(new CheckedRunnable() {
605 >                public void realRun() throws InterruptedException {
606 >                    threadsStarted.await();
607 >                    assertSame(one, q.take());
608 >                    checkEmpty(q);
609 >                }});
610 >        }
611      }
612  
613      /**
# Line 599 | Line 616 | public class LinkedTransferQueueTest ext
616      public void testPollInExecutor() {
617          final LinkedTransferQueue q = new LinkedTransferQueue();
618          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
619 <        ExecutorService executor = Executors.newFixedThreadPool(2);
619 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
620 >        try (PoolCleaner cleaner = cleaner(executor)) {
621  
622 <        executor.execute(new CheckedRunnable() {
623 <            public void realRun() throws InterruptedException {
624 <                assertNull(q.poll());
625 <                threadsStarted.await();
626 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
627 <                checkEmpty(q);
628 <            }});
629 <
630 <        executor.execute(new CheckedRunnable() {
613 <            public void realRun() throws InterruptedException {
614 <                threadsStarted.await();
615 <                q.put(one);
616 <            }});
622 >            executor.execute(new CheckedRunnable() {
623 >                public void realRun() throws InterruptedException {
624 >                    assertNull(q.poll());
625 >                    threadsStarted.await();
626 >                    long startTime = System.nanoTime();
627 >                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
628 >                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
629 >                    checkEmpty(q);
630 >                }});
631  
632 <        joinPool(executor);
632 >            executor.execute(new CheckedRunnable() {
633 >                public void realRun() throws InterruptedException {
634 >                    threadsStarted.await();
635 >                    q.put(one);
636 >                }});
637 >        }
638      }
639  
640      /**
# Line 625 | Line 644 | public class LinkedTransferQueueTest ext
644          Queue x = populatedQueue(SIZE);
645          Queue y = serialClone(x);
646  
647 <        assertTrue(x != y);
647 >        assertNotSame(y, x);
648          assertEquals(x.size(), y.size());
649          assertEquals(x.toString(), y.toString());
650          assertTrue(Arrays.equals(x.toArray(), y.toArray()));
# Line 646 | Line 665 | public class LinkedTransferQueueTest ext
665          assertEquals(0, q.size());
666          assertEquals(SIZE, l.size());
667          for (int i = 0; i < SIZE; ++i) {
668 <            assertEquals(l.get(i), i);
668 >            assertEquals(i, l.get(i));
669          }
670          q.add(zero);
671          q.add(one);
# Line 658 | Line 677 | public class LinkedTransferQueueTest ext
677          assertEquals(0, q.size());
678          assertEquals(2, l.size());
679          for (int i = 0; i < 2; ++i) {
680 <            assertEquals(l.get(i), i);
680 >            assertEquals(i, l.get(i));
681          }
682      }
683  
# Line 674 | Line 693 | public class LinkedTransferQueueTest ext
693          ArrayList l = new ArrayList();
694          q.drainTo(l);
695          assertTrue(l.size() >= SIZE);
696 <        for (int i = 0; i < SIZE; ++i) {
697 <            assertEquals(l.get(i), i);
698 <        }
680 <        awaitTermination(t, MEDIUM_DELAY_MS);
696 >        for (int i = 0; i < SIZE; ++i)
697 >            assertEquals(i, l.get(i));
698 >        awaitTermination(t);
699          assertTrue(q.size() + l.size() >= SIZE);
700      }
701  
# Line 693 | Line 711 | public class LinkedTransferQueueTest ext
711              ArrayList l = new ArrayList();
712              q.drainTo(l, i);
713              int k = (i < SIZE) ? i : SIZE;
714 <            assertEquals(l.size(), k);
715 <            assertEquals(q.size(), SIZE - k);
716 <            for (int j = 0; j < k; ++j) {
717 <                assertEquals(l.get(j), j);
718 <            }
701 <            while (q.poll() != null)
702 <                ;
714 >            assertEquals(k, l.size());
715 >            assertEquals(SIZE - k, q.size());
716 >            for (int j = 0; j < k; ++j)
717 >                assertEquals(j, l.get(j));
718 >            do {} while (q.poll() != null);
719          }
720      }
721  
# Line 716 | Line 732 | public class LinkedTransferQueueTest ext
732          Thread t = newStartedThread(new CheckedRunnable() {
733              public void realRun() throws InterruptedException {
734                  threadStarted.countDown();
735 +                long startTime = System.nanoTime();
736                  assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
737                  assertEquals(0, q.getWaitingConsumerCount());
738                  assertFalse(q.hasWaitingConsumer());
739 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
740              }});
741  
742          threadStarted.await();
743 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
744 <        assertEquals(1, q.getWaitingConsumerCount());
745 <        assertTrue(q.hasWaitingConsumer());
743 >        Callable<Boolean> oneConsumer
744 >            = new Callable<Boolean>() { public Boolean call() {
745 >                return q.hasWaitingConsumer()
746 >                && q.getWaitingConsumerCount() == 1; }};
747 >        waitForThreadToEnterWaitState(t, oneConsumer);
748  
749          assertTrue(q.offer(one));
750          assertEquals(0, q.getWaitingConsumerCount());
751          assertFalse(q.hasWaitingConsumer());
752  
753 <        awaitTermination(t, MEDIUM_DELAY_MS);
753 >        awaitTermination(t);
754      }
755  
756      /**
# Line 746 | Line 766 | public class LinkedTransferQueueTest ext
766  
767      /**
768       * transfer waits until a poll occurs. The transfered element
769 <     * is returned by this associated poll.
769 >     * is returned by the associated poll.
770       */
771      public void testTransfer2() throws InterruptedException {
772 <        final LinkedTransferQueue<Integer> q
753 <            = new LinkedTransferQueue<Integer>();
772 >        final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
773          final CountDownLatch threadStarted = new CountDownLatch(1);
774  
775          Thread t = newStartedThread(new CheckedRunnable() {
# Line 761 | Line 780 | public class LinkedTransferQueueTest ext
780              }});
781  
782          threadStarted.await();
783 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
784 <        assertEquals(1, q.size());
783 >        Callable<Boolean> oneElement
784 >            = new Callable<Boolean>() { public Boolean call() {
785 >                return !q.isEmpty() && q.size() == 1; }};
786 >        waitForThreadToEnterWaitState(t, oneElement);
787 >
788          assertSame(five, q.poll());
789          checkEmpty(q);
790 <        awaitTermination(t, MEDIUM_DELAY_MS);
790 >        awaitTermination(t);
791      }
792  
793      /**
794       * transfer waits until a poll occurs, and then transfers in fifo order
795       */
796      public void testTransfer3() throws InterruptedException {
797 <        final LinkedTransferQueue<Integer> q
776 <            = new LinkedTransferQueue<Integer>();
797 >        final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
798  
799          Thread first = newStartedThread(new CheckedRunnable() {
800              public void realRun() throws InterruptedException {
# Line 821 | Line 842 | public class LinkedTransferQueueTest ext
842          assertEquals(1, q.size());
843          assertTrue(q.offer(three));
844          assertSame(four, q.poll());
845 <        awaitTermination(t, MEDIUM_DELAY_MS);
845 >        awaitTermination(t);
846      }
847  
848      /**
849       * transfer waits until a take occurs. The transfered element
850 <     * is returned by this associated take.
850 >     * is returned by the associated take.
851       */
852      public void testTransfer5() throws InterruptedException {
853 <        final LinkedTransferQueue<Integer> q
833 <            = new LinkedTransferQueue<Integer>();
853 >        final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
854  
855          Thread t = newStartedThread(new CheckedRunnable() {
856              public void realRun() throws InterruptedException {
# Line 844 | Line 864 | public class LinkedTransferQueueTest ext
864          assertEquals(1, q.size());
865          assertSame(four, q.take());
866          checkEmpty(q);
867 <        awaitTermination(t, MEDIUM_DELAY_MS);
867 >        awaitTermination(t);
868      }
869  
870      /**
871       * tryTransfer(null) throws NullPointerException
872       */
873      public void testTryTransfer1() {
874 +        final LinkedTransferQueue q = new LinkedTransferQueue();
875          try {
855            final LinkedTransferQueue q = new LinkedTransferQueue();
876              q.tryTransfer(null);
877              shouldThrow();
878          } catch (NullPointerException success) {}
# Line 886 | Line 906 | public class LinkedTransferQueueTest ext
906                  assertTrue(q.tryTransfer(hotPotato));
907              }});
908  
909 <        assertSame(hotPotato, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
909 >        long startTime = System.nanoTime();
910 >        assertSame(hotPotato, q.poll(LONG_DELAY_MS, MILLISECONDS));
911 >        assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
912          checkEmpty(q);
913 <        awaitTermination(t, MEDIUM_DELAY_MS);
913 >        awaitTermination(t);
914      }
915  
916      /**
# Line 910 | Line 932 | public class LinkedTransferQueueTest ext
932  
933          assertSame(q.take(), hotPotato);
934          checkEmpty(q);
935 <        awaitTermination(t, MEDIUM_DELAY_MS);
935 >        awaitTermination(t);
936      }
937  
938      /**
# Line 923 | Line 945 | public class LinkedTransferQueueTest ext
945  
946          Thread t = newStartedThread(new CheckedRunnable() {
947              public void realRun() throws InterruptedException {
948 +                long startTime = System.nanoTime();
949                  Thread.currentThread().interrupt();
950                  try {
951                      q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS);
# Line 936 | Line 959 | public class LinkedTransferQueueTest ext
959                      shouldThrow();
960                  } catch (InterruptedException success) {}
961                  assertFalse(Thread.interrupted());
962 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
963              }});
964  
965          await(pleaseInterrupt);
# Line 953 | Line 977 | public class LinkedTransferQueueTest ext
977  
978          Thread t = newStartedThread(new CheckedRunnable() {
979              public void realRun() throws InterruptedException {
980 <                long t0 = System.nanoTime();
980 >                long startTime = System.nanoTime();
981                  assertFalse(q.tryTransfer(new Object(),
982                                            timeoutMillis(), MILLISECONDS));
983 <                assertTrue(millisElapsedSince(t0) >= timeoutMillis());
983 >                assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
984                  checkEmpty(q);
985              }});
986  
# Line 974 | Line 998 | public class LinkedTransferQueueTest ext
998  
999          Thread t = newStartedThread(new CheckedRunnable() {
1000              public void realRun() throws InterruptedException {
1001 <                assertTrue(q.tryTransfer(five, MEDIUM_DELAY_MS, MILLISECONDS));
1001 >                long startTime = System.nanoTime();
1002 >                assertTrue(q.tryTransfer(five, LONG_DELAY_MS, MILLISECONDS));
1003 >                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1004                  checkEmpty(q);
1005              }});
1006  
# Line 984 | Line 1010 | public class LinkedTransferQueueTest ext
1010          assertSame(four, q.poll());
1011          assertSame(five, q.poll());
1012          checkEmpty(q);
1013 <        awaitTermination(t, MEDIUM_DELAY_MS);
1013 >        awaitTermination(t);
1014      }
1015  
1016      /**
# Line 995 | Line 1021 | public class LinkedTransferQueueTest ext
1021          final LinkedTransferQueue q = new LinkedTransferQueue();
1022          assertTrue(q.offer(four));
1023          assertEquals(1, q.size());
1024 <        long t0 = System.nanoTime();
1024 >        long startTime = System.nanoTime();
1025          assertFalse(q.tryTransfer(five, timeoutMillis(), MILLISECONDS));
1026 <        assertTrue(millisElapsedSince(t0) >= timeoutMillis());
1026 >        assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
1027          assertEquals(1, q.size());
1028          assertSame(four, q.poll());
1029          assertNull(q.poll());
# Line 1005 | Line 1031 | public class LinkedTransferQueueTest ext
1031      }
1032  
1033      private LinkedTransferQueue<Integer> populatedQueue(int n) {
1034 <        LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>();
1034 >        LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
1035          checkEmpty(q);
1036          for (int i = 0; i < n; i++) {
1037              assertEquals(i, q.size());
# Line 1015 | Line 1041 | public class LinkedTransferQueueTest ext
1041          assertFalse(q.isEmpty());
1042          return q;
1043      }
1044 +
1045 +    /**
1046 +     * remove(null), contains(null) always return false
1047 +     */
1048 +    public void testNeverContainsNull() {
1049 +        Collection<?>[] qs = {
1050 +            new LinkedTransferQueue<Object>(),
1051 +            populatedQueue(2),
1052 +        };
1053 +
1054 +        for (Collection<?> q : qs) {
1055 +            assertFalse(q.contains(null));
1056 +            assertFalse(q.remove(null));
1057 +        }
1058 +    }
1059   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines