jdk/test/java/util/concurrent/tck/LinkedBlockingQueue8Test.java
author dl
Wed, 09 Aug 2017 17:40:38 -0700
changeset 46146 b3e220a04d3f
parent 44589 64d9270bd24c
permissions -rw-r--r--
8185099: Miscellaneous changes imported from jsr166 CVS 2017-08 Reviewed-by: martin, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42926
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
     1
/*
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
     3
 *
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
     6
 * published by the Free Software Foundation.
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
     7
 *
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    12
 * accompanied this code).
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    13
 *
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    17
 *
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    20
 * questions.
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    21
 */
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    22
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    23
/*
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    24
 * This file is available under and governed by the GNU General Public
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    25
 * License version 2 only, as published by the Free Software Foundation.
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    26
 * However, the following notice accompanied the original version of this
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    27
 * file:
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    28
 *
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    29
 * Written by Doug Lea and Martin Buchholz with assistance from
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    30
 * members of JCP JSR-166 Expert Group and released to the public
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    31
 * domain, as explained at
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    32
 * http://creativecommons.org/publicdomain/zero/1.0/
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    33
 */
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    34
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    35
import java.util.concurrent.LinkedBlockingQueue;
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    36
import java.util.Spliterator;
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    37
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    38
import junit.framework.Test;
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    39
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    40
public class LinkedBlockingQueue8Test extends JSR166TestCase {
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    41
    public static void main(String[] args) {
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    42
        main(suite(), args);
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    43
    }
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    44
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    45
    public static Test suite() {
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    46
        return newTestSuite(LinkedBlockingQueue8Test.class);
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    47
    }
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    48
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    49
    /**
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    50
     * Spliterator.getComparator always throws IllegalStateException
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    51
     */
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    52
    public void testSpliterator_getComparator() {
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    53
        assertThrows(IllegalStateException.class,
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    54
                     () -> new LinkedBlockingQueue().spliterator().getComparator());
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    55
    }
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    56
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    57
    /**
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    58
     * Spliterator characteristics are as advertised
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    59
     */
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    60
    public void testSpliterator_characteristics() {
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    61
        LinkedBlockingQueue q = new LinkedBlockingQueue();
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    62
        Spliterator s = q.spliterator();
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    63
        int characteristics = s.characteristics();
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    64
        int required = Spliterator.CONCURRENT
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    65
            | Spliterator.NONNULL
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    66
            | Spliterator.ORDERED;
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    67
        assertEquals(required, characteristics & required);
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    68
        assertTrue(s.hasCharacteristics(required));
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    69
        assertEquals(0, characteristics
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    70
                     & (Spliterator.DISTINCT
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    71
                        | Spliterator.IMMUTABLE
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    72
                        | Spliterator.SORTED));
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    73
    }
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    74
8b9cacdadb2d 8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff changeset
    75
}