# HG changeset patch
# User ptisnovs
# Date 1279815765 -7200
# Node ID 13939cd625076ff7cfd40556a9c44e5e9eb13094
# Parent  f63ef918ce3a1c4d403a85796dbb5a288539e46e
6969395: TEST_BUG: Tests in java/net sun/net problems
Summary: Synchronization of HttpServlet regression test with OpenJDK7
Reviewed-by: chegar

diff -r f63ef918ce3a -r 13939cd62507 test/com/sun/net/httpserver/Test1.java
--- openjdk.orig/jdk/test/com/sun/net/httpserver/Test1.java	Fri Jul 25 14:46:38 2008 +0400
+++ openjdk/jdk/test/com/sun/net/httpserver/Test1.java	Thu Jul 22 18:22:45 2010 +0200
@@ -24,17 +24,15 @@
 /**
  * @test
  * @bug 6270015
+ * @run main/othervm Test1
  * @summary  Light weight HTTP server
  */
 
 import com.sun.net.httpserver.*;
 
-import java.util.*;
 import java.util.concurrent.*;
 import java.io.*;
 import java.net.*;
-import java.security.*;
-import java.security.cert.*;
 import javax.net.ssl.*;
 
 /* basic http/s connectivity test
@@ -86,9 +84,12 @@
             System.out.println ("OK");
         } finally {
             delay();
-            s1.stop(2);
-            s2.stop(2);
-            executor.shutdown ();
+            if (s1 != null)
+                s1.stop(2);
+            if (s2 != null)
+                s2.stop(2);
+            if (executor != null)
+                executor.shutdown ();
         }
     }
 
diff -r f63ef918ce3a -r 13939cd62507 test/com/sun/net/httpserver/Test11.java
--- openjdk.orig/jdk/test/com/sun/net/httpserver/Test11.java	Fri Jul 25 14:46:38 2008 +0400
+++ openjdk/jdk/test/com/sun/net/httpserver/Test11.java	Thu Jul 22 18:22:45 2010 +0200
@@ -28,7 +28,6 @@
  */
 
 import java.net.*;
-import java.util.*;
 import java.util.concurrent.*;
 import java.io.*;
 import com.sun.net.httpserver.*;
@@ -52,22 +51,25 @@
 
     public static void main (String[] args) throws Exception {
         System.out.print ("Test 11: ");
-        HttpServer server = HttpServer.create (new InetSocketAddress(0), 0);
-        HttpContext ctx = server.createContext (
-            "/foo/bar/", new Handler ()
-        );
-        ExecutorService s =  Executors.newCachedThreadPool();
-        server.setExecutor (s);
-        server.start ();
-        URL url = new URL ("http://localhost:" + server.getAddress().getPort()+
-                "/Foo/bar/test.html");
-        HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
-        int r = urlc.getResponseCode();
-        System.out.println ("OK");
-        s.shutdown();
-        server.stop(5);
-        if (r == 200) {
-            throw new RuntimeException ("wrong response received");
+        HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
+        ExecutorService s = Executors.newCachedThreadPool();
+        try {
+            HttpContext ctx = server.createContext (
+                "/foo/bar/", new Handler ()
+            );
+            s =  Executors.newCachedThreadPool();
+            server.start ();
+            URL url = new URL ("http://localhost:" + server.getAddress().getPort()+
+                    "/Foo/bar/test.html");
+            HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
+            int r = urlc.getResponseCode();
+            if (r == 200) {
+                throw new RuntimeException ("wrong response received");
+            }
+            System.out.println ("OK");
+        } finally {
+            s.shutdown();
+            server.stop(2);
         }
     }
 }
diff -r f63ef918ce3a -r 13939cd62507 test/com/sun/net/httpserver/Test12.java
--- openjdk.orig/jdk/test/com/sun/net/httpserver/Test12.java	Fri Jul 25 14:46:38 2008 +0400
+++ openjdk/jdk/test/com/sun/net/httpserver/Test12.java	Thu Jul 22 18:22:45 2010 +0200
@@ -24,17 +24,15 @@
 /**
  * @test
  * @bug 6270015
+ * @run main/othervm Test12
  * @summary  Light weight HTTP server
  */
 
 import com.sun.net.httpserver.*;
 
