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:
Robert Muir 2010-12-03 21:18:51 +00:00
parent 6d4867eca0
commit 7249ebe483
1 changed files with 40 additions and 27 deletions

View File

@ -18,6 +18,7 @@
package org.apache.lucene.util; package org.apache.lucene.util;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -59,7 +60,7 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
private String systemError = null; private String systemError = null;
/** Buffer output until the end of the test */ /** 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; private static final org.apache.lucene.store.Lock lock;
@ -80,7 +81,6 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
/** Constructor for LuceneJUnitResultFormatter. */ /** Constructor for LuceneJUnitResultFormatter. */
public LuceneJUnitResultFormatter() { public LuceneJUnitResultFormatter() {
sb = new StringBuilder();
} }
/** /**
@ -116,13 +116,13 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
if (out == null) { if (out == null) {
return; // Quick return - no output do nothing. return; // Quick return - no output do nothing.
} }
sb = new ByteArrayOutputStream(); // don't reuse, so its gc'ed
try { try {
LogManager.getLogManager().readConfiguration(); LogManager.getLogManager().readConfiguration();
} catch (Exception e) {} } catch (Exception e) {}
sb.setLength(0); append("Testsuite: ");
sb.append("Testsuite: "); append(suite.getName());
sb.append(suite.getName()); append(StringUtils.LINE_SEP);
sb.append(StringUtils.LINE_SEP);
} }
/** /**
@ -130,21 +130,21 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
* @param suite the test suite * @param suite the test suite
*/ */
public synchronized void endTestSuite(JUnitTest suite) { public synchronized void endTestSuite(JUnitTest suite) {
sb.append("Tests run: "); append("Tests run: ");
sb.append(suite.runCount()); append(suite.runCount());
sb.append(", Failures: "); append(", Failures: ");
sb.append(suite.failureCount()); append(suite.failureCount());
sb.append(", Errors: "); append(", Errors: ");
sb.append(suite.errorCount()); append(suite.errorCount());
sb.append(", Time elapsed: "); append(", Time elapsed: ");
sb.append(numberFormat.format(suite.getRunTime() / ONE_SECOND)); append(numberFormat.format(suite.getRunTime() / ONE_SECOND));
sb.append(" sec"); append(" sec");
sb.append(StringUtils.LINE_SEP); append(StringUtils.LINE_SEP);
sb.append(StringUtils.LINE_SEP); append(StringUtils.LINE_SEP);
// append the err and output streams to the log // append the err and output streams to the log
if (systemOutput != null && systemOutput.length() > 0) { if (systemOutput != null && systemOutput.length() > 0) {
sb.append("------------- Standard Output ---------------") append("------------- Standard Output ---------------")
.append(StringUtils.LINE_SEP) .append(StringUtils.LINE_SEP)
.append(systemOutput) .append(systemOutput)
.append("------------- ---------------- ---------------") .append("------------- ---------------- ---------------")
@ -152,7 +152,7 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
} }
if (systemError != null && systemError.length() > 0) { if (systemError != null && systemError.length() > 0) {
sb.append("------------- Standard Error -----------------") append("------------- Standard Error -----------------")
.append(StringUtils.LINE_SEP) .append(StringUtils.LINE_SEP)
.append(systemError) .append(systemError)
.append("------------- ---------------- ---------------") .append("------------- ---------------- ---------------")
@ -163,7 +163,7 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
try { try {
lock.obtain(5000); lock.obtain(5000);
try { try {
out.write(sb.toString().getBytes()); sb.writeTo(out);
out.flush(); out.flush();
} finally { } finally {
try { try {
@ -252,14 +252,27 @@ public class LuceneJUnitResultFormatter implements JUnitResultFormatter {
endTest(test); endTest(test);
} }
sb.append(formatTest(test) + type); append(formatTest(test) + type);
sb.append(StringUtils.LINE_SEP); append(StringUtils.LINE_SEP);
sb.append(error.getMessage()); append(error.getMessage());
sb.append(StringUtils.LINE_SEP); append(StringUtils.LINE_SEP);
String strace = JUnitTestRunner.getFilteredTrace(error); String strace = JUnitTestRunner.getFilteredTrace(error);
sb.append(strace); append(strace);
sb.append(StringUtils.LINE_SEP); append(StringUtils.LINE_SEP);
sb.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));
} }
} }