test/jdk/java/net/httpclient/TimeoutOrdering.java
changeset 49944 4690a2871b44
parent 49765 ee6f7a61f3a5
child 56507 2294c51eae30
equal deleted inserted replaced
49943:8e1ed2a15845 49944:4690a2871b44
    75                                          .timeout(Duration.ofSeconds(TIMEOUTS[i]))
    75                                          .timeout(Duration.ofSeconds(TIMEOUTS[i]))
    76                                          .GET()
    76                                          .GET()
    77                                          .build();
    77                                          .build();
    78 
    78 
    79                 final HttpRequest req = requests[i];
    79                 final HttpRequest req = requests[i];
       
    80                 final int j = i;
    80                 CompletableFuture<HttpResponse<Object>> response = client
    81                 CompletableFuture<HttpResponse<Object>> response = client
    81                     .sendAsync(req, BodyHandlers.replacing(null))
    82                     .sendAsync(req, BodyHandlers.replacing(null))
    82                     .whenComplete((HttpResponse<Object> r, Throwable t) -> {
    83                     .whenComplete((HttpResponse<Object> r, Throwable t) -> {
    83                         if (r != null) {
    84                         if (r != null) {
    84                             out.println("Unexpected response: " + r);
    85                             out.println("Unexpected response for r" + j + ": " + r);
    85                             error = true;
    86                             error = true;
    86                         }
    87                         }
    87                         if (t != null) {
    88                         if (t != null) {
    88                             if (!(t.getCause() instanceof HttpTimeoutException)) {
    89                             if (!(t.getCause() instanceof HttpTimeoutException)) {
    89                                 out.println("Wrong exception type:" + t.toString());
    90                                 out.println("Wrong exception type for r" + j + ": " + t.toString());
    90                                 Throwable c = t.getCause() == null ? t : t.getCause();
    91                                 Throwable c = t.getCause() == null ? t : t.getCause();
    91                                 c.printStackTrace();
    92                                 c.printStackTrace();
    92                                 error = true;
    93                                 error = true;
    93                             } else {
    94                             } else {
    94                                 out.println("Caught expected timeout: " + t.getCause());
    95                                 out.println("Caught expected timeout for r" + j + ": " + t.getCause());
    95                             }
    96                             }
    96                         }
    97                         }
    97                         queue.add(req);
    98                         queue.add(req);
    98                     });
    99                     });
    99             }
   100             }
   115                                          .timeout(Duration.ofSeconds(TIMEOUTS[i]))
   116                                          .timeout(Duration.ofSeconds(TIMEOUTS[i]))
   116                                          .GET()
   117                                          .GET()
   117                                          .build();
   118                                          .build();
   118 
   119 
   119                 final HttpRequest req = requests[i];
   120                 final HttpRequest req = requests[i];
       
   121                 final int j = i;
   120                 executor.execute(() -> {
   122                 executor.execute(() -> {
   121                     try {
   123                     try {
   122                         client.send(req, BodyHandlers.replacing(null));
   124                         HttpResponse<?> r = client.send(req, BodyHandlers.replacing(null));
       
   125                         out.println("Unexpected response for r" + j + ": " + r);
       
   126                         error = true;
   123                     } catch (HttpTimeoutException e) {
   127                     } catch (HttpTimeoutException e) {
   124                         out.println("Caught expected timeout: " + e);
   128                         out.println("Caught expected timeout for r" + j +": " + e);
   125                         queue.offer(req);
       
   126                     } catch (IOException | InterruptedException ee) {
   129                     } catch (IOException | InterruptedException ee) {
   127                         Throwable c = ee.getCause() == null ? ee : ee.getCause();
   130                         Throwable c = ee.getCause() == null ? ee : ee.getCause();
       
   131                         out.println("Wrong exception type for r" + j + ": " + c.toString());
   128                         c.printStackTrace();
   132                         c.printStackTrace();
   129                         error = true;
   133                         error = true;
       
   134                     } finally {
       
   135                         queue.offer(req);
   130                     }
   136                     }
   131                 });
   137                 });
   132             }
   138             }
   133             System.out.println("All requests submitted. Waiting ...");
   139             System.out.println("All requests submitted. Waiting ...");
   134 
   140