http-client-branch: setReuseAddress(false) for all test ServerSockets http-client-branch
authorchegar
Sat, 03 Mar 2018 09:54:31 +0000
branchhttp-client-branch
changeset 56233 1753108d07b9
parent 56227 278e1c6c3e99
child 56234 fc391230cf7b
http-client-branch: setReuseAddress(false) for all test ServerSockets
test/jdk/java/net/httpclient/DigestEchoServer.java
test/jdk/java/net/httpclient/HandshakeFailureTest.java
test/jdk/java/net/httpclient/InterruptedBlockingSend.java
test/jdk/java/net/httpclient/InvalidSSLContextTest.java
test/jdk/java/net/httpclient/MappingResponseSubscriber.java
test/jdk/java/net/httpclient/MockServer.java
test/jdk/java/net/httpclient/ProxyAuthTest.java
test/jdk/java/net/httpclient/ProxyServer.java
test/jdk/java/net/httpclient/ShortRequestBody.java
test/jdk/java/net/httpclient/SmallTimeout.java
test/jdk/java/net/httpclient/SmokeTest.java
test/jdk/java/net/httpclient/TimeoutBasic.java
test/jdk/java/net/httpclient/TimeoutOrdering.java
test/jdk/java/net/httpclient/http2/BadHeadersTest.java
test/jdk/java/net/httpclient/http2/ProxyTest2.java
test/jdk/java/net/httpclient/http2/RedirectTest.java
test/jdk/java/net/httpclient/http2/Timeout.java
test/jdk/java/net/httpclient/http2/server/Http2TestServer.java
test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/FlowTest.java
test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java
test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLTubeTest.java
test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java
--- a/test/jdk/java/net/httpclient/DigestEchoServer.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/DigestEchoServer.java	Sat Mar 03 09:54:31 2018 +0000
@@ -293,7 +293,10 @@
 
         @Override
         protected ServerSocket createBindable() throws IOException {
-            return new ServerSocket(0);
+            ServerSocket ss = new ServerSocket();
+            ss.setReuseAddress(false);
+            ss.bind(new InetSocketAddress(0));
+            return ss;
         }
 
         @Override
--- a/test/jdk/java/net/httpclient/HandshakeFailureTest.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/HandshakeFailureTest.java	Sat Mar 03 09:54:31 2018 +0000
@@ -28,6 +28,7 @@
 import java.io.DataInputStream;
 import java.io.IOException;
 import java.io.UncheckedIOException;
+import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.URI;
@@ -173,6 +174,8 @@
 
         AbstractServer(String name, ServerSocket ss) throws IOException {
             super(name);
+            ss.setReuseAddress(false);
+            ss.bind(new InetSocketAddress(0));
             this.ss = ss;
             this.start();
         }
@@ -198,7 +201,7 @@
         private volatile int count;
 
         PlainServer() throws IOException {
-            super("PlainServer", new ServerSocket(0));
+            super("PlainServer", new ServerSocket());
         }
 
         @Override
@@ -265,7 +268,7 @@
         }
 
         SSLServer() throws IOException {
-            super("SSLServer", factory.createServerSocket(0));
+            super("SSLServer", factory.createServerSocket());
         }
 
         @Override
--- a/test/jdk/java/net/httpclient/InterruptedBlockingSend.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/InterruptedBlockingSend.java	Sat Mar 03 09:54:31 2018 +0000
@@ -21,6 +21,7 @@
  * questions.
  */
 
+import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.URI;
 import java.net.http.HttpClient;
