You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Denis Kishenko <dk...@gmail.com> on 2006/11/21 09:02:38 UTC

[classlib][net] issue H-1879 HttpURLConnectionTest

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

Re: [classlib][net] issue H-1879 HttpURLConnectionTest

Posted by Denis Kishenko <dk...@gmail.com>.
I can suggest add flag to avoid situation described above (see attached fix).

2006/11/21, Denis Kishenko <dk...@gmail.com>:
> Alexei,
>
> Yep, syncronization is necessary but not such way.
>
> As you said, test try to control server/proxy starting using
> bound.wait(5000). It looks like on linux server/proxy thread started
> eallier then on winxp.
>
> In other words, what we are waiting for
> 1. start server thread
> 2. bound.wait
> 3. bound.notify
> 4. start proxy thread
> 5. bound.wait
> 6. bound.notify
> 7. connect
> but we have on linux
> 1. start server thread
> 2. bound.notify
> 3. bound.wait
> ---- wait 5 seconds -----
> 4. start proxy thread
> 5. bound.notify
> 6. bound.wait
> ---- wait 5 seconds -----
> 7. connect
>
> So we try to connect when proxy closed.
>
> 2006/11/21, Alexei Fedotov <al...@gmail.com>:
> > Denis,
> > Thank you for your fix!
> >
> > Here are few comments. I don't think we need to remove
> > synchronization. Contrary, I believe we need to fix it somehow.
> >
> > For example, when wait(5000) expires without notification, this means
> > that the test fail, and we better should report it right at the same
> > place.
> >
> > Digging further we can see that actual accept() calls are not
> > synchronized at all. There should be someting like conditional
> > variable to synchronize such events. I will write back when I get an
> > idea how to do it properly.
> >
> > A second option is to increase reading timeout set by setSoTimeout -
> > probably servers do not start fast enough.
> >
> > Thanks again, Alexei
> >
> >
> > On 11/21/06, Denis Kishenko <dk...@gmail.com> wrote:
> > > Alexei,
> > >
> > > I attached fix to issue, could you try it, please?
> > >
> > > 2006/11/21, Alexei Fedotov <al...@gmail.com>:
> > > > Denis wrote,
> > > > > Yep, Harmony+DRLVM on SuSE
> > > >
> > > > A peculiar thing about this test is that it passes on SuSE 10, but
> > > > fails on SuSE 9 which is used for our regression test runs.
> > > >
> > > > --
> > > > Thank you,
> > > > Alexei
> > > >
> > > > On 11/21/06, Denis Kishenko <dk...@gmail.com> wrote:
> > > > > 2006/11/21, Jimmy, Jing Lv <fi...@gmail.com>:
> > > > > > Denis Kishenko wrote:
> > > > > > > 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
> > > > > > >
> > > > > >
> > > > > > The test passes on Harmony+IBMVME on WindowsXP on my desktop, so you
> > > > > > mean Harmony+DRLVM here?
> > > > > Yep, Harmony+DRLVM on SuSE
> > > > >
> > > > > >
> > > > > > But IMHO the VM does not matter in network issues, the native code call
> > > > > > directly to the system APIs(of course, through Port-Lib), so I wonder if
> > > > > > there's something wrong in thread(handle by VM)? Just a thought.
> > > > > >
> > > > > > And IMO, that telnet shall not connect to the server is due to
> > > > > > "serverSocket.setSoTimeout(1000);", which make "serverSocket.accept()"
> > > > > > wait for only one second.
> > > > > Of course I had changed timeout to 10sec when used telnet :)
> > > > >
> > > > > >
> > > > > > I have to download Harmony+DRLVM to debug into, but the speed of network
> > > > > > is poor here :)
> > > > > >
> > > > > >
> > > > > > --
> > > > > >
> > > > > > Best Regards!
> > > > > >
> > > > > > Jimmy, Jing Lv
> > > > > > China Software Development Lab, IBM
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Denis M. Kishenko
> > > > > Intel Middleware Products Division
> > > > >
> > > >
> > >
> > >
> > > --
> > > Denis M. Kishenko
> > > Intel Middleware Products Division
> > >
> >
> >
> > --
> > Thank you,
> > Alexei
> >
>
>
> --
> Denis M. Kishenko
> Intel Middleware Products Division
>


-- 
Denis M. Kishenko
Intel Middleware Products Division

Re: [classlib][net] issue H-1879 HttpURLConnectionTest

Posted by Denis Kishenko <dk...@gmail.com>.
Alexei,

Yep, syncronization is necessary but not such way.