-import java.util.*;
 import java.util.concurrent.*;
 import java.io.*;
 import java.net.*;
-import java.security.*;
-import java.security.cert.*;
 import javax.net.ssl.*;
 
 /* basic http/s connectivity test
@@ -85,9 +83,12 @@
             System.out.println ("OK");
         } finally {
             delay();
-            s1.stop(2);
-            s2.stop(2);
-            executor.shutdown ();
+            if (s1 != null)
+                s1.stop(2);
+            if (s2 != null)
+                s2.stop(2);
+            if (executor != null)
+                executor.shutdown ();
         }
     }
 
diff -r f63ef918ce3a -r 13939cd62507 test/com/sun/net/httpserver/Test13.java
--- openjdk.orig/jdk/test/com/sun/net/httpserver/Test13.java	Fri Jul 25 14:46:38 2008 +0400
+++ openjdk/jdk/test/com/sun/net/httpserver/Test13.java	Thu Jul 22 18:22:45 2010 +0200
@@ -24,17 +24,16 @@
 /**
  * @test
  * @bug 6270015
+ * @run main/othervm Test13
  * @summary  Light weight HTTP server
  */
 
 import com.sun.net.httpserver.*;
 
-import java.util.*;
 import java.util.concurrent.*;
 import java.io.*;
 import java.net.*;
-import java.security.*;
-import java.security.cert.*;
+
 import javax.net.ssl.*;
 
 /* basic http/s connectivity test
@@ -81,9 +80,12 @@
             System.out.println ("OK");
         } finally {
             delay();
-            s1.stop(2);
-            s2.stop(2);
-            executor.shutdown ();
+            if (s1 != null)
+                s1.stop(2);
+            if (s2 != null)
+                s2.stop(2);
+            if (executor != null)
+                executor.shutdown ();
         }
     }
 
diff -r f63ef918ce3a -r 13939cd62507 test/com/sun/net/httpserver/Test6a.java
--- openjdk.orig/jdk/test/com/sun/net/httpserver/Test6a.java	Fri Jul 25 14:46:38 2008 +0400
+++ openjdk/jdk/test/com/sun/net/httpserver/Test6a.java	Thu Jul 22 18:22:45 2010 +0200
@@ -24,17 +24,15 @@
 /**
  * @test
  * @bug 6270015
+ * @run main/othervm Test6a
  * @summary  Light weight HTTP server
  */
 
 import com.sun.net.httpserver.*;
 
-import java.util.*;
 import java.util.concurrent.*;
 import java.io.*;
 import java.net.*;
-import java.security.*;
-import javax.security.auth.callback.*;
 import javax.net.ssl.*;
 
 /**
diff -r f63ef918ce3a -r 13939cd62507 test/com/sun/net/httpserver/Test7a.java
--- openjdk.orig/jdk/test/com/sun/net/httpserver/Test7a.java	Fri Jul 25 14:46:38 2008 +0400
+++ openjdk/jdk/test/com/sun/net/httpserver/Test7a.java	Thu Jul 22 18:22:45 2010 +0200
@@ -24,18 +24,15 @@
 /**
  * @test
  * @bug 6270015
+ * @run main/othervm Test7a
  * @summary  Light weight HTTP server
  */
 
 import com.sun.net.httpserver.*;
 
-import java.util.*;
 import java.util.concurrent.*;
-import java.util.logging.*;
 import java.io.*;
 import java.net.*;
-import java.security.*;
-import javax.security.auth.callback.*;
 import javax.net.ssl.*;
 
 /**
diff -r f63ef918ce3a -r 13939cd62507 test/com/sun/net/httpserver/Test8a.java
--- openjdk.orig/jdk/test/com/sun/net/httpserver/Test8a.java	Fri Jul 25 14:46:38 2008 +0400
+++ openjdk/jdk/test/com/sun/net/httpserver/Test8a.java	Thu Jul 22 18:22:45 2010 +0200
@@ -24,18 +24,15 @@
 /**
  * @test
  * @bug 6270015
+ * @run main/othervm Test8a
  * @summary  Light weight HTTP server
  */
 
 import com.sun.net.httpserver.*;
 
