[ grinder-Bugs-2919190 ] setTimeout method does not effect read timeouts
"SourceForge.net" <[email protected]>
| Newsgroups | gmane.comp.java.grinder.devel |
|---|---|
| Message-ID | <[email protected]> |
Bugs item #2919190, was opened at 2009-12-22 16:43
Message generated for change (Tracker Item Submitted) made by amachang
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=118598&aid=2919190&group_id=18598
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: HTTP Plugin
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: amachang (amachang)
Assigned to: Nobody/Anonymous (nobody)
Summary: setTimeout method does not effect read timeouts
Initial Comment:
* Problem
Following javadoc mentions "Sets the timeout to be used for creating connections and reading responses.".
http://grinder.sourceforge.net/g3/script-javadoc/net/grinder/plugin/http/HTTPPluginConnection.html#setTimeout(int)
But, actually HTTPPluginControl.getConnectionDefaults().setTimeout(int) method does not effect read timeouts.
* Sample code to reproduce the problem.
==== net/grinder/plugin/http/TestReadTimeout.java ====
package net.grinder.plugin.http;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.atomic.*;
import junit.framework.*;
import net.grinder.common.*;
import net.grinder.plugininterface.*;
import net.grinder.script.*;
import net.grinder.statistics.*;
import net.grinder.testutility.*;
import net.grinder.util.*;
import HTTPClient.*;
public class TestReadTimeout extends TestCase {
private final RandomStubFactory<Grinder.ScriptContext> m_scriptContextStubFactory =
RandomStubFactory.create(Grinder.ScriptContext.class);
private final RandomStubFactory<Statistics> m_statisticsStubFactory =
RandomStubFactory.create(Statistics.class);
private final PluginThreadContext m_threadContext =
RandomStubFactory.create(PluginThreadContext.class).getStub();
private final SSLContextFactory m_sslContextFactory =
RandomStubFactory.create(SSLContextFactory.class).getStub();
private final RandomStubFactory<PluginProcessContext>
m_pluginProcessContextStubFactory =
RandomStubFactory.create(PluginProcessContext.class);
private final PluginProcessContext m_pluginProcessContext =
m_pluginProcessContextStubFactory.getStub();
private final RandomStubFactory<Statistics.StatisticsForTest>
m_statisticsForTestStubFactory =
RandomStubFactory.create(Statistics.StatisticsForTest.class);
private final Statistics.StatisticsForTest m_statisticsForTest =
m_statisticsForTestStubFactory.getStub();
private HTTPRequestHandler m_handler;
protected void setUp() throws Exception {
final HTTPPluginThreadState threadState =
new HTTPPluginThreadState(m_threadContext,
m_sslContextFactory,
null,
new StandardTimeAuthority());
m_statisticsStubFactory.setResult("isTestInProgress", Boolean.FALSE);
m_scriptContextStubFactory.setResult("getStatistics",
m_statisticsStubFactory.getStub());
m_pluginProcessContextStubFactory.setResult("getPluginThreadListener",
threadState);
m_pluginProcessContextStubFactory.setResult(
"getScriptContext",
m_scriptContextStubFactory.getStub());
m_pluginProcessContextStubFactory.setResult(
"getStatisticsServices", StatisticsServicesImplementation.getInstance());
m_statisticsStubFactory.assertNoMoreCalls();
new PluginRegistry() {
{
setInstance(this);
}
public void register(GrinderPlugin plugin) throws GrinderException {
plugin.initialize(m_pluginProcessContext);
}
};
HTTPPlugin.getPlugin().initialize(m_pluginProcessContext);
// Discard the registration of statistic views.
m_statisticsStubFactory.resetCallHistory();
m_handler = new HTTPRequestHandler();
}
protected void tearDown() throws Exception {
m_handler.shutdown();
}
public void testReadTimeout() throws Exception {
final AtomicReference<Exception> failure = new AtomicReference<Exception>();
final Thread th = new Thread(new Runnable() {
public void run() {
try {
final ServerSocket serverSocket = new ServerSocket(8089);
try {
final Socket clientSocket = serverSocket.accept();
try {
Thread.sleep(1000);
final PrintWriter pw = new PrintWriter(clientSocket.getOutputStream());
pw.print("HTTP/1.0 200 OK\r\n");
pw.print("Content-Type: text/plain\r\n");
pw.print("Content-Length: 4\r\n");
pw.print("Connection: close\r\n");
pw.print("\r\n");
pw.print("OK\r\n");
pw.close();
}
finally {
clientSocket.close();
}
}
finally {
serverSocket.close();
}
}
catch(Exception e) {
failure.set(e);
}
}
});
th.start();
final HTTPPluginConnectionDefaults connectionDefaults =
HTTPPluginConnectionDefaults.getConnectionDefaults();
final int originalTimeout = connectionDefaults.getTimeout();
try {
connectionDefaults.setTimeout(1);
try {
final HTTPRequest request = new HTTPRequest();
request.GET("http://127.0.0.1:8089");
fail("Expected TimeoutException");
}
catch (TimeoutException e) {
}
}
finally {
connectionDefaults.setTimeout(originalTimeout);
}
assertNull("Error has occured on tiny http server.", failure.get());
}
}
* Result of above sample code.
[junit] Testsuite: net.grinder.plugin.http.TestReadTimeout
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 1.702 sec
[junit]
[junit] Testcase: testReadTimeout took 1.654 sec
[junit] FAILED
[junit] Expected TimeoutException
[junit] junit.framework.AssertionFailedError: Expected TimeoutException
[junit] at net.grinder.plugin.http.TestReadTimeout.testReadTimeout(TestReadTimeout.java:161)
[junit]
* Potential fix
You should call socket.setSoTimeout(int) in HTTPConnection.sendRequest(Request, int), as is being done for the SSL case.
I wrote patch for the problems.
Please, apply it or consider it.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=118598&aid=2919190&group_id=18598
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev