test/jdk/java/net/Authenticator/Deadlock.java
changeset 55399 46049b8a5658
parent 47216 71c04702a3d5
equal deleted inserted replaced
55398:e53ec3b362f4 55399:46049b8a5658
     1 /*
     1 /*
     2  * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    23 
    23 
    24 /**
    24 /**
    25  * @test
    25  * @test
    26  * @bug 6648001
    26  * @bug 6648001
    27  * @modules jdk.httpserver
    27  * @modules jdk.httpserver
       
    28  * @library /test/lib
    28  * @run main/othervm/timeout=20 -ea:sun.net.www.protocol.http.AuthenticationInfo -Dhttp.auth.serializeRequests=true Deadlock
    29  * @run main/othervm/timeout=20 -ea:sun.net.www.protocol.http.AuthenticationInfo -Dhttp.auth.serializeRequests=true Deadlock
       
    30  * @run main/othervm/timeout=20 -Djava.net.preferIPv6Addresses=true
       
    31  *                              -ea:sun.net.www.protocol.http.AuthenticationInfo -Dhttp.auth.serializeRequests=true Deadlock
    29  * @summary  cancelling HTTP authentication causes deadlock
    32  * @summary  cancelling HTTP authentication causes deadlock
    30  */
    33  */
    31 
    34 
    32 import java.util.concurrent.Executors;
    35 import java.util.concurrent.Executors;
    33 import java.util.concurrent.ExecutorService;
    36 import java.util.concurrent.ExecutorService;
    34 import java.io.InputStream;
    37 import java.io.InputStream;
    35 import java.io.IOException;
    38 import java.io.IOException;
    36 import java.net.HttpURLConnection;
    39 import java.net.HttpURLConnection;
       
    40 import java.net.InetAddress;
    37 import java.net.InetSocketAddress;
    41 import java.net.InetSocketAddress;
    38 import java.net.PasswordAuthentication;
    42 import java.net.PasswordAuthentication;
       
    43 import java.net.Proxy;
    39 import java.net.URL;
    44 import java.net.URL;
    40 import com.sun.net.httpserver.BasicAuthenticator;
    45 import com.sun.net.httpserver.BasicAuthenticator;
    41 import com.sun.net.httpserver.Headers;
    46 import com.sun.net.httpserver.Headers;
    42 import com.sun.net.httpserver.HttpContext;
    47 import com.sun.net.httpserver.HttpContext;
    43 import com.sun.net.httpserver.HttpExchange;
    48 import com.sun.net.httpserver.HttpExchange;
    44 import com.sun.net.httpserver.HttpHandler;
    49 import com.sun.net.httpserver.HttpHandler;
    45 import com.sun.net.httpserver.HttpPrincipal;
    50 import com.sun.net.httpserver.HttpPrincipal;
    46 import com.sun.net.httpserver.HttpServer;
    51 import com.sun.net.httpserver.HttpServer;
       
    52 import jdk.test.lib.net.URIBuilder;
    47 
    53 
    48 public class Deadlock {
    54 public class Deadlock {
    49 
    55 
    50     public static void main (String[] args) throws Exception {
    56     public static void main (String[] args) throws Exception {
    51         Handler handler = new Handler();
    57         Handler handler = new Handler();
    52         InetSocketAddress addr = new InetSocketAddress (0);
    58         InetAddress loopback = InetAddress.getLoopbackAddress();
       
    59         InetSocketAddress addr = new InetSocketAddress (loopback, 0);
    53         HttpServer server = HttpServer.create(addr, 0);
    60         HttpServer server = HttpServer.create(addr, 0);
    54         HttpContext ctx = server.createContext("/test", handler);
    61         HttpContext ctx = server.createContext("/test", handler);
    55         BasicAuthenticator a = new BasicAuthenticator("foobar@test.realm") {
    62         BasicAuthenticator a = new BasicAuthenticator("foobar@test.realm") {
    56             @Override
    63             @Override
    57             public boolean checkCredentials (String username, String pw) {
    64             public boolean checkCredentials (String username, String pw) {
    95         @Override
   102         @Override
    96         public void run() {
   103         public void run() {
    97             URL url;
   104             URL url;
    98             HttpURLConnection urlc;
   105             HttpURLConnection urlc;
    99             try {
   106             try {
   100                 url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
   107                 url = URIBuilder.newBuilder()
   101                 urlc = (HttpURLConnection)url.openConnection ();
   108                     .scheme("http")
       
   109                     .loopback()
       
   110                     .port(server.getAddress().getPort())
       
   111                     .path("/test/foo.html")
       
   112                     .toURLUnchecked();
       
   113                 urlc = (HttpURLConnection)url.openConnection (Proxy.NO_PROXY);
   102             } catch (IOException e) {
   114             } catch (IOException e) {
   103                 error = true;
   115                 error = true;
   104                 return;
   116                 return;
   105             }
   117             }
   106             InputStream is = null;
   118             InputStream is = null;