jdk/test/javax/print/TestRaceCond.java
author jgodinez
Tue, 19 Aug 2008 16:04:06 -0700
changeset 1722 b676952a5943
child 2697 b27edaf0767e
permissions -rw-r--r--
6731826: race condition in UnixPrintServiceLookup Reviewed-by: campbell, tdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1722
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
     1
/*
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    21
 * have any questions.
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
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    46
        if (pserv1.hashCode() != pserv2.hashCode()) {
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    47
            throw new RuntimeException("Different hashCodes for equal print "
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    48
                            + "services: " + pserv1.hashCode() + " "
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    49
                            + pserv2.hashCode());
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    50
        }
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    51
    }
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    52
}
b676952a5943 6731826: race condition in UnixPrintServiceLookup
jgodinez
parents:
diff changeset
    53