mirror of https://github.com/apache/lucene.git
use less RAM/reclaim for the formatter console buffer (e.g. VERBOSE/logging)
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1042008 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6d4867eca0
commit
7249ebe483
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.lucene.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
@ -59,7 +60,7 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
|
|||
private String systemError = null;
|
||||
|
||||
/** Buffer output until the end of the test */
|
||||
private StringBuilder sb;
|
||||
private ByteArrayOutputStream sb; // use a BOS for our mostly ascii-output
|
||||
|
||||
private static final org.apache.lucene.store.Lock lock;
|
||||
|
||||
|
@ -80,7 +81,6 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
|
|||
|
||||
/** Constructor for LuceneJUnitResultFormatter. */
|
||||
public LuceneJUnitResultFormatter() {
|
||||
sb = new StringBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,13 +116,13 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
|
|||
if (out == null) {
|
||||
return; // Quick return - no output do nothing.
|
||||
}
|
||||
sb = new ByteArrayOutputStream(); // don't reuse, so its gc'ed
|
||||
try {
|
||||
LogManager.getLogManager().readConfiguration();
|
||||
} catch (Exception e) {}
|
||||
sb.setLength(0);
|
||||
sb.append("Testsuite: ");
|
||||
sb.append(suite.getName());
|
||||
sb.append(StringUtils.LINE_SEP);
|
||||
append("Testsuite: ");
|
||||
append(suite.getName());
|
||||
append(StringUtils.LINE_SEP);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,21 +130,21 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
|
|||
* @param suite the test suite
|
||||
*/
|
||||
public synchronized void endTestSuite(JUnitTest suite) {
|
||||
sb.append("Tests run: ");
|
||||
sb.append(suite.runCount());
|
||||
sb.append(", Failures: ");
|
||||
sb.append(suite.failureCount());
|
||||
sb.append(", Errors: ");
|
||||
sb.append(suite.errorCount());
|
||||
sb.append(", Time elapsed: ");
|
||||
sb.append(numberFormat.format(suite.getRunTime() / ONE_SECOND));
|
||||
sb.append(" sec");
|
||||
sb.append(StringUtils.LINE_SEP);
|
||||
sb.append(StringUtils.LINE_SEP);
|
||||
append("Tests run: ");
|
||||
append(suite.runCount());
|
||||
append(", Failures: ");
|
||||
append(suite.failureCount());
|
||||
append(", Errors: ");
|
||||
append(suite.errorCount());
|
||||
append(", Time elapsed: ");
|
||||
append(numberFormat.format(suite.getRunTime() / ONE_SECOND));
|
||||
append(" sec");
|
||||
append(StringUtils.LINE_SEP);
|
||||
append(StringUtils.LINE_SEP);
|
||||
|
||||
// append the err and output streams to the log
|
||||
if (systemOutput != null && systemOutput.length() > 0) {
|
||||
sb.append("------------- Standard Output ---------------")
|
||||
append("------------- Standard Output ---------------")
|
||||
.append(StringUtils.LINE_SEP)
|
||||
.append(systemOutput)
|
||||
.append("------------- ---------------- ---------------")
|
||||
|
@ -152,7 +152,7 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
|
|||
}
|
||||
|
||||
if (systemError != null && systemError.length() > 0) {
|
||||
sb.append("------------- Standard Error -----------------")
|
||||
append("------------- Standard Error -----------------")
|
||||
.append(StringUtils.LINE_SEP)
|
||||
.append(systemError)
|
||||
.append("------------- ---------------- ---------------")
|
||||
|
@ -163,7 +163,7 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
|
|||
try {
|
||||
lock.obtain(5000);
|
||||
try {
|
||||
out.write(sb.toString().getBytes());
|
||||
sb.writeTo(out);
|
||||
out.flush();
|
||||
} finally {
|
||||
try {
|
||||
|
@ -252,14 +252,27 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
|
|||
endTest(test);
|
||||
}
|
||||
|
||||
sb.append(formatTest(test) + type);
|
||||
sb.append(StringUtils.LINE_SEP);
|
||||
sb.append(error.getMessage());
|
||||
sb.append(StringUtils.LINE_SEP);
|
||||
append(formatTest(test) + type);
|
||||
append(StringUtils.LINE_SEP);
|
||||
append(error.getMessage());
|
||||
append(StringUtils.LINE_SEP);
|
||||
String strace = JUnitTestRunner.getFilteredTrace(error);
|
||||
sb.append(strace);
|
||||
sb.append(StringUtils.LINE_SEP);
|
||||
sb.append(StringUtils.LINE_SEP);
|
||||
append(strace);
|
||||
append(StringUtils.LINE_SEP);
|
||||
append(StringUtils.LINE_SEP);
|
||||
}
|
||||
|
||||
public LuceneJUnitResultFormatter append(String s) {
|
||||
try {
|
||||
sb.write(s.getBytes()); // intentionally use default charset, its a console.
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public LuceneJUnitResultFormatter append(long l) {
|
||||
return append(Long.toString(l));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue