jdk/test/javax/print/TestRaceCond.java
author iignatyev
Mon, 23 Dec 2013 18:39:47 +0000
changeset 22195 c39aa322d33a
parent 5506 202f599c92aa
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1722
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2697
diff changeset
     2
 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
1722
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
     4
 *
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
     8
 *
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    13
 * accompanied this code).
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    14
 *
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2697
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2697
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2697
diff changeset
    21
 * questions.
1722
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    22
 */
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    23
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    24
/*
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    25
 * @test
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    26
 * @bug 6731826
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    27
 * @summary  There should be no RuntimeException.
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    28
 * @run main TestRaceCond
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    29
 */
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    30
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    31
import javax.print.PrintService;
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    32
import javax.print.PrintServiceLookup;
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    33
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    34
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    35
public class TestRaceCond {
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    36
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    37
    public static void main(String argv[]) {
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    38
        trial();
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    39
    }
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    40
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    41
    static void trial() {
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    42
        PrintService pserv1 = PrintServiceLookup.lookupDefaultPrintService();
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    43
        PrintService[] pservs = PrintServiceLookup.lookupPrintServices(null, null);
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    44
        PrintService pserv2 = PrintServiceLookup.lookupDefaultPrintService();
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    45
2697
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents: 1722
diff changeset
    46
        if ((pserv1 == null) || (pserv2==null)) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents: 1722
diff changeset
    47
            return;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents: 1722
diff changeset
    48
        }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents: 1722
diff changeset
    49
1722
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    50
        if (pserv1.hashCode() != pserv2.hashCode()) {
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    51
            throw new RuntimeException("Different hashCodes for equal print "
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    52
                            + "services: " + pserv1.hashCode() + " "
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    53
                            + pserv2.hashCode());
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    54
        }
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    55
    }
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    56
}
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    57