-import java.util.*;
 import java.util.concurrent.*;
-import java.util.logging.*;
 import java.io.*;
 import java.net.*;
-import java.security.*;
-import javax.security.auth.callback.*;
 import javax.net.ssl.*;
 
 /**
@@ -50,46 +47,50 @@
         //h.setLevel (Level.INFO);
         //log.addHandler (h);
         //log.setLevel (Level.INFO);
-        Handler handler = new Handler();
-        InetSocketAddress addr = new InetSocketAddress (0);
-        HttpsServer server = HttpsServer.create (addr, 0);
-        HttpContext ctx = server.createContext ("/test", handler);
-        ExecutorService executor = Executors.newCachedThreadPool();
-        SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();
-        server.setHttpsConfigurator(new HttpsConfigurator (ssl));
-        server.setExecutor (executor);
-        server.start ();
+        HttpsServer server = null;
+        ExecutorService executor = null;
+        try {
+            Handler handler = new Handler();
+            InetSocketAddress addr = new InetSocketAddress (0);
+            server = HttpsServer.create (addr, 0);
+            HttpContext ctx = server.createContext ("/test", handler);
+            executor = Executors.newCachedThreadPool();
+            SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();
+            server.setHttpsConfigurator(new HttpsConfigurator (ssl));
+            server.setExecutor (executor);
+            server.start ();
 
-        URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");
-        System.out.print ("Test8a: " );
-        HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();
-        urlc.setDoOutput (true);
-        urlc.setRequestMethod ("POST");
-        urlc.setHostnameVerifier (new DummyVerifier());
-        urlc.setSSLSocketFactory (ssl.getSocketFactory());
-        OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000);
-        for (int i=0; i<SIZE; i++) {
-            os.write (i % 250);
+            URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");
+            System.out.print ("Test8a: " );
+            HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();
+            urlc.setDoOutput (true);
+            urlc.setRequestMethod ("POST");
+            urlc.setHostnameVerifier (new DummyVerifier());
+            urlc.setSSLSocketFactory (ssl.getSocketFactory());
+            OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000);
+            for (int i=0; i<SIZE; i++) {
+                os.write (i % 250);
+            }
+            os.close();
+            int resp = urlc.getResponseCode();
+            if (resp != 200) {
+                throw new RuntimeException ("test failed response code");
+            }
+            InputStream is = urlc.getInputStream ();
+            for (int i=0; i<SIZE; i++) {
+                int f = is.read();
+                if (f != (i % 250)) {
+                    System.out.println ("Setting error(" +f +")("+i+")" );
+                    error = true;
+                    break;
+                }
+            }
+            is.close();
+        } finally {
+            delay();
+            if (server != null) server.stop(2);
+            if (executor != null) executor.shutdown();
         }
-        os.close();
-        int resp = urlc.getResponseCode();
-        if (resp != 200) {
-            throw new RuntimeException ("test failed response code");
-        }
-        InputStream is = urlc.getInputStream ();
-        for (int i=0; i<SIZE; i++) {
-            int f = is.read();
-            if (f != (i % 250)) {
-                System.out.println ("Setting error(" +f +")("+i+")" );
-                error = true;
-                break;
-            }
-        }
-        is.close();
-
-        delay();
-        server.stop(2);
-        executor.shutdown();
         if (error) {
             throw new RuntimeException ("test failed error");
         }
diff -r f63ef918ce3a -r 13939cd62507 test/com/sun/net/httpserver/Test9.java
--- openjdk.orig/jdk/test/com/sun/net/httpserver/Test9.java	Fri Jul 25 14:46:38 2008 +0400
+++ openjdk/jdk/test/com/sun/net/httpserver/Test9.java	Thu Jul 22 18:22:45 2010 +0200
@@ -24,17 +24,15 @@
 /**
  * @test
  * @bug 6270015
+ * @run main/othervm Test9
  * @summary  Light weight HTTP server
  */
 
 import com.sun.net.httpserver.*;
 
