8037360: java/nio/channels/SocketChannel/Connect.java fails intermittently
authoralanb
Fri, 08 Apr 2016 16:38:37 +0100
changeset 36963 1558f7600497
parent 36962 472d86c9e55d
child 36964 0627478c1504
8037360: java/nio/channels/SocketChannel/Connect.java fails intermittently Reviewed-by: alanb Contributed-by: huaming.li@oracle.com
jdk/test/java/nio/channels/SocketChannel/Connect.java
jdk/test/java/nio/channels/TestServers.java
--- a/jdk/test/java/nio/channels/SocketChannel/Connect.java	Fri Apr 08 14:05:22 2016 +0300
+++ b/jdk/test/java/nio/channels/SocketChannel/Connect.java	Fri Apr 08 16:38:37 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
  */
 
 /* @test
- * @bug 4650679
+ * @bug 4650679 8037360
  * @summary Unit test for socket channels
  * @library ..
  */
@@ -42,9 +42,7 @@
             test1(echoServer);
         }
         try {
-            TestServers.RefusingServer refusingServer
-                = TestServers.RefusingServer.startNewServer();
-            test1(refusingServer);
+            test1(TestServers.RefusingServer.newRefusingServer());
             throw new Exception("Refused connection throws no exception");
         } catch (ConnectException ce) {
             // Correct result
--- a/jdk/test/java/nio/channels/TestServers.java	Fri Apr 08 14:05:22 2016 +0300
+++ b/jdk/test/java/nio/channels/TestServers.java	Fri Apr 08 16:38:37 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -80,13 +80,12 @@
             return address;
         }
 
-        public static RefusingServer startNewServer() throws IOException {
-            ServerSocket socket = new ServerSocket(0, 100,
-                    InetAddress.getLocalHost());
-            RefusingServer server = new RefusingServer(socket.getInetAddress(),
-                    socket.getLocalPort());
-            socket.close();
-            return server;
+        public static RefusingServer newRefusingServer() throws IOException {
+            // The port 1 is reserved for TCPMUX(RFC 1078), which is seldom used,
+            // and it's not used on all the test platform through JPRT.
+            // So we choose to use it as a refusing "server"'s "listen" port,
+            // it's much more stable than "open->close a server socket".
+            return new RefusingServer(InetAddress.getLocalHost(), 1);
         }
     }