test/jdk/sun/net/www/protocol/http/RetryUponTimeout.java
changeset 54314 46cf212cdcca
parent 47216 71c04702a3d5
child 54841 43439afaab4a
equal deleted inserted replaced
54313:440cbcf3b268 54314:46cf212cdcca
    22  */
    22  */
    23 
    23 
    24 /**
    24 /**
    25  * @test
    25  * @test
    26  * @bug 4772077
    26  * @bug 4772077
       
    27  * @library /test/lib
    27  * @summary  using defaultReadTimeout appear to retry request upon timeout
    28  * @summary  using defaultReadTimeout appear to retry request upon timeout
    28  * @modules java.base/sun.net.www
    29  * @modules java.base/sun.net.www
    29  */
    30  */
    30 
    31 
    31 import java.net.*;
    32 import java.net.*;
    32 import java.io.*;
    33 import java.io.*;
       
    34 import jdk.test.lib.net.URIBuilder;
    33 import sun.net.www.*;
    35 import sun.net.www.*;
    34 
    36 
    35 public class RetryUponTimeout implements Runnable {
    37 public class RetryUponTimeout implements Runnable {
    36     // run server
    38     // run server
    37     public void run(){
    39     public void run(){
    61         try {
    63         try {
    62             server = new ServerSocket (0);
    64             server = new ServerSocket (0);
    63             int port = server.getLocalPort ();
    65             int port = server.getLocalPort ();
    64             new Thread(new RetryUponTimeout()).start ();
    66             new Thread(new RetryUponTimeout()).start ();
    65 
    67 
    66             URL url = new URL("http://127.0.0.1:"+port);
    68             URL url = URIBuilder.newBuilder()
       
    69                 .scheme("http")
       
    70                 .loopback()
       
    71                 .port(port)
       
    72                 .toURL();
       
    73             System.out.println("URL: " + url);
    67             java.net.URLConnection uc = url.openConnection();
    74             java.net.URLConnection uc = url.openConnection();
    68             uc.setReadTimeout(1000);
    75             uc.setReadTimeout(1000);
    69             uc.getInputStream();
    76             uc.getInputStream();
    70         } catch (SocketTimeoutException stex) {
    77         } catch (SocketTimeoutException stex) {
    71             // expected exception
    78             // expected exception