@@ -40,7 +41,9 @@
 
     public static void main(String[] args) throws Exception {
         HttpClient client = HttpClient.newHttpClient();
-        try (ServerSocket ss = new ServerSocket(0, 20)) {
+        try (ServerSocket ss = new ServerSocket()) {
+            ss.setReuseAddress(false);
+            ss.bind(new InetSocketAddress(0));
             int port = ss.getLocalPort();
             URI uri = new URI("http://127.0.0.1:" + port + "/");
 
--- a/test/jdk/java/net/httpclient/InvalidSSLContextTest.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/InvalidSSLContextTest.java	Sat Mar 03 09:54:31 2018 +0000
@@ -32,6 +32,7 @@
 
 import java.io.IOException;
 import java.io.UncheckedIOException;
+import java.net.InetSocketAddress;
 import java.net.URI;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CompletionException;
@@ -141,7 +142,9 @@
         // server-side uses a different context to that of the client-side
         sslServerSocket = (SSLServerSocket)sslContext
                 .getServerSocketFactory()
-                .createServerSocket(0);
+                .createServerSocket();
+        sslServerSocket.setReuseAddress(false);
+        sslServerSocket.bind(new InetSocketAddress(0));
         uri = "https://localhost:" + sslServerSocket.getLocalPort() + "/";
 
         Thread t = new Thread("SSL-Server-Side") {
--- a/test/jdk/java/net/httpclient/MappingResponseSubscriber.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/MappingResponseSubscriber.java	Sat Mar 03 09:54:31 2018 +0000
@@ -30,7 +30,9 @@
  *          java.net.http/jdk.internal.net.http.common
  *          java.net.http/jdk.internal.net.http.frame
  *          java.net.http/jdk.internal.net.http.hpack
- * @run testng/othervm MappingResponseSubscriber
+ * @run testng/othervm
+ *       -Djdk.internal.httpclient.debug=true
+ *      MappingResponseSubscriber
  */
 
 import java.io.IOException;
--- a/test/jdk/java/net/httpclient/MockServer.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/MockServer.java	Sat Mar 03 09:54:31 2018 +0000
@@ -27,6 +27,7 @@
 import java.io.OutputStream;
 import javax.net.ServerSocketFactory;
 import javax.net.ssl.SSLServerSocket;
+import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.nio.charset.StandardCharsets;
@@ -287,7 +288,9 @@
     }
 
     MockServer(int port, ServerSocketFactory factory, String root) throws IOException {
-        ss = factory.createServerSocket(port);
+        ss = factory.createServerSocket();
+        ss.setReuseAddress(false);
+        ss.bind(new InetSocketAddress(0));
         this.root = root; // if specified, any request which don't have this value
                           // in their statusLine will be rejected.
         sockets = Collections.synchronizedList(new LinkedList<>());
--- a/test/jdk/java/net/httpclient/ProxyAuthTest.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/ProxyAuthTest.java	Sat Mar 03 09:54:31 2018 +0000
@@ -60,7 +60,9 @@
     private static final String AUTH_PASSWORD = "password";
 
     public static void main(String[] args) throws Exception {
-        try (ServerSocket ss = new ServerSocket(0)) {
+        try (ServerSocket ss = new ServerSocket()) {
+            ss.setReuseAddress(false);
+            ss.bind(new InetSocketAddress(0));
             int port = ss.getLocalPort();
             MyProxy proxy = new MyProxy(ss);
             (new Thread(proxy)).start();
--- a/test/jdk/java/net/httpclient/ProxyServer.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/ProxyServer.java	Sat Mar 03 09:54:31 2018 +0000
@@ -48,7 +48,9 @@
 
     public ProxyServer(Integer port, Boolean debug) throws IOException {
         this.debug = debug;
-        listener = new ServerSocket(port);
+        listener = new ServerSocket();
+        listener.setReuseAddress(false);
+        listener.bind(new InetSocketAddress(port));
         this.port = listener.getLocalPort();
         setName("ProxyListener");
         setDaemon(true);
--- a/test/jdk/java/net/httpclient/ShortRequestBody.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/ShortRequestBody.java	Sat Mar 03 09:54:31 2018 +0000
@@ -25,6 +25,7 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UncheckedIOException;
+import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.URI;
@@ -232,7 +233,10 @@
 
         Server() throws IOException {
             super("Test-Server");
-            ss = new ServerSocket(0); this.start();
+            ss = new ServerSocket();
+            ss.setReuseAddress(false);
+            ss.bind(new InetSocketAddress(0));
+            this.start();
         }
 
         int getPort() { return ss.getLocalPort(); }
--- a/test/jdk/java/net/httpclient/SmallTimeout.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/SmallTimeout.java	Sat Mar 03 09:54:31 2018 +0000
@@ -22,6 +22,7 @@
  */
 
 import java.io.IOException;
+import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.URI;
 import java.net.http.HttpClient;
@@ -77,7 +78,9 @@
     public static void main(String[] args) throws Exception {
         HttpClient client = HttpClient.newHttpClient();
 
-        try (ServerSocket ss = new ServerSocket(0, 20)) {
+        try (ServerSocket ss = new ServerSocket()) {
+            ss.setReuseAddress(false);
+            ss.bind(new InetSocketAddress(0));
             int port = ss.getLocalPort();
             URI uri = new URI("http://127.0.0.1:" + port + "/");
 
--- a/test/jdk/java/net/httpclient/SmokeTest.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/SmokeTest.java	Sat Mar 03 09:54:31 2018 +0000
@@ -33,7 +33,7 @@
  * @compile ../../../com/sun/net/httpserver/EchoHandler.java
  * @compile ../../../com/sun/net/httpserver/FileServerHandler.java
  * @run main/othervm
- *      -Djdk.internal.httpclient.debugX=true
+ *      -Djdk.internal.httpclient.debug=true
  *      -Djdk.httpclient.HttpClient.log=errors,ssl,trace
  *      SmokeTest
  */
--- a/test/jdk/java/net/httpclient/TimeoutBasic.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/TimeoutBasic.java	Sat Mar 03 09:54:31 2018 +0000
@@ -22,6 +22,7 @@
  */
 
 import java.io.IOException;
+import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.URI;
 import java.net.http.HttpClient;
@@ -140,7 +141,9 @@
         if (version != null) builder.version(version);
         HttpClient client = builder.build();
         out.printf("%ntest(version=%s, reqVersion=%s, scheme=%s)%n", version, reqVersion, scheme);
-        try (ServerSocket ss = ssf.createServerSocket(0, 20)) {
+        try (ServerSocket ss = ssf.createServerSocket()) {
+            ss.setReuseAddress(false);
+            ss.bind(new InetSocketAddress(0));
             int port = ss.getLocalPort();
             URI uri = new URI(scheme +"://127.0.0.1:" + port + "/");
 
--- a/test/jdk/java/net/httpclient/TimeoutOrdering.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/TimeoutOrdering.java	Sat Mar 03 09:54:31 2018 +0000
@@ -22,6 +22,7 @@
  */
 
 import java.io.IOException;
+import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.URI;
 import java.net.http.HttpClient;
@@ -59,7 +60,9 @@
     public static void main(String[] args) throws Exception {
         HttpClient client = HttpClient.newHttpClient();
 
-        try (ServerSocket ss = new ServerSocket(0, 20)) {
+        try (ServerSocket ss = new ServerSocket()) {
+            ss.setReuseAddress(false);
+            ss.bind(new InetSocketAddress(0));
             int port = ss.getLocalPort();
             URI uri = new URI("http://127.0.0.1:" + port + "/");
 
--- a/test/jdk/java/net/httpclient/http2/BadHeadersTest.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/BadHeadersTest.java	Sat Mar 03 09:54:31 2018 +0000
@@ -30,7 +30,7 @@
  * @library /lib/testlibrary server
  * @build Http2TestServer
  * @build jdk.testlibrary.SimpleSSLContext
- * @run testng/othervm BadHeadersTest
+ * @run testng/othervm -Djdk.internal.httpclient.debug=true BadHeadersTest
  */
 
 import jdk.internal.net.http.common.HttpHeadersImpl;
--- a/test/jdk/java/net/httpclient/http2/ProxyTest2.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/ProxyTest2.java	Sat Mar 03 09:54:31 2018 +0000
@@ -176,6 +176,7 @@
         }
 
         void start() throws IOException {
+            ss.setReuseAddress(false);
             ss.bind(new InetSocketAddress(0));
             accept.start();
         }
--- a/test/jdk/java/net/httpclient/http2/RedirectTest.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/RedirectTest.java	Sat Mar 03 09:54:31 2018 +0000
@@ -32,6 +32,7 @@
  *          java.net.http/jdk.internal.net.http.hpack
  * @run testng/othervm
  *      -Djdk.httpclient.HttpClient.log=frames,ssl,requests,responses,errors
+ *      -Djdk.internal.httpclient.debug=true
  *      RedirectTest
  */
 
--- a/test/jdk/java/net/httpclient/http2/Timeout.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/Timeout.java	Sat Mar 03 09:54:31 2018 +0000
@@ -23,6 +23,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.InetSocketAddress;
 import java.net.URI;
 import java.net.http.HttpClient;
 import java.net.http.HttpRequest;
@@ -69,7 +70,9 @@
                 (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
 
         try (SSLServerSocket ssocket =
-                (SSLServerSocket) factory.createServerSocket(RANDOM_PORT)) {
+                (SSLServerSocket) factory.createServerSocket()) {
+            ssocket.setReuseAddress(false);
+            ssocket.bind(new InetSocketAddress(RANDOM_PORT));
 
             // start server
             Thread server = new Thread(() -> {
--- a/test/jdk/java/net/httpclient/http2/server/Http2TestServer.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/server/Http2TestServer.java	Sat Mar 03 09:54:31 2018 +0000
@@ -167,7 +167,10 @@
     }
 
     final ServerSocket initPlaintext(int port) throws Exception {
-        return new ServerSocket(port);
+        ServerSocket ss = new ServerSocket();
+        ss.setReuseAddress(false);
+        ss.bind(new InetSocketAddress(0));
+        return ss;
     }
 
     public synchronized void stop() {
@@ -191,7 +194,9 @@
         } else {
             fac = SSLServerSocketFactory.getDefault();
         }
-        SSLServerSocket se = (SSLServerSocket) fac.createServerSocket(port);
+        SSLServerSocket se = (SSLServerSocket) fac.createServerSocket();
+        se.setReuseAddress(false);
+        se.bind(new InetSocketAddress(0));
         SSLParameters sslp = se.getSSLParameters();
         sslp.setApplicationProtocols(new String[]{"h2"});
         sslp.setEndpointIdentificationAlgorithm("HTTPS");
--- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/FlowTest.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/FlowTest.java	Sat Mar 03 09:54:31 2018 +0000
@@ -29,6 +29,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.nio.ByteBuffer;
 import java.security.KeyManagementException;
@@ -196,7 +197,9 @@
                               ExecutorService exec,
                               CountDownLatch allBytesReceived) throws IOException {
             SSLServerSocketFactory fac = ctx.getServerSocketFactory();
-            SSLServerSocket serv = (SSLServerSocket) fac.createServerSocket(0);
+            SSLServerSocket serv = (SSLServerSocket) fac.createServerSocket();
+            serv.setReuseAddress(false);
+            serv.bind(new InetSocketAddress(0));
             SSLParameters params = serv.getSSLParameters();
             params.setApplicationProtocols(new String[]{"proto2"});
             serv.setSSLParameters(params);
--- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java	Sat Mar 03 09:54:31 2018 +0000
@@ -27,6 +27,7 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UncheckedIOException;
+import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.URI;
@@ -80,7 +81,9 @@
 
     @Test
     public void test() throws Exception {
-        try (ServerSocket server = new ServerSocket(0)) {
+        try (ServerSocket server = new ServerSocket()) {
+            server.setReuseAddress(false);
+            server.bind(new InetSocketAddress(0));
             int port = server.getLocalPort();
             new TestServer(server).start();
 
--- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLTubeTest.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLTubeTest.java	Sat Mar 03 09:54:31 2018 +0000
@@ -37,6 +37,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.nio.ByteBuffer;
 import java.util.List;
@@ -83,7 +84,9 @@
                               ExecutorService exec,
                               CountDownLatch allBytesReceived) throws IOException {
             SSLServerSocketFactory fac = ctx.getServerSocketFactory();
-            SSLServerSocket serv = (SSLServerSocket) fac.createServerSocket(0);
+            SSLServerSocket serv = (SSLServerSocket) fac.createServerSocket();
+            serv.setReuseAddress(false);
+            serv.bind(new InetSocketAddress(0));
             SSLParameters params = serv.getSSLParameters();
             params.setApplicationProtocols(new String[]{"proto2"});
             serv.setSSLParameters(params);
--- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java	Fri Mar 02 15:14:03 2018 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java	Sat Mar 03 09:54:31 2018 +0000
@@ -81,7 +81,9 @@
     @Test
     public void test() throws Exception {
 
-        try (ServerSocket server = new ServerSocket(0)) {
+        try (ServerSocket server = new ServerSocket()) {
+            server.setReuseAddress(false);
+            server.bind(new InetSocketAddress(0));
             int port = server.getLocalPort();
 
             out.println("Listening on port " + server.getLocalPort());