equal
deleted
inserted
replaced
192 } |
192 } |
193 |
193 |
194 final String ENCODED = "/01%252F03/"; |
194 final String ENCODED = "/01%252F03/"; |
195 |
195 |
196 @Test(dataProvider = "servers") |
196 @Test(dataProvider = "servers") |
197 public void testServerClose(String uri, boolean sameClient) |
197 public void testServerClose(String uri, boolean sameClient) { |
198 throws Exception { |
|
199 HttpClient client = null; |
198 HttpClient client = null; |
200 out.printf("%n%s testServerClose(%s, %b)%n", now(), uri, sameClient); |
199 out.printf("%n%s testServerClose(%s, %b)%n", now(), uri, sameClient); |
201 uri = uri + ENCODED; |
200 uri = uri + ENCODED; |
202 for (int i=0; i< ITERATION_COUNT; i++) { |
201 for (int i=0; i< ITERATION_COUNT; i++) { |
203 if (!sameClient || client == null) |
202 if (!sameClient || client == null) |
207 |
206 |
208 HttpRequest req = HttpRequest.newBuilder(URI.create(uri)) |
207 HttpRequest req = HttpRequest.newBuilder(URI.create(uri)) |
209 .POST(bodyPublisher) |
208 .POST(bodyPublisher) |
210 .build(); |
209 .build(); |
211 BodyHandler<String> handler = BodyHandlers.ofString(); |
210 BodyHandler<String> handler = BodyHandlers.ofString(); |
212 CompletableFuture<HttpResponse<String>> responseCF = client.sendAsync(req, handler); |
211 HttpClient c = client; |
|
212 CompletableFuture<HttpResponse<String>> responseCF = c.sendAsync(req, handler); |
|
213 // retry POST if needed #### Replace with exceptionallyCompose |
|
214 responseCF = responseCF.handle((r,t) -> |
|
215 t == null ? CompletableFuture.completedFuture(r) |
|
216 : c.sendAsync(req, handler)).thenCompose(x -> x); |
213 HttpResponse<String> response = responseCF.join(); |
217 HttpResponse<String> response = responseCF.join(); |
214 String body = response.body(); |
218 String body = response.body(); |
215 if (!uri.contains(body)) { |
219 if (!uri.contains(body)) { |
216 System.err.println("Test failed: " + response); |
220 System.err.println("Test failed: " + response); |
217 throw new RuntimeException(uri + " doesn't contain '" + body + "'"); |
221 throw new RuntimeException(uri + " doesn't contain '" + body + "'"); |