As you said, test try to control server/proxy starting using
bound.wait(5000). It looks like on linux server/proxy thread started
eallier then on winxp.

In other words, what we are waiting for
1. start server thread
2. bound.wait
3. bound.notify
4. start proxy thread
5. bound.wait
6. bound.notify
7. connect
but we have on linux
1. start server thread
2. bound.notify
3. bound.wait
---- wait 5 seconds -----
4. start proxy thread
5. bound.notify
6. bound.wait
---- wait 5 seconds -----
7. connect

So we try to connect when proxy closed.

2006/11/21, Alexei Fedotov <al...@gmail.com>:
> Denis,
> Thank you for your fix!
>
> Here are few comments. I don't think we need to remove
> synchronization. Contrary, I believe we need to fix it somehow.
>
> For example, when wait(5000) expires without notification, this means
> that the test fail, and we better should report it right at the same
> place.
>
> Digging further we can see that actual accept() calls are not
> synchronized at all. There should be someting like conditional
> variable to synchronize such events. I will write back when I get an
> idea how to do it properly.
>
> A second option is to increase reading timeout set by setSoTimeout -
> probably servers do not start fast enough.
>
> Thanks again, Alexei
>
>
> On 11/21/06, Denis Kishenko <dk...@gmail.com> wrote:
> > Alexei,
> >
> > I attached fix to issue, could you try it, please?
> >
> > 2006/11/21, Alexei Fedotov <al...@gmail.com>:
> > > Denis wrote,
> > > > Yep, Harmony+DRLVM on SuSE
> > >
> > > A peculiar thing about this test is that it passes on SuSE 10, but
> > > fails on SuSE 9 which is used for our regression test runs.
> > >
> > > --
> > > Thank you,
> > > Alexei
> > >
> > > On 11/21/06, Denis Kishenko <dk...@gmail.com> wrote:
> > > > 2006/11/21, Jimmy, Jing Lv <fi...@gmail.com>:
> > > > > Denis Kishenko wrote:
> > > > > > 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
> > > > > >
> > > > >
> > > > > The test passes on Harmony+IBMVME on WindowsXP on my desktop, so you
> > > > > mean Harmony+DRLVM here?
> > > > Yep, Harmony+DRLVM on SuSE
> > > >
> > > > >
> > > > > But IMHO the VM does not matter in network issues, the native code call
> > > > > directly to the system APIs(of course, through Port-Lib), so I wonder if
> > > > > there's something wrong in thread(handle by VM)? Just a thought.
> > > > >
> > > > > And IMO, that telnet shall not connect to the server is due to
> > > > > "serverSocket.setSoTimeout(1000);", which make "serverSocket.accept()"
> > > > > wait for only one second.
> > > > Of course I had changed timeout to 10sec when used telnet :)
> > > >
> > > > >
> > > > > I have to download Harmony+DRLVM to debug into, but the speed of network
> > > > > is poor here :)
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > Best Regards!
> > > > >
> > > > > Jimmy, Jing Lv
> > > > > China Software Development Lab, IBM
> > > > >
> > > >
> > > >
> > > > --
> > > > Denis M. Kishenko
> > > > Intel Middleware Products Division
> > > >
> > >
> >
> >
> > --
> > Denis M. Kishenko
> > Intel Middleware Products Division
> >
>
>
> --
> Thank you,
> Alexei
>


-- 
Denis M. Kishenko
Intel Middleware Products Division

Re: [classlib][net] issue H-1879 HttpURLConnectionTest

Posted by Alexei Fedotov <al...@gmail.com>.
Denis,
Thank you for your fix!

Here are few comments. I don't think we need to remove
synchronization. Contrary, I believe we need to fix it somehow.

For example, when wait(5000) expires without notification, this means
that the test fail, and we better should report it right at the same
place.

Digging further we can see that actual accept() calls are not
synchronized at all. There should be someting like conditional
variable to synchronize such events. I will write back when I get an
idea how to do it properly.

A second option is to increase reading timeout set by setSoTimeout -
probably servers do not start fast enough.

Thanks again, Alexei


