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

Comparing jsr166/src/test/tck/ArrayBlockingQueueTest.java (file contents):
Revision 1.98 by dl, Tue Jan 26 13:33:05 2021 UTC vs.
Revision 1.100 by jsr166, Wed Jan 27 02:55:18 2021 UTC

# Line 173 | Line 173 | public class ArrayBlockingQueueTest exte
173      public void testConstructor7() {
174          Item[] items = defaultItems;
175          Collection<Item> elements = Arrays.asList(items);
176 <        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(SIZE, true, elements);
176 >        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(SIZE, true, elements);
177          for (int i = 0; i < SIZE; ++i)
178              mustEqual(items[i], q.poll());
179      }
# Line 217 | Line 217 | public class ArrayBlockingQueueTest exte
217       * Offer succeeds if not full; fails if full
218       */
219      public void testOffer() {
220 <        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(1);
220 >        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(1);
221          assertTrue(q.offer(zero));
222          assertFalse(q.offer(one));
223      }
# Line 226 | Line 226 | public class ArrayBlockingQueueTest exte
226       * add succeeds if not full; throws IllegalStateException if full
227       */
228      public void testAdd() {
229 <        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(SIZE);
229 >        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(SIZE);
230          for (int i = 0; i < SIZE; i++) assertTrue(q.add(itemFor(i)));
231          mustEqual(0, q.remainingCapacity());
232          try {
# Line 251 | Line 251 | public class ArrayBlockingQueueTest exte
251       * possibly adding some elements
252       */
253      public void testAddAll3() {
254 <        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(SIZE);
254 >        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(SIZE);
255          Item[] items = new Item[2]; items[0] = zero;
256          try {
257              q.addAll(Arrays.asList(items));
# Line 283 | Line 283 | public class ArrayBlockingQueueTest exte
283      public void testAddAll5() {
284          Item[] empty = new Item[0];
285          Item[] items = defaultItems;
286 <        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(SIZE);
286 >        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(SIZE);
287          assertFalse(q.addAll(Arrays.asList(empty)));
288          assertTrue(q.addAll(Arrays.asList(items)));
289          for (int i = 0; i < SIZE; ++i)
# Line 294 | Line 294 | public class ArrayBlockingQueueTest exte
294       * all elements successfully put are contained
295       */
296      public void testPut() throws InterruptedException {
297 <        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(SIZE);
297 >        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(SIZE);
298          for (int i = 0; i < SIZE; ++i) {
299              Item x = itemFor(i);
300              q.put(x);
# Line 307 | Line 307 | public class ArrayBlockingQueueTest exte
307       * put blocks interruptibly if full
308       */
309      public void testBlockingPut() throws InterruptedException {
310 <        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(SIZE);
310 >        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(SIZE);
311          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
312          Thread t = newStartedThread(new CheckedRunnable() {
313              public void realRun() throws InterruptedException {
# Line 344 | Line 344 | public class ArrayBlockingQueueTest exte
344       */
345      public void testPutWithTake() throws InterruptedException {
346          final int capacity = 2;
347 <        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(capacity);
347 >        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(capacity);
348          final CountDownLatch pleaseTake = new CountDownLatch(1);
349          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
350          Thread t = newStartedThread(new CheckedRunnable() {
# Line 384 | Line 384 | public class ArrayBlockingQueueTest exte
384       * timed offer times out if full and elements not taken
385       */
386      public void testTimedOffer() {
387 <        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(2);
387 >        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(2);
388          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
389          Thread t = newStartedThread(new CheckedRunnable() {
390              public void realRun() throws InterruptedException {
# Line 609 | Line 609 | public class ArrayBlockingQueueTest exte
609       */
610      public void testContainsAll() {
611          ArrayBlockingQueue<Item> q = populatedQueue(SIZE);
612 <        ArrayBlockingQueue<Item> p = new ArrayBlockingQueue<Item>(SIZE);
612 >        ArrayBlockingQueue<Item> p = new ArrayBlockingQueue<>(SIZE);
613          for (int i = 0; i < SIZE; ++i) {
614              assertTrue(q.containsAll(p));
615              assertFalse(p.containsAll(q));
# Line 712 | Line 712 | public class ArrayBlockingQueueTest exte
712      /**
713       * toArray(incompatible array type) throws ArrayStoreException
714       */
715 +    @SuppressWarnings("CollectionToArraySafeParameter")
716      public void testToArray_incompatibleArrayType() {
717          ArrayBlockingQueue<Item> q = populatedQueue(SIZE);
718          try {
# Line 747 | Line 748 | public class ArrayBlockingQueueTest exte
748       * iterator of empty collection has no elements
749       */
750      public void testEmptyIterator() {
751 <        assertIteratorExhausted(new ArrayBlockingQueue<Item>(SIZE).iterator());
751 >        assertIteratorExhausted(new ArrayBlockingQueue<>(SIZE).iterator());
752      }
753  
754      /**
755       * iterator.remove removes current element
756       */
757      public void testIteratorRemove() {
758 <        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(3);
758 >        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(3);
759          q.add(two);
760          q.add(one);
761          q.add(three);
# Line 773 | Line 774 | public class ArrayBlockingQueueTest exte
774       * iterator ordering is FIFO
775       */
776      public void testIteratorOrdering() {
777 <        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(3);
777 >        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(3);
778          q.add(one);
779          q.add(two);
780          q.add(three);
# Line 791 | Line 792 | public class ArrayBlockingQueueTest exte
792       * Modifications do not cause iterators to fail
793       */
794      public void testWeaklyConsistentIteration() {
795 <        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(3);
795 >        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(3);
796          q.add(one);
797          q.add(two);
798          q.add(three);
# Line 817 | Line 818 | public class ArrayBlockingQueueTest exte
818       * offer transfers elements across Executor tasks
819       */
820      public void testOfferInExecutor() {
821 <        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(2);
821 >        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(2);
822          q.add(one);
823          q.add(two);
824          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
# Line 844 | Line 845 | public class ArrayBlockingQueueTest exte
845       * timed poll retrieves elements across Executor threads
846       */
847      public void testPollInExecutor() {
848 <        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(2);
848 >        final ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(2);
849          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
850          final ExecutorService executor = Executors.newFixedThreadPool(2);
851          try (PoolCleaner cleaner = cleaner(executor)) {
# Line 887 | Line 888 | public class ArrayBlockingQueueTest exte
888       */
889      public void testDrainTo() {
890          ArrayBlockingQueue<Item> q = populatedQueue(SIZE);
891 <        ArrayList<Item> l = new ArrayList<Item>();
891 >        ArrayList<Item> l = new ArrayList<>();
892          q.drainTo(l);
893          mustEqual(0, q.size());
894          mustEqual(SIZE, l.size());
# Line 917 | Line 918 | public class ArrayBlockingQueueTest exte
918              }});
919  
920          t.start();
921 <        ArrayList<Item> l = new ArrayList<Item>();
921 >        ArrayList<Item> l = new ArrayList<>();
922          q.drainTo(l);
923          assertTrue(l.size() >= SIZE);
924          for (int i = 0; i < SIZE; ++i)
# Line 930 | Line 931 | public class ArrayBlockingQueueTest exte
931       * drainTo(c, n) empties first min(n, size) elements of queue into c
932       */
933      public void testDrainToN() {
934 <        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<Item>(SIZE * 2);
934 >        ArrayBlockingQueue<Item> q = new ArrayBlockingQueue<>(SIZE * 2);
935          for (int i = 0; i < SIZE + 2; ++i) {
936              for (int j = 0; j < SIZE; j++)
937                  mustOffer(q, j);
938 <            ArrayList<Item> l = new ArrayList<Item>();
938 >            ArrayList<Item> l = new ArrayList<>();
939              q.drainTo(l, i);
940              int k = (i < SIZE) ? i : SIZE;
941              mustEqual(k, l.size());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines