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.83 by jsr166, Wed Jan 27 01:57:24 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 677 | Line 677 | public class LinkedBlockingQueueTest ext
677       * iterator.remove removes current element
678       */
679      public void testIteratorRemove() {
680 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(3);
680 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(3);
681          q.add(two);
682          q.add(one);
683          q.add(three);
# Line 696 | Line 696 | public class LinkedBlockingQueueTest ext
696       * iterator ordering is FIFO
697       */
698      public void testIteratorOrdering() {
699 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(3);
699 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(3);
700          q.add(one);
701          q.add(two);
702          q.add(three);
# Line 712 | Line 712 | public class LinkedBlockingQueueTest ext
712       * Modifications do not cause iterators to fail
713       */
714      public void testWeaklyConsistentIteration() {
715 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(3);
715 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(3);
716          q.add(one);
717          q.add(two);
718          q.add(three);
# Line 738 | Line 738 | public class LinkedBlockingQueueTest ext
738       * offer transfers elements across Executor tasks
739       */
740      public void testOfferInExecutor() {
741 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(2);
741 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(2);
742          q.add(one);
743          q.add(two);
744          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
# Line 764 | Line 764 | public class LinkedBlockingQueueTest ext
764       * timed poll retrieves elements across Executor threads
765       */
766      public void testPollInExecutor() {
767 <        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>(2);
767 >        final LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>(2);
768          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
769          final ExecutorService executor = Executors.newFixedThreadPool(2);
770          try (PoolCleaner cleaner = cleaner(executor)) {
# Line 807 | Line 807 | public class LinkedBlockingQueueTest ext
807       */
808      public void testDrainTo() {
809          LinkedBlockingQueue<Item> q = populatedQueue(SIZE);
810 <        ArrayList<Item> l = new ArrayList<Item>();
810 >        ArrayList<Item> l = new ArrayList<>();
811          q.drainTo(l);
812          mustEqual(0, q.size());
813          mustEqual(SIZE, l.size());
# Line 837 | Line 837 | public class LinkedBlockingQueueTest ext
837              }});
838  
839          t.start();
840 <        ArrayList<Item> l = new ArrayList<Item>();
840 >        ArrayList<Item> l = new ArrayList<>();
841          q.drainTo(l);
842          assertTrue(l.size() >= SIZE);
843          for (int i = 0; i < SIZE; ++i)
# Line 850 | Line 850 | public class LinkedBlockingQueueTest ext
850       * drainTo(c, n) empties first min(n, size) elements of queue into c
851       */
852      public void testDrainToN() {
853 <        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<Item>();
853 >        LinkedBlockingQueue<Item> q = new LinkedBlockingQueue<>();
854          for (int i = 0; i < SIZE + 2; ++i) {
855              for (int j = 0; j < SIZE; j++)
856                  mustOffer(q, j);
857 <            ArrayList<Item> l = new ArrayList<Item>();
857 >            ArrayList<Item> l = new ArrayList<>();
858              q.drainTo(l, i);
859              int k = (i < SIZE) ? i : SIZE;
860              mustEqual(k, l.size());
# Line 870 | Line 870 | public class LinkedBlockingQueueTest ext
870       */
871      public void testNeverContainsNull() {
872          Collection<?>[] qs = {
873 <            new LinkedBlockingQueue<Object>(),
873 >            new LinkedBlockingQueue<>(),
874              populatedQueue(2),
875          };
876  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines