From 420e3ffcd020c2a6def58053a0b3c97a4dadcf42 Mon Sep 17 00:00:00 2001 From: chegar Date: Wed, 21 Jul 2010 13:29:26 +0100 Subject: [PATCH] 6969395: TEST_BUG: Tests in java/net sun/net problems Reviewed-by: alanb --- test/ProblemList.txt | 133 ---------------- test/com/sun/net/httpserver/Test1.java | 4 +- test/com/sun/net/httpserver/Test11.java | 36 ++--- test/com/sun/net/httpserver/Test12.java | 4 +- test/com/sun/net/httpserver/Test13.java | 5 +- test/com/sun/net/httpserver/Test6a.java | 4 +- test/com/sun/net/httpserver/Test7a.java | 5 +- test/com/sun/net/httpserver/Test8a.java | 83 +++++----- test/com/sun/net/httpserver/Test9.java | 4 +- test/com/sun/net/httpserver/Test9a.java | 4 +- .../com/sun/net/httpserver/bugs/B6361557.java | 7 +- .../com/sun/net/httpserver/bugs/B6373555.java | 4 +- .../net/DatagramSocket/DatagramTimeout.java | 14 +- test/java/net/DatagramSocket/SendSize.java | 48 ++---- test/java/net/Inet6Address/B6558853.java | 4 + .../net/Inet6Address/serialize/Serialize.java | 4 + test/java/net/InetAddress/CheckJNI.java | 2 + .../net/MulticastSocket/SetOutgoingIf.java | 4 + test/java/net/ResponseCache/B6181108.java | 4 +- .../net/ResponseCache/ResponseCacheTest.java | 26 +++- .../net/ResponseCache/getResponseCode.java | 5 + test/java/net/Socket/AccurateTimeout.java | 144 ------------------ test/java/net/Socket/CloseAvailable.java | 3 +- test/java/net/Socket/DeadlockTest.java | 65 ++++---- test/java/net/Socket/LingerTest.java | 8 +- test/java/net/Socket/LinkLocal.java | 18 ++- test/java/net/Socket/ProxyCons.java | 10 +- test/java/net/Socket/ReadTimeout.java | 10 +- .../java/net/Socket/SetReceiveBufferSize.java | 19 +-- test/java/net/Socket/SetSoLinger.java | 32 ++-- test/java/net/Socket/ShutdownBoth.java | 14 +- test/java/net/Socket/SoTimeout.java | 7 +- test/java/net/Socket/Timeout.java | 8 +- test/java/net/Socket/UrgentDataTest.java | 103 ++++++------- .../net/Socket/asyncClose/BrokenPipe.java | 4 +- .../net/Socket/setReuseAddress/Restart.java | 37 ++--- .../SocketClosedException.java | 76 +++------ .../net/SocketInputStream/SocketTimeout.java | 28 ++-- test/java/net/URL/GetContent.java | 6 +- test/java/net/URLClassLoader/ClassLoad.java | 31 +++- .../net/URLConnection/DisconnectAfterEOF.java | 5 +- .../HandleContentTypeWithAttrs.java | 10 +- .../HttpContinueStackOverflow.java | 45 +++--- .../net/URLConnection/Redirect307Test.java | 27 ++-- .../java/net/URLConnection/RedirectLimit.java | 4 + .../net/URLConnection/ResendPostBody.java | 8 +- .../net/URLConnection/SetIfModifiedSince.java | 2 +- test/java/net/URLConnection/TimeoutTest.java | 8 +- .../URLConnection/URLConnectionHeaders.java | 6 +- .../net/URLConnection/ZeroContentLength.java | 60 ++++++-- test/java/net/ipv6tests/B6521014.java | 2 + test/java/net/ipv6tests/TcpTest.java | 23 --- test/java/net/ipv6tests/Tests.java | 6 +- test/sun/net/ftp/FtpGetContent.java | 20 +-- test/sun/net/ftp/FtpURL.java | 17 +-- ...hunkedEncodingWithProgressMonitorTest.java | 6 +- .../www/http/ChunkedOutputStream/Test.java | 30 ++-- .../sun/net/www/http/HttpClient/B6726695.java | 2 + .../www/http/HttpClient/MultiThreadTest.java | 11 +- .../net/www/http/HttpClient/ProxyTest.java | 54 +++---- .../KeepAliveCache/KeepAliveTimerThread.java | 5 +- ...liveStreamCloseWithWrongContentLength.java | 20 +-- test/sun/net/www/httptest/HttpServer.java | 6 + .../sun/net/www/protocol/http/DigestTest.java | 21 +-- 64 files changed, 569 insertions(+), 856 deletions(-) delete mode 100644 test/java/net/Socket/AccurateTimeout.java diff --git a/test/ProblemList.txt b/test/ProblemList.txt index 748bcd868..b8769c970 100644 --- a/test/ProblemList.txt +++ b/test/ProblemList.txt @@ -369,139 +369,6 @@ javax/print/attribute/MediaMappingsTest.java generic-all # jdk_net -# Suspect many of these tests auffer from using fixed ports, no concrete -# evidence. - -# Times out on Windows X64 -sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java generic-all - -# Dies on Solaris 10 sparc and sparcv9, Linux -ea -esa with -# Interrupted or IO exception, maybe writing to non-unique named file? -com/sun/net/httpserver/bugs/B6373555.java generic-all - -# Fails on OpenSolaris, times out -java/net/MulticastSocket/SetOutgoingIf.java generic-all - -# Timed out on Solaris 10 X86. -com/sun/net/httpserver/Test3.java generic-all - -# Exception in test on windows -com/sun/net/httpserver/bugs/B6373555.java windows-all - -# One of these pollutes the samevm on Linux, too many open files, kills jtreg -com/sun/net/httpserver/bugs/B6339483.java generic-all -com/sun/net/httpserver/bugs/B6341616.java generic-all - -# Suspects in cascading samevm problem, solaris 11 i586 (needs othervm?) -# Suspect use of setHttps*()? -com/sun/net/httpserver/SelCacheTest.java generic-all -com/sun/net/httpserver/Test1.java generic-all -com/sun/net/httpserver/Test12.java generic-all -com/sun/net/httpserver/Test13.java generic-all -com/sun/net/httpserver/Test6a.java generic-all -com/sun/net/httpserver/Test7a.java generic-all -com/sun/net/httpserver/Test8a.java generic-all -com/sun/net/httpserver/Test9.java generic-all -com/sun/net/httpserver/Test9a.java generic-all - -# 10,000 connections, fails on Linux and makes tests&jtreg fail with samevm -com/sun/net/httpserver/bugs/B6361557.java generic-all - -# Address already in use with samevm? Always? Solaris sparc, probably ports -java/net/Authenticator/B4933582.sh generic-all -java/net/DatagramSocket/SendSize.java generic-all - -# Solaris 11: exception wrong address??? -java/net/Inet6Address/B6558853.java generic-all - -# Not closing stream on file i6a1, windows samevm problem -java/net/Inet6Address/serialize/Serialize.java generic-all - -# Linux x64 fails "network unreachable"? -java/net/ipv6tests/TcpTest.java generic-all - -# Linux i586, fails with unexpected output -java/net/MulticastSocket/NoLoopbackPackets.java linux-i586 - -# Address already in use -java/net/DatagramSocket/DatagramTimeout.java generic-all - -# Fails on windows, takes too long and fails -# Solaris 10 sparcv9, samevm, java.lang.Exception: Takes too long. Dead lock -java/net/Socket/DeadlockTest.java generic-all - -# Linux i586 address already in use or connection error, samevm issues -java/net/Socket/AccurateTimeout.java generic-all -java/net/Socket/asyncClose/BrokenPipe.java generic-all -java/net/Socket/CloseAvailable.java generic-all - -# Linux X64 address already in use, samevm issues -java/net/Socket/LingerTest.java generic-all -java/net/Socket/LinkLocal.java generic-all -java/net/Socket/NullHost.java generic-all -java/net/Socket/ProxyCons.java generic-all -java/net/Socket/ReadTimeout.java generic-all - -# Linux X64 address already in use, samevm issues -java/net/Socket/SetReceiveBufferSize.java generic-all - -# Linux i586 address already in use or connection error, samevm issues -java/net/Socket/setReuseAddress/Basic.java generic-all -java/net/Socket/setReuseAddress/Restart.java generic-all - -# Linux X64 address already in use, samevm issues -java/net/Socket/SetSoLinger.java generic-all - -# Address already in use, windows samevm -java/net/Socket/Timeout.java generic-all - -# Linux X64 address already in use, samevm issues -java/net/Socket/ShutdownBoth.java generic-all -java/net/Socket/SoTimeout.java generic-all -java/net/Socket/TestClose.java generic-all -java/net/Socket/UrgentDataTest.java generic-all -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/DisconnectAfterEOF.java generic-all -java/net/URLConnection/HandleContentTypeWithAttrs.java generic-all -java/net/URLConnection/Responses.java generic-all -java/net/URLConnection/TimeoutTest.java generic-all -java/net/URLConnection/ZeroContentLength.java generic-all - -# Solaris 11 i586 fails with samevm, not sure why -java/net/ResponseCache/B6181108.java generic-all -java/net/ResponseCache/ResponseCacheTest.java generic-all -java/net/URL/GetContent.java generic-all -java/net/URLConnection/HttpContinueStackOverflow.java generic-all -java/net/URLConnection/Redirect307Test.java generic-all -java/net/URLConnection/RedirectLimit.java generic-all -java/net/URLConnection/ResendPostBody.java generic-all -java/net/URL/OpenStream.java generic-all -java/net/URLClassLoader/ClassLoad.java generic-all -java/net/URLConnection/SetIfModifiedSince.java generic-all -java/net/URLConnection/URLConnectionHeaders.java generic-all - -# Linux i586 Connection refused or address already in use, samevm issues -sun/net/ftp/B6427768.java generic-all -sun/net/ftp/FtpGetContent.java generic-all -sun/net/ftp/FtpURL.java generic-all - -# Failed on solaris 10 i586, Exception: should have gotten HttpRetryException? -sun/net/www/http/ChunkedOutputStream/Test.java generic-all - -# Trouble cleaning up threads in samevm mode on solaris 11 i586 -sun/net/www/http/HttpClient/ProxyTest.java generic-all -sun/net/www/http/ChunkedInputStream/ChunkedEncodingTest.java generic-all -sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java generic-all -sun/net/www/http/HttpClient/B6726695.java generic-all -sun/net/www/http/HttpClient/MultiThreadTest.java generic-all -sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java generic-all - -# Connection refused, windows samevm -sun/net/www/protocol/http/DigestTest.java generic-all - ############################################################################ # jdk_io diff --git a/test/com/sun/net/httpserver/Test1.java b/test/com/sun/net/httpserver/Test1.java index 786b94eda..e58900e0f 100644 --- a/test/com/sun/net/httpserver/Test1.java +++ b/test/com/sun/net/httpserver/Test1.java @@ -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 diff --git a/test/com/sun/net/httpserver/Test11.java b/test/com/sun/net/httpserver/Test11.java index d3db07741..f683a16e8 100644 --- a/test/com/sun/net/httpserver/Test11.java +++ b/test/com/sun/net/httpserver/Test11.java @@ -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 class Test11 { 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 --git a/test/com/sun/net/httpserver/Test12.java b/test/com/sun/net/httpserver/Test12.java index d7dd0d931..6d9049697 100644 --- a/test/com/sun/net/httpserver/Test12.java +++ b/test/com/sun/net/httpserver/Test12.java @@ -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 diff --git a/test/com/sun/net/httpserver/Test13.java b/test/com/sun/net/httpserver/Test13.java index f990885f2..a42993220 100644 --- a/test/com/sun/net/httpserver/Test13.java +++ b/test/com/sun/net/httpserver/Test13.java @@ -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 diff --git a/test/com/sun/net/httpserver/Test6a.java b/test/com/sun/net/httpserver/Test6a.java index d22db274f..0367fa76d 100644 --- a/test/com/sun/net/httpserver/Test6a.java +++ b/test/com/sun/net/httpserver/Test6a.java @@ -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 --git a/test/com/sun/net/httpserver/Test7a.java b/test/com/sun/net/httpserver/Test7a.java index 3080b8073..67039f81d 100644 --- a/test/com/sun/net/httpserver/Test7a.java +++ b/test/com/sun/net/httpserver/Test7a.java @@ -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 --git a/test/com/sun/net/httpserver/Test8a.java b/test/com/sun/net/httpserver/Test8a.java index ed64d1a46..9e8f96a97 100644 --- a/test/com/sun/net/httpserver/Test8a.java +++ b/test/com/sun/net/httpserver/Test8a.java @@ -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 @@ public class Test8a extends Test { //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>)ois.readObject(); } catch (Exception ex) { @@ -206,6 +224,8 @@ static class NameVerifier implements HostnameVerifier { try { File file = new File(filename); fos = new FileOutputStream(file); + streams.add(fos); + files.add(file); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(rspHeaders); } catch (Exception ex) { diff --git a/test/java/net/ResponseCache/getResponseCode.java b/test/java/net/ResponseCache/getResponseCode.java index 02f0f565d..b5a4d0c2e 100644 --- a/test/java/net/ResponseCache/getResponseCode.java +++ b/test/java/net/ResponseCache/getResponseCode.java @@ -39,6 +39,7 @@ import java.io.*; public class getResponseCode { static URL url; static String FNPrefix; + static List resources = new ArrayList<>(); getResponseCode() throws Exception { url = new URL("http://localhost/file1.cache"); @@ -57,6 +58,9 @@ public class getResponseCode { new getResponseCode(); } finally{ ResponseCache.setDefault(null); + for (Closeable c : resources) { + try { c.close(); } catch (IOException unused) {} + } } } @@ -77,6 +81,7 @@ public class getResponseCode { public MyResponse(String filename) { try { fis = new FileInputStream(new File(filename)); + resources.add(fis); headers = (Map>)new ObjectInputStream(fis).readObject(); } catch (Exception ex) { throw new RuntimeException(ex.getMessage()); diff --git a/test/java/net/Socket/AccurateTimeout.java b/test/java/net/Socket/AccurateTimeout.java deleted file mode 100644 index 81a664d31..000000000 --- a/test/java/net/Socket/AccurateTimeout.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2002, 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 - * under the terms of the GNU General Public License version 2 only, as - * 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 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* @test - * @bug 4512028 - * @summary Check the tolerance on read timeouts. - */ -import java.net.*; -import java.io.*; - -public class AccurateTimeout { - - static final int TOLERANCE = 100; - - static boolean skipTest() { - String os = System.getProperty("os.name"); - if (os.equals("Windows 95") || - os.equals("Windows 98") || - os.equals("Windows Me")) { - - System.out.println("Due to an OS bug timeout tolerance cannot be tested on this OS"); - return true; - } - return false; - } - - public static void main(String args[]) throws Exception { - - if (skipTest()) { - return; - } - - int failures = 0; - int timeout; - - System.out.println(""); - System.out.println("Testing Socket.getInputStream().read() ..."); - System.out.println(""); - - ServerSocket ss = new ServerSocket(0); - Socket s1 = new Socket(InetAddress.getLocalHost(), ss.getLocalPort()); - Socket s2 = ss.accept(); - - InputStream in = s1.getInputStream(); - - timeout = 100; - while (timeout < 2500) { - s1.setSoTimeout(timeout); - - long startTime = System.currentTimeMillis(); - try { - in.read(); - } catch (SocketTimeoutException e) { - } - long actual = System.currentTimeMillis() - startTime; - - System.out.print("excepted: " + timeout + " actual: " + actual); - - if (Math.abs(actual-timeout) > TOLERANCE) { - System.out.print(" *** FAIL: outside tolerance"); - failures++; - } else { - System.out.print(" PASS."); - } - - System.out.println(""); - timeout += 200; - } - - s1.close(); - s2.close(); - ss.close(); - - - // ---------- - - - System.out.println(""); - System.out.println("Testing DatagramSocket.receive ..."); - System.out.println(""); - - byte b[] = new byte[8]; - DatagramPacket p = new DatagramPacket(b, b.length); - - DatagramSocket ds = new DatagramSocket(); - - timeout = 100; - while (timeout < 2500) { - ds.setSoTimeout(timeout); - - long startTime = System.currentTimeMillis(); - try { - ds.receive(p); - } catch (SocketTimeoutException e) { - } - long actual = System.currentTimeMillis() - startTime; - - System.out.print("excepted: " + timeout + " actual: " + actual); - - if (Math.abs(actual-timeout) > TOLERANCE) { - System.out.print(" *** FAIL: outside tolerance"); - failures++; - } else { - System.out.print(" PASS."); - } - - System.out.println(""); - timeout += 200; - } - - ds.close(); - - System.out.println(""); - - // --------- - - if (failures > 0) { - throw new Exception("Test failed: " + failures + - " test(s) outside tolerance"); - } - - } - -} diff --git a/test/java/net/Socket/CloseAvailable.java b/test/java/net/Socket/CloseAvailable.java index d7f208280..5e9fd5c97 100644 --- a/test/java/net/Socket/CloseAvailable.java +++ b/test/java/net/Socket/CloseAvailable.java @@ -47,6 +47,7 @@ public class CloseAvailable implements Runnable { t.start(); Socket soc = ss.accept(); + ss.close(); DataInputStream is = new DataInputStream(soc.getInputStream()); is.close(); @@ -64,7 +65,7 @@ public class CloseAvailable implements Runnable { public void run() { try { Socket s = new Socket(addr, port); - + s.close(); } catch (Exception e) { e.printStackTrace(); } diff --git a/test/java/net/Socket/DeadlockTest.java b/test/java/net/Socket/DeadlockTest.java index ff601c719..a5d7751f5 100644 --- a/test/java/net/Socket/DeadlockTest.java +++ b/test/java/net/Socket/DeadlockTest.java @@ -33,29 +33,32 @@ import java.io.*; public class DeadlockTest { public static void main(String [] argv) throws Exception { + ServerSocket ss = new ServerSocket(0); + Socket clientSocket = new Socket(); - // Start the server thread - Thread s1 = new Thread(new ServerThread()); - s1.start(); - - // Sleep to make sure s1 has created a server socket - Thread.sleep(1000); - - // Start the client thread - ClientThread ct = new ClientThread(); - Thread c1 = new Thread(ct); - c1.start(); - - // Wait for the client thread to finish - c1.join(40000); - - // If timeout, we assume there is a deadlock - if (c1.isAlive() == true) { - // Close the socket to force the server thread - // terminate too - s1.stop(); - ct.getSock().close(); - throw new Exception("Takes too long. Dead lock"); + try { + // Start the server thread + Thread s1 = new Thread(new ServerThread(ss)); + s1.start(); + + // Start the client thread + ClientThread ct = new ClientThread(clientSocket, ss.getLocalPort()); + Thread c1 = new Thread(ct); + c1.start(); + + // Wait for the client thread to finish + c1.join(20000); + + // If timeout, we assume there is a deadlock + if (c1.isAlive() == true) { + // Close the socket to force the server thread + // terminate too + s1.stop(); + throw new Exception("Takes too long. Dead lock"); + } + } finally { + ss.close(); + clientSocket.close(); } } } @@ -71,8 +74,8 @@ class ServerThread implements Runnable { Socket sock; - public ServerThread() throws Exception { - + public ServerThread(ServerSocket serverSocket) throws Exception { + this.server = serverSocket; } public void ping(int cnt) { @@ -85,7 +88,6 @@ class ServerThread implements Runnable { try { if (Thread.currentThread().getName().startsWith("child") == false) { - server = new ServerSocket(4711); sock = server.accept(); new Thread(this, "child").start(); @@ -107,6 +109,7 @@ class ServerThread implements Runnable { } } catch (Throwable e) { + System.out.println(e); // If anything goes wrong, just quit. } @@ -141,10 +144,11 @@ class ClientThread implements Runnable { Socket sock; - public ClientThread() throws Exception { + public ClientThread(Socket sock, int serverPort) throws Exception { try { - System.out.println("About to create a socket"); - sock = new Socket(InetAddress.getLocalHost().getHostName(), 4711); + System.out.println("About to connect the client socket"); + this.sock = sock; + this.sock.connect(new InetSocketAddress("localhost", serverPort)); System.out.println("connected"); out = new ObjectOutputStream(sock.getOutputStream()); @@ -156,10 +160,6 @@ class ClientThread implements Runnable { } } - public Socket getSock() { - return sock; - } - private int cnt = 1; public void run() { @@ -213,6 +213,7 @@ class Message implements java.io.Serializable { System.out.println("write message done " + cnt++); } catch (IOException ioe) { // Ignore the exception + System.out.println(ioe); } } } diff --git a/test/java/net/Socket/LingerTest.java b/test/java/net/Socket/LingerTest.java index 600dbd7db..c84e15311 100644 --- a/test/java/net/Socket/LingerTest.java +++ b/test/java/net/Socket/LingerTest.java @@ -81,7 +81,7 @@ public class LingerTest { public void run() { System.out.println ("Another starts"); try { - Thread.currentThread().sleep(delay); + Thread.sleep(delay); Socket s = new Socket("localhost", port); synchronized (this) { connected = true; @@ -105,7 +105,6 @@ public class LingerTest { Socket s1 = new Socket("localhost", ss.getLocalPort()); Socket s2 = ss.accept(); - // setup conditions for untransmitted data and lengthy // linger interval s1.setSendBufferSize(128*1024); @@ -122,14 +121,15 @@ public class LingerTest { thr.start(); // give sender time to queue the data - Thread.currentThread().sleep(1000); + Thread.sleep(1000); // close the socket asynchronously (new Thread(new Closer(s1))).start(); // give another time to run - Thread.currentThread().sleep(10000); + Thread.sleep(10000); + ss.close(); // check that another is done if (!another.connected()) { throw new RuntimeException("Another thread is blocked"); diff --git a/test/java/net/Socket/LinkLocal.java b/test/java/net/Socket/LinkLocal.java index 1d3288bdc..8a0aea287 100644 --- a/test/java/net/Socket/LinkLocal.java +++ b/test/java/net/Socket/LinkLocal.java @@ -58,11 +58,10 @@ public class LinkLocal { } catch (SocketException e) { failed++; System.out.println("Test failed: " + e); + } finally { + s.close(); + ss.close(); } - - // clean up - s.close(); - ss.close(); } static void UdpTest(InetAddress ia, boolean connected) throws Exception { @@ -93,16 +92,16 @@ public class LinkLocal { ds1.send(p); System.out.println("Packet has been sent."); - ds2.setSoTimeout(1000); + ds2.setSoTimeout(5000); ds2.receive(p); System.out.println("Test passed - packet received."); } catch (SocketException e) { failed++; System.out.println("Test failed: " + e); + } finally { + ds1.close(); + ds2.close(); } - - ds1.close(); - ds2.close(); } static void TestAddress(InetAddress ia) throws Exception { @@ -138,6 +137,9 @@ public class LinkLocal { Enumeration nifs = NetworkInterface.getNetworkInterfaces(); while (nifs.hasMoreElements()) { NetworkInterface ni = (NetworkInterface)nifs.nextElement(); + if (!ni.isUp()) + continue; + Enumeration addrs = ni.getInetAddresses(); while (addrs.hasMoreElements()) { InetAddress addr = (InetAddress)addrs.nextElement(); diff --git a/test/java/net/Socket/ProxyCons.java b/test/java/net/Socket/ProxyCons.java index 901638ec2..da8033707 100644 --- a/test/java/net/Socket/ProxyCons.java +++ b/test/java/net/Socket/ProxyCons.java @@ -39,6 +39,7 @@ public class ProxyCons { public void run () { try { Socket s = server.accept (); + s.close(); while (!finished ()) { Thread.sleep (500); } @@ -58,10 +59,9 @@ public class ProxyCons { public ProxyCons() { } - void test() { + void test() throws Exception { + ServerSocket ss = new ServerSocket(0); try { - ServerSocket ss = new ServerSocket(); - ss.bind(new InetSocketAddress(0)); Server s = new Server(ss); s.start(); Socket sock = new Socket(Proxy.NO_PROXY); @@ -70,10 +70,12 @@ public class ProxyCons { sock.close(); } catch (java.io.IOException e) { throw new RuntimeException(e); + } finally { + ss.close(); } } - public static void main(String[] args) { + public static void main(String[] args) throws Exception { ProxyCons c = new ProxyCons(); c.test(); } diff --git a/test/java/net/Socket/ReadTimeout.java b/test/java/net/Socket/ReadTimeout.java index 26097827e..89fe41504 100644 --- a/test/java/net/Socket/ReadTimeout.java +++ b/test/java/net/Socket/ReadTimeout.java @@ -44,7 +44,7 @@ public class ReadTimeout { sin = InetAddress.getLocalHost(); srv = new ServerSocket(port); port = srv.getLocalPort(); - soc = new Socket(sin, port, true); + soc = new Socket(sin, port); soc1 = srv.accept(); soc.setSoTimeout(tout); @@ -53,10 +53,10 @@ public class ReadTimeout { os = soc1.getOutputStream(); is.read(); } catch(InterruptedIOException e) { + } finally { + soc.close(); + soc1.close(); + srv.close(); } - - soc.close(); - soc1.close(); - srv.close(); } } diff --git a/test/java/net/Socket/SetReceiveBufferSize.java b/test/java/net/Socket/SetReceiveBufferSize.java index 562010d48..fa5302a48 100644 --- a/test/java/net/Socket/SetReceiveBufferSize.java +++ b/test/java/net/Socket/SetReceiveBufferSize.java @@ -32,29 +32,14 @@ import java.net.Socket; import java.net.ServerSocket; public class SetReceiveBufferSize { - class Server extends Thread { - private ServerSocket ss; - public Server(ServerSocket ss) { - this.ss = ss; - } - - public void run() { - try { - ss.accept(); - } catch (Exception e) { - } - } - } - public static void main(String[] args) throws Exception { SetReceiveBufferSize s = new SetReceiveBufferSize(); } public SetReceiveBufferSize() throws Exception { ServerSocket ss = new ServerSocket(0); - Server serv = new Server(ss); - serv.start(); Socket s = new Socket("localhost", ss.getLocalPort()); + Socket accepted = ss.accept(); try { s.setReceiveBufferSize(0); } catch (IllegalArgumentException e) { @@ -62,6 +47,8 @@ public class SetReceiveBufferSize { } catch (Exception ex) { } finally { ss.close(); + s.close(); + accepted.close(); } throw new RuntimeException("IllegalArgumentException not thrown!"); } diff --git a/test/java/net/Socket/SetSoLinger.java b/test/java/net/Socket/SetSoLinger.java index 97351f352..f2eaff438 100644 --- a/test/java/net/Socket/SetSoLinger.java +++ b/test/java/net/Socket/SetSoLinger.java @@ -30,36 +30,24 @@ import java.net.*; -public class SetSoLinger implements Runnable { - static ServerSocket ss; - static InetAddress addr; - static int port; +public class SetSoLinger { + static final int LINGER = 65546; public static void main(String args[]) throws Exception { - boolean error = true; - int linger = 65546; - int value = 0; - addr = InetAddress.getLocalHost(); - ss = new ServerSocket(0); - port = ss.getLocalPort(); + int value; + InetAddress addr = InetAddress.getLocalHost(); + ServerSocket ss = new ServerSocket(0); + int port = ss.getLocalPort(); - Thread t = new Thread(new SetSoLinger()); - t.start(); + Socket s = new Socket(addr, port); Socket soc = ss.accept(); - soc.setSoLinger(true, linger); + soc.setSoLinger(true, LINGER); value = soc.getSoLinger(); soc.close(); + s.close(); + ss.close(); if(value != 65535) throw new RuntimeException("Failed. Value not properly reduced."); } - - public void run() { - try { - Socket s = new Socket(addr, port); - } catch (Exception e) { - e.printStackTrace(); - } - } - } diff --git a/test/java/net/Socket/ShutdownBoth.java b/test/java/net/Socket/ShutdownBoth.java index bf19924e0..99281c76e 100644 --- a/test/java/net/Socket/ShutdownBoth.java +++ b/test/java/net/Socket/ShutdownBoth.java @@ -36,12 +36,14 @@ public class ShutdownBoth { Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort()); Socket s2 = ss.accept(); - s1.shutdownInput(); - s1.shutdownOutput(); // failed b55 - - s1.close(); - s2.close(); - ss.close(); + try { + s1.shutdownInput(); + s1.shutdownOutput(); // failed b55 + } finally { + s1.close(); + s2.close(); + ss.close(); + } } } diff --git a/test/java/net/Socket/SoTimeout.java b/test/java/net/Socket/SoTimeout.java index 1273d968c..0b1e44852 100644 --- a/test/java/net/Socket/SoTimeout.java +++ b/test/java/net/Socket/SoTimeout.java @@ -52,9 +52,10 @@ public class SoTimeout implements Runnable { t.start(); Socket s = serverSocket.accept(); + serverSocket.close(); - // set a 1 second timeout on the socket - s.setSoTimeout(1000); + // set a 5 second timeout on the socket + s.setSoTimeout(5000); s.getInputStream().read(b, 0, b.length); s.close(); @@ -64,7 +65,7 @@ public class SoTimeout implements Runnable { // this sequence should complete fairly quickly and if it // takes something resembling the the SoTimeout value then // we are probably incorrectly blocking and not waking up - if (waited > 500) { + if (waited > 2000) { throw new Exception("shouldn't take " + waited + " to complete"); } } diff --git a/test/java/net/Socket/Timeout.java b/test/java/net/Socket/Timeout.java index 653db8f72..31471acfc 100644 --- a/test/java/net/Socket/Timeout.java +++ b/test/java/net/Socket/Timeout.java @@ -31,18 +31,16 @@ import java.net.*; import java.io.*; public class Timeout { - - public static ServerSocket sock; - public static void main(String[] args) throws Exception { boolean success = false; + ServerSocket sock = new ServerSocket(0); try { - ServerSocket sock; - sock = new ServerSocket(2333); sock.setSoTimeout(2); sock.accept(); } catch (InterruptedIOException e) { success = true; + } finally { + sock.close(); } if (!success) throw new RuntimeException("Socket timeout failure."); diff --git a/test/java/net/Socket/UrgentDataTest.java b/test/java/net/Socket/UrgentDataTest.java index 7b6a8dca1..d63bc5cb8 100644 --- a/test/java/net/Socket/UrgentDataTest.java +++ b/test/java/net/Socket/UrgentDataTest.java @@ -90,63 +90,64 @@ public class UrgentDataTest { } public void run () throws Exception { - if (isClient) { - client = new Socket (clHost, clPort); - clis = client.getInputStream(); - clos = client.getOutputStream(); - client.setOOBInline (true); - if (client.getOOBInline() != true) { - throw new RuntimeException ("Setting OOBINLINE failed"); - } - } - if (isServer) { - server = listener.accept (); - sis = server.getInputStream(); - sos = server.getOutputStream(); - } - if (isClient) { - clos.write ("Hello".getBytes ()); - client.sendUrgentData (100); - clos.write ("world".getBytes ()); - } - // read Hello world from server (during which oob byte must have been dropped) - String s = "Helloworld"; - if (isServer) { - for (int y=0; y= 0) { throw ioe; } + } finally { + server.close(); } - server.close(); } } diff --git a/test/java/net/Socket/setReuseAddress/Restart.java b/test/java/net/Socket/setReuseAddress/Restart.java index 90c2a1810..08bb5af2f 100644 --- a/test/java/net/Socket/setReuseAddress/Restart.java +++ b/test/java/net/Socket/setReuseAddress/Restart.java @@ -39,27 +39,28 @@ public class Restart { */ public static void main(String args[]) throws Exception { + ServerSocket ss = new ServerSocket(0); + Socket s1 = null, s2 = null; + try { + int port = ss.getLocalPort(); - InetSocketAddress isa = new InetSocketAddress(0); - ServerSocket ss = new ServerSocket(); - ss.bind(isa); + s1 = new Socket(InetAddress.getLocalHost(), port); + s2 = ss.accept(); - int port = ss.getLocalPort(); + // close server socket and the accepted connection + ss.close(); + s2.close(); - Socket s1 = new Socket(InetAddress.getLocalHost(), port); - Socket s2 = ss.accept(); + ss = new ServerSocket(); + ss.bind( new InetSocketAddress(port) ); + ss.close(); - // close server socket and the accepted connection - ss.close(); - s2.close(); - - boolean failed = false; - - ss = new ServerSocket(); - ss.bind( new InetSocketAddress(port) ); - ss.close(); - - // close the client socket - s1.close(); + // close the client socket + s1.close(); + } finally { + if (ss != null) ss.close(); + if (s1 != null) s1.close(); + if (s2 != null) s2.close(); + } } } diff --git a/test/java/net/SocketInputStream/SocketClosedException.java b/test/java/net/SocketInputStream/SocketClosedException.java index b116cd21d..cf141863a 100644 --- a/test/java/net/SocketInputStream/SocketClosedException.java +++ b/test/java/net/SocketInputStream/SocketClosedException.java @@ -32,68 +32,37 @@ import java.io.*; import java.net.*; public class SocketClosedException { - - /* - * Is the server ready to serve? - */ - volatile static boolean serverReady = false; - - /* - * Define the server side of the test. - * - * If the server prematurely exits, serverReady will be set to true - * to avoid infinite hangs. - */ static void doServerSide() throws Exception { - ServerSocket serverSocket = new ServerSocket(serverPort); - serverPort = serverSocket.getLocalPort(); - - /* - * Signal Client, we're ready for a connect. - */ - serverReady = true; - - Socket socket = serverSocket.accept(); - - InputStream is = socket.getInputStream(); - OutputStream os = socket.getOutputStream(); - - os.write(85); - os.flush(); - socket.close(); - } + try { + Socket socket = serverSocket.accept(); - /* - * Define the client side of the test. - * - * If the server prematurely exits, serverReady will be set to true - * to avoid infinite hangs. - */ - static void doClientSide() throws Exception { + OutputStream os = socket.getOutputStream(); - /* - * Wait for server to get started. - */ - while (!serverReady) { - Thread.sleep(5000); + os.write(85); + os.flush(); + socket.close(); + } finally { + serverSocket.close(); } + } - Socket socket = new Socket("localhost", serverPort); + static void doClientSide(int port) throws Exception { + Socket socket = new Socket("localhost", port); InputStream is = socket.getInputStream(); - OutputStream os = socket.getOutputStream(); - int read = is.read(); + is.read(); socket.close(); - read = is.read(); + is.read(); } - static int serverPort = 0; + static ServerSocket serverSocket; static Exception serverException = null; public static void main(String[] args) throws Exception { + serverSocket = new ServerSocket(0); startServer(); try { - doClientSide(); + doClientSide(serverSocket.getLocalPort()); } catch (SocketException e) { if (!e.getMessage().equalsIgnoreCase("Socket closed")) { throw new Exception("Received a wrong exception message: " + @@ -108,21 +77,14 @@ public class SocketClosedException { } static void startServer() { - Thread serverThread = new Thread() { + (new Thread() { public void run() { try { doServerSide(); } catch (Exception e) { - /* - * server thread just died. - * Release the client, if not active already... - */ - System.err.println("Server died..."); - serverReady = true; - serverException = e; + e.printStackTrace(); } } - }; - serverThread.start(); + }).start(); } } diff --git a/test/java/net/SocketInputStream/SocketTimeout.java b/test/java/net/SocketInputStream/SocketTimeout.java index 37d84162f..ad4c70acb 100644 --- a/test/java/net/SocketInputStream/SocketTimeout.java +++ b/test/java/net/SocketInputStream/SocketTimeout.java @@ -31,26 +31,24 @@ import java.net.*; import java.io.*; public class SocketTimeout { + static final int TIMEOUT = 1000; + public static void main(String args[]) throws Exception { - InetAddress sin = null; + InetAddress sin = InetAddress.getLocalHost(); Socket soc = null,soc1 = null; InputStream is = null; - OutputStream os = null; ServerSocket srv = null; int port = 0; - int tout = 1000; - sin = InetAddress.getLocalHost(); - srv = new ServerSocket(port); + srv = new ServerSocket(0); port = srv.getLocalPort(); soc = new Socket(sin, port); soc1 = srv.accept(); - soc.setSoTimeout(tout); - srv.setSoTimeout(tout); + soc.setSoTimeout(TIMEOUT); + srv.setSoTimeout(TIMEOUT); try { is = soc.getInputStream(); - os = soc1.getOutputStream(); is.read(); } catch(InterruptedIOException e) { try { @@ -59,6 +57,9 @@ public class SocketTimeout { } catch(NoClassDefFoundError e1) { throw new Exception ("SocketTimeoutException: not found"); } + } finally { + soc.close(); + soc1.close(); } // now check accept @@ -72,12 +73,14 @@ public class SocketTimeout { } catch(NoClassDefFoundError e1) { throw new Exception ("SocketTimeoutException: not found"); } + } finally { + srv.close(); } // Now check DatagramSocket.receive() DatagramSocket dg = new DatagramSocket (); - dg.setSoTimeout (tout); + dg.setSoTimeout (TIMEOUT); try { dg.receive (new DatagramPacket (new byte [64], 64)); @@ -88,11 +91,8 @@ public class SocketTimeout { } catch(NoClassDefFoundError e1) { throw new Exception ("SocketTimeoutException: not found"); } + } finally { + dg.close(); } - - soc.close(); - soc1.close(); - srv.close(); - dg.close(); } } diff --git a/test/java/net/URL/GetContent.java b/test/java/net/URL/GetContent.java index b913cfe07..aa32da29b 100644 --- a/test/java/net/URL/GetContent.java +++ b/test/java/net/URL/GetContent.java @@ -53,11 +53,13 @@ public class GetContent implements Runnable { // wait for client to read response - otherwise http // client get error and re-establish connection - Thread.currentThread().sleep(2000); + Thread.sleep(2000); s.close(); } catch (Exception e) { e.printStackTrace(); + } finally { + try { ss.close(); } catch (IOException unused) {} } } @@ -81,8 +83,6 @@ public class GetContent implements Runnable { error = false; } - ss.close(); - if (error) throw new RuntimeException("No IOException generated."); } diff --git a/test/java/net/URLClassLoader/ClassLoad.java b/test/java/net/URLClassLoader/ClassLoad.java index b9aa687b4..c23073f93 100644 --- a/test/java/net/URLClassLoader/ClassLoad.java +++ b/test/java/net/URLClassLoader/ClassLoad.java @@ -27,20 +27,45 @@ * @summary Test for FileNotFoundException when loading bogus class */ -import java.net.*; -import java.io.*; +import java.io.InputStream; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.URL; +import java.net.URLClassLoader; +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; public class ClassLoad { public static void main(String[] args) throws Exception { boolean error = true; + + // Start a dummy server to return 404 + HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); + HttpHandler handler = new HttpHandler() { + public void handle(HttpExchange t) throws IOException { + InputStream is = t.getRequestBody(); + while (is.read() != -1); + t.sendResponseHeaders (404, -1); + t.close(); + } + }; + server.createContext("/", handler); + server.start(); + + // Client request try { - URL url = new URL(args.length >= 1 ? args[0] : "http://jini.east/"); + URL url = new URL("http://localhost:" + server.getAddress().getPort()); String name = args.length >= 2 ? args[1] : "foo.bar.Baz"; ClassLoader loader = new URLClassLoader(new URL[] { url }); + System.out.println(url); Class c = loader.loadClass(name); System.out.println("Loaded class \"" + c.getName() + "\"."); } catch (ClassNotFoundException ex) { + System.out.println(ex); error = false; + } finally { + server.stop(0); } if (error) throw new RuntimeException("No ClassNotFoundException generated"); diff --git a/test/java/net/URLConnection/DisconnectAfterEOF.java b/test/java/net/URLConnection/DisconnectAfterEOF.java index 927fedfd9..0a3814794 100644 --- a/test/java/net/URLConnection/DisconnectAfterEOF.java +++ b/test/java/net/URLConnection/DisconnectAfterEOF.java @@ -56,7 +56,6 @@ public class DisconnectAfterEOF { int cl = -1; int remaining = -1; StringBuffer sb = new StringBuffer(); - Random r = new Random(); boolean close = false; boolean inBody = false; @@ -239,8 +238,6 @@ public class DisconnectAfterEOF { } public static void main(String args[]) throws Exception { - Random r = new Random(); - // start server ServerSocket ss = new ServerSocket(0); Server svr = new Server(ss); @@ -273,7 +270,7 @@ public class DisconnectAfterEOF { URLConnection uc1 = doRequest(uri); doResponse(uc1); - Thread.currentThread().sleep(2000); + Thread.sleep(2000); URLConnection uc2 = doRequest(uri); diff --git a/test/java/net/URLConnection/HandleContentTypeWithAttrs.java b/test/java/net/URLConnection/HandleContentTypeWithAttrs.java index 3cad25dbe..50fcd388f 100644 --- a/test/java/net/URLConnection/HandleContentTypeWithAttrs.java +++ b/test/java/net/URLConnection/HandleContentTypeWithAttrs.java @@ -111,9 +111,8 @@ class myHttpServer implements Runnable, Cloneable { } catch(Exception e) { System.out.print("Server failure\n"); e.printStackTrace(); - try { - serverSocket.close(); - } catch(IOException e2) {} + } finally { + try { serverSocket.close(); } catch(IOException unused) {} } } else { try { @@ -127,10 +126,9 @@ class myHttpServer implements Runnable, Cloneable { } catch(Exception e) { // System.out.print("Service handler failure\n"); // e.printStackTrace(); + } finally { + try { close(); } catch(IOException unused) {} } - try { - close(); - } catch(IOException e2) {} } } diff --git a/test/java/net/URLConnection/HttpContinueStackOverflow.java b/test/java/net/URLConnection/HttpContinueStackOverflow.java index 8d9aab013..502adf9fa 100644 --- a/test/java/net/URLConnection/HttpContinueStackOverflow.java +++ b/test/java/net/URLConnection/HttpContinueStackOverflow.java @@ -30,7 +30,7 @@ */ import java.io.BufferedReader; import java.io.InputStreamReader; -import java.io.OutputStreamWriter; +import java.io.IOException; import java.io.PrintStream; import java.net.ServerSocket; import java.net.Socket; @@ -41,61 +41,56 @@ public class HttpContinueStackOverflow { static class Server implements Runnable { int port; + ServerSocket serverSock ; - Server(int port) { - this.port = port; + Server() throws IOException { + serverSock = new ServerSocket(0); + } + + int getLocalPort() { + return serverSock.getLocalPort(); } public void run() { + Socket sock = null; try { - /* bind to port and wait for connection */ - ServerSocket serverSock = new ServerSocket( port ); serverSock.setSoTimeout(10000); - Socket sock = serverSock.accept(); + sock = serverSock.accept(); /* setup streams and read http request */ BufferedReader in = new BufferedReader( new InputStreamReader(sock.getInputStream())); PrintStream out = new PrintStream( sock.getOutputStream() ); - String request = in.readLine(); + in.readLine(); /* send continue followed by invalid response */ out.println("HTTP/1.1 100 Continue\r"); out.println("\r"); out.println("junk junk junk"); out.flush(); - - sock.close(); } catch (Exception e) { e.printStackTrace(); + } finally { + try { serverSock.close(); } catch (IOException unused) {} + try { sock.close(); } catch (IOException unused) {} } } } - HttpContinueStackOverflow(int port) throws Exception { + HttpContinueStackOverflow() throws Exception { /* create the server */ - Server s = new Server(port); - Thread thr = new Thread(s); - thr.start(); - - /* wait for server to bind to port */ - try { - Thread.currentThread().sleep(2000); - } catch (Exception e) { } + Server s = new Server(); + (new Thread(s)).start(); /* connect to server, connect to server and get response code */ - URL url = new URL("http", "localhost", port, "anything.html"); + URL url = new URL("http", "localhost", s.getLocalPort(), "anything.html"); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - int respCode = conn.getResponseCode(); + conn.getResponseCode(); System.out.println("TEST PASSED"); } public static void main(String args[]) throws Exception { - int port = 4090; - if (args.length > 0) { - port = Integer.parseInt(args[0]); - } System.out.println("Testing 100-Continue"); - new HttpContinueStackOverflow(port); + new HttpContinueStackOverflow(); } } diff --git a/test/java/net/URLConnection/Redirect307Test.java b/test/java/net/URLConnection/Redirect307Test.java index b0a85e14d..37f044eda 100644 --- a/test/java/net/URLConnection/Redirect307Test.java +++ b/test/java/net/URLConnection/Redirect307Test.java @@ -37,11 +37,11 @@ class RedirServer extends Thread { OutputStream os; int port; - String reply1 = "HTTP/1.1 307 Temporary Redirect\r\n" + + String reply1Part1 = "HTTP/1.1 307 Temporary Redirect\r\n" + "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" + "Server: Apache/1.3.14 (Unix)\r\n" + "Location: http://localhost:"; - String reply2 = "/redirected.html\r\n" + + String reply1Part2 = "/redirected.html\r\n" + "Connection: close\r\n" + "Content-Type: text/html; charset=iso-8859-1\r\n\r\n" + "Hello"; @@ -49,9 +49,10 @@ class RedirServer extends Thread { RedirServer (ServerSocket y) { s = y; port = s.getLocalPort(); + System.out.println("Server created listening on " + port); } - String reply3 = "HTTP/1.1 200 Ok\r\n" + + String reply2 = "HTTP/1.1 200 Ok\r\n" + "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" + "Server: Apache/1.3.14 (Unix)\r\n" + "Connection: close\r\n" + @@ -64,16 +65,24 @@ class RedirServer extends Thread { is = s1.getInputStream (); os = s1.getOutputStream (); is.read (); - String reply = reply1 + port + reply2; + String reply = reply1Part1 + port + reply1Part2; os.write (reply.getBytes()); + os.close(); /* wait for redirected connection */ s.setSoTimeout (5000); s1 = s.accept (); + is = s1.getInputStream (); os = s1.getOutputStream (); - os.write (reply3.getBytes()); + is.read(); + os.write (reply2.getBytes()); + os.close(); } catch (Exception e) { /* Just need thread to terminate */ + System.out.println("Server: caught " + e); + e.printStackTrace(); + } finally { + try { s.close(); } catch (IOException unused) {} } } }; @@ -84,10 +93,7 @@ public class Redirect307Test { public static final int DELAY = 10; public static void main(String[] args) throws Exception { - int nLoops = 1; - int nSize = 10; - int port, n =0; - byte b[] = new byte[nSize]; + int port; RedirServer server; ServerSocket sock; @@ -119,7 +125,8 @@ public class Redirect307Test { } } catch(IOException e) { - throw new RuntimeException ("Exception caught"); + e.printStackTrace(); + throw new RuntimeException ("Exception caught + " + e); } } } diff --git a/test/java/net/URLConnection/RedirectLimit.java b/test/java/net/URLConnection/RedirectLimit.java index 979a938b9..b0ef22b94 100644 --- a/test/java/net/URLConnection/RedirectLimit.java +++ b/test/java/net/URLConnection/RedirectLimit.java @@ -76,15 +76,19 @@ class RedirLimitServer extends Thread { is.read (); String reply = reply1 + port + "/redirect" + i + reply2; os.write (reply.getBytes()); + os.close(); } s1 = s.accept (); is = s1.getInputStream (); os = s1.getOutputStream (); is.read (); os.write (reply3.getBytes()); + os.close(); } catch (Exception e) { /* Just need thread to terminate */ + } finally { + try { s.close(); } catch (IOException unused) {} } } }; diff --git a/test/java/net/URLConnection/ResendPostBody.java b/test/java/net/URLConnection/ResendPostBody.java index 8bdd5fa09..99331584b 100644 --- a/test/java/net/URLConnection/ResendPostBody.java +++ b/test/java/net/URLConnection/ResendPostBody.java @@ -109,8 +109,11 @@ public class ResendPostBody { while (!finished()) { Thread.sleep (1000); } + out.close(); } catch (Exception e) { System.err.println ("Server Exception: " + e); + } finally { + try { server.close(); } catch (IOException unused) {} } } } @@ -134,7 +137,7 @@ public class ResendPostBody { public void execute () throws Exception { - byte b[] = "X=ABCDEFGHZZZ".getBytes(); + byte b[] = "X=ABCDEFGHZZZ".getBytes(); ss = new ServerSocket (0); server = new Server (ss); @@ -163,8 +166,9 @@ public class ResendPostBody { /* Read the response */ int resp = conURL.getResponseCode (); + server.setFinished (true); + if (resp != 200) throw new RuntimeException ("Response code was not 200: " + resp); - server.setFinished (true); } } diff --git a/test/java/net/URLConnection/SetIfModifiedSince.java b/test/java/net/URLConnection/SetIfModifiedSince.java index e5681fc56..f66d9385c 100644 --- a/test/java/net/URLConnection/SetIfModifiedSince.java +++ b/test/java/net/URLConnection/SetIfModifiedSince.java @@ -23,7 +23,7 @@ /* @test * @bug 4397096 - * @run main SetIfModifiedSince + * @run main/othervm SetIfModifiedSince * @summary setIfModifiedSince() of HttpURLConnection sets invalid date of default locale */ diff --git a/test/java/net/URLConnection/TimeoutTest.java b/test/java/net/URLConnection/TimeoutTest.java index c5c4f58d7..e8c32982c 100644 --- a/test/java/net/URLConnection/TimeoutTest.java +++ b/test/java/net/URLConnection/TimeoutTest.java @@ -43,8 +43,9 @@ public class TimeoutTest { try { Socket s = server.accept (); while (!finished ()) { - Thread.sleep (2000); + Thread.sleep (1000); } + s.close(); } catch (Exception e) { } } @@ -70,9 +71,12 @@ public class TimeoutTest { URL url = new URL ("http://127.0.0.1:"+ss.getLocalPort()); URLConnection urlc = url.openConnection (); InputStream is = urlc.getInputStream (); + throw new RuntimeException("Should have received timeout"); } catch (SocketTimeoutException e) { - s.done (); return; + } finally { + s.done(); + ss.close(); } } } diff --git a/test/java/net/URLConnection/URLConnectionHeaders.java b/test/java/net/URLConnection/URLConnectionHeaders.java index 3c162f0e0..4896e7a0b 100644 --- a/test/java/net/URLConnection/URLConnectionHeaders.java +++ b/test/java/net/URLConnection/URLConnectionHeaders.java @@ -70,8 +70,10 @@ public class URLConnectionHeaders { w.newLine(); w.flush(); s.close (); - srv.close (); // or else the HTTPURLConnection will retry - } catch (IOException e) { e.printStackTrace();} + } catch (IOException e) { e.printStackTrace(); + } finally { + try { srv.close(); } catch (IOException unused) {} + } } } diff --git a/test/java/net/URLConnection/ZeroContentLength.java b/test/java/net/URLConnection/ZeroContentLength.java index 237520ae1..3da6ac1ab 100644 --- a/test/java/net/URLConnection/ZeroContentLength.java +++ b/test/java/net/URLConnection/ZeroContentLength.java @@ -58,6 +58,14 @@ public class ZeroContentLength { contentLength = cl; } + static synchronized String getResponse() { + return response; + } + + static synchronized int getContentLength() { + return contentLength; + } + /* * Worker thread to service single connection - can service * multiple http requests on same connection. @@ -71,25 +79,44 @@ public class ZeroContentLength { this.id = id; } + final int CR = '\r'; + final int LF = '\n'; + public void run() { try { s.setSoTimeout(2000); - int max = 100; + int max = 20; // there should only be 20 connections + InputStream in = new BufferedInputStream(s.getInputStream()); for (;;) { - - // read entire request from client - byte b[] = new byte[100]; - InputStream in = s.getInputStream(); - int n, total=0; + // read entire request from client, until CR LF CR LF + int c, total=0; try { - do { - n = in.read(b); - if (n > 0) total += n; - } while (n > 0); - } catch (SocketTimeoutException e) { } + while ((c = in.read()) > 0) { + total++; + if (c == CR) { + if ((c = in.read()) > 0) { + total++; + if (c == LF) { + if ((c = in.read()) > 0) { + total++; + if (c == CR) { + if ((c = in.read()) > 0) { + total++; + if (c == LF) { + break; + } + } + } + } + } + } + } + + } + } catch (SocketTimeoutException e) {} debug("worker " + id + ": Read request from client " + @@ -105,19 +132,20 @@ public class ZeroContentLength { new BufferedOutputStream( s.getOutputStream() )); - out.print("HTTP/1.1 " + response + "\r\n"); - if (contentLength >= 0) { - out.print("Content-Length: " + contentLength + + out.print("HTTP/1.1 " + getResponse() + "\r\n"); + int clen = getContentLength(); + if (clen >= 0) { + out.print("Content-Length: " + clen + "\r\n"); } out.print("\r\n"); - for (int i=0; i upper || got < lower) { throw new RuntimeException ("checkTime failed: got " + got + " expected " + expected); } diff --git a/test/sun/net/ftp/FtpGetContent.java b/test/sun/net/ftp/FtpGetContent.java index 46428dd3f..c736fd437 100644 --- a/test/sun/net/ftp/FtpGetContent.java +++ b/test/sun/net/ftp/FtpGetContent.java @@ -391,6 +391,10 @@ public class FtpGetContent { done = true; } + synchronized boolean done() { + return done; + } + synchronized public void setPortEnabled(boolean ok) { portEnabled = ok; } @@ -431,12 +435,13 @@ public class FtpGetContent { public void run() { try { Socket client; - while (!done) { + while (!done()) { client = server.accept(); (new FtpServerHandler(client)).start(); } - server.close(); } catch(Exception e) { + } finally { + try { server.close(); } catch (IOException unused) {} } } } @@ -463,18 +468,13 @@ public class FtpGetContent { bytesRead = stream.read(buffer); } stream.close(); - server.terminate(); - server.interrupt(); if (totalBytes != filesize) throw new RuntimeException("wrong file size!"); } catch (IOException e) { - try { - server.terminate(); - server.interrupt(); - } catch (Exception e2) { - } throw new RuntimeException(e.getMessage()); + } finally { + server.terminate(); + server.server.close(); } } - } diff --git a/test/sun/net/ftp/FtpURL.java b/test/sun/net/ftp/FtpURL.java index c642fb38b..1d50e49ba 100644 --- a/test/sun/net/ftp/FtpURL.java +++ b/test/sun/net/ftp/FtpURL.java @@ -438,8 +438,9 @@ public class FtpURL { client = server.accept(); (new FtpServerHandler(client)).run(); } - server.close(); } catch(Exception e) { + } finally { + try { server.close(); } catch (IOException unused) {} } } } @@ -448,10 +449,9 @@ public class FtpURL { } public FtpURL() throws Exception { - FtpServer server = null; + FtpServer server = new FtpServer(0); BufferedReader in = null; try { - server = new FtpServer(0); server.start(); int port = server.getPort(); @@ -497,17 +497,14 @@ public class FtpURL { throw new RuntimeException("Incorrect filename received"); if (! "/usr".equals(server.pwd())) throw new RuntimeException("Incorrect pwd received"); - in.close(); // We're done! } catch (Exception e) { - try { - in.close(); - server.terminate(); - server.interrupt(); - } catch(Exception ex) { - } throw new RuntimeException("FTP support error: " + e.getMessage()); + } finally { + try { in.close(); } catch (IOException unused) {} + server.terminate(); + server.server.close(); } } } diff --git a/test/sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java b/test/sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java index 1fc3767cd..b2cdf6ec0 100644 --- a/test/sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java +++ b/test/sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java @@ -30,9 +30,7 @@ * @summary ChunkedEncoding unit test; MeteredStream/ProgressData problem */ -import java.io.*; import java.net.*; -import java.security.*; import java.util.BitSet; import sun.net.ProgressMeteringPolicy; import sun.net.ProgressMonitor; @@ -42,8 +40,10 @@ import sun.net.ProgressEvent; public class ChunkedEncodingWithProgressMonitorTest { public static void main (String[] args) throws Exception { ProgressMonitor.setMeteringPolicy(new MyProgressMeteringPolicy()); - ProgressMonitor.getDefault().addProgressListener(new MyProgressListener()); + ProgressListener listener = new MyProgressListener(); + ProgressMonitor.getDefault().addProgressListener(listener); ChunkedEncodingTest.test(); + ProgressMonitor.getDefault().removeProgressListener(listener); if (flag.cardinality() != 3) { throw new RuntimeException("All three methods in ProgressListener"+ diff --git a/test/sun/net/www/http/ChunkedOutputStream/Test.java b/test/sun/net/www/http/ChunkedOutputStream/Test.java index 10026cf94..48d365a7c 100644 --- a/test/sun/net/www/http/ChunkedOutputStream/Test.java +++ b/test/sun/net/www/http/ChunkedOutputStream/Test.java @@ -34,7 +34,7 @@ import com.sun.net.httpserver.*; public class Test implements HttpHandler { - static int count = 0; + static volatile int count = 0; static final String str1 = "Helloworld1234567890abcdefghijklmnopqrstuvwxyz"+ "1234567890abcdefkjsdlkjflkjsldkfjlsdkjflkj"+ @@ -46,9 +46,9 @@ public class Test implements HttpHandler { public void handle(HttpExchange exchange) { String reqbody; try { - switch (count) { - case 0: /* test1 -- keeps conn alive */ - case 1: /* test2 -- closes conn */ + switch (exchange.getRequestURI().toString()) { + case "/test/test1": /* test1 -- keeps conn alive */ + case "/test/test2": /* test2 -- closes conn */ printRequestURI(exchange); reqbody = read(exchange.getRequestBody()); if (!reqbody.equals(str1)) { @@ -72,7 +72,7 @@ public class Test implements HttpHandler { resHeaders.set("Connection", "close"); } break; - case 2: /* test 3 */ + case "/test/test3": /* test 3 */ printRequestURI(exchange); reqbody = read(exchange.getRequestBody()); @@ -93,19 +93,19 @@ public class Test implements HttpHandler { exchange.sendResponseHeaders(200, reqbody.length()); write(exchange.getResponseBody(), reqbody); break; - case 3: /* test 4 */ - case 4: /* test 5 */ + case "/test/test4": /* test 4 */ + case "/test/test5": /* test 5 */ printRequestURI(exchange); break; - case 5: /* test 6 */ + case "/test/test6": /* test 6 */ printRequestURI(exchange); resHeaders = exchange.getResponseHeaders() ; resHeaders.set("Location", "http://foo.bar/"); resHeaders.set("Connection", "close"); exchange.sendResponseHeaders(307, 0); break; - case 6: /* test 7 */ - case 7: /* test 8 */ + case "/test/test7": /* test 7 */ + case "/test/test8": /* test 8 */ printRequestURI(exchange); reqbody = read(exchange.getRequestBody()); if (reqbody != null && !"".equals(reqbody)) { @@ -116,7 +116,7 @@ public class Test implements HttpHandler { resHeaders.set("Connection", "close"); exchange.sendResponseHeaders(200, 0); break; - case 8: /* test 9 */ + case "/test/test9": /* test 9 */ printRequestURI(exchange); reqbody = read(exchange.getRequestBody()); if (!reqbody.equals(str1)) { @@ -134,7 +134,7 @@ public class Test implements HttpHandler { exchange.sendResponseHeaders(200, reqbody.length()); write(exchange.getResponseBody(), reqbody); break; - case 9: /* test10 */ + case "/test/test10": /* test10 */ printRequestURI(exchange); InputStream is = exchange.getRequestBody(); String s = read (is, str1.length()); @@ -158,7 +158,7 @@ public class Test implements HttpHandler { exchange.sendResponseHeaders(200, 0); } break; - case 10: /* test11 */ + case "/test/test11": /* test11 */ printRequestURI(exchange); is = exchange.getRequestBody(); s = read (is, str1.length()); @@ -182,7 +182,7 @@ public class Test implements HttpHandler { exchange.sendResponseHeaders(200, 0); } break; - case 11: /* test12 */ + case "/test/test12": /* test12 */ printRequestURI(exchange); is = exchange.getRequestBody(); @@ -203,8 +203,8 @@ public class Test implements HttpHandler { } break; } - exchange.close(); count ++; + exchange.close(); } catch (IOException e) { e.printStackTrace(); } diff --git a/test/sun/net/www/http/HttpClient/B6726695.java b/test/sun/net/www/http/HttpClient/B6726695.java index e601ea70c..9e69e8e3d 100644 --- a/test/sun/net/www/http/HttpClient/B6726695.java +++ b/test/sun/net/www/http/HttpClient/B6726695.java @@ -147,6 +147,8 @@ public class B6726695 extends Thread { serverIgnore(s); } catch (IOException e) { e.printStackTrace(); + } finally { + try { server.close(); } catch (IOException unused) {} } } diff --git a/test/sun/net/www/http/HttpClient/MultiThreadTest.java b/test/sun/net/www/http/HttpClient/MultiThreadTest.java index 1118365c2..750e4d0d0 100644 --- a/test/sun/net/www/http/HttpClient/MultiThreadTest.java +++ b/test/sun/net/www/http/HttpClient/MultiThreadTest.java @@ -100,11 +100,12 @@ public class MultiThreadTest extends Thread { } } catch (Exception e) { throw new RuntimeException (e.getMessage()); - } - synchronized (threadlock) { - threadCounter --; - if (threadCounter == 0) { - threadlock.notifyAll(); + } finally { + synchronized (threadlock) { + threadCounter --; + if (threadCounter == 0) { + threadlock.notifyAll(); + } } } } diff --git a/test/sun/net/www/http/HttpClient/ProxyTest.java b/test/sun/net/www/http/HttpClient/ProxyTest.java index e67fd82ac..62395f6fc 100644 --- a/test/sun/net/www/http/HttpClient/ProxyTest.java +++ b/test/sun/net/www/http/HttpClient/ProxyTest.java @@ -47,7 +47,7 @@ public class ProxyTest { private class HttpProxyServer extends Thread { private ServerSocket server; private int port; - private boolean done = false; + private volatile boolean done = false; private String askedUrl; /** @@ -125,12 +125,8 @@ public class ProxyTest { } } - public HttpProxyServer(int port) { - this.port = port; - } - - public HttpProxyServer() { - this(0); + public HttpProxyServer() throws IOException { + server = new ServerSocket(0); } public int getPort() { @@ -148,51 +144,49 @@ public class ProxyTest { */ synchronized public void terminate() { done = true; + try { server.close(); } catch (IOException unused) {} } public void run() { try { - server = new ServerSocket(port); Socket client; while (!done) { client = server.accept(); (new HttpProxyHandler(client)).start(); } - server.close(); } catch (Exception e) { + } finally { + try { server.close(); } catch (IOException unused) {} } } } - public static void main(String[] args) { + public static void main(String[] args) throws Exception { ProxyTest test = new ProxyTest(); } - public ProxyTest() { + public ProxyTest() throws Exception { + BufferedReader in = null; String testURL = "ftp://anonymous:password@myhost.mydomain/index.html"; HttpProxyServer server = new HttpProxyServer(); try { - server.start(); - int port = 0; - while (port == 0) { - Thread.sleep(500); - port = server.getPort(); - } - - System.setProperty("ftp.proxyHost","localhost"); - System.setProperty("ftp.proxyPort", String.valueOf(port)); - URL url = new URL(testURL); - InputStream ins = url.openStream(); - BufferedReader in = new BufferedReader(new InputStreamReader(ins)); - String line; - do { - line = in.readLine(); - } while (line != null); - in.close(); - server.terminate(); - server.interrupt(); + server.start(); + int port = server.getPort(); + + Proxy ftpProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", port)); + URL url = new URL(testURL); + InputStream ins = (url.openConnection(ftpProxy)).getInputStream(); + in = new BufferedReader(new InputStreamReader(ins)); + String line; + do { + line = in.readLine(); + } while (line != null); + in.close(); } catch (Exception e) { e.printStackTrace(); + } finally { + server.terminate(); + try { in.close(); } catch (IOException unused) {} } /* * If the URLs don't match, we've got a bug! diff --git a/test/sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java b/test/sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java index f0cdf6c77..6868de892 100644 --- a/test/sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java +++ b/test/sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java @@ -91,9 +91,10 @@ public class KeepAliveTimerThread { out.flush(); s.close(); - server.close(); } catch (Exception e) { e.printStackTrace(); + } finally { + try { server.close(); } catch (IOException unused) {} } } } @@ -118,6 +119,8 @@ public class KeepAliveTimerThread { if (grp.activeCount() > 0) { throw new RuntimeException("Keep-alive thread started in wrong thread group"); } + + grp.destroy(); } } diff --git a/test/sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java b/test/sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java index 866e62e9d..18f978c5c 100644 --- a/test/sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java +++ b/test/sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java @@ -43,10 +43,6 @@ public class KeepAliveStreamCloseWithWrongContentLength { srv = s; } - Socket getSocket () { - return (s); - } - public void run() { try { s = srv.accept (); @@ -57,7 +53,7 @@ public class KeepAliveStreamCloseWithWrongContentLength { is.read(); } OutputStreamWriter ow = - new OutputStreamWriter(s.getOutputStream()); + new OutputStreamWriter((os = s.getOutputStream())); ow.write("HTTP/1.0 200 OK\n"); // Note: The client expects 10 bytes. @@ -71,19 +67,16 @@ public class KeepAliveStreamCloseWithWrongContentLength { // Note: The (buggy) server only sends 9 bytes. ow.write("123456789"); ow.flush(); - ow.close(); } catch (Exception e) { + } finally { + try {if (os != null) { os.close(); }} catch (IOException e) {} } } } - /* - * - */ - - public static void main (String[] args) { + public static void main (String[] args) throws Exception { + ServerSocket serversocket = new ServerSocket (0); try { - ServerSocket serversocket = new ServerSocket (0); int port = serversocket.getLocalPort (); XServer server = new XServer (serversocket); server.start (); @@ -100,11 +93,12 @@ public class KeepAliveStreamCloseWithWrongContentLength { } } is.close(); - server.getSocket().close (); } catch (IOException e) { return; } catch (NullPointerException e) { throw new RuntimeException (e); + } finally { + if (serversocket != null) serversocket.close(); } } } diff --git a/test/sun/net/www/httptest/HttpServer.java b/test/sun/net/www/httptest/HttpServer.java index 0a999b8a5..8fcca408f 100644 --- a/test/sun/net/www/httptest/HttpServer.java +++ b/test/sun/net/www/httptest/HttpServer.java @@ -188,6 +188,7 @@ public class HttpServer { sock.configureBlocking (false); sock.register (selector, SelectionKey.OP_READ); nconn ++; + System.out.println("SERVER: new connection. chan[" + sock + "]"); if (nconn == maxconn) { /* deregister */ listenerKey.cancel (); @@ -197,7 +198,9 @@ public class HttpServer { if (key.isReadable()) { boolean closed; SocketChannel chan = (SocketChannel) key.channel(); + System.out.println("SERVER: connection readable. chan[" + chan + "]"); if (key.attachment() != null) { + System.out.println("Server: comsume"); closed = consume (chan); } else { closed = read (chan, key); @@ -375,6 +378,7 @@ public class HttpServer { synchronized void orderlyCloseChannel (SelectionKey key) throws IOException { SocketChannel ch = (SocketChannel)key.channel (); + System.out.println("SERVER: orderlyCloseChannel chan[" + ch + "]"); ch.socket().shutdownOutput(); key.attach (this); clist.add (key); @@ -382,6 +386,8 @@ public class HttpServer { synchronized void abortiveCloseChannel (SelectionKey key) throws IOException { SocketChannel ch = (SocketChannel)key.channel (); + System.out.println("SERVER: abortiveCloseChannel chan[" + ch + "]"); + Socket s = ch.socket (); s.setSoLinger (true, 0); ch.close(); diff --git a/test/sun/net/www/protocol/http/DigestTest.java b/test/sun/net/www/protocol/http/DigestTest.java index ba17d5294..c9d82fdc2 100644 --- a/test/sun/net/www/protocol/http/DigestTest.java +++ b/test/sun/net/www/protocol/http/DigestTest.java @@ -95,10 +95,11 @@ class DigestServer extends Thread { os.write (reply.getBytes()); Thread.sleep (2000); s1.close (); - } - catch (Exception e) { + } catch (Exception e) { System.out.println (e); e.printStackTrace(); + } finally { + try { s.close(); } catch (IOException unused) {} } } @@ -204,15 +205,12 @@ public class DigestTest { public static void main(String[] args) throws Exception { - int nLoops = 1; - int nSize = 10; - int port, n =0; - byte b[] = new byte[nSize]; + int port; DigestServer server; ServerSocket sock; try { - sock = new ServerSocket (5000); + sock = new ServerSocket (0); port = sock.getLocalPort (); } catch (Exception e) { @@ -225,21 +223,18 @@ public class DigestTest { boolean passed = false; try { - Authenticator.setDefault (new MyAuthenticator ()); String s = "http://localhost:" + port + DigestServer.uri; URL url = new URL(s); java.net.URLConnection conURL = url.openConnection(); InputStream in = conURL.getInputStream(); - int c; - while ((c = in.read ()) != -1) { - } + while (in.read () != -1) {} in.close (); - } - catch(ProtocolException e) { + } catch(ProtocolException e) { passed = true; } + if (!passed) { throw new RuntimeException ("Expected a ProtocolException from wrong password"); } -- GitLab