6937703: java/net regression test issues with samevm
authorchegar
Thu, 25 Mar 2010 09:38:56 +0000
changeset 5165 5693cc1e95c6
parent 5164 337ae296b6d6
child 5166 81f798aa5765
child 5196 d6b7fa6e317f
6937703: java/net regression test issues with samevm Reviewed-by: alanb
jdk/test/ProblemList.txt
jdk/test/java/net/ProxySelector/B6737819.java
jdk/test/java/net/ResponseCache/ResponseCacheTest.java
jdk/test/java/net/ResponseCache/getResponseCode.java
jdk/test/java/net/URL/TestIPv6Addresses.java
jdk/test/java/net/URLClassLoader/HttpTest.java
jdk/test/java/net/URLConnection/B5052093.java
jdk/test/java/net/URLConnection/contentHandler/UserContentHandler.java
--- a/jdk/test/ProblemList.txt	Thu Mar 25 12:07:42 2010 +0800
+++ b/jdk/test/ProblemList.txt	Thu Mar 25 09:38:56 2010 +0000
@@ -684,8 +684,6 @@
 java/net/SocketInputStream/SocketTimeout.java		 	generic-all
 
 # Linux i586, address already in use or timeout, samevm issues
-java/net/URLConnection/B5052093.java			 	generic-all
-java/net/URLConnection/contentHandler/UserContentHandler.java 	generic-all
 java/net/URLConnection/DisconnectAfterEOF.java		 	generic-all
 java/net/URLConnection/HandleContentTypeWithAttrs.java	 	generic-all
 java/net/URLConnection/Responses.java			 	generic-all
@@ -696,8 +694,6 @@
 java/net/ResponseCache/B6181108.java				generic-all
 java/net/ResponseCache/ResponseCacheTest.java			generic-all
 java/net/URL/GetContent.java					generic-all
-java/net/URL/TestIPv6Addresses.java				generic-all
-java/net/URLClassLoader/HttpTest.java				generic-all
 java/net/URLConnection/HttpContinueStackOverflow.java		generic-all
 java/net/URLConnection/Redirect307Test.java			generic-all
 java/net/URLConnection/RedirectLimit.java			generic-all
@@ -726,9 +722,6 @@
 # Connection refused, windows samevm
 sun/net/www/protocol/http/DigestTest.java			generic-all
 
-# Fails on Fedora 9 32bit & 64bit & Solaris 10, wrong proxy for http://localhost/index.html
-java/net/ProxySelector/B6737819.java				generic-all
-
 ############################################################################
 
 # jdk_nio
--- a/jdk/test/java/net/ProxySelector/B6737819.java	Thu Mar 25 12:07:42 2010 +0800
+++ b/jdk/test/java/net/ProxySelector/B6737819.java	Thu Mar 25 09:38:56 2010 +0000
@@ -23,9 +23,15 @@
 /*
  * @test
  * @bug 6737819
+ * @run main/othervm B6737819
  * @summary sun.misc.net.DefaultProxySelector doesn't use proxy setting to localhost
  */
 
+/* Run in othervm mode since the test sets HTTP proxy system properties that
+ * are read once and cached by the protocol handler. A previous test using the
+ * HTTP handler may run and these system properties may be ignored for this test.
+ */
+
 import java.net.ProxySelector;
 import java.net.Proxy;
 import java.net.URI;
--- a/jdk/test/java/net/ResponseCache/ResponseCacheTest.java	Thu Mar 25 12:07:42 2010 +0800
+++ b/jdk/test/java/net/ResponseCache/ResponseCacheTest.java	Thu Mar 25 09:38:56 2010 +0000
@@ -150,10 +150,14 @@
         }
     }
     public static void main(String args[]) throws Exception {
-        ResponseCache.setDefault(new MyResponseCache());
-        FNPrefix = System.getProperty("test.src", ".")+"/";
-        OutFNPrefix = System.getProperty("test.scratch", ".")+"/";
-        new ResponseCacheTest();
+        try {
+            ResponseCache.setDefault(new MyResponseCache());
+            FNPrefix = System.getProperty("test.src", ".")+"/";
+            OutFNPrefix = System.getProperty("test.scratch", ".")+"/";
+            new ResponseCacheTest();
+        } finally{
+            ResponseCache.setDefault(null);
+        }
     }
 
     static class MyResponseCache extends ResponseCache {
--- a/jdk/test/java/net/ResponseCache/getResponseCode.java	Thu Mar 25 12:07:42 2010 +0800
+++ b/jdk/test/java/net/ResponseCache/getResponseCode.java	Thu Mar 25 09:38:56 2010 +0000
@@ -30,8 +30,7 @@
 import java.net.*;
 import java.util.*;
 import java.io.*;
-import java.nio.*;
-import sun.net.www.ParseUtil;
+
 
 /**
  * Request should get serviced by the cache handler. Response get
@@ -52,9 +51,13 @@
         }
     }
     public static void main(String args[]) throws Exception {
-        ResponseCache.setDefault(new MyResponseCache());
-        FNPrefix = System.getProperty("test.src", ".")+"/";
-        new getResponseCode();
+        try {
+            ResponseCache.setDefault(new MyResponseCache());
+            FNPrefix = System.getProperty("test.src", ".")+"/";
+            new getResponseCode();
+        } finally{
+            ResponseCache.setDefault(null);
+        }
     }
 
     static class MyResponseCache extends ResponseCache {
--- a/jdk/test/java/net/URL/TestIPv6Addresses.java	Thu Mar 25 12:07:42 2010 +0800
+++ b/jdk/test/java/net/URL/TestIPv6Addresses.java	Thu Mar 25 09:38:56 2010 +0000
@@ -23,8 +23,12 @@
 
 /* @test
  * @bug 4451522 4460484
+ * @run main/othervm TestIPv6Addresses
  * @summary URI and URL getHost() methods don't comform to RFC 2732
  */
+
+// Run in othervm because the tests sets a SecurityManager
+
 import java.net.*;
 
 public class TestIPv6Addresses {
--- a/jdk/test/java/net/URLClassLoader/HttpTest.java	Thu Mar 25 12:07:42 2010 +0800
+++ b/jdk/test/java/net/URLClassLoader/HttpTest.java	Thu Mar 25 09:38:56 2010 +0000
@@ -56,9 +56,9 @@
             }
 
             public void run() {
+                InputStream in = null;
                 try {
-
-                    InputStream in = s.getInputStream();
+                    in = s.getInputStream();
                     for (;;) {
 
                         // read entire request from client
@@ -111,6 +111,9 @@
                     } // for
 
                 } catch (Exception e) {
+                    unexpected(e);
+                } finally {
+                    if (in != null) { try {in.close(); } catch(IOException e) {unexpected(e);} }
                 }
             }
         }
