From 2677d57f426d5a286285f9569784059ab66ce1a3 Mon Sep 17 00:00:00 2001 From: chegar Date: Thu, 25 Mar 2010 09:38:56 +0000 Subject: [PATCH] 6937703: java/net regression test issues with samevm Reviewed-by: alanb --- test/ProblemList.txt | 7 ---- test/java/net/ProxySelector/B6737819.java | 6 +++ .../net/ResponseCache/ResponseCacheTest.java | 12 ++++-- .../net/ResponseCache/getResponseCode.java | 13 +++--- test/java/net/URL/TestIPv6Addresses.java | 4 ++ test/java/net/URLClassLoader/HttpTest.java | 13 +++++- test/java/net/URLConnection/B5052093.java | 40 ++++++++++++------- .../contentHandler/UserContentHandler.java | 12 +++++- 8 files changed, 72 insertions(+), 35 deletions(-) diff --git a/test/ProblemList.txt b/test/ProblemList.txt index bc30709bc..12d997ca6 100644 --- a/test/ProblemList.txt +++ b/test/ProblemList.txt @@ -684,8 +684,6 @@ java/net/SocketInputStream/SocketClosedException.java generic-all 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/URLConnection/ZeroContentLength.java generic-all 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 @@ sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java generic-all # 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 diff --git a/test/java/net/ProxySelector/B6737819.java b/test/java/net/ProxySelector/B6737819.java index 360f1ae4a..6e8eb5532 100644 --- a/test/java/net/ProxySelector/B6737819.java +++ b/test/java/net/ProxySelector/B6737819.java @@ -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; diff --git a/test/java/net/ResponseCache/ResponseCacheTest.java b/test/java/net/ResponseCache/ResponseCacheTest.java index f2486883e..95ddceb07 100644 --- a/test/java/net/ResponseCache/ResponseCacheTest.java +++ b/test/java/net/ResponseCache/ResponseCacheTest.java @@ -150,10 +150,14 @@ static class NameVerifier implements HostnameVerifier { } } 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 { diff --git a/test/java/net/ResponseCache/getResponseCode.java b/test/java/net/ResponseCache/getResponseCode.java index a05f81b14..b25cf2869 100644 --- a/test/java/net/ResponseCache/getResponseCode.java +++ b/test/java/net/ResponseCache/getResponseCode.java @@ -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 class getResponseCode { } } 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 { diff --git a/test/java/net/URL/TestIPv6Addresses.java b/test/java/net/URL/TestIPv6Addresses.java index adb43f65e..44f9d0283 100644 --- a/test/java/net/URL/TestIPv6Addresses.java +++ b/test/java/net/URL/TestIPv6Addresses.java @@ -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 { diff --git a/test/java/net/URLClassLoader/HttpTest.java b/test/java/net/URLClassLoader/HttpTest.java index e04331f01..c7935b20a 100644 --- a/test/java/net/URLClassLoader/HttpTest.java +++ b/test/java/net/URLClassLoader/HttpTest.java @@ -56,9 +56,9 @@ public class HttpTest { } public void run() { + InputStream in = null; try { - - InputStream in = s.getInputStream(); + in = s.getInputStream(); for (;;) { // read entire request from client @@ -111,6 +111,9 @@ public class HttpTest { } // for } catch (Exception e) { + unexpected(e); + } finally { + if (in != null) { try {in.close(); } catch(IOException e) {unexpected(e);} } } } } @@ -131,6 +134,11 @@ public class HttpTest { } } + 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 @@ public class HttpTest { // 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; diff --git a/test/java/net/URLConnection/B5052093.java b/test/java/net/URLConnection/B5052093.java index c1add42c8..6d14b1311 100644 --- a/test/java/net/URLConnection/B5052093.java +++ b/test/java/net/URLConnection/B5052093.java @@ -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 class B5052093 implements HttpCallback { 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(); + } } } diff --git a/test/java/net/URLConnection/contentHandler/UserContentHandler.java b/test/java/net/URLConnection/contentHandler/UserContentHandler.java index 0a571d45b..2f4d5f621 100644 --- a/test/java/net/URLConnection/contentHandler/UserContentHandler.java +++ b/test/java/net/URLConnection/contentHandler/UserContentHandler.java @@ -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 @@ public class UserContentHandler implements Runnable { // 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(); -- GitLab