Skip to content

Commit

Permalink
[FIXED JENKINS-15382] Memory exhaustion parsing large test stdio from…
Browse files Browse the repository at this point in the history
… Surefire.(cherry picked from commit fe934aa)

Conflicts:
	changelog.html
  • Loading branch information
jglick authored and vjuranek committed Oct 22, 2012
1 parent 64fa3a2 commit 4acc879
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
11 changes: 11 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,17 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
</ul>
</div><!--=TRUNK-END=-->

<!-- these changes are controlled by the release process. DO NOT MODIFY -->
<div id="rc" style="display:none;"><!--=BEGIN=-->
<h3><a name=v1.485>What's new in 1.485</a> <!--=DATE=--></h3>

This comment has been minimized.

Copy link
@jglick

jglick Oct 22, 2012

Author Member

Bad cherry pick?

This comment has been minimized.

Copy link
@vjuranek

vjuranek Oct 22, 2012

Member

Thanks for spotting it, fixed in be6d2cc (wrongly resolved merge conflict)

<ul class=image>
<li class=bug>
Memory exhaustion parsing large test stdio from Surefire.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15382">issue 15382</a>)
<li class='rfe'>
Memory footprint improvement, especially under large HTTP request threads.
<li class=bug>
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/hudson/tasks/junit/CaseResult.java
Expand Up @@ -131,24 +131,24 @@ private static float parseTime(Element testCase) {
}

private static final int HALF_MAX_SIZE = 500;
static String possiblyTrimStdio(Collection<CaseResult> results, boolean keepLongStdio, String stdio) { // HUDSON-6516
static String possiblyTrimStdio(Collection<CaseResult> results, boolean keepLongStdio, CharSequence stdio) { // HUDSON-6516
if (stdio == null) {
return null;
}
if (keepLongStdio) {
return stdio;
return stdio.toString();
}
for (CaseResult result : results) {
if (result.errorStackTrace != null) {
return stdio;
return stdio.toString();
}
}
int len = stdio.length();
int middle = len - HALF_MAX_SIZE * 2;
if (middle <= 0) {
return stdio;
return stdio.toString();
}
return stdio.substring(0, HALF_MAX_SIZE) + "...[truncated " + middle + " chars]..." + stdio.substring(len - HALF_MAX_SIZE, len);
return stdio.subSequence(0, HALF_MAX_SIZE) + "...[truncated " + middle + " chars]..." + stdio.subSequence(len - HALF_MAX_SIZE, len);
}

/**
Expand Down
25 changes: 18 additions & 7 deletions core/src/main/java/hudson/tasks/junit/SuiteResult.java
Expand Up @@ -26,7 +26,6 @@
import hudson.tasks.test.TestObject;
import hudson.util.IOException2;
import hudson.util.io.ParserConfigurator;
import org.apache.commons.io.FileUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
Expand All @@ -36,7 +35,12 @@

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -182,26 +186,33 @@ private SuiteResult(File xmlReport, Element suite, boolean keepLongStdio) throws
addCase(new CaseResult(this, e, classname, keepLongStdio));
}

String stdout = suite.elementText("system-out");
String stderr = suite.elementText("system-err");
String stdout = CaseResult.possiblyTrimStdio(cases, keepLongStdio, suite.elementText("system-out"));
String stderr = CaseResult.possiblyTrimStdio(cases, keepLongStdio, suite.elementText("system-err"));
if (stdout==null && stderr==null) {
// Surefire never puts stdout/stderr in the XML. Instead, it goes to a separate file
// Surefire never puts stdout/stderr in the XML. Instead, it goes to a separate file (when ${maven.test.redirectTestOutputToFile}).
Matcher m = SUREFIRE_FILENAME.matcher(xmlReport.getName());
if (m.matches()) {
// look for ***-output.txt from TEST-***.xml
File mavenOutputFile = new File(xmlReport.getParentFile(),m.group(1)+"-output.txt");
if (mavenOutputFile.exists()) {
try {
stdout = FileUtils.readFileToString(mavenOutputFile);
RandomAccessFile raf = new RandomAccessFile(mavenOutputFile, "r");
try {
ByteBuffer bb = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, mavenOutputFile.length());
CharBuffer cb = Charset.defaultCharset().decode(bb);
stdout = CaseResult.possiblyTrimStdio(cases, keepLongStdio, cb);
} finally {
raf.close();
}
} catch (IOException e) {
throw new IOException2("Failed to read "+mavenOutputFile,e);
}
}
}
}

this.stdout = CaseResult.possiblyTrimStdio(cases, keepLongStdio, stdout);
this.stderr = CaseResult.possiblyTrimStdio(cases, keepLongStdio, stderr);
this.stdout = stdout;
this.stderr = stderr;
}

/*package*/ void addCase(CaseResult cr) {
Expand Down

0 comments on commit 4acc879

Please sign in to comment.