Apache Lucene open-source search software
use less RAM/reclaim for the formatter console buffer (e.g. VERBOSE/logging)
Robert Muir7249ebe4837d
diff --git a/lucene/src/test/org/apache/lucene/util/LuceneJUnitResultFormatter.java b/lucene/src/test/org/apache/lucene/util/LuceneJUnitResultFormatter.javaindex c2895d8ec65..27cce18234e 100644--- a/lucene/src/test/org/apache/lucene/util/LuceneJUnitResultFormatter.java+++ b/lucene/src/test/org/apache/lucene/util/LuceneJUnitResultFormatter.java@@ -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-outputprivate 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'edtry {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 logif (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));}}