Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1 from rborer/master
JENKINS-13504: use the HTTP timeout inside the connection
  • Loading branch information
swestcott committed Apr 19, 2012
2 parents f643b32 + 10dbaa8 commit 26a6cc4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/main/java/hudson/plugins/fitnesse/FitnesseExecutor.java
Expand Up @@ -194,7 +194,8 @@ public void run() {
} catch (Exception e) {
// swallow - file may not exist
}
final byte[] bytes = getHttpBytes(logger, readFromURL, runnerWithTimeOut);
final byte[] bytes = getHttpBytes(logger, readFromURL, runnerWithTimeOut,
builder.getFitnesseHttpTimeout());
writeFitnesseResults(logger, writeToFilePath, bytes);
}
};
Expand All @@ -208,13 +209,14 @@ public void onReset() {
runnerWithTimeOut.run(readAndWriteResults, logToConsole);
}

public byte[] getHttpBytes(PrintStream log, URL pageCmdTarget, Resettable timeout) {
public byte[] getHttpBytes(PrintStream log, URL pageCmdTarget, Resettable timeout, int httpTimeout) {
InputStream inputStream = null;
ByteArrayOutputStream bucket = new ByteArrayOutputStream();

try {
log.println("Connnecting to " + pageCmdTarget);
HttpURLConnection connection = (HttpURLConnection) pageCmdTarget.openConnection();
connection.setReadTimeout(httpTimeout);
log.println("Connected: " + connection.getResponseCode() + "/" + connection.getResponseMessage());

inputStream = connection.getInputStream();
Expand Down
Expand Up @@ -2,6 +2,8 @@

import hudson.EnvVars;
import hudson.FilePath;
import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -13,9 +15,6 @@
import java.util.HashMap;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;

public class FitnesseExecutorTest {

private static final String LINE_SEPARATOR = System.getProperty("line.separator");
Expand Down Expand Up @@ -215,7 +214,8 @@ public void getHttpBytesShouldReturnContentFromUrlWriteToLogAndCallReset() throw
Resettable resettable = new Resettable() {
public void reset() { resetWasCalled = true; }
};
byte[] bytes = executor.getHttpBytes(new PrintStream(logBucket), new URL("http://hudson-ci.org/"), resettable);
byte[] bytes = executor.getHttpBytes(new PrintStream(logBucket), new URL("http://hudson-ci.org/"),
resettable, 60*1000);
Assert.assertTrue(bytes.length > 0);
Assert.assertTrue(new String(bytes).contains("<html"));
Assert.assertTrue(new String(bytes).contains("</html>"));
Expand Down

0 comments on commit 26a6cc4

Please sign in to comment.