changeset 468:8d5a2f11d6c6

6941936: Broken pipe error of test case DNSIdentities.java 6943219: test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/DNSIdentities.java fail in linux Summary: Testcase correction. Reviewed-by: chegar, andrew, darcy
author ptisnovs
date Tue, 04 Jan 2011 17:38:35 +0100
parents 3a8a8b5f1612
children 884dab2cfd50
files test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/DNSIdentities.java test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsPost.java test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressDNSIdentities.java test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressIPIdentities.java test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPIdentities.java test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Identities.java test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Redirect.java
diffstat 7 files changed, 160 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/DNSIdentities.java	Tue Dec 28 11:23:04 2010 -0800
+++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/DNSIdentities.java	Tue Jan 04 17:38:35 2011 +0100
@@ -624,6 +624,11 @@
     volatile static boolean serverReady = false;
 
     /*
+     * Is the connection ready to close?
+     */
+    volatile static boolean closeReady = false;
+
+    /*
      * Turn on SSL debugging?
      */
     static boolean debug = false;
@@ -652,9 +657,6 @@
 
         SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
         sslSocket.setNeedClientAuth(true);
-        if (sslSocket instanceof SSLSocketImpl) {
-            ((SSLSocketImpl)sslSocket).trySetHostnameVerification("HTTPS");
-        }
 
         PrintStream out =
                 new PrintStream(sslSocket.getOutputStream());
@@ -670,11 +672,14 @@
             out.print("Testing\r\n");
             out.flush();
         } finally {
-             // close the socket
-             Thread.sleep(2000);
-             System.out.println("Server closing socket");
-             sslSocket.close();
-             serverReady = false;
+            // close the socket
+            while (!closeReady) {
+                Thread.sleep(50);
+            }
+
+            System.out.println("Server closing socket");
+            sslSocket.close();
+            serverReady = false;
         }
 
     }
@@ -704,12 +709,17 @@
         URL url = new URL("https://localhost:" + serverPort+"/");
         System.out.println("url is "+url.toString());
 
-        http = (HttpsURLConnection)url.openConnection();
+        try {
+            http = (HttpsURLConnection)url.openConnection();
 
-        int respCode = http.getResponseCode();
-        System.out.println("respCode = "+respCode);
-
-        http.disconnect();
+            int respCode = http.getResponseCode();
+            System.out.println("respCode = "+respCode);
+        } finally {
+            if (http != null) {
+                http.disconnect();
+            }
+            closeReady = true;
+        }
     }
 
     /*
--- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsPost.java	Tue Dec 28 11:23:04 2010 -0800
+++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsPost.java	Tue Jan 04 17:38:35 2011 +0100
@@ -61,6 +61,11 @@
     volatile static boolean serverReady = false;
 
     /*
+     * Is the connection ready to close?
+     */
+    volatile static boolean closeReady = false;
+
+    /*
      * Turn on SSL debugging?
      */
     static boolean debug = false;
@@ -98,25 +103,34 @@
         serverReady = true;
 
         SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
-        InputStream sslIS = sslSocket.getInputStream();
-        OutputStream sslOS = sslSocket.getOutputStream();
-        BufferedReader br = new BufferedReader(new InputStreamReader(sslIS));
-        PrintStream ps = new PrintStream(sslOS);
-        // process HTTP POST request from client
-        System.out.println("status line: "+br.readLine());
-        String msg = null;
-        while ((msg = br.readLine()) != null && msg.length() > 0);
+        try {
+            InputStream sslIS = sslSocket.getInputStream();
+            OutputStream sslOS = sslSocket.getOutputStream();
+            BufferedReader br =
+                        new BufferedReader(new InputStreamReader(sslIS));
+            PrintStream ps = new PrintStream(sslOS);
 
-        msg = br.readLine();
-        if (msg.equals(postMsg)) {
-            ps.println("HTTP/1.1 200 OK\n\n");
-        } else {
-            ps.println("HTTP/1.1 500 Not OK\n\n");
+            // process HTTP POST request from client
+            System.out.println("status line: "+br.readLine());
+            String msg = null;
+            while ((msg = br.readLine()) != null && msg.length() > 0);
+
+            msg = br.readLine();
+            if (msg.equals(postMsg)) {
+                ps.println("HTTP/1.1 200 OK\n\n");
+            } else {
+                ps.println("HTTP/1.1 500 Not OK\n\n");
+            }
+            ps.flush();
+
+            // close the socket
+            while (!closeReady) {
+                Thread.sleep(50);
+            }
+        } finally {
+            sslSocket.close();
+            sslServerSocket.close();
         }
-        ps.flush();
-        Thread.sleep(2000);
-        sslSocket.close();
-        sslServerSocket.close();
     }
 
     /*
@@ -144,12 +158,17 @@
 
         http.setRequestMethod("POST");
         PrintStream ps = new PrintStream(http.getOutputStream());
-        ps.println(postMsg);
-        ps.flush();
-        if (http.getResponseCode() != 200) {
-            throw new RuntimeException("test Failed");
+        try {
+            ps.println(postMsg);
+            ps.flush();
+            if (http.getResponseCode() != 200) {
+                throw new RuntimeException("test Failed");
+            }
+        } finally {
+            ps.close();
+            http.disconnect();
+            closeReady = true;
         }
-        ps.close();
     }
 
     static class NameVerifier implements HostnameVerifier {
--- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressDNSIdentities.java	Tue Dec 28 11:23:04 2010 -0800
+++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressDNSIdentities.java	Tue Jan 04 17:38:35 2011 +0100
@@ -652,9 +652,6 @@
 
         SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
         sslSocket.setNeedClientAuth(true);
-        if (sslSocket instanceof SSLSocketImpl) {
-            ((SSLSocketImpl)sslSocket).trySetHostnameVerification("HTTPS");
-        }
 
         PrintStream out =
                 new PrintStream(sslSocket.getOutputStream());
--- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressIPIdentities.java	Tue Dec 28 11:23:04 2010 -0800
+++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressIPIdentities.java	Tue Jan 04 17:38:35 2011 +0100
@@ -625,6 +625,11 @@
     volatile static boolean serverReady = false;
 
     /*
+     * Is the connection ready to close?
+     */
+    volatile static boolean closeReady = false;
+
+    /*
      * Turn on SSL debugging?
      */
     static boolean debug = false;
