Hi all

I'm investigating H-1879 and need some help or recommendations from net guru.
I have extracted failed test from
org.apache.harmony.tests.internal.net.www.protocol.http.HttpURLConnectionTest,
please see below. It failed with connection refused exception.

Java code works well, it looks like some problem with native code. By
the way telnet can't connect to created server too.

If somebody can help with this issue it would be great.

Thanks.

=========== Test ==============

package org.apache.harmony.tests.internal.net.www.protocol.http;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.URL;

import junit.framework.TestCase;

public class SimpleTest extends TestCase {

   private final static Object bound = new Object();

   static class MockServer extends Thread {
       ServerSocket serverSocket;
       boolean accepted = false;

       public MockServer(String name) throws IOException {
           super(name);
        
           serverSocket = new ServerSocket(0);
           serverSocket.setSoTimeout(1000);
       }

       public int port() {
           return serverSocket.getLocalPort();
       }

       public void run() {
           try {
               synchronized (bound) {
                   bound.notify();
               }
               try {
                    serverSocket.accept().close();
                   accepted = true;
               } catch (SocketTimeoutException ignore) {
               }
               serverSocket.close();
           } catch (IOException e) {
               throw new RuntimeException(e);
           }
       }
   }

   public void testUsingProxy() throws Exception {
       MockServer server = new MockServer("server");
       MockServer proxy = new MockServer("proxy");
        
       URL url = new URL("http://localhost:"; + server.port());

       HttpURLConnection connection = (HttpURLConnection) url
               .openConnection(new Proxy(Proxy.Type.HTTP,
                       new InetSocketAddress("localhost",
                           proxy.port())));

//      HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        
       connection.setConnectTimeout(2000);
       connection.setReadTimeout(2000);

       server.start();
       synchronized(bound) {
           bound.wait(5000);
       }
       proxy.start();
       synchronized(bound) {
           bound.wait(5000);
       }

        connection.connect();

       server.join();
       proxy.join();
   }

}

========= Harmony+drlvm output ============
There was 1 error:
1) 
testUsingProxy(org.apache.harmony.tests.internal.net.www.protocol.http.SimpleTest)java.net.ConnectException:
localhost/127.0.0.1:57896 - Connection refused
       at 
org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:224)
       at 
org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:496)
       at java.net.Socket.connect(Socket.java:980)
       at 
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:627)
       at 
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:608)
       at 
org.apache.harmony.tests.internal.net.www.protocol.http.SimpleTest.testUsingProxy(SimpleTest.java:78)
       at java.lang.reflect.VMReflection.invokeMethod(Native Method)

FAILURES!!!
Tests run: 1,  Failures: 0,  Errors: 1

--
Denis M. Kishenko
Intel Middleware Products Division

Reply via email to