This is the mail archive of the
mauve-patches@sources.redhat.com
mailing list for the Mauve project.
gnu.testlet.java.net.Socket tests
- From: Bryce McKinlay <mckinlay at redhat dot com>
- To: mauve-patches at sources dot redhat dot com
- Date: Wed, 09 Feb 2005 23:39:47 -0500
- Subject: gnu.testlet.java.net.Socket tests
I noticed that these tests:
gnu/testlet/java/net/Socket/jdk12.java
gnu/testlet/java/net/Socket/jdk13.java
gnu/testlet/java/net/Socket/jdk14.java
Were taking a very long time to fail on my mauve runs (there seem to be
other tests that also are slowing things down, but these ones were
particularly noticable). The problem is they are trying to connect to a
remote server on port 25 which is unreachable through a firewall.
This patch changes them to start their own local server in another thread.
Bryce
2005-02-09 Bryce McKinlay <mckinlay@redhat.com>
* gnu/testlet/java/net/Socket/ServerThread.java: New file.
* gnu/testlet/java/net/Socket/jdk12.java: Use ServerThread instead
of trying to connect to external server.
* gnu/testlet/java/net/Socket/jdk13.java: Likewise.
* gnu/testlet/java/net/Socket/jdk14.java: Likewise.
Index: gnu/testlet/java/net/Socket/ServerThread.java
===================================================================
RCS file: gnu/testlet/java/net/Socket/ServerThread.java
diff -N gnu/testlet/java/net/Socket/ServerThread.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/net/Socket/ServerThread.java 10 Feb 2005 04:35:29 -0000
@@ -0,0 +1,90 @@
+// Tags: not-a-test
+
+/*
+ Copyright (C) 2005 Free Software Foundation
+
+ This file is part of Mauve.
+
+ Mauve is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ Mauve 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 for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Mauve; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+package gnu.testlet.java.net.Socket;
+import gnu.testlet.TestHarness;
+import java.net.*;
+import java.io.*;
+
+/* Implements a simple server socket listening on a port.
+Socket tests can connect to this port. */
+
+class ServerThread extends Thread
+{
+ ServerSocket sock;
+ TestHarness harness;
+
+ public ServerThread(TestHarness harness)
+ {
+ this(harness, 14610);
+ }
+
+ public ServerThread(TestHarness harness, int port)
+ {
+ this.harness = harness;
+ try
+ {
+ sock = new ServerSocket(port);
+ this.start();
+ }
+ catch (IOException x)
+ {
+ harness.fail(x.toString());
+ }
+ }
+
+ public void close()
+ {
+ try
+ {
+ sock.close();
+ }
+ catch (IOException x)
+ {
+ harness.fail(x.toString());
+ }
+ }
+
+ public void run()
+ {
+ try
+ {
+ while (true)
+ {
+ Socket s = sock.accept();
+ InputStream is = s.getInputStream();
+ byte[] data = new byte[512];
+ boolean done = false;
+ while (!done)
+ {
+ if (is.read(data, 0, data.length) < 0)
+ done = true;
+ }
+ }
+ }
+ catch (IOException x)
+ {
+ // Ignored
+ }
+ }
+}
Index: gnu/testlet/java/net/Socket/jdk12.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/net/Socket/jdk12.java,v
retrieving revision 1.3
diff -u -r1.3 jdk12.java
--- gnu/testlet/java/net/Socket/jdk12.java 12 Aug 2004 15:11:12 -0000 1.3
+++ gnu/testlet/java/net/Socket/jdk12.java 10 Feb 2005 04:35:29 -0000
@@ -1,4 +1,5 @@
// Tags: JDK1.2
+// Uses: ServerThread
/*
Copyright (C) 2003 C. Brian Jones
@@ -34,9 +35,10 @@
{
public void test (TestHarness harness)
{
- String host = ((SimpleTestHarness) harness).getMailHost();
- int port = 25;
+ String host = "localhost";
+ int port = 14610;
Socket sock = null;
+ ServerThread server = new ServerThread(harness, port);
try
{
sock = new Socket (host, port);
@@ -56,6 +58,7 @@
try {
if (sock != null)
sock.close();
+ server.close();
} catch(IOException ignored) {}
}
}
Index: gnu/testlet/java/net/Socket/jdk13.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/net/Socket/jdk13.java,v
retrieving revision 1.4
diff -u -r1.4 jdk13.java
--- gnu/testlet/java/net/Socket/jdk13.java 12 Aug 2004 15:11:12 -0000 1.4
+++ gnu/testlet/java/net/Socket/jdk13.java 10 Feb 2005 04:35:29 -0000
@@ -1,4 +1,5 @@
// Tags: JDK1.3
+// Uses: ServerThread
/*
Copyright (C) 2003 C. Brian Jones
@@ -34,9 +35,10 @@
{
public void test (TestHarness harness)
{
- String host = ((SimpleTestHarness) harness).getMailHost();
- int port = 25;
+ String host = "localhost";
+ int port = 14610;
Socket sock = null;
+ ServerThread server = new ServerThread(harness, port);
try
{
harness.checkPoint("getKeepAlive()");
@@ -59,6 +61,7 @@
try {
if (sock != null)
sock.close();
+ server.close();
} catch(IOException ignored) {}
}
}
Index: gnu/testlet/java/net/Socket/jdk14.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/net/Socket/jdk14.java,v
retrieving revision 1.4
diff -u -r1.4 jdk14.java
--- gnu/testlet/java/net/Socket/jdk14.java 25 Nov 2004 09:46:48 -0000 1.4
+++ gnu/testlet/java/net/Socket/jdk14.java 10 Feb 2005 04:35:29 -0000
@@ -1,4 +1,5 @@
// Tags: JDK1.4
+// Uses: ServerThread
/*
Copyright (C) 2003 C. Brian Jones
@@ -34,9 +35,10 @@
{
public void test (TestHarness harness)
{
- String host = ((SimpleTestHarness) harness).getMailHost();
- int port = 25;
+ String host = "localhost";
+ int port = 14610;
Socket sock = null;
+ ServerThread server = new ServerThread(harness, port);
try
{
sock = new Socket (); // unconnected socket
@@ -73,6 +75,7 @@
try {
if (sock != null)
sock.close();
+ server.close();
} catch(IOException ignored) {}
}
}