-import java.util.*;
 import java.util.concurrent.*;
 import java.io.*;
 import java.net.*;
-import java.security.*;
-import java.security.cert.*;
 import javax.net.ssl.*;
 
 /* Same as Test1 but requests run in parallel.
@@ -97,9 +95,12 @@
             System.out.println ("OK");
         } finally {
             delay();
-            s1.stop(2);
-            s2.stop(2);
-            executor.shutdown ();
+            if (s1 != null)
+                s1.stop(2);
+            if (s2 != null)
+                s2.stop(2);
+            if (executor != null)
+                executor.shutdown ();
         }
     }
 
diff -r f63ef918ce3a -r 13939cd62507 test/com/sun/net/httpserver/Test9a.java
--- openjdk.orig/jdk/test/com/sun/net/httpserver/Test9a.java	Fri Jul 25 14:46:38 2008 +0400
+++ openjdk/jdk/test/com/sun/net/httpserver/Test9a.java	Thu Jul 22 18:22:45 2010 +0200
@@ -24,17 +24,15 @@
 /**
  * @test
  * @bug 6270015
+ * @run main/othervm Test9a
  * @summary  Light weight HTTP server
  */
 
 import com.sun.net.httpserver.*;
 
-import java.util.*;
 import java.util.concurrent.*;
 import java.io.*;
 import java.net.*;
-import java.security.*;
-import java.security.cert.*;
 import javax.net.ssl.*;
 
 /* Same as Test1 but requests run in parallel.
@@ -92,8 +90,10 @@
             System.out.println ("OK");
         } finally {
             delay();
-            server.stop(2);
-            executor.shutdown ();
+            if (server != null)
+                server.stop(2);
+            if (executor != null)
+                executor.shutdown();
         }
     }
 
diff -r f63ef918ce3a -r 13939cd62507 test/com/sun/net/httpserver/bugs/B6361557.java
--- openjdk.orig/jdk/test/com/sun/net/httpserver/bugs/B6361557.java	Fri Jul 25 14:46:38 2008 +0400
+++ openjdk/jdk/test/com/sun/net/httpserver/bugs/B6361557.java	Thu Jul 22 18:22:45 2010 +0200
@@ -35,12 +35,9 @@
 import java.nio.*;
 import java.nio.channels.*;
 import java.net.*;
-import java.security.*;
-import java.security.cert.*;
-import javax.net.ssl.*;
 
 /**
- * The test simply opens 10,000 separate connections
+ * The test simply opens 1,000 separate connections
  * and invokes one http request on each. The client does
  * not close any sockets until after they are closed
  * by the server. This verifies the basic ability
@@ -49,6 +46,7 @@
 public class B6361557 {
 
     public static boolean error = false;
+    static final int NUM = 1000;
 
     static class Handler implements HttpHandler {
         int invocation = 1;
@@ -75,7 +73,6 @@
         server.setExecutor (executor);
         server.start ();
 
-        final int NUM = 10000;
         ByteBuffer buf = ByteBuffer.allocate (4096);
         InetSocketAddress destaddr = new InetSocketAddress (
                 "127.0.0.1", server.getAddress().getPort()
diff -r f63ef918ce3a -r 13939cd62507 test/com/sun/net/httpserver/bugs/B6373555.java
--- openjdk.orig/jdk/test/com/sun/net/httpserver/bugs/B6373555.java	Fri Jul 25 14:46:38 2008 +0400
+++ openjdk/jdk/test/com/sun/net/httpserver/bugs/B6373555.java	Thu Jul 22 18:22:45 2010 +0200
@@ -46,7 +46,7 @@
     private static Object lock;
     static HttpServer httpServer;
     static ExecutorService pool, execs;
-    static int NUM = 4000;
+    static int NUM = 1000;
 
     public static void main(String[] args) throws Exception {
         try {
@@ -125,7 +125,7 @@
                 }
             }
             catch(Exception e) {
-                //e.printStackTrace();
+                e.printStackTrace();
                 System.out.print (".");
                 error = true;
             }
