test/jdk/java/net/httpclient/ManyRequests.java
branchhttp-client-branch
changeset 55763 634d8e14c172
parent 47216 71c04702a3d5
child 55942 8d4770c22b63
equal deleted inserted replaced
55762:e947a3a50a95 55763:634d8e14c172
    54 import java.util.Arrays;
    54 import java.util.Arrays;
    55 import java.util.Formatter;
    55 import java.util.Formatter;
    56 import java.util.HashMap;
    56 import java.util.HashMap;
    57 import java.util.LinkedList;
    57 import java.util.LinkedList;
    58 import java.util.Random;
    58 import java.util.Random;
    59 import java.util.concurrent.ExecutorService;
       
    60 import java.util.logging.Logger;
    59 import java.util.logging.Logger;
    61 import java.util.logging.Level;
    60 import java.util.logging.Level;
    62 import java.util.concurrent.CompletableFuture;
    61 import java.util.concurrent.CompletableFuture;
    63 import javax.net.ssl.SSLContext;
    62 import javax.net.ssl.SSLContext;
    64 import jdk.testlibrary.SimpleSSLContext;
    63 import jdk.testlibrary.SimpleSSLContext;
    65 import static jdk.incubator.http.HttpRequest.BodyProcessor.fromByteArray;
    64 import static jdk.incubator.http.HttpRequest.BodyPublisher.fromByteArray;
    66 import static jdk.incubator.http.HttpResponse.BodyHandler.asByteArray;
    65 import static jdk.incubator.http.HttpResponse.BodyHandler.asByteArray;
    67 
    66 
    68 public class ManyRequests {
    67 public class ManyRequests {
    69 
    68 
    70     volatile static int counter = 0;
    69     volatile static int counter = 0;
    89         try {
    88         try {
    90             test(server, client);
    89             test(server, client);
    91             System.out.println("OK");
    90             System.out.println("OK");
    92         } finally {
    91         } finally {
    93             server.stop(0);
    92             server.stop(0);
    94             ((ExecutorService)client.executor()).shutdownNow();
       
    95         }
    93         }
    96     }
    94     }
    97 
    95 
    98     //static final int REQUESTS = 1000;
    96     //static final int REQUESTS = 1000;
    99     static final int REQUESTS = 20;
    97     static final int REQUESTS = 20;
   109             System.out.println("Server: received " + e.getRequestURI());
   107             System.out.println("Server: received " + e.getRequestURI());
   110             super.handle(e);
   108             super.handle(e);
   111         }
   109         }
   112         protected void close(OutputStream os) throws IOException {
   110         protected void close(OutputStream os) throws IOException {
   113             if (INSERT_DELAY) {
   111             if (INSERT_DELAY) {
   114                 try { Thread.sleep(rand.nextInt(200)); } catch (InterruptedException e) {}
   112                 try { Thread.sleep(rand.nextInt(200)); }
   115             }
   113                 catch (InterruptedException e) {}
   116             super.close(os);
   114             }
       
   115             os.close();
   117         }
   116         }
   118         protected void close(InputStream is) throws IOException {
   117         protected void close(InputStream is) throws IOException {
   119             if (INSERT_DELAY) {
   118             if (INSERT_DELAY) {
   120                 try { Thread.sleep(rand.nextInt(200)); } catch (InterruptedException e) {}
   119                 try { Thread.sleep(rand.nextInt(200)); }
   121             }
   120                 catch (InterruptedException e) {}
   122             super.close(is);
   121             }
       
   122             is.close();
   123         }
   123         }
   124     }
   124     }
   125 
   125 
   126     static void test(HttpsServer server, HttpClient client) throws Exception {
   126     static void test(HttpsServer server, HttpClient client) throws Exception {
   127         int port = server.getAddress().getPort();
   127         int port = server.getAddress().getPort();