36
37 /*
38 * @test
39 * @bug 6805775 6815766
40 * @summary Check weak consistency of concurrent queue iterators
41 */
42
43 @SuppressWarnings({"unchecked", "rawtypes"})
44 public class IteratorWeakConsistency {
45
46 void test(String[] args) throws Throwable {
47 test(new LinkedBlockingQueue());
48 test(new LinkedBlockingQueue(20));
49 test(new LinkedBlockingDeque());
50 test(new LinkedBlockingDeque(20));
51 test(new ConcurrentLinkedDeque());
52 test(new ConcurrentLinkedQueue());
53 test(new LinkedTransferQueue());
54 // Other concurrent queues (e.g. ArrayBlockingQueue) do not
55 // currently have weakly consistent iterators.
56 // test(new ArrayBlockingQueue(20));
57 }
58
59 void test(Queue q) {
60 // TODO: make this more general
61 try {
62 for (int i = 0; i < 10; i++)
63 q.add(i);
64 Iterator it = q.iterator();
65 q.poll();
66 q.poll();
67 q.poll();
68 q.remove(7);
69 List list = new ArrayList();
70 while (it.hasNext())
71 list.add(it.next());
72 equal(list, Arrays.asList(0, 3, 4, 5, 6, 8, 9));
73 check(! list.contains(null));
74 System.out.printf("%s: %s%n",
75 q.getClass().getSimpleName(),
76 list);
|
36
37 /*
38 * @test
39 * @bug 6805775 6815766
40 * @summary Check weak consistency of concurrent queue iterators
41 */
42
43 @SuppressWarnings({"unchecked", "rawtypes"})
44 public class IteratorWeakConsistency {
45
46 void test(String[] args) throws Throwable {
47 test(new LinkedBlockingQueue());
48 test(new LinkedBlockingQueue(20));
49 test(new LinkedBlockingDeque());
50 test(new LinkedBlockingDeque(20));
51 test(new ConcurrentLinkedDeque());
52 test(new ConcurrentLinkedQueue());
53 test(new LinkedTransferQueue());
54 // Other concurrent queues (e.g. ArrayBlockingQueue) do not
55 // currently have weakly consistent iterators.
56 // As of 2010-09, ArrayBlockingQueue passes this test, but
57 // does not fully implement weak consistency.
58 test(new ArrayBlockingQueue(20));
59 }
60
61 void test(Queue q) {
62 // TODO: make this more general
63 try {
64 for (int i = 0; i < 10; i++)
65 q.add(i);
66 Iterator it = q.iterator();
67 q.poll();
68 q.poll();
69 q.poll();
70 q.remove(7);
71 List list = new ArrayList();
72 while (it.hasNext())
73 list.add(it.next());
74 equal(list, Arrays.asList(0, 3, 4, 5, 6, 8, 9));
75 check(! list.contains(null));
76 System.out.printf("%s: %s%n",
77 q.getClass().getSimpleName(),
78 list);
|