On 4 Jun 2007, at 19:09, Jerome Louvel wrote:
Hi Stian,
We haven't tried yet, but if you can help us pinpoint the issue
that would
be appreciated.
src/test/java/no/soiland/test/MultipleCalls.java:
package no.soiland.test;
import org.junit.Test;
import org.restlet.Client;
import org.restlet.data.Method;
import org.restlet.data.Protocol;
import org.restlet.data.Reference;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.data.Status;
public class MultipleCalls {
private static final String WEBSITE = "http://www.restlet.org/";
private static final int CALLS = 20;
// 5 seconds timeout
private static final int TIMEOUT=5*1000;
private Client sharedClient = new Client(Protocol.HTTP);
private void makeLotsOfCalls(boolean freshClient) {
for (int i=0; i<CALLS; i++) {
Client client;
if (freshClient) {
client = new Client(Protocol.HTTP);
} else {
client = sharedClient;
}
Request request = new Request(Method.GET, new
Reference(WEBSITE));
Response response = client.handle(request);
if (! response.getStatus().equals(Status.SUCCESS_OK)) {
System.out.println("\nFailed on " + i);
} else {
System.out.print(".");
System.out.flush();
}
}
}
@Test(timeout=TIMEOUT)
public void callsFresh() {
System.out.println("Testing with fresh clients");
System.out.flush();
makeLotsOfCalls(true);
System.out.print("\n");
}
@Test(timeout=TIMEOUT)
public void callsShared() {
System.out.println("Testing with shared client");
System.out.flush();
makeLotsOfCalls(false);
System.out.print("\n");
}
}
Using Maven2 with pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>no.soiland.test</groupId>
<artifactId>restlet-client-test</artifactId>
<version>0.0.1</version>
<description>
Test a dead-lock problem with Restlet's Client class
</description>
<repositories>
<repository>
<id>restlet</id>
<name>Restlet repository</name>
<url>http://maven.restlet.org</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.restlet</groupId>
<artifactId>org.restlet</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.noelios.restlet</groupId>
<artifactId>com.noelios.restlet.ext.httpclient</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</project>
Produces:
Testing with fresh clients
....................
Testing with shared client
..Jun 6, 2007 11:18:27 AM com.noelios.restlet.http.HttpClientHelper
handle
WARNING: Error while handling an HTTP client call:
Jun 6, 2007 11:18:27 AM com.noelios.restlet.http.HttpClientHelper handle
INFO: Error while handling an HTTP client call
java.lang.IllegalThreadStateException: Interrupted while waiting in
MultiThreadedHttpConnectionManager
at
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetCo
nnection(MultiThreadedHttpConnectionManager.java:522)
at
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConn
ectionWithTimeout(MultiThreadedHttpConnectionManager.java:416)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod
(HttpMethodDirector.java:153)
at org.apache.commons.httpclient.HttpClient.executeMethod
(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod
(HttpClient.java:323)
at com.noelios.restlet.ext.httpclient.HttpMethodCall.sendRequest
(HttpMethodCall.java:182)
at com.noelios.restlet.http.HttpClientConverter.commit
(HttpClientConverter.java:100)
at com.noelios.restlet.http.HttpClientHelper.handle
(HttpClientHelper.java:86)
at org.restlet.Client.handle(Client.java:110)
at org.restlet.Uniform.handle(Uniform.java:97)
at no.soiland.test.MultipleCalls.makeLotsOfCalls(MultipleCalls.java:32)
at no.soiland.test.MultipleCalls.callsShared(MultipleCalls.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody
(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected
(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod
(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.access$0
(TestMethodRunner.java:74)
at org.junit.internal.runners.TestMethodRunner$1.call
(TestMethodRunner.java:55)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
at java.util.concurrent.FutureTask.run(FutureTask.java:123)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:613)
...
java.lang.Exception: test timed out after 5000 milliseconds
at org.junit.internal.runners.TestMethodRunner.runWithTimeout
(TestMethodRunner.java:68)
at org.junit.internal.runners.TestMethodRunner.run
(TestMethodRunner.java:43)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod
(TestClassMethodsRunner.java:71)
at org.junit.internal.runners.TestClassMethodsRunner.run
(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected
(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run
(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run
(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run
(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run
(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main
(RemoteTestRunner.java:196)
So with the shared client it only manages two calls before it hangs.
Replace with com.noelios.restlet.ext.net instead of httpclient in the
pom and it works fine.
I have not tested with the latest SVN as it's a pain to get it
working in Eclipse.
(I'm struggling a bit with Maven to get it to run the test cases
directly there, when I get that working I'll send a zip, but as you
see quite a simple test-case triggers the bug, at least on OS X 10.4
with Java 5.)
--
Stian Soiland, myGrid team
School of Computer Science
The University of Manchester
http://www.cs.man.ac.uk/~ssoiland/