On 11/21/06, Denis Kishenko <dk...@gmail.com> wrote:
> Alexei,
>
> I attached fix to issue, could you try it, please?
>
> 2006/11/21, Alexei Fedotov <al...@gmail.com>:
> > Denis wrote,
> > > Yep, Harmony+DRLVM on SuSE
> >
> > A peculiar thing about this test is that it passes on SuSE 10, but
> > fails on SuSE 9 which is used for our regression test runs.
> >
> > --
> > Thank you,
> > Alexei
> >
> > On 11/21/06, Denis Kishenko <dk...@gmail.com> wrote:
> > > 2006/11/21, Jimmy, Jing Lv <fi...@gmail.com>:
> > > > Denis Kishenko wrote:
> > > > > 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
> > > > >
> > > >
> > > > The test passes on Harmony+IBMVME on WindowsXP on my desktop, so you
> > > > mean Harmony+DRLVM here?
> > > Yep, Harmony+DRLVM on SuSE
> > >
> > > >
> > > > But IMHO the VM does not matter in network issues, the native code call
> > > > directly to the system APIs(of course, through Port-Lib), so I wonder if
> > > > there's something wrong in thread(handle by VM)? Just a thought.
> > > >
> > > > And IMO, that telnet shall not connect to the server is due to
> > > > "serverSocket.setSoTimeout(1000);", which make "serverSocket.accept()"
> > > > wait for only one second.
> > > Of course I had changed timeout to 10sec when used telnet :)
> > >
> > > >
> > > > I have to download Harmony+DRLVM to debug into, but the speed of network
> > > > is poor here :)
> > > >
> > > >
> > > > --
> > > >
> > > > Best Regards!
> > > >
> > > > Jimmy, Jing Lv
> > > > China Software Development Lab, IBM
> > > >
> > >
> > >
> > > --
> > > Denis M. Kishenko
> > > Intel Middleware Products Division
> > >
> >
>
>
> --
> Denis M. Kishenko
> Intel Middleware Products Division
>


-- 
Thank you,
Alexei

Re: [classlib][net] issue H-1879 HttpURLConnectionTest

Posted by Denis Kishenko <dk...@gmail.com>.
Alexei,

I attached fix to issue, could you try it, please?

2006/11/21, Alexei Fedotov <al...@gmail.com>:
> Denis wrote,
> > Yep, Harmony+DRLVM on SuSE
>
> A peculiar thing about this test is that it passes on SuSE 10, but
> fails on SuSE 9 which is used for our regression test runs.
>
> --
> Thank you,
> Alexei
>
> On 11/21/06, Denis Kishenko <dk...@gmail.com> wrote:
> > 2006/11/21, Jimmy, Jing Lv <fi...@gmail.com>:
> > > Denis Kishenko wrote:
> > > > 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
> > > >
> > >
> > > The test passes on Harmony+IBMVME on WindowsXP on my desktop, so you
> > > mean Harmony+DRLVM here?
> > Yep, Harmony+DRLVM on SuSE
> >
> > >
> > > But IMHO the VM does not matter in network issues, the native code call
> > > directly to the system APIs(of course, through Port-Lib), so I wonder if
> > > there's something wrong in thread(handle by VM)? Just a thought.
> > >
> > > And IMO, that telnet shall not connect to the server is due to
> > > "serverSocket.setSoTimeout(1000);", which make "serverSocket.accept()"
> > > wait for only one second.
> > Of course I had changed timeout to 10sec when used telnet :)
> >
> > >
> > > I have to download Harmony+DRLVM to debug into, but the speed of network
> > > is poor here :)
> > >
> > >
> > > --
> > >
> > > Best Regards!
> > >
> > > Jimmy, Jing Lv
> > > China Software Development Lab, IBM
> > >
> >
> >
> > --
> > Denis M. Kishenko
> > Intel Middleware Products Division
> >
>


-- 
Denis M. Kishenko
Intel Middleware Products Division

Re: [classlib][net] issue H-1879 HttpURLConnectionTest

Posted by Alexei Fedotov <al...@gmail.com>.
Denis wrote,
> Yep, Harmony+DRLVM on SuSE

A peculiar thing about this test is that it passes on SuSE 10, but
fails on SuSE 9 which is used for our regression test runs.

-- 
Thank you,
Alexei

On 11/21/06, Denis Kishenko <dk...@gmail.com> wrote:
> 2006/11/21, Jimmy, Jing Lv <fi...@gmail.com>:
> > Denis Kishenko wrote:
> > > 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
> > >
> >
> > The test passes on Harmony+IBMVME on WindowsXP on my desktop, so you
> > mean Harmony+DRLVM here?
> Yep, Harmony+DRLVM on SuSE
>
> >
> > But IMHO the VM does not matter in network issues, the native code call
> > directly to the system APIs(of course, through Port-Lib), so I wonder if
> > there's something wrong in thread(handle by VM)? Just a thought.
> >
> > And IMO, that telnet shall not connect to the server is due to
> > "serverSocket.setSoTimeout(1000);", which make "serverSocket.accept()"
> > wait for only one second.
> Of course I had changed timeout to 10sec when used telnet :)
>
> >
> > I have to download Harmony+DRLVM to debug into, but the speed of network
> > is poor here :)
> >
> >
> > --
> >
> > Best Regards!
> >
> > Jimmy, Jing Lv
> > China Software Development Lab, IBM
> >
>
>
> --
> Denis M. Kishenko
> Intel Middleware Products Division
>

