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.43 by jsr166, Sun Nov 28 08:43:53 2010 UTC vs.
Revision 1.60 by jsr166, Fri May 15 18:21:19 2015 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include John Vint
6   */
7  
8 < import java.io.BufferedInputStream;
9 < import java.io.BufferedOutputStream;
10 < import java.io.ByteArrayInputStream;
11 < import java.io.ByteArrayOutputStream;
12 < import java.io.ObjectInputStream;
13 < import java.io.ObjectOutputStream;
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.concurrent.*;
17 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
18 < import static java.util.concurrent.TimeUnit.NANOSECONDS;
16 > import java.util.Queue;
17 > import java.util.concurrent.BlockingQueue;
18 > import java.util.concurrent.CountDownLatch;
19 > import java.util.concurrent.Executors;
20 > import java.util.concurrent.ExecutorService;
21 > import java.util.concurrent.LinkedTransferQueue;
22 >
23   import junit.framework.Test;
23 import junit.framework.TestSuite;
24  
25   @SuppressWarnings({"unchecked", "rawtypes"})
26   public class LinkedTransferQueueTest extends JSR166TestCase {
# Line 32 | 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() {
# Line 65 | Line 65 | public class LinkedTransferQueueTest ext
65       * NullPointerException
66       */
67      public void testConstructor3() {
68 +        Collection<Integer> elements = Arrays.asList(new Integer[SIZE]);
69          try {
70 <            Integer[] ints = new Integer[SIZE];
70 <            new LinkedTransferQueue(Arrays.asList(ints));
70 >            new LinkedTransferQueue(elements);
71              shouldThrow();
72          } catch (NullPointerException success) {}
73      }
# Line 77 | Line 77 | public class LinkedTransferQueueTest ext
77       * throws NullPointerException
78       */
79      public void testConstructor4() {
80 +        Integer[] ints = new Integer[SIZE];
81 +        for (int i = 0; i < SIZE-1; ++i)
82 +            ints[i] = i;
83 +        Collection<Integer> elements = Arrays.asList(ints);
84          try {
85 <            Integer[] ints = new Integer[SIZE];
82 <            for (int i = 0; i < SIZE - 1; ++i) {
83 <                ints[i] = i;
84 <            }
85 <            new LinkedTransferQueue(Arrays.asList(ints));
85 >            new LinkedTransferQueue(elements);
86              shouldThrow();
87          } catch (NullPointerException success) {}
88      }
# Line 115 | Line 115 | public class LinkedTransferQueueTest ext
115       * remainingCapacity() always returns Integer.MAX_VALUE
116       */
117      public void testRemainingCapacity() {
118 <        LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
118 >        BlockingQueue q = populatedQueue(SIZE);
119          for (int i = 0; i < SIZE; ++i) {
120              assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
121              assertEquals(SIZE - i, q.size());
122 <            q.remove();
122 >            assertEquals(i, q.remove());
123          }
124          for (int i = 0; i < SIZE; ++i) {
125              assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
126              assertEquals(i, q.size());
127 <            q.add(i);
127 >            assertTrue(q.add(i));
128          }
129      }
130  
131      /**
132     * offer(null) throws NullPointerException
133     */
134    public void testOfferNull() {
135        try {
136            LinkedTransferQueue q = new LinkedTransferQueue();
137            q.offer(null);
138            shouldThrow();
139        } catch (NullPointerException success) {}
140    }
141
142    /**
143     * add(null) throws NullPointerException
144     */
145    public void testAddNull() {
146        try {
147            LinkedTransferQueue q = new LinkedTransferQueue();
148            q.add(null);
149            shouldThrow();
150        } catch (NullPointerException success) {}
151    }
152
153    /**
154     * addAll(null) throws NullPointerException
155     */
156    public void testAddAll1() {
157        try {
158            LinkedTransferQueue q = new LinkedTransferQueue();
159            q.addAll(null);
160            shouldThrow();
161        } catch (NullPointerException success) {}
162    }
163
164    /**
132       * addAll(this) throws IllegalArgumentException
133       */
134      public void testAddAllSelf() {
135 +        LinkedTransferQueue q = populatedQueue(SIZE);
136          try {
169            LinkedTransferQueue q = populatedQueue(SIZE);
137              q.addAll(q);
138              shouldThrow();
139          } catch (IllegalArgumentException success) {}
140      }
141  
142      /**
176     * addAll of a collection with null elements throws NullPointerException
177     */
178    public void testAddAll2() {
179        try {
180            LinkedTransferQueue q = new LinkedTransferQueue();
181            Integer[] ints = new Integer[SIZE];
182            q.addAll(Arrays.asList(ints));
183            shouldThrow();
184        } catch (NullPointerException success) {}
185    }
186
187    /**
143       * addAll of a collection with any null elements throws
144       * NullPointerException after possibly adding some elements
145       */
146      public void testAddAll3() {
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          try {
193            LinkedTransferQueue q = new LinkedTransferQueue();
194            Integer[] ints = new Integer[SIZE];
195            for (int i = 0; i < SIZE - 1; ++i) {
196                ints[i] = i;
197            }
152              q.addAll(Arrays.asList(ints));
153              shouldThrow();
154          } catch (NullPointerException success) {}
# Line 218 | Line 172 | public class LinkedTransferQueueTest ext
172      }
173  
174      /**
221     * put(null) throws NullPointerException
222     */
223    public void testPutNull() throws InterruptedException {
224        try {
225            LinkedTransferQueue q = new LinkedTransferQueue();
226            q.put(null);
227            shouldThrow();
228        } catch (NullPointerException success) {}
229    }
230
231    /**
175       * all elements successfully put are contained
176       */
177      public void testPut() {
178          LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>();
179          for (int i = 0; i < SIZE; ++i) {
180 <            assertEquals(q.size(), i);
180 >            assertEquals(i, q.size());
181              q.put(i);
182              assertTrue(q.contains(i));
183          }
# Line 254 | Line 197 | public class LinkedTransferQueueTest ext
197       * take removes existing elements until empty, then blocks interruptibly
198       */
199      public void testBlockingTake() throws InterruptedException {
200 <        final BlockingQueue<Integer> q = populatedQueue(SIZE);
201 <        final CountDownLatch aboutToWait = new CountDownLatch(1);
200 >        final BlockingQueue q = populatedQueue(SIZE);
201 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
202          Thread t = newStartedThread(new CheckedRunnable() {
203              public void realRun() throws InterruptedException {
204                  for (int i = 0; i < SIZE; ++i) {
205 <                    assertEquals(i, (int) q.take());
205 >                    assertEquals(i, q.take());
206                  }
207 <                aboutToWait.countDown();
207 >
208 >                Thread.currentThread().interrupt();
209 >                try {
210 >                    q.take();
211 >                    shouldThrow();
212 >                } catch (InterruptedException success) {}
213 >                assertFalse(Thread.interrupted());
214 >
215 >                pleaseInterrupt.countDown();
216                  try {
217                      q.take();
218                      shouldThrow();
219                  } catch (InterruptedException success) {}
220 +                assertFalse(Thread.interrupted());
221              }});
222  
223 <        aboutToWait.await();
224 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
223 >        await(pleaseInterrupt);
224 >        assertThreadStaysAlive(t);
225          t.interrupt();
226 <        awaitTermination(t, MEDIUM_DELAY_MS);
275 <        checkEmpty(q);
226 >        awaitTermination(t);
227      }
228  
229      /**
# Line 305 | Line 256 | public class LinkedTransferQueueTest ext
256      public void testTimedPoll() throws InterruptedException {
257          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
258          for (int i = 0; i < SIZE; ++i) {
259 <            long t0 = System.nanoTime();
260 <            assertEquals(i, (int) q.poll(SMALL_DELAY_MS, MILLISECONDS));
261 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
262 <        }
263 <        long t0 = System.nanoTime();
264 <        assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
265 <        assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
259 >            long startTime = System.nanoTime();
260 >            assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
261 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
262 >        }
263 >        long startTime = System.nanoTime();
264 >        assertNull(q.poll(timeoutMillis(), MILLISECONDS));
265 >        assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
266          checkEmpty(q);
267      }
268  
# Line 417 | Line 368 | public class LinkedTransferQueueTest ext
368      }
369  
370      /**
420     * remove(x) removes x and returns true if present
421     */
422    public void testRemoveElement() throws InterruptedException {
423        LinkedTransferQueue q = populatedQueue(SIZE);
424        for (int i = 1; i < SIZE; i+=2) {
425            assertTrue(q.contains(i));
426            assertTrue(q.remove(i));
427            assertFalse(q.contains(i));
428            assertTrue(q.contains(i-1));
429        }
430        for (int i = 0; i < SIZE; i+=2) {
431            assertTrue(q.contains(i));
432            assertTrue(q.remove(i));
433            assertFalse(q.contains(i));
434            assertFalse(q.remove(i+1));
435            assertFalse(q.contains(i+1));
436        }
437        checkEmpty(q);
438    }
439
440    /**
371       * An add following remove(x) succeeds
372       */
373      public void testRemoveElementAndAdd() throws InterruptedException {
# Line 553 | Line 483 | public class LinkedTransferQueueTest ext
483      }
484  
485      /**
556     * toArray(null) throws NullPointerException
557     */
558    public void testToArray_NullArg() {
559        LinkedTransferQueue q = populatedQueue(SIZE);
560        try {
561            q.toArray(null);
562            shouldThrow();
563        } catch (NullPointerException success) {}
564    }
565
566    /**
486       * toArray(incompatible array type) throws ArrayStoreException
487       */
488      public void testToArray1_BadArg() {
# Line 580 | Line 499 | public class LinkedTransferQueueTest ext
499      public void testIterator() throws InterruptedException {
500          LinkedTransferQueue q = populatedQueue(SIZE);
501          Iterator it = q.iterator();
502 <        int i = 0;
503 <        while (it.hasNext()) {
504 <            assertEquals(it.next(), i++);
505 <        }
502 >        int i;
503 >        for (i = 0; it.hasNext(); i++)
504 >            assertTrue(q.contains(it.next()));
505 >        assertEquals(i, SIZE);
506 >        assertIteratorExhausted(it);
507 >
508 >        it = q.iterator();
509 >        for (i = 0; it.hasNext(); i++)
510 >            assertEquals(it.next(), q.take());
511          assertEquals(i, SIZE);
512 +        assertIteratorExhausted(it);
513 +    }
514 +
515 +    /**
516 +     * iterator of empty collection has no elements
517 +     */
518 +    public void testEmptyIterator() {
519 +        assertIteratorExhausted(new LinkedTransferQueue().iterator());
520      }
521  
522      /**
# Line 646 | Line 578 | public class LinkedTransferQueueTest ext
578          LinkedTransferQueue q = populatedQueue(SIZE);
579          String s = q.toString();
580          for (int i = 0; i < SIZE; ++i) {
581 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
581 >            assertTrue(s.contains(String.valueOf(i)));
582          }
583      }
584  
# Line 655 | Line 587 | public class LinkedTransferQueueTest ext
587       */
588      public void testOfferInExecutor() {
589          final LinkedTransferQueue q = new LinkedTransferQueue();
590 <        final CountDownLatch threadsStarted = new CountDownLatch(2);
590 >        final CheckedBarrier threadsStarted = new CheckedBarrier(2);
591          ExecutorService executor = Executors.newFixedThreadPool(2);
592  
593          executor.execute(new CheckedRunnable() {
594              public void realRun() throws InterruptedException {
663                threadsStarted.countDown();
595                  threadsStarted.await();
596 <                assertTrue(q.offer(one, MEDIUM_DELAY_MS, MILLISECONDS));
596 >                assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
597              }});
598  
599          executor.execute(new CheckedRunnable() {
600              public void realRun() throws InterruptedException {
670                threadsStarted.countDown();
601                  threadsStarted.await();
602                  assertSame(one, q.take());
603                  checkEmpty(q);
# Line 681 | Line 611 | public class LinkedTransferQueueTest ext
611       */
612      public void testPollInExecutor() {
613          final LinkedTransferQueue q = new LinkedTransferQueue();
614 <        final CountDownLatch threadsStarted = new CountDownLatch(2);
614 >        final CheckedBarrier threadsStarted = new CheckedBarrier(2);
615          ExecutorService executor = Executors.newFixedThreadPool(2);
616  
617          executor.execute(new CheckedRunnable() {
618              public void realRun() throws InterruptedException {
619                  assertNull(q.poll());
690                threadsStarted.countDown();
620                  threadsStarted.await();
621 <                assertSame(one, q.poll(SMALL_DELAY_MS, MILLISECONDS));
621 >                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
622                  checkEmpty(q);
623              }});
624  
625          executor.execute(new CheckedRunnable() {
626              public void realRun() throws InterruptedException {
698                threadsStarted.countDown();
627                  threadsStarted.await();
628                  q.put(one);
629              }});
# Line 707 | Line 635 | public class LinkedTransferQueueTest ext
635       * A deserialized serialized queue has same elements in same order
636       */
637      public void testSerialization() throws Exception {
638 <        LinkedTransferQueue q = populatedQueue(SIZE);
639 <
712 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
713 <        ObjectOutputStream out
714 <            = new ObjectOutputStream(new BufferedOutputStream(bout));
715 <        out.writeObject(q);
716 <        out.close();
717 <
718 <        ByteArrayInputStream bin
719 <            = new ByteArrayInputStream(bout.toByteArray());
720 <        ObjectInputStream in
721 <            = new ObjectInputStream(new BufferedInputStream(bin));
722 <        LinkedTransferQueue r = (LinkedTransferQueue) in.readObject();
638 >        Queue x = populatedQueue(SIZE);
639 >        Queue y = serialClone(x);
640  
641 <        assertEquals(q.size(), r.size());
642 <        assertEquals(q.toString(), r.toString());
643 <        assertTrue(Arrays.equals(q.toArray(), r.toArray()));
644 <        while (!q.isEmpty()) {
645 <            assertEquals(q.remove(), r.remove());
641 >        assertNotSame(y, x);
642 >        assertEquals(x.size(), y.size());
643 >        assertEquals(x.toString(), y.toString());
644 >        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
645 >        while (!x.isEmpty()) {
646 >            assertFalse(y.isEmpty());
647 >            assertEquals(x.remove(), y.remove());
648          }
649 <    }
731 <
732 <    /**
733 <     * drainTo(null) throws NullPointerException
734 <     */
735 <    public void testDrainToNull() {
736 <        LinkedTransferQueue q = populatedQueue(SIZE);
737 <        try {
738 <            q.drainTo(null);
739 <            shouldThrow();
740 <        } catch (NullPointerException success) {}
741 <    }
742 <
743 <    /**
744 <     * drainTo(this) throws IllegalArgumentException
745 <     */
746 <    public void testDrainToSelf() {
747 <        LinkedTransferQueue q = populatedQueue(SIZE);
748 <        try {
749 <            q.drainTo(q);
750 <            shouldThrow();
751 <        } catch (IllegalArgumentException success) {}
649 >        assertTrue(y.isEmpty());
650      }
651  
652      /**
# Line 758 | Line 656 | public class LinkedTransferQueueTest ext
656          LinkedTransferQueue q = populatedQueue(SIZE);
657          ArrayList l = new ArrayList();
658          q.drainTo(l);
659 <        assertEquals(q.size(), 0);
660 <        assertEquals(l.size(), SIZE);
659 >        assertEquals(0, q.size());
660 >        assertEquals(SIZE, l.size());
661          for (int i = 0; i < SIZE; ++i) {
662 <            assertEquals(l.get(i), i);
662 >            assertEquals(i, l.get(i));
663          }
664          q.add(zero);
665          q.add(one);
# Line 770 | Line 668 | public class LinkedTransferQueueTest ext
668          assertTrue(q.contains(one));
669          l.clear();
670          q.drainTo(l);
671 <        assertEquals(q.size(), 0);
672 <        assertEquals(l.size(), 2);
671 >        assertEquals(0, q.size());
672 >        assertEquals(2, l.size());
673          for (int i = 0; i < 2; ++i) {
674 <            assertEquals(l.get(i), i);
674 >            assertEquals(i, l.get(i));
675          }
676      }
677  
# Line 789 | Line 687 | public class LinkedTransferQueueTest ext
687          ArrayList l = new ArrayList();
688          q.drainTo(l);
689          assertTrue(l.size() >= SIZE);
690 <        for (int i = 0; i < SIZE; ++i) {
691 <            assertEquals(l.get(i), i);
794 <        }
690 >        for (int i = 0; i < SIZE; ++i)
691 >            assertEquals(i, l.get(i));
692          awaitTermination(t, MEDIUM_DELAY_MS);
693          assertTrue(q.size() + l.size() >= SIZE);
694      }
695  
696      /**
800     * drainTo(null, n) throws NullPointerException
801     */
802    public void testDrainToNullN() {
803        LinkedTransferQueue q = populatedQueue(SIZE);
804        try {
805            q.drainTo(null, SIZE);
806            shouldThrow();
807        } catch (NullPointerException success) {}
808    }
809
810    /**
811     * drainTo(this, n) throws IllegalArgumentException
812     */
813    public void testDrainToSelfN() {
814        LinkedTransferQueue q = populatedQueue(SIZE);
815        try {
816            q.drainTo(q, SIZE);
817            shouldThrow();
818        } catch (IllegalArgumentException success) {}
819    }
820
821    /**
697       * drainTo(c, n) empties first min(n, size) elements of queue into c
698       */
699      public void testDrainToN() {
# Line 830 | Line 705 | public class LinkedTransferQueueTest ext
705              ArrayList l = new ArrayList();
706              q.drainTo(l, i);
707              int k = (i < SIZE) ? i : SIZE;
708 <            assertEquals(l.size(), k);
709 <            assertEquals(q.size(), SIZE - k);
710 <            for (int j = 0; j < k; ++j) {
711 <                assertEquals(l.get(j), j);
712 <            }
838 <            while (q.poll() != null)
839 <                ;
708 >            assertEquals(k, l.size());
709 >            assertEquals(SIZE - k, q.size());
710 >            for (int j = 0; j < k; ++j)
711 >                assertEquals(j, l.get(j));
712 >            do {} while (q.poll() != null);
713          }
714      }
715  
# Line 846 | Line 719 | public class LinkedTransferQueueTest ext
719       */
720      public void testWaitingConsumer() throws InterruptedException {
721          final LinkedTransferQueue q = new LinkedTransferQueue();
722 <        assertEquals(q.getWaitingConsumerCount(), 0);
722 >        assertEquals(0, q.getWaitingConsumerCount());
723          assertFalse(q.hasWaitingConsumer());
724          final CountDownLatch threadStarted = new CountDownLatch(1);
725  
# Line 854 | Line 727 | public class LinkedTransferQueueTest ext
727              public void realRun() throws InterruptedException {
728                  threadStarted.countDown();
729                  assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
730 <                assertEquals(q.getWaitingConsumerCount(), 0);
730 >                assertEquals(0, q.getWaitingConsumerCount());
731                  assertFalse(q.hasWaitingConsumer());
732              }});
733  
734          threadStarted.await();
735          waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
736 <        assertEquals(q.getWaitingConsumerCount(), 1);
736 >        assertEquals(1, q.getWaitingConsumerCount());
737          assertTrue(q.hasWaitingConsumer());
738  
739          assertTrue(q.offer(one));
740 <        assertEquals(q.getWaitingConsumerCount(), 0);
740 >        assertEquals(0, q.getWaitingConsumerCount());
741          assertFalse(q.hasWaitingConsumer());
742  
743          awaitTermination(t, MEDIUM_DELAY_MS);
# Line 988 | Line 861 | public class LinkedTransferQueueTest ext
861       * tryTransfer(null) throws NullPointerException
862       */
863      public void testTryTransfer1() {
864 +        final LinkedTransferQueue q = new LinkedTransferQueue();
865          try {
992            final LinkedTransferQueue q = new LinkedTransferQueue();
866              q.tryTransfer(null);
867              shouldThrow();
868          } catch (NullPointerException success) {}
# Line 1051 | Line 924 | public class LinkedTransferQueueTest ext
924      }
925  
926      /**
927 <     * tryTransfer waits the amount given, and throws
1055 <     * InterruptedException when interrupted.
927 >     * tryTransfer blocks interruptibly if no takers
928       */
929      public void testTryTransfer5() throws InterruptedException {
930          final LinkedTransferQueue q = new LinkedTransferQueue();
931 <        final CountDownLatch threadStarted = new CountDownLatch(1);
931 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
932          assertTrue(q.isEmpty());
933  
934          Thread t = newStartedThread(new CheckedRunnable() {
935              public void realRun() throws InterruptedException {
936 <                long t0 = System.nanoTime();
937 <                threadStarted.countDown();
936 >                Thread.currentThread().interrupt();
937 >                try {
938 >                    q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS);
939 >                    shouldThrow();
940 >                } catch (InterruptedException success) {}
941 >                assertFalse(Thread.interrupted());
942 >
943 >                pleaseInterrupt.countDown();
944                  try {
945                      q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS);
946                      shouldThrow();
947                  } catch (InterruptedException success) {}
948 <                assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
1071 <                assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
948 >                assertFalse(Thread.interrupted());
949              }});
950  
951 <        threadStarted.await();
952 <        while (q.isEmpty())
1076 <            Thread.yield();
1077 <        Thread.sleep(SHORT_DELAY_MS);
951 >        await(pleaseInterrupt);
952 >        assertThreadStaysAlive(t);
953          t.interrupt();
954 <        awaitTermination(t, MEDIUM_DELAY_MS);
954 >        awaitTermination(t);
955          checkEmpty(q);
956      }
957  
# Line 1090 | Line 965 | public class LinkedTransferQueueTest ext
965              public void realRun() throws InterruptedException {
966                  long t0 = System.nanoTime();
967                  assertFalse(q.tryTransfer(new Object(),
968 <                                          SHORT_DELAY_MS, MILLISECONDS));
969 <                assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
968 >                                          timeoutMillis(), MILLISECONDS));
969 >                assertTrue(millisElapsedSince(t0) >= timeoutMillis());
970                  checkEmpty(q);
971              }});
972  
973 <        awaitTermination(t, MEDIUM_DELAY_MS);
973 >        awaitTermination(t);
974          checkEmpty(q);
975      }
976  
# Line 1131 | Line 1006 | public class LinkedTransferQueueTest ext
1006          assertTrue(q.offer(four));
1007          assertEquals(1, q.size());
1008          long t0 = System.nanoTime();
1009 <        assertFalse(q.tryTransfer(five, SHORT_DELAY_MS, MILLISECONDS));
1010 <        assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
1009 >        assertFalse(q.tryTransfer(five, timeoutMillis(), MILLISECONDS));
1010 >        assertTrue(millisElapsedSince(t0) >= timeoutMillis());
1011          assertEquals(1, q.size());
1012          assertSame(four, q.poll());
1013          assertNull(q.poll());
# Line 1150 | Line 1025 | public class LinkedTransferQueueTest ext
1025          assertFalse(q.isEmpty());
1026          return q;
1027      }
1028 +
1029 +    /**
1030 +     * remove(null), contains(null) always return false
1031 +     */
1032 +    public void testNeverContainsNull() {
1033 +        Collection<?>[] qs = {
1034 +            new LinkedTransferQueue<Object>(),
1035 +            populatedQueue(2),
1036 +        };
1037 +
1038 +        for (Collection<?> q : qs) {
1039 +            assertFalse(q.contains(null));
1040 +            assertFalse(q.remove(null));
1041 +        }
1042 +    }
1043   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines