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

Comparing jsr166/src/test/tck/LinkedBlockingQueueTest.java (file contents):
Revision 1.82 by dl, Tue Jan 26 13:33:06 2021 UTC vs.
Revision 1.84 by jsr166, Wed Jan 27 02:55:18 2021 UTC

# Line 129 | Line 129 | public class LinkedBlockingQueueTest ext
129       */
130      public void testConstructor6() {
131          Item[] items = defaultItems;
132 <        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(Arrays.asList(items));
132 >        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(Arrays.asList(items));
133          for (int i = 0; i < SIZE; ++i)
134              mustEqual(items[i], q.poll());
135      }
# Line 138 | Line 138 | public class LinkedBlockingQueueTest ext
138       * Queue transitions from empty to full when elements added
139       */
140      public void testEmptyFull() {
141 <        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(2);
141 >        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(2);
142          assertTrue(q.isEmpty());
143          mustEqual(2, q.remainingCapacity());
144          q.add(one);
# Line 170 | Line 170 | public class LinkedBlockingQueueTest ext
170       * Offer succeeds if not full; fails if full
171       */
172      public void testOffer() {
173 <        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(1);
173 >        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(1);
174          assertTrue(q.offer(zero));
175          assertFalse(q.offer(one));
176      }
# Line 179 | Line 179 | public class LinkedBlockingQueueTest ext
179       * add succeeds if not full; throws IllegalStateException if full
180       */
181      public void testAdd() {
182 <        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(SIZE);
182 >        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(SIZE);
183          for (int i = 0; i < SIZE; ++i)
184              mustAdd(q, i);
185          mustEqual(0, q.remainingCapacity());
# Line 205 | Line 205 | public class LinkedBlockingQueueTest ext
205       * possibly adding some elements
206       */
207      public void testAddAll3() {
208 <        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(SIZE);
208 >        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(SIZE);
209          Item[] items = new Item[2]; items[0] = zero;
210          Collection<Item> elements = Arrays.asList(items);
211          try {
# Line 218 | Line 218 | public class LinkedBlockingQueueTest ext
218       * addAll throws IllegalStateException if not enough room
219       */
220      public void testAddAll4() {
221 <        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(SIZE - 1);
221 >        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(SIZE - 1);
222          Item[] items = defaultItems;
223          Collection<Item> elements = Arrays.asList(items);
224          try {
# Line 233 | Line 233 | public class LinkedBlockingQueueTest ext
233      public void testAddAll5() {
234          Item[] empty = new Item[0];
235          Item[] items = defaultItems;
236 <        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(SIZE);
236 >        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(SIZE);
237          assertFalse(q.addAll(Arrays.asList(empty)));
238          assertTrue(q.addAll(Arrays.asList(items)));
239          for (int i = 0; i < SIZE; ++i)
# Line 244 | Line 244 | public class LinkedBlockingQueueTest ext
244       * all elements successfully put are contained
245       */
246      public void testPut() throws InterruptedException {
247 <        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(SIZE);
247 >        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(SIZE);
248          for (int i = 0; i < SIZE; ++i) {
249              Item x = itemFor(i);
250              q.put(x);
# Line 257 | Line 257 | public class LinkedBlockingQueueTest ext
257       * put blocks interruptibly if full
258       */
259      public void testBlockingPut() throws InterruptedException {
260 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(SIZE);
260 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(SIZE);
261          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
262          Thread t = newStartedThread(new CheckedRunnable() {
263              public void realRun() throws InterruptedException {
# Line 294 | Line 294 | public class LinkedBlockingQueueTest ext
294       */
295      public void testPutWithTake() throws InterruptedException {
296          final int capacity = 2;
297 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(2);
297 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(2);
298          final CountDownLatch pleaseTake = new CountDownLatch(1);
299          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
300          Thread t = newStartedThread(new CheckedRunnable() {
# Line 334 | Line 334 | public class LinkedBlockingQueueTest ext
334       * timed offer times out if full and elements not taken
335       */
336      public void testTimedOffer() {
337 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(2);
337 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(2);
338          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
339          Thread t = newStartedThread(new CheckedRunnable() {
340              public void realRun() throws InterruptedException {
# Line 526 | Line 526 | public class LinkedBlockingQueueTest ext
526       * An add following remove(x) succeeds
527       */
528      public void testRemoveElementAndAdd() throws InterruptedException {
529 <        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>();
529 >        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>();
530          assertTrue(q.add(one));
531          assertTrue(q.add(two));
532          mustRemove(q, one);
# Line 568 | Line 568 | public class LinkedBlockingQueueTest ext
568       */
569      public void testContainsAll() {
570          LinkedBlockingQueue<Item> q = populatedQueue(SIZE);
571 <        LinkedBlockingQueue<Item> p = new LinkedBlockingQueue<Item>(SIZE);
571 >        LinkedBlockingQueue<Item> p = new LinkedBlockingQueue<>(SIZE);
572          for (int i = 0; i < SIZE; ++i) {
573              assertTrue(q.containsAll(p));
574              assertFalse(p.containsAll(q));
# Line 639 | Line 639 | public class LinkedBlockingQueueTest ext
639      /**
640       * toArray(incompatible array type) throws ArrayStoreException
641       */
642 <    public void testToArray1_BadArg() {
642 >    @SuppressWarnings("CollectionToArraySafeParameter")
643 >    public void testToArray_incompatibleArrayType() {
644          LinkedBlockingQueue<Item> q = populatedQueue(SIZE);
645          try {
646              q.toArray(new String[10]);
# Line 677 | Line 678 | public class LinkedBlockingQueueTest ext
678       * iterator.remove removes current element
679       */
680      public void testIteratorRemove() {
681 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(3);
681 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(3);
682          q.add(two);
683          q.add(one);
684          q.add(three);
# Line 696 | Line 697 | public class LinkedBlockingQueueTest ext
697       * iterator ordering is FIFO
698       */
699      public void testIteratorOrdering() {
700 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(3);
700 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(3);
701          q.add(one);
702          q.add(two);
703          q.add(three);
# Line 712 | Line 713 | public class LinkedBlockingQueueTest ext
713       * Modifications do not cause iterators to fail
714       */
715      public void testWeaklyConsistentIteration() {
716 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(3);
716 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(3);
717          q.add(one);
718          q.add(two);
719          q.add(three);
# Line 738 | Line 739 | public class LinkedBlockingQueueTest ext
739       * offer transfers elements across Executor tasks
740       */
741      public void testOfferInExecutor() {
742 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(2);
742 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(2);
743          q.add(one);
744          q.add(two);
745          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
# Line 764 | Line 765 | public class LinkedBlockingQueueTest ext
765       * timed poll retrieves elements across Executor threads
766       */
767      public void testPollInExecutor() {
768 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(2);
768 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(2);
769          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
770          final ExecutorService executor = Executors.newFixedThreadPool(2);
771          try (PoolCleaner cleaner = cleaner(executor)) {
# Line 807 | Line 808 | public class LinkedBlockingQueueTest ext
808       */
809      public void testDrainTo() {
810          LinkedBlockingQueue<Item> q = populatedQueue(SIZE);
811 <        ArrayList<Item> l = new ArrayList<Item>();
811 >        ArrayList<Item> l = new ArrayList<>();
812          q.drainTo(l);
813          mustEqual(0, q.size());
814          mustEqual(SIZE, l.size());
# Line 837 | Line 838 | public class LinkedBlockingQueueTest ext
838              }});
839  
840          t.start();
841 <        ArrayList<Item> l = new ArrayList<Item>();
841 >        ArrayList<Item> l = new ArrayList<>();
842          q.drainTo(l);
843          assertTrue(l.size() >= SIZE);
844          for (int i = 0; i < SIZE; ++i)
# Line 850 | Line 851 | public class LinkedBlockingQueueTest ext
851       * drainTo(c, n) empties first min(n, size) elements of queue into c
852       */
853      public void testDrainToN() {
854 <        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>();
854 >        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>();
855          for (int i = 0; i < SIZE + 2; ++i) {
856              for (int j = 0; j < SIZE; j++)
857                  mustOffer(q, j);
858 <            ArrayList<Item> l = new ArrayList<Item>();
858 >            ArrayList<Item> l = new ArrayList<>();
859              q.drainTo(l, i);
860              int k = (i < SIZE) ? i : SIZE;
861              mustEqual(k, l.size());
# Line 870 | Line 871 | public class LinkedBlockingQueueTest ext
871       */
872      public void testNeverContainsNull() {
873          Collection<?>[] qs = {
874 <            new LinkedBlockingQueue<Object>(),
874 >            new LinkedBlockingQueue<>(),
875              populatedQueue(2),
876          };
877  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines