< prev index next >

test/jdk/java/util/concurrent/tck/ArrayBlockingQueueTest.java

Print this page
8234131: Miscellaneous changes imported from jsr166 CVS 2020-12
Reviewed-by: martin


 698         assertEquals(size, a3.length);
 699         Integer[] a4 = new Integer[size];
 700         assertSame(a4, q.toArray(a4));
 701         Integer[] a5 = new Integer[size + 1];
 702         Arrays.fill(a5, 42);
 703         assertSame(a5, q.toArray(a5));
 704         Integer[] a6 = new Integer[size + 2];
 705         Arrays.fill(a6, 42);
 706         assertSame(a6, q.toArray(a6));
 707         Object[][] as = { a1, a2, a3, a4, a5, a6 };
 708         for (Object[] a : as) {
 709             if (a.length > size) assertNull(a[size]);
 710             if (a.length > size + 1) assertEquals(42, a[size + 1]);
 711         }
 712         Iterator it = q.iterator();
 713         Integer s = q.peek();
 714         for (int i = 0; i < size; i++) {
 715             Integer x = (Integer) it.next();
 716             assertEquals(s + i, (int) x);
 717             for (Object[] a : as)
 718                 assertSame(a1[i], x);
 719         }
 720     }
 721 
 722     /**
 723      * toArray() and toArray(a) contain all elements in FIFO order
 724      */
 725     public void testToArray() {
 726         final ThreadLocalRandom rnd = ThreadLocalRandom.current();
 727         final int size = rnd.nextInt(6);
 728         final int capacity = Math.max(1, size + rnd.nextInt(size + 1));
 729         ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<>(capacity);
 730         for (int i = 0; i < size; i++) {
 731             checkToArray(q);
 732             q.add(i);
 733         }
 734         // Provoke wraparound
 735         int added = size * 2;
 736         for (int i = 0; i < added; i++) {
 737             checkToArray(q);
 738             assertEquals((Integer) i, q.poll());




 698         assertEquals(size, a3.length);
 699         Integer[] a4 = new Integer[size];
 700         assertSame(a4, q.toArray(a4));
 701         Integer[] a5 = new Integer[size + 1];
 702         Arrays.fill(a5, 42);
 703         assertSame(a5, q.toArray(a5));
 704         Integer[] a6 = new Integer[size + 2];
 705         Arrays.fill(a6, 42);
 706         assertSame(a6, q.toArray(a6));
 707         Object[][] as = { a1, a2, a3, a4, a5, a6 };
 708         for (Object[] a : as) {
 709             if (a.length > size) assertNull(a[size]);
 710             if (a.length > size + 1) assertEquals(42, a[size + 1]);
 711         }
 712         Iterator it = q.iterator();
 713         Integer s = q.peek();
 714         for (int i = 0; i < size; i++) {
 715             Integer x = (Integer) it.next();
 716             assertEquals(s + i, (int) x);
 717             for (Object[] a : as)
 718                 assertSame(a[i], x);
 719         }
 720     }
 721 
 722     /**
 723      * toArray() and toArray(a) contain all elements in FIFO order
 724      */
 725     public void testToArray() {
 726         final ThreadLocalRandom rnd = ThreadLocalRandom.current();
 727         final int size = rnd.nextInt(6);
 728         final int capacity = Math.max(1, size + rnd.nextInt(size + 1));
 729         ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<>(capacity);
 730         for (int i = 0; i < size; i++) {
 731             checkToArray(q);
 732             q.add(i);
 733         }
 734         // Provoke wraparound
 735         int added = size * 2;
 736         for (int i = 0; i < added; i++) {
 737             checkToArray(q);
 738             assertEquals((Integer) i, q.poll());


< prev index next >