@@ -131,6 +134,11 @@
             }
         }
 
+        void unexpected(Exception e) {
+            System.out.println(e);
+            e.printStackTrace();
+        }
+
         public static HttpServer create() throws Exception {
             if (svr != null)
                 return svr;
@@ -211,6 +219,7 @@
         //          one GET request
         svr.counters().reset();
         InputStream in = cl.getResourceAsStream("foo2.gif");
+        in.close();
         System.out.println(svr.counters());
         if (svr.counters().getCount() > 1) {
             failed = true;
--- a/jdk/test/java/net/URLConnection/B5052093.java	Thu Mar 25 12:07:42 2010 +0800
+++ b/jdk/test/java/net/URLConnection/B5052093.java	Thu Mar 25 09:38:56 2010 +0000
@@ -1,12 +1,10 @@
 /*
- * Copyright (c) 2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  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
  * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
+ * published by the Free Software Foundation.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -66,17 +64,29 @@
 
     public static void main(String[] args) throws Exception {
         server = new HttpServer(new B5052093(), 1, 10, 0);
-        URL url = new URL("http://localhost:"+server.getLocalPort()+"/foo");
-        URLConnection conn = url.openConnection();
-        int i = conn.getContentLength();
-        long l = conn.getContentLengthLong();
-        if (i != -1 || l != testSize)
-            throw new RuntimeException("Wrong content-length from http");
+        try {
+            URL url = new URL("http://localhost:"+server.getLocalPort()+"/foo");
+            URLConnection conn = url.openConnection();
+            int i = conn.getContentLength();
+            long l = conn.getContentLengthLong();
+            if (i != -1 || l != testSize) {
+                System.out.println("conn.getContentLength = " + i);
+                System.out.println("conn.getContentLengthLong = " + l);
+                System.out.println("testSize = " + testSize);
+                throw new RuntimeException("Wrong content-length from http");
+            }
 
-        URLConnection fu = new LargeFileURLConnection(new LargeFile());
-        i = fu.getContentLength();
-        l = fu.getContentLengthLong();
-        if (i != -1 || l != testSize)
-            throw new RuntimeException("Wrong content-length from file");
+            URLConnection fu = new LargeFileURLConnection(new LargeFile());
+            i = fu.getContentLength();
+            l = fu.getContentLengthLong();
+            if (i != -1 || l != testSize) {
+                System.out.println("fu.getContentLength = " + i);
+                System.out.println("fu.getContentLengthLong = " + l);
+                System.out.println("testSize = " + testSize);
+                throw new RuntimeException("Wrong content-length from file");
+            }
+        } finally {
+            server.terminate();
+        }
     }
 }
--- a/jdk/test/java/net/URLConnection/contentHandler/UserContentHandler.java	Thu Mar 25 12:07:42 2010 +0800
+++ b/jdk/test/java/net/URLConnection/contentHandler/UserContentHandler.java	Thu Mar 25 09:38:56 2010 +0000
@@ -25,8 +25,16 @@
  * @bug 4191147
  * @summary 1.2beta4 does not load user defined content handlers
  * @build UserContentHandler
- * @run main UserContentHandler
+ * @run main/othervm UserContentHandler
  */
+
+/* Run in othervm mode since the test sets a system property, java.content.handler.pkgs,
+ * that prepends a specific package prefix defining a text/plain content
+ * handler. If other URLConnection tests run before this one they might trigger
+ * the Sun implementation text/plain content handler in sun.net.www.content
+ * to be loaded and cached, this will break this test.
+ */
+
 import java.net.*;
 import java.io.*;
 import java.util.*;
@@ -55,7 +63,7 @@
             // don't close the connection immediately as otherwise
             // the http headers may not have been received and the
             // http client will re-connect.
-            Thread.currentThread().sleep(2000);
+            Thread.sleep(2000);
 
             s.close();