--- a/test/jdk/sun/net/www/http/HttpClient/RetryPost.java Thu Oct 17 20:27:44 2019 +0100
+++ b/test/jdk/sun/net/www/http/HttpClient/RetryPost.java Thu Oct 17 20:53:35 2019 +0100
@@ -54,23 +54,19 @@
MyHandler httpHandler;
ExecutorService executorService;
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
if (args.length == 1 && args[0].equals("noRetry"))
shouldRetry = false;
new RetryPost();
}
- public RetryPost() {
- try {
- startHttpServer(shouldRetry);
- doClient();
- } catch (IOException ioe) {
- System.err.println(ioe);
- }
+ public RetryPost() throws Exception {
+ startHttpServer(shouldRetry);
+ doClient();
}
- void doClient() {
+ void doClient() throws Exception {
try {
InetSocketAddress address = httpServer.getAddress();
URL url = URIBuilder.newBuilder()
@@ -88,15 +84,17 @@
throw new RuntimeException("Failed: POST request being retried");
} catch (SocketException se) {
+ System.out.println("Got expected exception: " + se);
// this is what we expect to happen and is OK.
- if (shouldRetry && httpHandler.getCallCount() != 2)
+ if (shouldRetry && httpHandler.getCallCount() != 2) {
+ se.printStackTrace(System.out);
throw new RuntimeException("Failed: Handler should have been called twice. " +
"It was called "+ httpHandler.getCallCount() + " times");
- else if (!shouldRetry && httpHandler.getCallCount() != 1)
+ } else if (!shouldRetry && httpHandler.getCallCount() != 1) {
+ se.printStackTrace(System.out);
throw new RuntimeException("Failed: Handler should have only been called once" +
"It was called "+ httpHandler.getCallCount() + " times");
- } catch (IOException e) {
- e.printStackTrace();
+ }
} finally {
httpServer.stop(1);
executorService.shutdown();
@@ -119,8 +117,8 @@
}
class MyHandler implements HttpHandler {
- int callCount = 0;
- boolean shouldRetry;
+ volatile int callCount = 0;
+ final boolean shouldRetry;
public MyHandler(boolean shouldRetry) {
this.shouldRetry = shouldRetry;