@@ -653,9 +658,6 @@
 
         SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
         sslSocket.setNeedClientAuth(true);
-        if (sslSocket instanceof SSLSocketImpl) {
-            ((SSLSocketImpl)sslSocket).trySetHostnameVerification("HTTPS");
-        }
 
         PrintStream out =
                 new PrintStream(sslSocket.getOutputStream());
@@ -672,7 +674,10 @@
             out.flush();
         } finally {
              // close the socket
-             Thread.sleep(2000);
+             while (!closeReady) {
+                 Thread.sleep(50);
+             }
+
              System.out.println("Server closing socket");
              sslSocket.close();
              serverReady = false;
@@ -705,12 +710,17 @@
         URL url = new URL("https://127.0.0.1:" + serverPort+"/");
         System.out.println("url is "+url.toString());
 
-        http = (HttpsURLConnection)url.openConnection();
+        try {
+            http = (HttpsURLConnection)url.openConnection();
 
-        int respCode = http.getResponseCode();
-        System.out.println("respCode = "+respCode);
-
-        http.disconnect();
+            int respCode = http.getResponseCode();
+            System.out.println("respCode = "+respCode);
+        } finally {
+            if (http != null) {
+                http.disconnect();
+            }
+            closeReady = true;
+        }
     }
 
     /*
--- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPIdentities.java	Tue Dec 28 11:23:04 2010 -0800
+++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPIdentities.java	Tue Jan 04 17:38:35 2011 +0100
@@ -625,6 +625,11 @@
     volatile static boolean serverReady = false;
 
     /*
+     * Is the connection ready to close?
+     */
+    volatile static boolean closeReady = false;
+
+    /*
      * Turn on SSL debugging?
      */
     static boolean debug = false;
@@ -653,9 +658,6 @@
 
         SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
         sslSocket.setNeedClientAuth(true);
-        if (sslSocket instanceof SSLSocketImpl) {
-            ((SSLSocketImpl)sslSocket).trySetHostnameVerification("HTTPS");
-        }
 
         PrintStream out =
                 new PrintStream(sslSocket.getOutputStream());
@@ -672,7 +674,10 @@
             out.flush();
         } finally {
              // close the socket
-             Thread.sleep(2000);
+             while (!closeReady) {
+                 Thread.sleep(50);
+             }
+
              System.out.println("Server closing socket");
              sslSocket.close();
              serverReady = false;
@@ -705,12 +710,17 @@
         URL url = new URL("https://localhost:" + serverPort+"/");
         System.out.println("url is "+url.toString());
 
-        http = (HttpsURLConnection)url.openConnection();
+        try {
+            http = (HttpsURLConnection)url.openConnection();
 
-        int respCode = http.getResponseCode();
-        System.out.println("respCode = "+respCode);
-
-        http.disconnect();
+            int respCode = http.getResponseCode();
+            System.out.println("respCode = "+respCode);
+        } finally {
+            if (http != null) {
+                http.disconnect();
+            }
+            closeReady = true;
+        }
     }
 
     /*
--- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Identities.java	Tue Dec 28 11:23:04 2010 -0800
+++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Identities.java	Tue Jan 04 17:38:35 2011 +0100
@@ -624,6 +624,11 @@
     volatile static boolean serverReady = false;
 
     /*
+     * Is the connection ready to close?
+     */
+    volatile static boolean closeReady = false;
+
+    /*
      * Turn on SSL debugging?
      */
     static boolean debug = false;
