harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r603210 - in /harmony/enhanced/buildtest/branches/2.0/tests/reliability: run/exclude.linux_x86_64 run/run.normal.mode.settings.xml src/java/org/apache/harmony/test/reliability/api/net/HttpConnectionTest.java
Date Tue, 11 Dec 2007 11:26:58 GMT
Author: smishura
Date: Tue Dec 11 03:26:48 2007
New Revision: 603210

URL: http://svn.apache.org/viewvc?rev=603210&view=rev
Log:
Apply patch from HARMONY-5266:
([buildtest][reliability] HttpConnectionTest fails when www.apache.org is not accessible)

Modified:
    harmony/enhanced/buildtest/branches/2.0/tests/reliability/run/exclude.linux_x86_64
    harmony/enhanced/buildtest/branches/2.0/tests/reliability/run/run.normal.mode.settings.xml
    harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/net/HttpConnectionTest.java

Modified: harmony/enhanced/buildtest/branches/2.0/tests/reliability/run/exclude.linux_x86_64
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/run/exclude.linux_x86_64?rev=603210&r1=603209&r2=603210&view=diff
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/run/exclude.linux_x86_64 (original)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/run/exclude.linux_x86_64 Tue
Dec 11 03:26:48 2007
@@ -2,7 +2,6 @@
 ##           20071030 test run failures
 api.kernel.thread.VolatileVariableTest.DekkerTest 
 api.net.DatagramTest 
-api.net.HttpConnectionTest 
 api.net.SingleConnectTest 
 api.nio.buffers.ByteBufferallocateTest 
 api.nio.channels.filechannel.MappedByteBufferForceTest 

Modified: harmony/enhanced/buildtest/branches/2.0/tests/reliability/run/run.normal.mode.settings.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/run/run.normal.mode.settings.xml?rev=603210&r1=603209&r2=603210&view=diff
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/run/run.normal.mode.settings.xml
(original)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/run/run.normal.mode.settings.xml
Tue Dec 11 03:26:48 2007
@@ -517,7 +517,7 @@
 <!-- api.net.HttpConnectionTest -->
 
 	    <!-- URLs to scan  -->
-	    <property name="api.net.HttpConnectionTest.URLs" value="http://harmony.apache.org/;http://issues.apache.org/jira/browse/HARMONY;http://harmony.apache.org/quickhelp_contributors.html"
/>
+	    <property name="api.net.HttpConnectionTest.URLs" value="" />
 
 <!-- vm.classloading.ClassUnloadingTest -->
 

Modified: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/net/HttpConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/net/HttpConnectionTest.java?rev=603210&r1=603209&r2=603210&view=diff
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/net/HttpConnectionTest.java
(original)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/net/HttpConnectionTest.java
Tue Dec 11 03:26:48 2007
@@ -24,12 +24,16 @@
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.InetSocketAddress;
 import java.net.MalformedURLException;
 import java.net.Proxy;
 import java.net.URL;
+import java.net.Socket;
+import java.net.ServerSocket;
 import java.util.regex.Pattern;
 
 import org.apache.harmony.test.reliability.share.Test;
@@ -37,7 +41,7 @@
 /*
  * Goal: Test HttpURLConnection functionality
  *
- *  passed parameters:
+ *  passed optional parameters:
  *  parameter[0] - urls for web pages you want to get, all urls are to be listed consequently
  *  via ";" with no blanks or tabs
  *  E.g http://harmony.apache.org/;http://issues.apache.org/jira/browse/HARMONY
@@ -49,13 +53,14 @@
  *   
  *  No crash, hang or fail is excpected.
  *  
- *  Note: All input parameters are to be set properly as test could fail due to wrong 
- *  set proxy or Url address.
+ *  If no parameters are set then internal stab http server is started for testing.
  *  */
 
 public class HttpConnectionTest extends Test{
+    static volatile boolean failed = false;
     String[] testedUrlStrings = null;
     Proxy prx = null;
+    HttpServerStub sPort = null;
 
     public static void main(String[] params){
         System.exit(new HttpConnectionTest().test(params));
@@ -63,8 +68,16 @@
     
     public int test(String[] params){
         parseParams(params);
+
+
         if (testedUrlStrings == null){
-            return fail("Urls to test are not set");
+            sPort = new HttpServerStub();
+            if (!sPort.isAlive())
+            {
+                return fail("Failed to start server");
+            }
+            testedUrlStrings = new String[1];
+            testedUrlStrings[0] = "http://localhost:" + sPort.port + "/";
         }
 
         for (int i=0; i<testedUrlStrings.length;i++){
@@ -79,7 +92,11 @@
                 return fail("FAILED");
             }
         }
-        
+
+        if (failed == true)
+        {
+            return fail("FAILED");
+        }
         return pass("OK");
     }
     
@@ -115,11 +132,12 @@
             while((buf = br.readLine()) != null){
                 resultedString += buf;
             }
-            //System.out.println(resultedString);
+            // System.out.println("resultedString:" + resultedString);
             hur.disconnect();
             
         } catch (IOException e) {
             log.add("Failed to connect to " + hur.getURL() + " : " + e.getMessage());
+            e.printStackTrace();
             return false;
         }
         
@@ -138,3 +156,90 @@
         
     }
 }
+
+class HttpServerStub extends Thread
+{
+    int port = 0;
+    ServerSocket ss = null;
+    boolean started = false;
+    final static int sizeOfMessage = 1000;
+    String content = null;
+    HttpServerStub()
+    {
+        try
+        {
+            ss = new ServerSocket(0);
+        }
+        catch (IOException e1)
+        {
+            return;
+        }
+        port = ss.getLocalPort();
+        start();
+        started = true;
+    }
+    public void close()
+    {
+        try {
+            if (started)
+            {
+                started = false;
+                ss.close(); 
+            }
+        }
+        catch (IOException ioe)
+        {
+        }
+    }
+    public void run()
+    {
+        try
+        {
+            Socket socket = ss.accept();
+            try
+            {
+                InputStream in = socket.getInputStream();
+                OutputStream out = socket.getOutputStream();
+
+                byte[] buf = new byte[sizeOfMessage];
+                int red = in.read(buf, 0, sizeOfMessage);
+                // The content is so big because otherwise the test is too fast and
+                // could exhaust all operating system sockets causing the failure 
+                content = "Content-Type:   text/html;charset=iso-8859-1\n\n<html>\n<body>\n";
+                for (int l = 0; l < 2000; l++)
+                {
+                    content += "<p>Hello, Word!\n";
+                }
+                content += "</body>\n</html>\n";
+                out.write(content.getBytes());
+            }
+            catch (IOException e)
+            {
+                HttpConnectionTest.log.add("Server thread " + getId() + " could not get streams:
" + e.getMessage());
+                e.printStackTrace();
+                HttpConnectionTest.failed = true;
+                return;
+            }
+            socket.close();
+        }
+        catch (IOException e)
+        {
+            HttpConnectionTest.log.add("Server thread " + getId() + " could not accept request:
" + e.getMessage());
+            e.printStackTrace();
+            HttpConnectionTest.failed = true;
+            return;
+        }
+
+        try
+        {
+            ss.close();
+        }
+        catch (IOException e)
+        {
+            HttpConnectionTest.log.add("Failed to close ServerSocket on port " + port);
+            HttpConnectionTest.failed = true;
+            return;
+        }
+    }
+}
+



Mime
View raw message