Re: [classlib][net] issue H-1879 HttpURLConnectionTest

Posted by Denis Kishenko <dk...@gmail.com>.
Additional log information showed that HttpURLConnection tried to
connect when proxy had already closed. I changed proxy timeout to
10secs and test worked very well. Another way to fix problem is to
exclude waiting while server/proxy started. It's nececcary to delete
from testUsingProxy and testUsingProxySelector next code
            synchronized(bound) {
                bound.wait(5000);
            }
I checked this fix on linux and winXP, test is ok. I prefer the second
way because of test execution time will be decreased.

Because of on WinXP this test is ok, may be it's sensitive to
implementation of thread synchronization on different platforms or may
be it's vm issue.

Thoughs?

2006/11/21, Denis Kishenko <dk...@gmail.com>:
> 2006/11/21, Jimmy, Jing Lv <fi...@gmail.com>:
> > Denis Kishenko wrote:
> > > 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
> > >
> >
> > The test passes on Harmony+IBMVME on WindowsXP on my desktop, so you
> > mean Harmony+DRLVM here?
> Yep, Harmony+DRLVM on SuSE
>
> >
> > But IMHO the VM does not matter in network issues, the native code call
> > directly to the system APIs(of course, through Port-Lib), so I wonder if
> > there's something wrong in thread(handle by VM)? Just a thought.
> >
> > And IMO, that telnet shall not connect to the server is due to
> > "serverSocket.setSoTimeout(1000);", which make "serverSocket.accept()"
> > wait for only one second.
> Of course I had changed timeout to 10sec when used telnet :)
>
> >
> > I have to download Harmony+DRLVM to debug into, but the speed of network
> > is poor here :)
> >
> >
> > --
> >
> > Best Regards!
> >
> > Jimmy, Jing Lv
> > China Software Development Lab, IBM
> >
>
>
> --
> Denis M. Kishenko
> Intel Middleware Products Division
>


-- 
Denis M. Kishenko
Intel Middleware Products Division

Re: [classlib][net] issue H-1879 HttpURLConnectionTest

Posted by Denis Kishenko <dk...@gmail.com>.
2006/11/21, Jimmy, Jing Lv <fi...@gmail.com>:
> Denis Kishenko wrote:
> > 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
> >
>
> The test passes on Harmony+IBMVME on WindowsXP on my desktop, so you
> mean Harmony+DRLVM here?
Yep, Harmony+DRLVM on SuSE

>
> But IMHO the VM does not matter in network issues, the native code call
> directly to the system APIs(of course, through Port-Lib), so I wonder if
> there's something wrong in thread(handle by VM)? Just a thought.
>
> And IMO, that telnet shall not connect to the server is due to
> "serverSocket.setSoTimeout(1000);", which make "serverSocket.accept()"
> wait for only one second.
Of course I had changed timeout to 10sec when used telnet :)

>
> I have to download Harmony+DRLVM to debug into, but the speed of network
> is poor here :)
>
>
> --
>
> Best Regards!
>
> Jimmy, Jing Lv
> China Software Development Lab, IBM
>


-- 
Denis M. Kishenko
Intel Middleware Products Division

Re: [classlib][net] issue H-1879 HttpURLConnectionTest

Posted by "Jimmy, Jing Lv" <fi...@gmail.com>.
Denis Kishenko wrote:
> 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
> 

The test passes on Harmony+IBMVME on WindowsXP on my desktop, so you 
mean Harmony+DRLVM here?

But IMHO the VM does not matter in network issues, the native code call 
directly to the system APIs(of course, through Port-Lib), so I wonder if 
there's something wrong in thread(handle by VM)? Just a thought.

And IMO, that telnet shall not connect to the server is due to 
"serverSocket.setSoTimeout(1000);", which make "serverSocket.accept()" 
wait for only one second.

I have to download Harmony+DRLVM to debug into, but the speed of network 
is poor here :)


-- 

Best Regards!

Jimmy, Jing Lv
China Software Development Lab, IBM

[classlib][net] issue H-1879 HttpURLConnectionTest

Posted by Denis Kishenko <dk...@gmail.com>.
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