@@ -652,9 +657,6 @@
 
         SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
         sslSocket.setNeedClientAuth(true);
-        if (sslSocket instanceof SSLSocketImpl) {
-            ((SSLSocketImpl)sslSocket).trySetHostnameVerification("HTTPS");
-        }
 
         PrintStream out =
                 new PrintStream(sslSocket.getOutputStream());
@@ -671,7 +673,10 @@
             out.flush();
         } finally {
              // close the socket
-             Thread.sleep(2000);
+             while (!closeReady) {
+                 Thread.sleep(50);
+             }
+
              System.out.println("Server closing socket");
              sslSocket.close();
              serverReady = false;
@@ -704,12 +709,17 @@
         URL url = new URL("https://localhost:" + serverPort+"/");
         System.out.println("url is "+url.toString());
 
-        http = (HttpsURLConnection)url.openConnection();
+        try {
+            http = (HttpsURLConnection)url.openConnection();
 
-        int respCode = http.getResponseCode();
-        System.out.println("respCode = "+respCode);
-
-        http.disconnect();
+            int respCode = http.getResponseCode();
+            System.out.println("respCode = "+respCode);
+        } finally {
+            if (http != null) {
+                http.disconnect();
+            }
+            closeReady = true;
+        }
     }
 
     /*
--- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Redirect.java	Tue Dec 28 11:23:04 2010 -0800
+++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Redirect.java	Tue Jan 04 17:38:35 2011 +0100
@@ -61,6 +61,11 @@
     volatile static boolean serverReady = false;
 
     /*
+     * Is the connection ready to close?
+     */
+    volatile static boolean closeReady = false;
+
+    /*
      * Turn on SSL debugging?
      */
     static boolean debug = false;
@@ -98,24 +103,33 @@
         serverReady = true;
 
         SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
-        InputStream sslIS = sslSocket.getInputStream();
-        OutputStream sslOS = sslSocket.getOutputStream();
-        BufferedReader br = new BufferedReader(new InputStreamReader(sslIS));
-        PrintStream ps = new PrintStream(sslOS);
-        // process HTTP POST request from client
-        System.out.println("status line: "+br.readLine());
+        try {
+            InputStream sslIS = sslSocket.getInputStream();
+            OutputStream sslOS = sslSocket.getOutputStream();
+            BufferedReader br =
+                        new BufferedReader(new InputStreamReader(sslIS));
+            PrintStream ps = new PrintStream(sslOS);
 
-        ps.println("HTTP/1.1 307 Redirect");
-        ps.println("Location: https://localhost:"+serverPort+"/index.html\n\n");
-        ps.flush();
-        sslSocket = (SSLSocket) sslServerSocket.accept();
-        sslOS = sslSocket.getOutputStream();
-        ps = new PrintStream(sslOS);
-        ps.println("HTTP/1.1 200 Redirect succeeded\n\n");
-        ps.flush();
-        Thread.sleep(2000);
-        sslSocket.close();
-        sslServerSocket.close();
+            // process HTTP POST request from client
+            System.out.println("status line: "+br.readLine());
+
+            ps.println("HTTP/1.1 307 Redirect");
+            ps.println("Location: https://localhost:" + serverPort +
+                                                            "/index.html\n\n");
+            ps.flush();
+            sslSocket = (SSLSocket) sslServerSocket.accept();
+            sslOS = sslSocket.getOutputStream();
+            ps = new PrintStream(sslOS);
+            ps.println("HTTP/1.1 200 Redirect succeeded\n\n");
+            ps.flush();
+        } finally {
+            // close the socket
+            while (!closeReady) {
+                Thread.sleep(50);
+            }
+            sslSocket.close();
+            sslServerSocket.close();
+        }
     }
 
     /*
@@ -139,10 +153,14 @@
         HttpsURLConnection.setDefaultHostnameVerifier(
                                       new NameVerifier());
         HttpsURLConnection http = (HttpsURLConnection)url.openConnection();
-
-        System.out.println("response header: "+http.getHeaderField(0));
-        if (http.getResponseCode() != 200) {
-            throw new RuntimeException("test Failed");
+        try {
+            System.out.println("response header: "+http.getHeaderField(0));
+            if (http.getResponseCode() != 200) {
+                throw new RuntimeException("test Failed");
+            }
+        } finally {
+            http.disconnect();
+            closeReady = true;
         }
     }