test/jdk/java/util/Collection/BiggernYours.java
author pli
Tue, 16 Jul 2019 00:57:00 +0000
changeset 55689 8c5c9d86e1d6
parent 48541 946e34c2dec9
permissions -rw-r--r--
8227512: [TESTBUG] Fix JTReg javac test failures with Graal Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24692
268fbc344d53 8037866: Replace the Fun class in tests with lambdas
igerasim
parents: 14342
diff changeset
     2
 * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4110
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4110
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4110
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6415641 6377302
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Concurrent collections are permitted to lie about their size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Martin Buchholz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
48541
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    31
import java.util.Arrays;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    32
import java.util.Collection;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    33
import java.util.Map;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    34
import java.util.NavigableMap;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    35
import java.util.NavigableSet;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    36
import java.util.Objects;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    37
import java.util.Random;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    38
import java.util.Set;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    39
import java.util.TreeSet;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    40
import java.util.concurrent.ArrayBlockingQueue;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    41
import java.util.concurrent.ConcurrentHashMap;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    42
import java.util.concurrent.ConcurrentLinkedDeque;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    43
import java.util.concurrent.ConcurrentLinkedQueue;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    44
import java.util.concurrent.ConcurrentSkipListMap;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    45
import java.util.concurrent.ConcurrentSkipListSet;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    46
import java.util.concurrent.CopyOnWriteArrayList;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    47
import java.util.concurrent.CopyOnWriteArraySet;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    48
import java.util.concurrent.LinkedBlockingDeque;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    49
import java.util.concurrent.LinkedBlockingQueue;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    50
import java.util.concurrent.LinkedTransferQueue;
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    51
import java.util.concurrent.PriorityBlockingQueue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
@SuppressWarnings("unchecked")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class BiggernYours {
12859
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    55
    static final Random rnd = new Random(18675309);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static void compareCollections(Collection c1, Collection c2) {
12859
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    58
        Object[] c1Array = c1.toArray();
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    59
        Object[] c2Array = c2.toArray();
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    60
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    61
        check(c1Array.length == c2Array.length);
32991
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents: 32649
diff changeset
    62
        for (Object aC1 : c1Array) {
12859
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    63
            boolean found = false;
32991
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents: 32649
diff changeset
    64
            for (Object aC2 : c2Array) {
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents: 32649
diff changeset
    65
                if (Objects.equals(aC1, aC2)) {
12859
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    66
                    found = true;
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    67
                    break;
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    68
                }
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    69
            }
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    70
32991
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents: 32649
diff changeset
    71
            if (!found)
12859
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    72
                fail(aC1 + " not found in " + Arrays.toString(c2Array));
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 7668
diff changeset
    73
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    static void compareMaps(Map m1, Map m2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        compareCollections(m1.keySet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                           m2.keySet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        compareCollections(m1.values(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                           m2.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        compareCollections(m1.entrySet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                           m2.entrySet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    static void compareNavigableMaps(NavigableMap m1, NavigableMap m2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        compareMaps(m1, m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        compareMaps(m1.descendingMap(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    m2.descendingMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        compareMaps(m1.tailMap(Integer.MIN_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    m2.tailMap(Integer.MIN_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        compareMaps(m1.headMap(Integer.MAX_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    m2.headMap(Integer.MAX_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    static void compareNavigableSets(NavigableSet s1, NavigableSet s2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        compareCollections(s1, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        compareCollections(s1.descendingSet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                           s2.descendingSet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        compareCollections(s1.tailSet(Integer.MIN_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                           s2.tailSet(Integer.MIN_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 24692
diff changeset
   103
    abstract static class MapFrobber { abstract void frob(Map m); }
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 24692
diff changeset
   104
    abstract static class SetFrobber { abstract void frob(Set s); }
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 24692
diff changeset
   105
    abstract static class ColFrobber { abstract void frob(Collection c); }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    static ColFrobber adder(final int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return new ColFrobber() {void frob(Collection c) { c.add(i); }};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    static final ColFrobber[] adders =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    { adder(1), adder(3), adder(2) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    static MapFrobber putter(final int k, final int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return new MapFrobber() {void frob(Map m) { m.put(k,v); }};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    static final MapFrobber[] putters =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    { putter(1, -2), putter(3, -6), putter(2, -4) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    static void unexpected(Throwable t, Object suspect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        System.out.println(suspect.getClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        unexpected(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    static void testCollections(Collection c1, Collection c2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            compareCollections(c1, c2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            for (ColFrobber adder : adders) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                for (Collection c : new Collection[]{c1, c2})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    adder.frob(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                compareCollections(c1, c2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } catch (Throwable t) { unexpected(t, c1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    static void testNavigableSets(NavigableSet s1, NavigableSet s2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            compareNavigableSets(s1, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            for (ColFrobber adder : adders) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                for (Set s : new Set[]{s1, s2})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    adder.frob(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                compareNavigableSets(s1, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        } catch (Throwable t) { unexpected(t, s1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    static void testMaps(Map m1, Map m2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            compareMaps(m1, m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            for (MapFrobber putter : putters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                for (Map m : new Map[]{m1, m2})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    putter.frob(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                compareMaps(m1, m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        } catch (Throwable t) { unexpected(t, m1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    static void testNavigableMaps(NavigableMap m1, NavigableMap m2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            compareNavigableMaps(m1, m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            for (MapFrobber putter : putters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                for (Map m : new Map[]{m1, m2})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    putter.frob(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                compareNavigableMaps(m1, m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        } catch (Throwable t) { unexpected(t, m1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    static int randomize(int size) { return rnd.nextInt(size + 2); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    @SuppressWarnings("serial")
48541
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
   173
    private static void realMain(String[] args) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        testNavigableMaps(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            new ConcurrentSkipListMap(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            new ConcurrentSkipListMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        testNavigableSets(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            new ConcurrentSkipListSet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            new ConcurrentSkipListSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            new CopyOnWriteArraySet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            new CopyOnWriteArraySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            new CopyOnWriteArrayList(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            new CopyOnWriteArrayList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            new TreeSet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            new TreeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        testMaps(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            new ConcurrentHashMap(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            new ConcurrentHashMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        testCollections(
6672
f01ef94a63e7 6981113: Add ConcurrentLinkedDeque
dl
parents: 5506
diff changeset
   205
            new ConcurrentLinkedDeque(),
f01ef94a63e7 6981113: Add ConcurrentLinkedDeque
dl
parents: 5506
diff changeset
   206
            new ConcurrentLinkedDeque() {
f01ef94a63e7 6981113: Add ConcurrentLinkedDeque
dl
parents: 5506
diff changeset
   207
                public int size() {return randomize(super.size());}});
f01ef94a63e7 6981113: Add ConcurrentLinkedDeque
dl
parents: 5506
diff changeset
   208
f01ef94a63e7 6981113: Add ConcurrentLinkedDeque
dl
parents: 5506
diff changeset
   209
        testCollections(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            new ConcurrentLinkedQueue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            new ConcurrentLinkedQueue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
4110
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 3708
diff changeset
   214
        testCollections(
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 3708
diff changeset
   215
            new LinkedTransferQueue(),
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 3708
diff changeset
   216
            new LinkedTransferQueue() {
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 3708
diff changeset
   217
                public int size() {return randomize(super.size());}});
3708
f838f712922e 6868712: Improve concurrent queue tests
dl
parents: 2
diff changeset
   218
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            new LinkedBlockingQueue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            new LinkedBlockingQueue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            new LinkedBlockingDeque(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            new LinkedBlockingDeque() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            new ArrayBlockingQueue(5),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            new ArrayBlockingQueue(5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            new PriorityBlockingQueue(5),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            new PriorityBlockingQueue(5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    //--------------------- Infrastructure ---------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    static volatile int passed = 0, failed = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    static void pass() {passed++;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    static void fail() {failed++; Thread.dumpStack();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    static void fail(String msg) {System.out.println(msg); fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    static void unexpected(Throwable t) {failed++; t.printStackTrace();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    static void check(boolean cond) {if (cond) pass(); else fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    static void equal(Object x, Object y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (x == null ? y == null : x.equals(y)) pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        else fail(x + " not equal to " + y);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    static void arrayEqual(Object[] x, Object[] y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (x == null ? y == null : Arrays.equals(x, y)) pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        else fail(Arrays.toString(x) + " not equal to " + Arrays.toString(y));}
48541
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
   253
    public static void main(String[] args) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        try {realMain(args);} catch (Throwable t) {unexpected(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (failed > 0) throw new AssertionError("Some tests failed");}
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 24692
diff changeset
   257
    private abstract static class CheckedThread extends Thread {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        abstract void realRun() throws Throwable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            try {realRun();} catch (Throwable t) {unexpected(t);}}}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
}