提交 420e3ffc 编写于 作者: C chegar

6969395: TEST_BUG: Tests in java/net sun/net problems

Reviewed-by: alanb
上级 2ec0fbca
...@@ -369,139 +369,6 @@ javax/print/attribute/MediaMappingsTest.java generic-all ...@@ -369,139 +369,6 @@ javax/print/attribute/MediaMappingsTest.java generic-all
# jdk_net # 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 # jdk_io
......
...@@ -24,17 +24,15 @@ ...@@ -24,17 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test1
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/* basic http/s connectivity test /* basic http/s connectivity test
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
*/ */
import java.net.*; import java.net.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
...@@ -52,22 +51,25 @@ public class Test11 { ...@@ -52,22 +51,25 @@ public class Test11 {
public static void main (String[] args) throws Exception { public static void main (String[] args) throws Exception {
System.out.print ("Test 11: "); System.out.print ("Test 11: ");
HttpServer server = HttpServer.create (new InetSocketAddress(0), 0); HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
HttpContext ctx = server.createContext ( ExecutorService s = Executors.newCachedThreadPool();
"/foo/bar/", new Handler () try {
); HttpContext ctx = server.createContext (
ExecutorService s = Executors.newCachedThreadPool(); "/foo/bar/", new Handler ()
server.setExecutor (s); );
server.start (); s = Executors.newCachedThreadPool();
URL url = new URL ("http://localhost:" + server.getAddress().getPort()+ server.start ();
"/Foo/bar/test.html"); URL url = new URL ("http://localhost:" + server.getAddress().getPort()+
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); "/Foo/bar/test.html");
int r = urlc.getResponseCode(); HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
System.out.println ("OK"); int r = urlc.getResponseCode();
s.shutdown(); if (r == 200) {
server.stop(5); throw new RuntimeException ("wrong response received");
if (r == 200) { }
throw new RuntimeException ("wrong response received"); System.out.println ("OK");
} finally {
s.shutdown();
server.stop(2);
} }
} }
} }
...@@ -24,17 +24,15 @@ ...@@ -24,17 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test12
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/* basic http/s connectivity test /* basic http/s connectivity test
......
...@@ -24,17 +24,16 @@ ...@@ -24,17 +24,16 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test13
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/* basic http/s connectivity test /* basic http/s connectivity test
......
...@@ -24,17 +24,15 @@ ...@@ -24,17 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test6a
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/** /**
......
...@@ -24,18 +24,15 @@ ...@@ -24,18 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test7a
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.logging.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/** /**
......
...@@ -24,18 +24,15 @@ ...@@ -24,18 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test8a
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.logging.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/** /**
...@@ -50,46 +47,50 @@ public class Test8a extends Test { ...@@ -50,46 +47,50 @@ public class Test8a extends Test {
//h.setLevel (Level.INFO); //h.setLevel (Level.INFO);
//log.addHandler (h); //log.addHandler (h);
//log.setLevel (Level.INFO); //log.setLevel (Level.INFO);
Handler handler = new Handler(); HttpsServer server = null;
InetSocketAddress addr = new InetSocketAddress (0); ExecutorService executor = null;
HttpsServer server = HttpsServer.create (addr, 0); try {
HttpContext ctx = server.createContext ("/test", handler); Handler handler = new Handler();
ExecutorService executor = Executors.newCachedThreadPool(); InetSocketAddress addr = new InetSocketAddress (0);
SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get(); server = HttpsServer.create (addr, 0);
server.setHttpsConfigurator(new HttpsConfigurator (ssl)); HttpContext ctx = server.createContext ("/test", handler);
server.setExecutor (executor); executor = Executors.newCachedThreadPool();
server.start (); 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"); URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");
System.out.print ("Test8a: " ); System.out.print ("Test8a: " );
HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection (); HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();
urlc.setDoOutput (true); urlc.setDoOutput (true);
urlc.setRequestMethod ("POST"); urlc.setRequestMethod ("POST");
urlc.setHostnameVerifier (new DummyVerifier()); urlc.setHostnameVerifier (new DummyVerifier());
urlc.setSSLSocketFactory (ssl.getSocketFactory()); urlc.setSSLSocketFactory (ssl.getSocketFactory());
OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000); OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000);
for (int i=0; i<SIZE; i++) { for (int i=0; i<SIZE; i++) {
os.write (i % 250); os.write (i % 250);
} }
os.close(); os.close();
int resp = urlc.getResponseCode(); int resp = urlc.getResponseCode();
if (resp != 200) { if (resp != 200) {
throw new RuntimeException ("test failed response code"); throw new RuntimeException ("test failed response code");
}
InputStream is = urlc.getInputStream ();
for (int i=0; i<SIZE; i++) {
int f = is.read();
if (f != (i % 250)) {
System.out.println ("Setting error(" +f +")("+i+")" );
error = true;
break;
} }
InputStream is = urlc.getInputStream ();
for (int i=0; i<SIZE; i++) {
int f = is.read();
if (f != (i % 250)) {
System.out.println ("Setting error(" +f +")("+i+")" );
error = true;
break;
}
}
is.close();
} finally {
delay();
if (server != null) server.stop(2);
if (executor != null) executor.shutdown();
} }
is.close();
delay();
server.stop(2);
executor.shutdown();
if (error) { if (error) {
throw new RuntimeException ("test failed error"); throw new RuntimeException ("test failed error");
} }
......
...@@ -24,17 +24,15 @@ ...@@ -24,17 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test9
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/* Same as Test1 but requests run in parallel. /* Same as Test1 but requests run in parallel.
......
...@@ -24,17 +24,15 @@ ...@@ -24,17 +24,15 @@
/** /**
* @test * @test
* @bug 6270015 * @bug 6270015
* @run main/othervm Test9a
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*; import javax.net.ssl.*;
/* Same as Test1 but requests run in parallel. /* Same as Test1 but requests run in parallel.
......
...@@ -35,12 +35,9 @@ import java.io.*; ...@@ -35,12 +35,9 @@ import java.io.*;
import java.nio.*; import java.nio.*;
import java.nio.channels.*; import java.nio.channels.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*;
/** /**
* The test simply opens 10,000 separate connections * The test simply opens 1,000 separate connections
* and invokes one http request on each. The client does * and invokes one http request on each. The client does
* not close any sockets until after they are closed * not close any sockets until after they are closed
* by the server. This verifies the basic ability * by the server. This verifies the basic ability
...@@ -49,6 +46,7 @@ import javax.net.ssl.*; ...@@ -49,6 +46,7 @@ import javax.net.ssl.*;
public class B6361557 { public class B6361557 {
public static boolean error = false; public static boolean error = false;
static final int NUM = 1000;
static class Handler implements HttpHandler { static class Handler implements HttpHandler {
int invocation = 1; int invocation = 1;
...@@ -75,7 +73,6 @@ public class B6361557 { ...@@ -75,7 +73,6 @@ public class B6361557 {
server.setExecutor (executor); server.setExecutor (executor);
server.start (); server.start ();
final int NUM = 10000;
ByteBuffer buf = ByteBuffer.allocate (4096); ByteBuffer buf = ByteBuffer.allocate (4096);
InetSocketAddress destaddr = new InetSocketAddress ( InetSocketAddress destaddr = new InetSocketAddress (
"127.0.0.1", server.getAddress().getPort() "127.0.0.1", server.getAddress().getPort()
......
...@@ -46,7 +46,7 @@ public class B6373555 { ...@@ -46,7 +46,7 @@ public class B6373555 {
private static Object lock; private static Object lock;
static HttpServer httpServer; static HttpServer httpServer;
static ExecutorService pool, execs; static ExecutorService pool, execs;
static int NUM = 4000; static int NUM = 1000;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
try { try {
...@@ -125,7 +125,7 @@ public class B6373555 { ...@@ -125,7 +125,7 @@ public class B6373555 {
} }
} }
catch(Exception e) { catch(Exception e) {
//e.printStackTrace(); e.printStackTrace();
System.out.print ("."); System.out.print (".");
error = true; error = true;
} }
......
...@@ -27,25 +27,25 @@ ...@@ -27,25 +27,25 @@
* @summary test to see if timeout hangs * @summary test to see if timeout hangs
* @run main/timeout=15 DatagramTimeout * @run main/timeout=15 DatagramTimeout
*/ */
import java.net.*; import java.net.DatagramPacket;
import java.io.*; import java.net.DatagramSocket;
import java.net.SocketTimeoutException;
public class DatagramTimeout { public class DatagramTimeout {
public static ServerSocket sock;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
boolean success = false; boolean success = false;
DatagramSocket sock = new DatagramSocket();
try { try {
DatagramSocket sock;
DatagramPacket p; DatagramPacket p;
byte[] buffer = new byte[50]; byte[] buffer = new byte[50];
p = new DatagramPacket(buffer, buffer.length); p = new DatagramPacket(buffer, buffer.length);
sock = new DatagramSocket(2333);
sock.setSoTimeout(2); sock.setSoTimeout(2);
sock.receive(p); sock.receive(p);
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
success = true; success = true;
} finally {
sock.close();
} }
if (!success) if (!success)
throw new RuntimeException("Socket timeout failure."); throw new RuntimeException("Socket timeout failure.");
......
...@@ -32,35 +32,26 @@ ...@@ -32,35 +32,26 @@
* @author Benjamin Renaud * @author Benjamin Renaud
*/ */
import java.io.*; import java.io.IOException;
import java.net.*; import java.net.DatagramPacket;
import java.util.*; import java.net.DatagramSocket;
import java.net.InetAddress;
public class SendSize { public class SendSize {
static final int clientPort = 8989;
static final int serverPort = 9999;
static final int bufferLength = 512; static final int bufferLength = 512;
static final int packetLength = 256; static final int packetLength = 256;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
new ServerThread().start(); DatagramSocket serverSocket = new DatagramSocket();
new ClientThread().start(); new ServerThread(serverSocket).start();
new ClientThread(serverSocket.getLocalPort()).start();
} }
static class ServerThread extends Thread { static class ServerThread extends Thread {
int port;
DatagramSocket server; DatagramSocket server;
ServerThread(int port) throws IOException { ServerThread(DatagramSocket server) {
this.port = port; this.server = server;
this.server = new DatagramSocket(port);
}
ServerThread() throws IOException {
this(SendSize.serverPort);
} }
public void run() { public void run() {
...@@ -85,33 +76,22 @@ public class SendSize { ...@@ -85,33 +76,22 @@ public class SendSize {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("caugth: " + e); throw new RuntimeException("caugth: " + e);
} finally {
if (server != null) { server.close(); }
} }
} }
} }
static class ClientThread extends Thread { static class ClientThread extends Thread {
int port;
int serverPort; int serverPort;
int bufferLength;
int packetLength;
DatagramSocket client; DatagramSocket client;
InetAddress host; InetAddress host;
ClientThread(int port, int serverPort, ClientThread(int serverPort)throws IOException {
int bufferLength, int packetLength) throws IOException {
this.port = port;
this.serverPort = serverPort; this.serverPort = serverPort;
this.host = InetAddress.getLocalHost(); this.host = InetAddress.getLocalHost();
this.bufferLength = bufferLength; this.client = new DatagramSocket();
this.packetLength = packetLength;
this.client = new DatagramSocket(port, host);
}
ClientThread() throws IOException {
this(SendSize.clientPort, SendSize.serverPort,
SendSize.bufferLength, SendSize.packetLength);
} }
public void run() { public void run() {
...@@ -129,6 +109,8 @@ public class SendSize { ...@@ -129,6 +109,8 @@ public class SendSize {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("caught: " + e); throw new RuntimeException("caught: " + e);
} finally {
if (client != null) { client.close(); }
} }
} }
} }
......
...@@ -43,6 +43,9 @@ public class B6558853 implements Runnable { ...@@ -43,6 +43,9 @@ public class B6558853 implements Runnable {
InetAddress dest = null; InetAddress dest = null;
while (l.hasMoreElements() && dest == null) { while (l.hasMoreElements() && dest == null) {
NetworkInterface nif = l.nextElement(); NetworkInterface nif = l.nextElement();
if (!nif.isUp())
continue;
for (InterfaceAddress a : nif.getInterfaceAddresses()) { for (InterfaceAddress a : nif.getInterfaceAddresses()) {
if (a.getAddress() instanceof Inet6Address) { if (a.getAddress() instanceof Inet6Address) {
Inet6Address a6 = (Inet6Address) a.getAddress(); Inet6Address a6 = (Inet6Address) a.getAddress();
...@@ -53,6 +56,7 @@ public class B6558853 implements Runnable { ...@@ -53,6 +56,7 @@ public class B6558853 implements Runnable {
} }
} }
} }
System.out.println("Using " + dest);
if (dest != null) { if (dest != null) {
B6558853 test = new B6558853(dest, port); B6558853 test = new B6558853(dest, port);
Thread thread = new Thread(test); Thread thread = new Thread(test);
......
...@@ -72,6 +72,7 @@ public class Serialize { ...@@ -72,6 +72,7 @@ public class Serialize {
File file = new File (System.getProperty("test.src"), "serial1.4.2.ser"); File file = new File (System.getProperty("test.src"), "serial1.4.2.ser");
ois = new ObjectInputStream(new FileInputStream(file)); ois = new ObjectInputStream(new FileInputStream(file));
nobj = (Inet6Address) ois.readObject(); nobj = (Inet6Address) ois.readObject();
ois.close();
if (!nobj.equals (InetAddress.getByName ("::1"))) { if (!nobj.equals (InetAddress.getByName ("::1"))) {
throw new RuntimeException ("old ::1 not deserialized right"); throw new RuntimeException ("old ::1 not deserialized right");
} }
...@@ -90,6 +91,8 @@ public class Serialize { ...@@ -90,6 +91,8 @@ public class Serialize {
nobj = (Inet6Address) ois.readObject(); nobj = (Inet6Address) ois.readObject();
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new RuntimeException("6656849 Not fixed: NullPointer when deserializing"); throw new RuntimeException("6656849 Not fixed: NullPointer when deserializing");
} finally {
ois.close();
} }
System.out.println(nobj); System.out.println(nobj);
System.out.println("All tests passed"); System.out.println("All tests passed");
...@@ -102,6 +105,7 @@ public class Serialize { ...@@ -102,6 +105,7 @@ public class Serialize {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("i6a1.ser")); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("i6a1.ser"));
Inet6Address nobj = (Inet6Address) ois.readObject(); Inet6Address nobj = (Inet6Address) ois.readObject();
ois.close();
if (nobj.equals(obj)) { if (nobj.equals(obj)) {
return true; return true;
......
...@@ -56,6 +56,8 @@ public class CheckJNI { ...@@ -56,6 +56,8 @@ public class CheckJNI {
while (ifs.hasMoreElements()) { while (ifs.hasMoreElements()) {
NetworkInterface nif = (NetworkInterface)ifs.nextElement(); NetworkInterface nif = (NetworkInterface)ifs.nextElement();
if (!nif.isUp())
continue;
Enumeration addrs = nif.getInetAddresses(); Enumeration addrs = nif.getInetAddresses();
while (addrs.hasMoreElements()) { while (addrs.hasMoreElements()) {
InetAddress addr = (InetAddress) addrs.nextElement(); InetAddress addr = (InetAddress) addrs.nextElement();
......
...@@ -76,6 +76,10 @@ public class SetOutgoingIf { ...@@ -76,6 +76,10 @@ public class SetOutgoingIf {
// now determine what (if any) type of addresses are assigned to this interface // now determine what (if any) type of addresses are assigned to this interface
for (InetAddress addr : Collections.list(nic.getInetAddresses())) { for (InetAddress addr : Collections.list(nic.getInetAddresses())) {
if (addr.isAnyLocalAddress())
continue;
System.out.println(" addr " + addr);
if (addr instanceof Inet4Address) { if (addr instanceof Inet4Address) {
netIf.ipv4Address(true); netIf.ipv4Address(true);
} else if (addr instanceof Inet6Address) { } else if (addr instanceof Inet6Address) {
......
...@@ -67,9 +67,10 @@ public class B6181108 implements Runnable { ...@@ -67,9 +67,10 @@ public class B6181108 implements Runnable {
out.flush(); out.flush();
s.close(); s.close();
ss.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try { ss.close(); } catch (IOException unused) {}
} }
} }
...@@ -100,6 +101,7 @@ public class B6181108 implements Runnable { ...@@ -100,6 +101,7 @@ public class B6181108 implements Runnable {
URLConnection urlc = url.openConnection(); URLConnection urlc = url.openConnection();
int i = ((HttpURLConnection)(urlc)).getResponseCode(); int i = ((HttpURLConnection)(urlc)).getResponseCode();
System.out.println ("response code = " + i); System.out.println ("response code = " + i);
ResponseCache.setDefault(null);
} }
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import java.io.*; import java.io.*;
import java.nio.*;
import sun.net.www.ParseUtil; import sun.net.www.ParseUtil;
import javax.net.ssl.*; import javax.net.ssl.*;
...@@ -43,11 +42,16 @@ public class ResponseCacheTest implements Runnable { ...@@ -43,11 +42,16 @@ public class ResponseCacheTest implements Runnable {
static URL url1; static URL url1;
static URL url2; static URL url2;
static String FNPrefix, OutFNPrefix; static String FNPrefix, OutFNPrefix;
static List<Closeable> streams = new ArrayList<>();
static List<File> files = new ArrayList<>();
/* /*
* Our "http" server to return a 404 */ * Our "http" server to return a 404 */
public void run() { public void run() {
Socket s = null;
FileInputStream fis = null;
try { try {
Socket s = ss.accept(); s = ss.accept();
InputStream is = s.getInputStream (); InputStream is = s.getInputStream ();
BufferedReader r = new BufferedReader(new InputStreamReader(is)); BufferedReader r = new BufferedReader(new InputStreamReader(is));
...@@ -68,7 +72,7 @@ public class ResponseCacheTest implements Runnable { ...@@ -68,7 +72,7 @@ public class ResponseCacheTest implements Runnable {
out.print("Content-Length: "+file2.length()+"\r\n"); out.print("Content-Length: "+file2.length()+"\r\n");
out.print("Connection: close\r\n"); out.print("Connection: close\r\n");
out.print("\r\n"); out.print("\r\n");
FileInputStream fis = new FileInputStream(file2); fis = new FileInputStream(file2);
byte[] buf = new byte[(int)file2.length()]; byte[] buf = new byte[(int)file2.length()];
int len; int len;
while ((len = fis.read(buf)) != -1) { while ((len = fis.read(buf)) != -1) {
...@@ -81,6 +85,10 @@ public class ResponseCacheTest implements Runnable { ...@@ -81,6 +85,10 @@ public class ResponseCacheTest implements Runnable {
ss.close(); ss.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try { ss.close(); } catch (IOException unused) {}
try { s.close(); } catch (IOException unused) {}
try { fis.close(); } catch (IOException unused) {}
} }
} }
static class NameVerifier implements HostnameVerifier { static class NameVerifier implements HostnameVerifier {
...@@ -144,11 +152,14 @@ static class NameVerifier implements HostnameVerifier { ...@@ -144,11 +152,14 @@ static class NameVerifier implements HostnameVerifier {
// assert (headers1 == headers2 && file1 == file2.2) // assert (headers1 == headers2 && file1 == file2.2)
File file1 = new File(OutFNPrefix+"file1"); File file1 = new File(OutFNPrefix+"file1");
File file2 = new File(OutFNPrefix+"file2.2"); File file2 = new File(OutFNPrefix+"file2.2");
files.add(file1);
files.add(file2);
System.out.println("headers1"+headers1+"\nheaders2="+headers2); System.out.println("headers1"+headers1+"\nheaders2="+headers2);
if (!headers1.equals(headers2) || file1.length() != file2.length()) { if (!headers1.equals(headers2) || file1.length() != file2.length()) {
throw new RuntimeException("test failed"); throw new RuntimeException("test failed");
} }
} }
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
try { try {
ResponseCache.setDefault(new MyResponseCache()); ResponseCache.setDefault(new MyResponseCache());
...@@ -157,6 +168,12 @@ static class NameVerifier implements HostnameVerifier { ...@@ -157,6 +168,12 @@ static class NameVerifier implements HostnameVerifier {
new ResponseCacheTest(); new ResponseCacheTest();
} finally{ } finally{
ResponseCache.setDefault(null); ResponseCache.setDefault(null);
for (Closeable c: streams) {
try { c.close(); } catch (IOException unused) {}
}
for (File f: files) {
f.delete();
}
} }
} }
...@@ -184,6 +201,7 @@ static class NameVerifier implements HostnameVerifier { ...@@ -184,6 +201,7 @@ static class NameVerifier implements HostnameVerifier {
public MyCacheResponse(String filename) { public MyCacheResponse(String filename) {
try { try {
fis = new FileInputStream(new File(filename)); fis = new FileInputStream(new File(filename));
streams.add(fis);
ObjectInputStream ois = new ObjectInputStream(fis); ObjectInputStream ois = new ObjectInputStream(fis);
headers = (Map<String,List<String>>)ois.readObject(); headers = (Map<String,List<String>>)ois.readObject();
} catch (Exception ex) { } catch (Exception ex) {
...@@ -206,6 +224,8 @@ static class NameVerifier implements HostnameVerifier { ...@@ -206,6 +224,8 @@ static class NameVerifier implements HostnameVerifier {
try { try {
File file = new File(filename); File file = new File(filename);
fos = new FileOutputStream(file); fos = new FileOutputStream(file);
streams.add(fos);
files.add(file);
ObjectOutputStream oos = new ObjectOutputStream(fos); ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(rspHeaders); oos.writeObject(rspHeaders);
} catch (Exception ex) { } catch (Exception ex) {
......
...@@ -39,6 +39,7 @@ import java.io.*; ...@@ -39,6 +39,7 @@ import java.io.*;
public class getResponseCode { public class getResponseCode {
static URL url; static URL url;
static String FNPrefix; static String FNPrefix;
static List<Closeable> resources = new ArrayList<>();
getResponseCode() throws Exception { getResponseCode() throws Exception {
url = new URL("http://localhost/file1.cache"); url = new URL("http://localhost/file1.cache");
...@@ -57,6 +58,9 @@ public class getResponseCode { ...@@ -57,6 +58,9 @@ public class getResponseCode {
new getResponseCode(); new getResponseCode();
} finally{ } finally{
ResponseCache.setDefault(null); ResponseCache.setDefault(null);
for (Closeable c : resources) {
try { c.close(); } catch (IOException unused) {}
}
} }
} }
...@@ -77,6 +81,7 @@ public class getResponseCode { ...@@ -77,6 +81,7 @@ public class getResponseCode {
public MyResponse(String filename) { public MyResponse(String filename) {
try { try {
fis = new FileInputStream(new File(filename)); fis = new FileInputStream(new File(filename));
resources.add(fis);
headers = (Map<String,List<String>>)new ObjectInputStream(fis).readObject(); headers = (Map<String,List<String>>)new ObjectInputStream(fis).readObject();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex.getMessage()); throw new RuntimeException(ex.getMessage());
......
/*
* 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");
}
}
}
...@@ -47,6 +47,7 @@ public class CloseAvailable implements Runnable { ...@@ -47,6 +47,7 @@ public class CloseAvailable implements Runnable {
t.start(); t.start();
Socket soc = ss.accept(); Socket soc = ss.accept();
ss.close();
DataInputStream is = new DataInputStream(soc.getInputStream()); DataInputStream is = new DataInputStream(soc.getInputStream());
is.close(); is.close();
...@@ -64,7 +65,7 @@ public class CloseAvailable implements Runnable { ...@@ -64,7 +65,7 @@ public class CloseAvailable implements Runnable {
public void run() { public void run() {
try { try {
Socket s = new Socket(addr, port); Socket s = new Socket(addr, port);
s.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -33,29 +33,32 @@ import java.io.*; ...@@ -33,29 +33,32 @@ import java.io.*;
public class DeadlockTest { public class DeadlockTest {
public static void main(String [] argv) throws Exception { public static void main(String [] argv) throws Exception {
ServerSocket ss = new ServerSocket(0);
Socket clientSocket = new Socket();
// Start the server thread try {
Thread s1 = new Thread(new ServerThread()); // Start the server thread
s1.start(); Thread s1 = new Thread(new ServerThread(ss));
s1.start();
// Sleep to make sure s1 has created a server socket
Thread.sleep(1000); // Start the client thread
ClientThread ct = new ClientThread(clientSocket, ss.getLocalPort());
// Start the client thread Thread c1 = new Thread(ct);
ClientThread ct = new ClientThread(); c1.start();
Thread c1 = new Thread(ct);
c1.start(); // Wait for the client thread to finish
c1.join(20000);
// Wait for the client thread to finish
c1.join(40000); // If timeout, we assume there is a deadlock
if (c1.isAlive() == true) {
// If timeout, we assume there is a deadlock // Close the socket to force the server thread
if (c1.isAlive() == true) { // terminate too
// Close the socket to force the server thread s1.stop();
// terminate too throw new Exception("Takes too long. Dead lock");
s1.stop(); }
ct.getSock().close(); } finally {
throw new Exception("Takes too long. Dead lock"); ss.close();
clientSocket.close();
} }
} }
} }
...@@ -71,8 +74,8 @@ class ServerThread implements Runnable { ...@@ -71,8 +74,8 @@ class ServerThread implements Runnable {
Socket sock; Socket sock;
public ServerThread() throws Exception { public ServerThread(ServerSocket serverSocket) throws Exception {
this.server = serverSocket;
} }
public void ping(int cnt) { public void ping(int cnt) {
...@@ -85,7 +88,6 @@ class ServerThread implements Runnable { ...@@ -85,7 +88,6 @@ class ServerThread implements Runnable {
try { try {
if (Thread.currentThread().getName().startsWith("child") == false) { if (Thread.currentThread().getName().startsWith("child") == false) {
server = new ServerSocket(4711);
sock = server.accept(); sock = server.accept();
new Thread(this, "child").start(); new Thread(this, "child").start();
...@@ -107,6 +109,7 @@ class ServerThread implements Runnable { ...@@ -107,6 +109,7 @@ class ServerThread implements Runnable {
} }
} catch (Throwable e) { } catch (Throwable e) {
System.out.println(e);
// If anything goes wrong, just quit. // If anything goes wrong, just quit.
} }
...@@ -141,10 +144,11 @@ class ClientThread implements Runnable { ...@@ -141,10 +144,11 @@ class ClientThread implements Runnable {
Socket sock; Socket sock;
public ClientThread() throws Exception { public ClientThread(Socket sock, int serverPort) throws Exception {
try { try {
System.out.println("About to create a socket"); System.out.println("About to connect the client socket");
sock = new Socket(InetAddress.getLocalHost().getHostName(), 4711); this.sock = sock;
this.sock.connect(new InetSocketAddress("localhost", serverPort));
System.out.println("connected"); System.out.println("connected");
out = new ObjectOutputStream(sock.getOutputStream()); out = new ObjectOutputStream(sock.getOutputStream());
...@@ -156,10 +160,6 @@ class ClientThread implements Runnable { ...@@ -156,10 +160,6 @@ class ClientThread implements Runnable {
} }
} }
public Socket getSock() {
return sock;
}
private int cnt = 1; private int cnt = 1;
public void run() { public void run() {
...@@ -213,6 +213,7 @@ class Message implements java.io.Serializable { ...@@ -213,6 +213,7 @@ class Message implements java.io.Serializable {
System.out.println("write message done " + cnt++); System.out.println("write message done " + cnt++);
} catch (IOException ioe) { } catch (IOException ioe) {
// Ignore the exception // Ignore the exception
System.out.println(ioe);
} }
} }
} }
......
...@@ -81,7 +81,7 @@ public class LingerTest { ...@@ -81,7 +81,7 @@ public class LingerTest {
public void run() { public void run() {
System.out.println ("Another starts"); System.out.println ("Another starts");
try { try {
Thread.currentThread().sleep(delay); Thread.sleep(delay);
Socket s = new Socket("localhost", port); Socket s = new Socket("localhost", port);
synchronized (this) { synchronized (this) {
connected = true; connected = true;
...@@ -105,7 +105,6 @@ public class LingerTest { ...@@ -105,7 +105,6 @@ public class LingerTest {
Socket s1 = new Socket("localhost", ss.getLocalPort()); Socket s1 = new Socket("localhost", ss.getLocalPort());
Socket s2 = ss.accept(); Socket s2 = ss.accept();
// setup conditions for untransmitted data and lengthy // setup conditions for untransmitted data and lengthy
// linger interval // linger interval
s1.setSendBufferSize(128*1024); s1.setSendBufferSize(128*1024);
...@@ -122,14 +121,15 @@ public class LingerTest { ...@@ -122,14 +121,15 @@ public class LingerTest {
thr.start(); thr.start();
// give sender time to queue the data // give sender time to queue the data
Thread.currentThread().sleep(1000); Thread.sleep(1000);
// close the socket asynchronously // close the socket asynchronously
(new Thread(new Closer(s1))).start(); (new Thread(new Closer(s1))).start();
// give another time to run // give another time to run
Thread.currentThread().sleep(10000); Thread.sleep(10000);
ss.close();
// check that another is done // check that another is done
if (!another.connected()) { if (!another.connected()) {
throw new RuntimeException("Another thread is blocked"); throw new RuntimeException("Another thread is blocked");
......
...@@ -58,11 +58,10 @@ public class LinkLocal { ...@@ -58,11 +58,10 @@ public class LinkLocal {
} catch (SocketException e) { } catch (SocketException e) {
failed++; failed++;
System.out.println("Test failed: " + e); 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 { static void UdpTest(InetAddress ia, boolean connected) throws Exception {
...@@ -93,16 +92,16 @@ public class LinkLocal { ...@@ -93,16 +92,16 @@ public class LinkLocal {
ds1.send(p); ds1.send(p);
System.out.println("Packet has been sent."); System.out.println("Packet has been sent.");
ds2.setSoTimeout(1000); ds2.setSoTimeout(5000);
ds2.receive(p); ds2.receive(p);
System.out.println("Test passed - packet received."); System.out.println("Test passed - packet received.");
} catch (SocketException e) { } catch (SocketException e) {
failed++; failed++;
System.out.println("Test failed: " + e); System.out.println("Test failed: " + e);
} finally {
ds1.close();
ds2.close();
} }
ds1.close();
ds2.close();
} }
static void TestAddress(InetAddress ia) throws Exception { static void TestAddress(InetAddress ia) throws Exception {
...@@ -138,6 +137,9 @@ public class LinkLocal { ...@@ -138,6 +137,9 @@ public class LinkLocal {
Enumeration nifs = NetworkInterface.getNetworkInterfaces(); Enumeration nifs = NetworkInterface.getNetworkInterfaces();
while (nifs.hasMoreElements()) { while (nifs.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface)nifs.nextElement(); NetworkInterface ni = (NetworkInterface)nifs.nextElement();
if (!ni.isUp())
continue;
Enumeration addrs = ni.getInetAddresses(); Enumeration addrs = ni.getInetAddresses();
while (addrs.hasMoreElements()) { while (addrs.hasMoreElements()) {
InetAddress addr = (InetAddress)addrs.nextElement(); InetAddress addr = (InetAddress)addrs.nextElement();
......
...@@ -39,6 +39,7 @@ public class ProxyCons { ...@@ -39,6 +39,7 @@ public class ProxyCons {
public void run () { public void run () {
try { try {
Socket s = server.accept (); Socket s = server.accept ();
s.close();
while (!finished ()) { while (!finished ()) {
Thread.sleep (500); Thread.sleep (500);
} }
...@@ -58,10 +59,9 @@ public class ProxyCons { ...@@ -58,10 +59,9 @@ public class ProxyCons {
public ProxyCons() { public ProxyCons() {
} }
void test() { void test() throws Exception {
ServerSocket ss = new ServerSocket(0);
try { try {
ServerSocket ss = new ServerSocket();
ss.bind(new InetSocketAddress(0));
Server s = new Server(ss); Server s = new Server(ss);
s.start(); s.start();
Socket sock = new Socket(Proxy.NO_PROXY); Socket sock = new Socket(Proxy.NO_PROXY);
...@@ -70,10 +70,12 @@ public class ProxyCons { ...@@ -70,10 +70,12 @@ public class ProxyCons {
sock.close(); sock.close();
} catch (java.io.IOException e) { } catch (java.io.IOException e) {
throw new RuntimeException(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(); ProxyCons c = new ProxyCons();
c.test(); c.test();
} }
......
...@@ -44,7 +44,7 @@ public class ReadTimeout { ...@@ -44,7 +44,7 @@ public class ReadTimeout {
sin = InetAddress.getLocalHost(); sin = InetAddress.getLocalHost();
srv = new ServerSocket(port); srv = new ServerSocket(port);
port = srv.getLocalPort(); port = srv.getLocalPort();
soc = new Socket(sin, port, true); soc = new Socket(sin, port);
soc1 = srv.accept(); soc1 = srv.accept();
soc.setSoTimeout(tout); soc.setSoTimeout(tout);
...@@ -53,10 +53,10 @@ public class ReadTimeout { ...@@ -53,10 +53,10 @@ public class ReadTimeout {
os = soc1.getOutputStream(); os = soc1.getOutputStream();
is.read(); is.read();
} catch(InterruptedIOException e) { } catch(InterruptedIOException e) {
} finally {
soc.close();
soc1.close();
srv.close();
} }
soc.close();
soc1.close();
srv.close();
} }
} }
...@@ -32,29 +32,14 @@ import java.net.Socket; ...@@ -32,29 +32,14 @@ import java.net.Socket;
import java.net.ServerSocket; import java.net.ServerSocket;
public class SetReceiveBufferSize { 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 { public static void main(String[] args) throws Exception {
SetReceiveBufferSize s = new SetReceiveBufferSize(); SetReceiveBufferSize s = new SetReceiveBufferSize();
} }
public SetReceiveBufferSize() throws Exception { public SetReceiveBufferSize() throws Exception {
ServerSocket ss = new ServerSocket(0); ServerSocket ss = new ServerSocket(0);
Server serv = new Server(ss);
serv.start();
Socket s = new Socket("localhost", ss.getLocalPort()); Socket s = new Socket("localhost", ss.getLocalPort());
Socket accepted = ss.accept();
try { try {
s.setReceiveBufferSize(0); s.setReceiveBufferSize(0);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
...@@ -62,6 +47,8 @@ public class SetReceiveBufferSize { ...@@ -62,6 +47,8 @@ public class SetReceiveBufferSize {
} catch (Exception ex) { } catch (Exception ex) {
} finally { } finally {
ss.close(); ss.close();
s.close();
accepted.close();
} }
throw new RuntimeException("IllegalArgumentException not thrown!"); throw new RuntimeException("IllegalArgumentException not thrown!");
} }
......
...@@ -30,36 +30,24 @@ ...@@ -30,36 +30,24 @@
import java.net.*; import java.net.*;
public class SetSoLinger implements Runnable { public class SetSoLinger {
static ServerSocket ss; static final int LINGER = 65546;
static InetAddress addr;
static int port;
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
boolean error = true; int value;
int linger = 65546; InetAddress addr = InetAddress.getLocalHost();
int value = 0; ServerSocket ss = new ServerSocket(0);
addr = InetAddress.getLocalHost(); int port = ss.getLocalPort();
ss = new ServerSocket(0);
port = ss.getLocalPort();
Thread t = new Thread(new SetSoLinger()); Socket s = new Socket(addr, port);
t.start();
Socket soc = ss.accept(); Socket soc = ss.accept();
soc.setSoLinger(true, linger); soc.setSoLinger(true, LINGER);
value = soc.getSoLinger(); value = soc.getSoLinger();
soc.close(); soc.close();
s.close();
ss.close();
if(value != 65535) if(value != 65535)
throw new RuntimeException("Failed. Value not properly reduced."); throw new RuntimeException("Failed. Value not properly reduced.");
} }
public void run() {
try {
Socket s = new Socket(addr, port);
} catch (Exception e) {
e.printStackTrace();
}
}
} }
...@@ -36,12 +36,14 @@ public class ShutdownBoth { ...@@ -36,12 +36,14 @@ public class ShutdownBoth {
Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort()); Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort());
Socket s2 = ss.accept(); Socket s2 = ss.accept();
s1.shutdownInput(); try {
s1.shutdownOutput(); // failed b55 s1.shutdownInput();
s1.shutdownOutput(); // failed b55
s1.close(); } finally {
s2.close(); s1.close();
ss.close(); s2.close();
ss.close();
}
} }
} }
...@@ -52,9 +52,10 @@ public class SoTimeout implements Runnable { ...@@ -52,9 +52,10 @@ public class SoTimeout implements Runnable {
t.start(); t.start();
Socket s = serverSocket.accept(); Socket s = serverSocket.accept();
serverSocket.close();
// set a 1 second timeout on the socket // set a 5 second timeout on the socket
s.setSoTimeout(1000); s.setSoTimeout(5000);
s.getInputStream().read(b, 0, b.length); s.getInputStream().read(b, 0, b.length);
s.close(); s.close();
...@@ -64,7 +65,7 @@ public class SoTimeout implements Runnable { ...@@ -64,7 +65,7 @@ public class SoTimeout implements Runnable {
// this sequence should complete fairly quickly and if it // this sequence should complete fairly quickly and if it
// takes something resembling the the SoTimeout value then // takes something resembling the the SoTimeout value then
// we are probably incorrectly blocking and not waking up // we are probably incorrectly blocking and not waking up
if (waited > 500) { if (waited > 2000) {
throw new Exception("shouldn't take " + waited + " to complete"); throw new Exception("shouldn't take " + waited + " to complete");
} }
} }
......
...@@ -31,18 +31,16 @@ import java.net.*; ...@@ -31,18 +31,16 @@ import java.net.*;
import java.io.*; import java.io.*;
public class Timeout { public class Timeout {
public static ServerSocket sock;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
boolean success = false; boolean success = false;
ServerSocket sock = new ServerSocket(0);
try { try {
ServerSocket sock;
sock = new ServerSocket(2333);
sock.setSoTimeout(2); sock.setSoTimeout(2);
sock.accept(); sock.accept();
} catch (InterruptedIOException e) { } catch (InterruptedIOException e) {
success = true; success = true;
} finally {
sock.close();
} }
if (!success) if (!success)
throw new RuntimeException("Socket timeout failure."); throw new RuntimeException("Socket timeout failure.");
......
...@@ -90,63 +90,64 @@ public class UrgentDataTest { ...@@ -90,63 +90,64 @@ public class UrgentDataTest {
} }
public void run () throws Exception { public void run () throws Exception {
if (isClient) { try {
client = new Socket (clHost, clPort); if (isClient) {
clis = client.getInputStream(); client = new Socket (clHost, clPort);
clos = client.getOutputStream(); clis = client.getInputStream();
client.setOOBInline (true); clos = client.getOutputStream();
if (client.getOOBInline() != true) { client.setOOBInline (true);
throw new RuntimeException ("Setting OOBINLINE failed"); 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<s.length(); y++) {
int c = sis.read ();
if (c != (int)s.charAt (y)) {
throw new RuntimeException ("Unexpected character read");
} }
} }
// Do the same from server to client if (isServer) {
sos.write ("Hello".getBytes ()); server = listener.accept ();
server.sendUrgentData (101); sis = server.getInputStream();
sos.write ("World".getBytes ()); sos = server.getOutputStream();
} }
if (isClient) { if (isClient) {
// read Hello world from client (during which oob byte must have been read) clos.write ("Hello".getBytes ());
s="Hello"; client.sendUrgentData (100);
for (int y=0; y<s.length(); y++) { clos.write ("world".getBytes ());
int c = clis.read ();
if (c != (int)s.charAt (y)) {
throw new RuntimeException ("Unexpected character read");
}
} }
if (clis.read() != 101) { // read Hello world from server (during which oob byte must have been dropped)
throw new RuntimeException ("OOB byte not received"); String s = "Helloworld";
if (isServer) {
for (int y=0; y<s.length(); y++) {
int c = sis.read ();
if (c != (int)s.charAt (y)) {
throw new RuntimeException ("Unexpected character read");
}
}
// Do the same from server to client
sos.write ("Hello".getBytes ());
server.sendUrgentData (101);
sos.write ("World".getBytes ());
} }
s="World"; if (isClient) {
for (int y=0; y<s.length(); y++) { // read Hello world from client (during which oob byte must have been read)
int c = clis.read (); s="Hello";
if (c != (int)s.charAt (y)) { for (int y=0; y<s.length(); y++) {
throw new RuntimeException ("Unexpected character read"); int c = clis.read ();
if (c != (int)s.charAt (y)) {
throw new RuntimeException ("Unexpected character read");
}
}
if (clis.read() != 101) {
throw new RuntimeException ("OOB byte not received");
}
s="World";
for (int y=0; y<s.length(); y++) {
int c = clis.read ();
if (c != (int)s.charAt (y)) {
throw new RuntimeException ("Unexpected character read");
}
} }
} }
} finally {
if (listener != null) listener.close();
if (client != null) client.close ();
if (server != null) server.close ();
} }
if (isClient)
client.close ();
if (isServer)
server.close ();
} }
} }
...@@ -61,7 +61,6 @@ public class BrokenPipe { ...@@ -61,7 +61,6 @@ public class BrokenPipe {
try { try {
client.getOutputStream().write(new byte[1000000]); client.getOutputStream().write(new byte[1000000]);
} catch (IOException ioe) { } catch (IOException ioe) {
/* /*
* Check that the exception text doesn't indicate the * Check that the exception text doesn't indicate the
* socket is closed. In tiger we should be able to * socket is closed. In tiger we should be able to
...@@ -71,8 +70,9 @@ public class BrokenPipe { ...@@ -71,8 +70,9 @@ public class BrokenPipe {
if (text.toLowerCase().indexOf("closed") >= 0) { if (text.toLowerCase().indexOf("closed") >= 0) {
throw ioe; throw ioe;
} }
} finally {
server.close();
} }
server.close();
} }
} }
...@@ -39,27 +39,28 @@ public class Restart { ...@@ -39,27 +39,28 @@ public class Restart {
*/ */
public static void main(String args[]) throws Exception { 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); s1 = new Socket(InetAddress.getLocalHost(), port);
ServerSocket ss = new ServerSocket(); s2 = ss.accept();
ss.bind(isa);
int port = ss.getLocalPort(); // close server socket and the accepted connection
ss.close();
s2.close();
Socket s1 = new Socket(InetAddress.getLocalHost(), port); ss = new ServerSocket();
Socket s2 = ss.accept(); ss.bind( new InetSocketAddress(port) );
ss.close();
// close server socket and the accepted connection // close the client socket
ss.close(); s1.close();
s2.close(); } finally {
if (ss != null) ss.close();
boolean failed = false; if (s1 != null) s1.close();
if (s2 != null) s2.close();
ss = new ServerSocket(); }
ss.bind( new InetSocketAddress(port) );
ss.close();
// close the client socket
s1.close();
} }
} }
...@@ -32,68 +32,37 @@ import java.io.*; ...@@ -32,68 +32,37 @@ import java.io.*;
import java.net.*; import java.net.*;
public class SocketClosedException { 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 { static void doServerSide() throws Exception {
ServerSocket serverSocket = new ServerSocket(serverPort); try {
serverPort = serverSocket.getLocalPort(); Socket socket = serverSocket.accept();
/*
* 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();
}
/* OutputStream os = socket.getOutputStream();
* 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 {
/* os.write(85);
* Wait for server to get started. os.flush();
*/ socket.close();
while (!serverReady) { } finally {
Thread.sleep(5000); 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(); InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
int read = is.read(); is.read();
socket.close(); socket.close();
read = is.read(); is.read();
} }
static int serverPort = 0; static ServerSocket serverSocket;
static Exception serverException = null; static Exception serverException = null;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
serverSocket = new ServerSocket(0);
startServer(); startServer();
try { try {
doClientSide(); doClientSide(serverSocket.getLocalPort());
} catch (SocketException e) { } catch (SocketException e) {
if (!e.getMessage().equalsIgnoreCase("Socket closed")) { if (!e.getMessage().equalsIgnoreCase("Socket closed")) {
throw new Exception("Received a wrong exception message: " + throw new Exception("Received a wrong exception message: " +
...@@ -108,21 +77,14 @@ public class SocketClosedException { ...@@ -108,21 +77,14 @@ public class SocketClosedException {
} }
static void startServer() { static void startServer() {
Thread serverThread = new Thread() { (new Thread() {
public void run() { public void run() {
try { try {
doServerSide(); doServerSide();
} catch (Exception e) { } catch (Exception e) {
/* e.printStackTrace();
* server thread just died.
* Release the client, if not active already...
*/
System.err.println("Server died...");
serverReady = true;
serverException = e;
} }
} }
}; }).start();
serverThread.start();
} }
} }
...@@ -31,26 +31,24 @@ import java.net.*; ...@@ -31,26 +31,24 @@ import java.net.*;
import java.io.*; import java.io.*;
public class SocketTimeout { public class SocketTimeout {
static final int TIMEOUT = 1000;
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
InetAddress sin = null; InetAddress sin = InetAddress.getLocalHost();
Socket soc = null,soc1 = null; Socket soc = null,soc1 = null;
InputStream is = null; InputStream is = null;
OutputStream os = null;
ServerSocket srv = null; ServerSocket srv = null;
int port = 0; int port = 0;
int tout = 1000;
sin = InetAddress.getLocalHost(); srv = new ServerSocket(0);
srv = new ServerSocket(port);
port = srv.getLocalPort(); port = srv.getLocalPort();
soc = new Socket(sin, port); soc = new Socket(sin, port);
soc1 = srv.accept(); soc1 = srv.accept();
soc.setSoTimeout(tout); soc.setSoTimeout(TIMEOUT);
srv.setSoTimeout(tout); srv.setSoTimeout(TIMEOUT);
try { try {
is = soc.getInputStream(); is = soc.getInputStream();
os = soc1.getOutputStream();
is.read(); is.read();
} catch(InterruptedIOException e) { } catch(InterruptedIOException e) {
try { try {
...@@ -59,6 +57,9 @@ public class SocketTimeout { ...@@ -59,6 +57,9 @@ public class SocketTimeout {
} catch(NoClassDefFoundError e1) { } catch(NoClassDefFoundError e1) {
throw new Exception ("SocketTimeoutException: not found"); throw new Exception ("SocketTimeoutException: not found");
} }
} finally {
soc.close();
soc1.close();
} }
// now check accept // now check accept
...@@ -72,12 +73,14 @@ public class SocketTimeout { ...@@ -72,12 +73,14 @@ public class SocketTimeout {
} catch(NoClassDefFoundError e1) { } catch(NoClassDefFoundError e1) {
throw new Exception ("SocketTimeoutException: not found"); throw new Exception ("SocketTimeoutException: not found");
} }
} finally {
srv.close();
} }
// Now check DatagramSocket.receive() // Now check DatagramSocket.receive()
DatagramSocket dg = new DatagramSocket (); DatagramSocket dg = new DatagramSocket ();
dg.setSoTimeout (tout); dg.setSoTimeout (TIMEOUT);
try { try {
dg.receive (new DatagramPacket (new byte [64], 64)); dg.receive (new DatagramPacket (new byte [64], 64));
...@@ -88,11 +91,8 @@ public class SocketTimeout { ...@@ -88,11 +91,8 @@ public class SocketTimeout {
} catch(NoClassDefFoundError e1) { } catch(NoClassDefFoundError e1) {
throw new Exception ("SocketTimeoutException: not found"); throw new Exception ("SocketTimeoutException: not found");
} }
} finally {
dg.close();
} }
soc.close();
soc1.close();
srv.close();
dg.close();
} }
} }
...@@ -53,11 +53,13 @@ public class GetContent implements Runnable { ...@@ -53,11 +53,13 @@ public class GetContent implements Runnable {
// wait for client to read response - otherwise http // wait for client to read response - otherwise http
// client get error and re-establish connection // client get error and re-establish connection
Thread.currentThread().sleep(2000); Thread.sleep(2000);
s.close(); s.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try { ss.close(); } catch (IOException unused) {}
} }
} }
...@@ -81,8 +83,6 @@ public class GetContent implements Runnable { ...@@ -81,8 +83,6 @@ public class GetContent implements Runnable {
error = false; error = false;
} }
ss.close();
if (error) if (error)
throw new RuntimeException("No IOException generated."); throw new RuntimeException("No IOException generated.");
} }
......
...@@ -27,20 +27,45 @@ ...@@ -27,20 +27,45 @@
* @summary Test for FileNotFoundException when loading bogus class * @summary Test for FileNotFoundException when loading bogus class
*/ */
import java.net.*; import java.io.InputStream;
import java.io.*; 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 class ClassLoad {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
boolean error = true; 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 { 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"; String name = args.length >= 2 ? args[1] : "foo.bar.Baz";
ClassLoader loader = new URLClassLoader(new URL[] { url }); ClassLoader loader = new URLClassLoader(new URL[] { url });
System.out.println(url);
Class c = loader.loadClass(name); Class c = loader.loadClass(name);
System.out.println("Loaded class \"" + c.getName() + "\"."); System.out.println("Loaded class \"" + c.getName() + "\".");
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
System.out.println(ex);
error = false; error = false;
} finally {
server.stop(0);
} }
if (error) if (error)
throw new RuntimeException("No ClassNotFoundException generated"); throw new RuntimeException("No ClassNotFoundException generated");
......
...@@ -56,7 +56,6 @@ public class DisconnectAfterEOF { ...@@ -56,7 +56,6 @@ public class DisconnectAfterEOF {
int cl = -1; int cl = -1;
int remaining = -1; int remaining = -1;
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
Random r = new Random();
boolean close = false; boolean close = false;
boolean inBody = false; boolean inBody = false;
...@@ -239,8 +238,6 @@ public class DisconnectAfterEOF { ...@@ -239,8 +238,6 @@ public class DisconnectAfterEOF {
} }
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
Random r = new Random();
// start server // start server
ServerSocket ss = new ServerSocket(0); ServerSocket ss = new ServerSocket(0);
Server svr = new Server(ss); Server svr = new Server(ss);
...@@ -273,7 +270,7 @@ public class DisconnectAfterEOF { ...@@ -273,7 +270,7 @@ public class DisconnectAfterEOF {
URLConnection uc1 = doRequest(uri); URLConnection uc1 = doRequest(uri);
doResponse(uc1); doResponse(uc1);
Thread.currentThread().sleep(2000); Thread.sleep(2000);
URLConnection uc2 = doRequest(uri); URLConnection uc2 = doRequest(uri);
......
...@@ -111,9 +111,8 @@ class myHttpServer implements Runnable, Cloneable { ...@@ -111,9 +111,8 @@ class myHttpServer implements Runnable, Cloneable {
} catch(Exception e) { } catch(Exception e) {
System.out.print("Server failure\n"); System.out.print("Server failure\n");
e.printStackTrace(); e.printStackTrace();
try { } finally {
serverSocket.close(); try { serverSocket.close(); } catch(IOException unused) {}
} catch(IOException e2) {}
} }
} else { } else {
try { try {
...@@ -127,10 +126,9 @@ class myHttpServer implements Runnable, Cloneable { ...@@ -127,10 +126,9 @@ class myHttpServer implements Runnable, Cloneable {
} catch(Exception e) { } catch(Exception e) {
// System.out.print("Service handler failure\n"); // System.out.print("Service handler failure\n");
// e.printStackTrace(); // e.printStackTrace();
} finally {
try { close(); } catch(IOException unused) {}
} }
try {
close();
} catch(IOException e2) {}
} }
} }
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
*/ */
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
...@@ -41,61 +41,56 @@ public class HttpContinueStackOverflow { ...@@ -41,61 +41,56 @@ public class HttpContinueStackOverflow {
static class Server implements Runnable { static class Server implements Runnable {
int port; int port;
ServerSocket serverSock ;
Server(int port) { Server() throws IOException {
this.port = port; serverSock = new ServerSocket(0);
}
int getLocalPort() {
return serverSock.getLocalPort();
} }
public void run() { public void run() {
Socket sock = null;
try { try {
/* bind to port and wait for connection */
ServerSocket serverSock = new ServerSocket( port );
serverSock.setSoTimeout(10000); serverSock.setSoTimeout(10000);
Socket sock = serverSock.accept(); sock = serverSock.accept();
/* setup streams and read http request */ /* setup streams and read http request */
BufferedReader in = new BufferedReader( BufferedReader in = new BufferedReader(
new InputStreamReader(sock.getInputStream())); new InputStreamReader(sock.getInputStream()));
PrintStream out = new PrintStream( sock.getOutputStream() ); PrintStream out = new PrintStream( sock.getOutputStream() );
String request = in.readLine(); in.readLine();
/* send continue followed by invalid response */ /* send continue followed by invalid response */
out.println("HTTP/1.1 100 Continue\r"); out.println("HTTP/1.1 100 Continue\r");
out.println("\r"); out.println("\r");
out.println("junk junk junk"); out.println("junk junk junk");
out.flush(); out.flush();
sock.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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 */ /* create the server */
Server s = new Server(port); Server s = new Server();
Thread thr = new Thread(s); (new Thread(s)).start();
thr.start();
/* wait for server to bind to port */
try {
Thread.currentThread().sleep(2000);
} catch (Exception e) { }
/* connect to server, connect to server and get response code */ /* 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(); HttpURLConnection conn = (HttpURLConnection)url.openConnection();
int respCode = conn.getResponseCode(); conn.getResponseCode();
System.out.println("TEST PASSED"); System.out.println("TEST PASSED");
} }
public static void main(String args[]) throws Exception { 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"); System.out.println("Testing 100-Continue");
new HttpContinueStackOverflow(port); new HttpContinueStackOverflow();
} }
} }
...@@ -37,11 +37,11 @@ class RedirServer extends Thread { ...@@ -37,11 +37,11 @@ class RedirServer extends Thread {
OutputStream os; OutputStream os;
int port; 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" + "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
"Server: Apache/1.3.14 (Unix)\r\n" + "Server: Apache/1.3.14 (Unix)\r\n" +
"Location: http://localhost:"; "Location: http://localhost:";
String reply2 = "/redirected.html\r\n" + String reply1Part2 = "/redirected.html\r\n" +
"Connection: close\r\n" + "Connection: close\r\n" +
"Content-Type: text/html; charset=iso-8859-1\r\n\r\n" + "Content-Type: text/html; charset=iso-8859-1\r\n\r\n" +
"<html>Hello</html>"; "<html>Hello</html>";
...@@ -49,9 +49,10 @@ class RedirServer extends Thread { ...@@ -49,9 +49,10 @@ class RedirServer extends Thread {
RedirServer (ServerSocket y) { RedirServer (ServerSocket y) {
s = y; s = y;
port = s.getLocalPort(); 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" + "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
"Server: Apache/1.3.14 (Unix)\r\n" + "Server: Apache/1.3.14 (Unix)\r\n" +
"Connection: close\r\n" + "Connection: close\r\n" +
...@@ -64,16 +65,24 @@ class RedirServer extends Thread { ...@@ -64,16 +65,24 @@ class RedirServer extends Thread {
is = s1.getInputStream (); is = s1.getInputStream ();
os = s1.getOutputStream (); os = s1.getOutputStream ();
is.read (); is.read ();
String reply = reply1 + port + reply2; String reply = reply1Part1 + port + reply1Part2;
os.write (reply.getBytes()); os.write (reply.getBytes());
os.close();
/* wait for redirected connection */ /* wait for redirected connection */
s.setSoTimeout (5000); s.setSoTimeout (5000);
s1 = s.accept (); s1 = s.accept ();
is = s1.getInputStream ();
os = s1.getOutputStream (); os = s1.getOutputStream ();
os.write (reply3.getBytes()); is.read();
os.write (reply2.getBytes());
os.close();
} }
catch (Exception e) { catch (Exception e) {
/* Just need thread to terminate */ /* 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 { ...@@ -84,10 +93,7 @@ public class Redirect307Test {
public static final int DELAY = 10; public static final int DELAY = 10;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
int nLoops = 1; int port;
int nSize = 10;
int port, n =0;
byte b[] = new byte[nSize];
RedirServer server; RedirServer server;
ServerSocket sock; ServerSocket sock;
...@@ -119,7 +125,8 @@ public class Redirect307Test { ...@@ -119,7 +125,8 @@ public class Redirect307Test {
} }
} }
catch(IOException e) { catch(IOException e) {
throw new RuntimeException ("Exception caught"); e.printStackTrace();
throw new RuntimeException ("Exception caught + " + e);
} }
} }
} }
...@@ -76,15 +76,19 @@ class RedirLimitServer extends Thread { ...@@ -76,15 +76,19 @@ class RedirLimitServer extends Thread {
is.read (); is.read ();
String reply = reply1 + port + "/redirect" + i + reply2; String reply = reply1 + port + "/redirect" + i + reply2;
os.write (reply.getBytes()); os.write (reply.getBytes());
os.close();
} }
s1 = s.accept (); s1 = s.accept ();
is = s1.getInputStream (); is = s1.getInputStream ();
os = s1.getOutputStream (); os = s1.getOutputStream ();
is.read (); is.read ();
os.write (reply3.getBytes()); os.write (reply3.getBytes());
os.close();
} }
catch (Exception e) { catch (Exception e) {
/* Just need thread to terminate */ /* Just need thread to terminate */
} finally {
try { s.close(); } catch (IOException unused) {}
} }
} }
}; };
......
...@@ -109,8 +109,11 @@ public class ResendPostBody { ...@@ -109,8 +109,11 @@ public class ResendPostBody {
while (!finished()) { while (!finished()) {
Thread.sleep (1000); Thread.sleep (1000);
} }
out.close();
} catch (Exception e) { } catch (Exception e) {
System.err.println ("Server Exception: " + e); System.err.println ("Server Exception: " + e);
} finally {
try { server.close(); } catch (IOException unused) {}
} }
} }
} }
...@@ -134,7 +137,7 @@ public class ResendPostBody { ...@@ -134,7 +137,7 @@ public class ResendPostBody {
public void execute () throws Exception { public void execute () throws Exception {
byte b[] = "X=ABCDEFGHZZZ".getBytes(); byte b[] = "X=ABCDEFGHZZZ".getBytes();
ss = new ServerSocket (0); ss = new ServerSocket (0);
server = new Server (ss); server = new Server (ss);
...@@ -163,8 +166,9 @@ public class ResendPostBody { ...@@ -163,8 +166,9 @@ public class ResendPostBody {
/* Read the response */ /* Read the response */
int resp = conURL.getResponseCode (); int resp = conURL.getResponseCode ();
server.setFinished (true);
if (resp != 200) if (resp != 200)
throw new RuntimeException ("Response code was not 200: " + resp); throw new RuntimeException ("Response code was not 200: " + resp);
server.setFinished (true);
} }
} }
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* @test /* @test
* @bug 4397096 * @bug 4397096
* @run main SetIfModifiedSince * @run main/othervm SetIfModifiedSince
* @summary setIfModifiedSince() of HttpURLConnection sets invalid date of default locale * @summary setIfModifiedSince() of HttpURLConnection sets invalid date of default locale
*/ */
......
...@@ -43,8 +43,9 @@ public class TimeoutTest { ...@@ -43,8 +43,9 @@ public class TimeoutTest {
try { try {
Socket s = server.accept (); Socket s = server.accept ();
while (!finished ()) { while (!finished ()) {
Thread.sleep (2000); Thread.sleep (1000);
} }
s.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
...@@ -70,9 +71,12 @@ public class TimeoutTest { ...@@ -70,9 +71,12 @@ public class TimeoutTest {
URL url = new URL ("http://127.0.0.1:"+ss.getLocalPort()); URL url = new URL ("http://127.0.0.1:"+ss.getLocalPort());
URLConnection urlc = url.openConnection (); URLConnection urlc = url.openConnection ();
InputStream is = urlc.getInputStream (); InputStream is = urlc.getInputStream ();
throw new RuntimeException("Should have received timeout");
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
s.done ();
return; return;
} finally {
s.done();
ss.close();
} }
} }
} }
...@@ -70,8 +70,10 @@ public class URLConnectionHeaders { ...@@ -70,8 +70,10 @@ public class URLConnectionHeaders {
w.newLine(); w.newLine();
w.flush(); w.flush();
s.close (); 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) {}
}
} }
} }
......
...@@ -58,6 +58,14 @@ public class ZeroContentLength { ...@@ -58,6 +58,14 @@ public class ZeroContentLength {
contentLength = cl; contentLength = cl;
} }
static synchronized String getResponse() {
return response;
}
static synchronized int getContentLength() {
return contentLength;
}
/* /*
* Worker thread to service single connection - can service * Worker thread to service single connection - can service
* multiple http requests on same connection. * multiple http requests on same connection.
...@@ -71,25 +79,44 @@ public class ZeroContentLength { ...@@ -71,25 +79,44 @@ public class ZeroContentLength {
this.id = id; this.id = id;
} }
final int CR = '\r';
final int LF = '\n';
public void run() { public void run() {
try { try {
s.setSoTimeout(2000); s.setSoTimeout(2000);
int max = 100; int max = 20; // there should only be 20 connections
InputStream in = new BufferedInputStream(s.getInputStream());
for (;;) { for (;;) {
// read entire request from client, until CR LF CR LF
// read entire request from client int c, total=0;
byte b[] = new byte[100];
InputStream in = s.getInputStream();
int n, total=0;
try { try {
do { while ((c = in.read()) > 0) {
n = in.read(b); total++;
if (n > 0) total += n; if (c == CR) {
} while (n > 0); if ((c = in.read()) > 0) {
} catch (SocketTimeoutException e) { } 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 + debug("worker " + id +
": Read request from client " + ": Read request from client " +
...@@ -105,19 +132,20 @@ public class ZeroContentLength { ...@@ -105,19 +132,20 @@ public class ZeroContentLength {
new BufferedOutputStream( new BufferedOutputStream(
s.getOutputStream() )); s.getOutputStream() ));
out.print("HTTP/1.1 " + response + "\r\n"); out.print("HTTP/1.1 " + getResponse() + "\r\n");
if (contentLength >= 0) { int clen = getContentLength();
out.print("Content-Length: " + contentLength + if (clen >= 0) {
out.print("Content-Length: " + clen +
"\r\n"); "\r\n");
} }
out.print("\r\n"); out.print("\r\n");
for (int i=0; i<contentLength; i++) { for (int i=0; i<clen; i++) {
out.write( (byte)'.' ); out.write( (byte)'.' );
} }
out.flush(); out.flush();
debug("worked " + id + debug("worked " + id +
": Sent response to client, length: " + contentLength); ": Sent response to client, length: " + clen);
if (--max == 0) { if (--max == 0) {
s.close(); s.close();
......
...@@ -58,6 +58,8 @@ public class B6521014 { ...@@ -58,6 +58,8 @@ public class B6521014 {
Enumeration e = NetworkInterface.getNetworkInterfaces(); Enumeration e = NetworkInterface.getNetworkInterfaces();
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
NetworkInterface ifc = (NetworkInterface) e.nextElement(); NetworkInterface ifc = (NetworkInterface) e.nextElement();
if (!ifc.isUp())
continue;
Enumeration addrs = ifc.getInetAddresses(); Enumeration addrs = ifc.getInetAddresses();
while (addrs.hasMoreElements()) { while (addrs.hasMoreElements()) {
InetAddress a = (InetAddress)addrs.nextElement(); InetAddress a = (InetAddress)addrs.nextElement();
......
...@@ -38,7 +38,6 @@ public class TcpTest extends Tests { ...@@ -38,7 +38,6 @@ public class TcpTest extends Tests {
static InetAddress ia4any; static InetAddress ia4any;
static InetAddress ia6any; static InetAddress ia6any;
static Inet6Address ia6addr; static Inet6Address ia6addr;
static InetAddress ia6bad; /* a global 6to4 IPv6 address, which cant be connected to */
static Inet4Address ia4addr; static Inet4Address ia4addr;
static { static {
...@@ -47,14 +46,6 @@ public class TcpTest extends Tests { ...@@ -47,14 +46,6 @@ public class TcpTest extends Tests {
try { try {
ia4any = InetAddress.getByName ("0.0.0.0"); ia4any = InetAddress.getByName ("0.0.0.0");
ia6any = InetAddress.getByName ("::0"); ia6any = InetAddress.getByName ("::0");
if (ia6addr != null) {
int scope = ia6addr.getScopeId();
if (scope != 0) {
ia6bad = InetAddress.getByName ("fe80::1:2:3:4:5:6%"+scope);
}
} else {
ia6bad = InetAddress.getByName ("fe80::1:2:3:4:5:6");
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -69,7 +60,6 @@ public class TcpTest extends Tests { ...@@ -69,7 +60,6 @@ public class TcpTest extends Tests {
dprintln ("Local Addresses"); dprintln ("Local Addresses");
dprintln (ia4addr.toString()); dprintln (ia4addr.toString());
dprintln (ia6addr.toString()); dprintln (ia6addr.toString());
dprintln ("Bad address: " + ia6bad);
test1 (0); test1 (0);
test1 (5100); test1 (5100);
test2(); test2();
...@@ -224,19 +214,6 @@ public class TcpTest extends Tests { ...@@ -224,19 +214,6 @@ public class TcpTest extends Tests {
c1.close (); c2.close(); c1.close (); c2.close();
s1.close (); s2.close(); s1.close (); s2.close();
/* check if connect() timesout when connecting to unknown dest. */
c1 = new Socket();
t1 = System.currentTimeMillis();
InetSocketAddress ad1 = new InetSocketAddress (ia6bad, 2500);
try {
c1.connect (ad1, 5000);
throw new RuntimeException ("timeout exception was expected");
} catch (SocketTimeoutException e) {
t1 = System.currentTimeMillis() - t1;
checkTime (t1, 5000);
} catch (NoRouteToHostException e1) {
}
System.out.println ("Test3: OK"); System.out.println ("Test3: OK");
} }
......
...@@ -134,11 +134,11 @@ public class Tests { ...@@ -134,11 +134,11 @@ public class Tests {
} }
} }
/* check the time got is within 20% of the time expected */ /* check the time got is within 50% of the time expected */
public static void checkTime (long got, long expected) { public static void checkTime (long got, long expected) {
dprintln ("checkTime: got " + got + " expected " + expected); dprintln ("checkTime: got " + got + " expected " + expected);
long upper = expected + (expected / 5); long upper = expected + (expected / 2);
long lower = expected - (expected / 5); long lower = expected - (expected / 2);
if (got > upper || got < lower) { if (got > upper || got < lower) {
throw new RuntimeException ("checkTime failed: got " + got + " expected " + expected); throw new RuntimeException ("checkTime failed: got " + got + " expected " + expected);
} }
......
...@@ -391,6 +391,10 @@ public class FtpGetContent { ...@@ -391,6 +391,10 @@ public class FtpGetContent {
done = true; done = true;
} }
synchronized boolean done() {
return done;
}
synchronized public void setPortEnabled(boolean ok) { synchronized public void setPortEnabled(boolean ok) {
portEnabled = ok; portEnabled = ok;
} }
...@@ -431,12 +435,13 @@ public class FtpGetContent { ...@@ -431,12 +435,13 @@ public class FtpGetContent {
public void run() { public void run() {
try { try {
Socket client; Socket client;
while (!done) { while (!done()) {
client = server.accept(); client = server.accept();
(new FtpServerHandler(client)).start(); (new FtpServerHandler(client)).start();
} }
server.close();
} catch(Exception e) { } catch(Exception e) {
} finally {
try { server.close(); } catch (IOException unused) {}
} }
} }
} }
...@@ -463,18 +468,13 @@ public class FtpGetContent { ...@@ -463,18 +468,13 @@ public class FtpGetContent {
bytesRead = stream.read(buffer); bytesRead = stream.read(buffer);
} }
stream.close(); stream.close();
server.terminate();
server.interrupt();
if (totalBytes != filesize) if (totalBytes != filesize)
throw new RuntimeException("wrong file size!"); throw new RuntimeException("wrong file size!");
} catch (IOException e) { } catch (IOException e) {
try {
server.terminate();
server.interrupt();
} catch (Exception e2) {
}
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e.getMessage());
} finally {
server.terminate();
server.server.close();
} }
} }
} }
...@@ -438,8 +438,9 @@ public class FtpURL { ...@@ -438,8 +438,9 @@ public class FtpURL {
client = server.accept(); client = server.accept();
(new FtpServerHandler(client)).run(); (new FtpServerHandler(client)).run();
} }
server.close();
} catch(Exception e) { } catch(Exception e) {
} finally {
try { server.close(); } catch (IOException unused) {}
} }
} }
} }
...@@ -448,10 +449,9 @@ public class FtpURL { ...@@ -448,10 +449,9 @@ public class FtpURL {
} }
public FtpURL() throws Exception { public FtpURL() throws Exception {
FtpServer server = null; FtpServer server = new FtpServer(0);
BufferedReader in = null; BufferedReader in = null;
try { try {
server = new FtpServer(0);
server.start(); server.start();
int port = server.getPort(); int port = server.getPort();
...@@ -497,17 +497,14 @@ public class FtpURL { ...@@ -497,17 +497,14 @@ public class FtpURL {
throw new RuntimeException("Incorrect filename received"); throw new RuntimeException("Incorrect filename received");
if (! "/usr".equals(server.pwd())) if (! "/usr".equals(server.pwd()))
throw new RuntimeException("Incorrect pwd received"); throw new RuntimeException("Incorrect pwd received");
in.close();
// We're done! // We're done!
} catch (Exception e) { } catch (Exception e) {
try {
in.close();
server.terminate();
server.interrupt();
} catch(Exception ex) {
}
throw new RuntimeException("FTP support error: " + e.getMessage()); throw new RuntimeException("FTP support error: " + e.getMessage());
} finally {
try { in.close(); } catch (IOException unused) {}
server.terminate();
server.server.close();
} }
} }
} }
...@@ -30,9 +30,7 @@ ...@@ -30,9 +30,7 @@
* @summary ChunkedEncoding unit test; MeteredStream/ProgressData problem * @summary ChunkedEncoding unit test; MeteredStream/ProgressData problem
*/ */
import java.io.*;
import java.net.*; import java.net.*;
import java.security.*;
import java.util.BitSet; import java.util.BitSet;
import sun.net.ProgressMeteringPolicy; import sun.net.ProgressMeteringPolicy;
import sun.net.ProgressMonitor; import sun.net.ProgressMonitor;
...@@ -42,8 +40,10 @@ import sun.net.ProgressEvent; ...@@ -42,8 +40,10 @@ import sun.net.ProgressEvent;
public class ChunkedEncodingWithProgressMonitorTest { public class ChunkedEncodingWithProgressMonitorTest {
public static void main (String[] args) throws Exception { public static void main (String[] args) throws Exception {
ProgressMonitor.setMeteringPolicy(new MyProgressMeteringPolicy()); ProgressMonitor.setMeteringPolicy(new MyProgressMeteringPolicy());
ProgressMonitor.getDefault().addProgressListener(new MyProgressListener()); ProgressListener listener = new MyProgressListener();
ProgressMonitor.getDefault().addProgressListener(listener);
ChunkedEncodingTest.test(); ChunkedEncodingTest.test();
ProgressMonitor.getDefault().removeProgressListener(listener);
if (flag.cardinality() != 3) { if (flag.cardinality() != 3) {
throw new RuntimeException("All three methods in ProgressListener"+ throw new RuntimeException("All three methods in ProgressListener"+
......
...@@ -34,7 +34,7 @@ import com.sun.net.httpserver.*; ...@@ -34,7 +34,7 @@ import com.sun.net.httpserver.*;
public class Test implements HttpHandler { public class Test implements HttpHandler {
static int count = 0; static volatile int count = 0;
static final String str1 = "Helloworld1234567890abcdefghijklmnopqrstuvwxyz"+ static final String str1 = "Helloworld1234567890abcdefghijklmnopqrstuvwxyz"+
"1234567890abcdefkjsdlkjflkjsldkfjlsdkjflkj"+ "1234567890abcdefkjsdlkjflkjsldkfjlsdkjflkj"+
...@@ -46,9 +46,9 @@ public class Test implements HttpHandler { ...@@ -46,9 +46,9 @@ public class Test implements HttpHandler {
public void handle(HttpExchange exchange) { public void handle(HttpExchange exchange) {
String reqbody; String reqbody;
try { try {
switch (count) { switch (exchange.getRequestURI().toString()) {
case 0: /* test1 -- keeps conn alive */ case "/test/test1": /* test1 -- keeps conn alive */
case 1: /* test2 -- closes conn */ case "/test/test2": /* test2 -- closes conn */
printRequestURI(exchange); printRequestURI(exchange);
reqbody = read(exchange.getRequestBody()); reqbody = read(exchange.getRequestBody());
if (!reqbody.equals(str1)) { if (!reqbody.equals(str1)) {
...@@ -72,7 +72,7 @@ public class Test implements HttpHandler { ...@@ -72,7 +72,7 @@ public class Test implements HttpHandler {
resHeaders.set("Connection", "close"); resHeaders.set("Connection", "close");
} }
break; break;
case 2: /* test 3 */ case "/test/test3": /* test 3 */
printRequestURI(exchange); printRequestURI(exchange);
reqbody = read(exchange.getRequestBody()); reqbody = read(exchange.getRequestBody());
...@@ -93,19 +93,19 @@ public class Test implements HttpHandler { ...@@ -93,19 +93,19 @@ public class Test implements HttpHandler {
exchange.sendResponseHeaders(200, reqbody.length()); exchange.sendResponseHeaders(200, reqbody.length());
write(exchange.getResponseBody(), reqbody); write(exchange.getResponseBody(), reqbody);
break; break;
case 3: /* test 4 */ case "/test/test4": /* test 4 */
case 4: /* test 5 */ case "/test/test5": /* test 5 */
printRequestURI(exchange); printRequestURI(exchange);
break; break;
case 5: /* test 6 */ case "/test/test6": /* test 6 */
printRequestURI(exchange); printRequestURI(exchange);
resHeaders = exchange.getResponseHeaders() ; resHeaders = exchange.getResponseHeaders() ;
resHeaders.set("Location", "http://foo.bar/"); resHeaders.set("Location", "http://foo.bar/");
resHeaders.set("Connection", "close"); resHeaders.set("Connection", "close");
exchange.sendResponseHeaders(307, 0); exchange.sendResponseHeaders(307, 0);
break; break;
case 6: /* test 7 */ case "/test/test7": /* test 7 */
case 7: /* test 8 */ case "/test/test8": /* test 8 */
printRequestURI(exchange); printRequestURI(exchange);
reqbody = read(exchange.getRequestBody()); reqbody = read(exchange.getRequestBody());
if (reqbody != null && !"".equals(reqbody)) { if (reqbody != null && !"".equals(reqbody)) {
...@@ -116,7 +116,7 @@ public class Test implements HttpHandler { ...@@ -116,7 +116,7 @@ public class Test implements HttpHandler {
resHeaders.set("Connection", "close"); resHeaders.set("Connection", "close");
exchange.sendResponseHeaders(200, 0); exchange.sendResponseHeaders(200, 0);
break; break;
case 8: /* test 9 */ case "/test/test9": /* test 9 */
printRequestURI(exchange); printRequestURI(exchange);
reqbody = read(exchange.getRequestBody()); reqbody = read(exchange.getRequestBody());
if (!reqbody.equals(str1)) { if (!reqbody.equals(str1)) {
...@@ -134,7 +134,7 @@ public class Test implements HttpHandler { ...@@ -134,7 +134,7 @@ public class Test implements HttpHandler {
exchange.sendResponseHeaders(200, reqbody.length()); exchange.sendResponseHeaders(200, reqbody.length());
write(exchange.getResponseBody(), reqbody); write(exchange.getResponseBody(), reqbody);
break; break;
case 9: /* test10 */ case "/test/test10": /* test10 */
printRequestURI(exchange); printRequestURI(exchange);
InputStream is = exchange.getRequestBody(); InputStream is = exchange.getRequestBody();
String s = read (is, str1.length()); String s = read (is, str1.length());
...@@ -158,7 +158,7 @@ public class Test implements HttpHandler { ...@@ -158,7 +158,7 @@ public class Test implements HttpHandler {
exchange.sendResponseHeaders(200, 0); exchange.sendResponseHeaders(200, 0);
} }
break; break;
case 10: /* test11 */ case "/test/test11": /* test11 */
printRequestURI(exchange); printRequestURI(exchange);
is = exchange.getRequestBody(); is = exchange.getRequestBody();
s = read (is, str1.length()); s = read (is, str1.length());
...@@ -182,7 +182,7 @@ public class Test implements HttpHandler { ...@@ -182,7 +182,7 @@ public class Test implements HttpHandler {
exchange.sendResponseHeaders(200, 0); exchange.sendResponseHeaders(200, 0);
} }
break; break;
case 11: /* test12 */ case "/test/test12": /* test12 */
printRequestURI(exchange); printRequestURI(exchange);
is = exchange.getRequestBody(); is = exchange.getRequestBody();
...@@ -203,8 +203,8 @@ public class Test implements HttpHandler { ...@@ -203,8 +203,8 @@ public class Test implements HttpHandler {
} }
break; break;
} }
exchange.close();
count ++; count ++;
exchange.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -147,6 +147,8 @@ public class B6726695 extends Thread { ...@@ -147,6 +147,8 @@ public class B6726695 extends Thread {
serverIgnore(s); serverIgnore(s);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try { server.close(); } catch (IOException unused) {}
} }
} }
......
...@@ -100,11 +100,12 @@ public class MultiThreadTest extends Thread { ...@@ -100,11 +100,12 @@ public class MultiThreadTest extends Thread {
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException (e.getMessage()); throw new RuntimeException (e.getMessage());
} } finally {
synchronized (threadlock) { synchronized (threadlock) {
threadCounter --; threadCounter --;
if (threadCounter == 0) { if (threadCounter == 0) {
threadlock.notifyAll(); threadlock.notifyAll();
}
} }
} }
} }
......
...@@ -47,7 +47,7 @@ public class ProxyTest { ...@@ -47,7 +47,7 @@ public class ProxyTest {
private class HttpProxyServer extends Thread { private class HttpProxyServer extends Thread {
private ServerSocket server; private ServerSocket server;
private int port; private int port;
private boolean done = false; private volatile boolean done = false;
private String askedUrl; private String askedUrl;
/** /**
...@@ -125,12 +125,8 @@ public class ProxyTest { ...@@ -125,12 +125,8 @@ public class ProxyTest {
} }
} }
public HttpProxyServer(int port) { public HttpProxyServer() throws IOException {
this.port = port; server = new ServerSocket(0);
}
public HttpProxyServer() {
this(0);
} }
public int getPort() { public int getPort() {
...@@ -148,51 +144,49 @@ public class ProxyTest { ...@@ -148,51 +144,49 @@ public class ProxyTest {
*/ */
synchronized public void terminate() { synchronized public void terminate() {
done = true; done = true;
try { server.close(); } catch (IOException unused) {}
} }
public void run() { public void run() {
try { try {
server = new ServerSocket(port);
Socket client; Socket client;
while (!done) { while (!done) {
client = server.accept(); client = server.accept();
(new HttpProxyHandler(client)).start(); (new HttpProxyHandler(client)).start();
} }
server.close();
} catch (Exception e) { } 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(); ProxyTest test = new ProxyTest();
} }
public ProxyTest() { public ProxyTest() throws Exception {
BufferedReader in = null;
String testURL = "ftp://anonymous:password@myhost.mydomain/index.html"; String testURL = "ftp://anonymous:password@myhost.mydomain/index.html";
HttpProxyServer server = new HttpProxyServer(); HttpProxyServer server = new HttpProxyServer();
try { try {
server.start(); server.start();
int port = 0; int port = server.getPort();
while (port == 0) {
Thread.sleep(500); Proxy ftpProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", port));
port = server.getPort(); URL url = new URL(testURL);
} InputStream ins = (url.openConnection(ftpProxy)).getInputStream();
in = new BufferedReader(new InputStreamReader(ins));
System.setProperty("ftp.proxyHost","localhost"); String line;
System.setProperty("ftp.proxyPort", String.valueOf(port)); do {
URL url = new URL(testURL); line = in.readLine();
InputStream ins = url.openStream(); } while (line != null);
BufferedReader in = new BufferedReader(new InputStreamReader(ins)); in.close();
String line;
do {
line = in.readLine();
} while (line != null);
in.close();
server.terminate();
server.interrupt();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
server.terminate();
try { in.close(); } catch (IOException unused) {}
} }
/* /*
* If the URLs don't match, we've got a bug! * If the URLs don't match, we've got a bug!
......
...@@ -91,9 +91,10 @@ public class KeepAliveTimerThread { ...@@ -91,9 +91,10 @@ public class KeepAliveTimerThread {
out.flush(); out.flush();
s.close(); s.close();
server.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try { server.close(); } catch (IOException unused) {}
} }
} }
} }
...@@ -118,6 +119,8 @@ public class KeepAliveTimerThread { ...@@ -118,6 +119,8 @@ public class KeepAliveTimerThread {
if (grp.activeCount() > 0) { if (grp.activeCount() > 0) {
throw new RuntimeException("Keep-alive thread started in wrong thread group"); throw new RuntimeException("Keep-alive thread started in wrong thread group");
} }
grp.destroy();
} }
} }
...@@ -43,10 +43,6 @@ public class KeepAliveStreamCloseWithWrongContentLength { ...@@ -43,10 +43,6 @@ public class KeepAliveStreamCloseWithWrongContentLength {
srv = s; srv = s;
} }
Socket getSocket () {
return (s);
}
public void run() { public void run() {
try { try {
s = srv.accept (); s = srv.accept ();
...@@ -57,7 +53,7 @@ public class KeepAliveStreamCloseWithWrongContentLength { ...@@ -57,7 +53,7 @@ public class KeepAliveStreamCloseWithWrongContentLength {
is.read(); is.read();
} }
OutputStreamWriter ow = OutputStreamWriter ow =
new OutputStreamWriter(s.getOutputStream()); new OutputStreamWriter((os = s.getOutputStream()));
ow.write("HTTP/1.0 200 OK\n"); ow.write("HTTP/1.0 200 OK\n");
// Note: The client expects 10 bytes. // Note: The client expects 10 bytes.
...@@ -71,19 +67,16 @@ public class KeepAliveStreamCloseWithWrongContentLength { ...@@ -71,19 +67,16 @@ public class KeepAliveStreamCloseWithWrongContentLength {
// Note: The (buggy) server only sends 9 bytes. // Note: The (buggy) server only sends 9 bytes.
ow.write("123456789"); ow.write("123456789");
ow.flush(); ow.flush();
ow.close();
} catch (Exception e) { } catch (Exception e) {
} finally {
try {if (os != null) { os.close(); }} catch (IOException e) {}
} }
} }
} }
/* public static void main (String[] args) throws Exception {
* ServerSocket serversocket = new ServerSocket (0);
*/
public static void main (String[] args) {
try { try {
ServerSocket serversocket = new ServerSocket (0);
int port = serversocket.getLocalPort (); int port = serversocket.getLocalPort ();
XServer server = new XServer (serversocket); XServer server = new XServer (serversocket);
server.start (); server.start ();
...@@ -100,11 +93,12 @@ public class KeepAliveStreamCloseWithWrongContentLength { ...@@ -100,11 +93,12 @@ public class KeepAliveStreamCloseWithWrongContentLength {
} }
} }
is.close(); is.close();
server.getSocket().close ();
} catch (IOException e) { } catch (IOException e) {
return; return;
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new RuntimeException (e); throw new RuntimeException (e);
} finally {
if (serversocket != null) serversocket.close();
} }
} }
} }
...@@ -188,6 +188,7 @@ public class HttpServer { ...@@ -188,6 +188,7 @@ public class HttpServer {
sock.configureBlocking (false); sock.configureBlocking (false);
sock.register (selector, SelectionKey.OP_READ); sock.register (selector, SelectionKey.OP_READ);
nconn ++; nconn ++;
System.out.println("SERVER: new connection. chan[" + sock + "]");
if (nconn == maxconn) { if (nconn == maxconn) {
/* deregister */ /* deregister */
listenerKey.cancel (); listenerKey.cancel ();
...@@ -197,7 +198,9 @@ public class HttpServer { ...@@ -197,7 +198,9 @@ public class HttpServer {
if (key.isReadable()) { if (key.isReadable()) {
boolean closed; boolean closed;
SocketChannel chan = (SocketChannel) key.channel(); SocketChannel chan = (SocketChannel) key.channel();
System.out.println("SERVER: connection readable. chan[" + chan + "]");
if (key.attachment() != null) { if (key.attachment() != null) {
System.out.println("Server: comsume");
closed = consume (chan); closed = consume (chan);
} else { } else {
closed = read (chan, key); closed = read (chan, key);
...@@ -375,6 +378,7 @@ public class HttpServer { ...@@ -375,6 +378,7 @@ public class HttpServer {
synchronized void orderlyCloseChannel (SelectionKey key) throws IOException { synchronized void orderlyCloseChannel (SelectionKey key) throws IOException {
SocketChannel ch = (SocketChannel)key.channel (); SocketChannel ch = (SocketChannel)key.channel ();
System.out.println("SERVER: orderlyCloseChannel chan[" + ch + "]");
ch.socket().shutdownOutput(); ch.socket().shutdownOutput();
key.attach (this); key.attach (this);
clist.add (key); clist.add (key);
...@@ -382,6 +386,8 @@ public class HttpServer { ...@@ -382,6 +386,8 @@ public class HttpServer {
synchronized void abortiveCloseChannel (SelectionKey key) throws IOException { synchronized void abortiveCloseChannel (SelectionKey key) throws IOException {
SocketChannel ch = (SocketChannel)key.channel (); SocketChannel ch = (SocketChannel)key.channel ();
System.out.println("SERVER: abortiveCloseChannel chan[" + ch + "]");
Socket s = ch.socket (); Socket s = ch.socket ();
s.setSoLinger (true, 0); s.setSoLinger (true, 0);
ch.close(); ch.close();
......
...@@ -95,10 +95,11 @@ class DigestServer extends Thread { ...@@ -95,10 +95,11 @@ class DigestServer extends Thread {
os.write (reply.getBytes()); os.write (reply.getBytes());
Thread.sleep (2000); Thread.sleep (2000);
s1.close (); s1.close ();
} } catch (Exception e) {
catch (Exception e) {
System.out.println (e); System.out.println (e);
e.printStackTrace(); e.printStackTrace();
} finally {
try { s.close(); } catch (IOException unused) {}
} }
} }
...@@ -204,15 +205,12 @@ public class DigestTest { ...@@ -204,15 +205,12 @@ public class DigestTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
int nLoops = 1; int port;
int nSize = 10;
int port, n =0;
byte b[] = new byte[nSize];
DigestServer server; DigestServer server;
ServerSocket sock; ServerSocket sock;
try { try {
sock = new ServerSocket (5000); sock = new ServerSocket (0);
port = sock.getLocalPort (); port = sock.getLocalPort ();
} }
catch (Exception e) { catch (Exception e) {
...@@ -225,21 +223,18 @@ public class DigestTest { ...@@ -225,21 +223,18 @@ public class DigestTest {
boolean passed = false; boolean passed = false;
try { try {
Authenticator.setDefault (new MyAuthenticator ()); Authenticator.setDefault (new MyAuthenticator ());
String s = "http://localhost:" + port + DigestServer.uri; String s = "http://localhost:" + port + DigestServer.uri;
URL url = new URL(s); URL url = new URL(s);
java.net.URLConnection conURL = url.openConnection(); java.net.URLConnection conURL = url.openConnection();
InputStream in = conURL.getInputStream(); InputStream in = conURL.getInputStream();
int c; while (in.read () != -1) {}
while ((c = in.read ()) != -1) {
}
in.close (); in.close ();
} } catch(ProtocolException e) {
catch(ProtocolException e) {
passed = true; passed = true;
} }
if (!passed) { if (!passed) {
throw new RuntimeException ("Expected a ProtocolException from wrong password"); throw new RuntimeException ("Expected a ProtocolException from wrong password");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册