You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2010/12/03 22:23:35 UTC

svn commit: r1042011 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/src/test/org/apache/lucene/util/LuceneJUnitResultFormatter.java solr/

Author: rmuir
Date: Fri Dec  3 21:23:30 2010
New Revision: 1042011

URL: http://svn.apache.org/viewvc?rev=1042011&view=rev
Log:
use less RAM/reclaim for the formatter console buffer (e.g. VERBOSE/logging)

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/LuceneJUnitResultFormatter.java
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/LuceneJUnitResultFormatter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/LuceneJUnitResultFormatter.java?rev=1042011&r1=1042010&r2=1042011&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/LuceneJUnitResultFormatter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/LuceneJUnitResultFormatter.java Fri Dec  3 21:23:30 2010
@@ -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 
   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 
 
   /** Constructor for LuceneJUnitResultFormatter. */
   public LuceneJUnitResultFormatter() {
-    sb = new StringBuilder();
   }
   
   /**
@@ -116,13 +116,13 @@ public class LuceneJUnitResultFormatter 
     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 
    * @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 
     }
     
     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 
       try {
         lock.obtain(5000);
         try {
-          out.write(sb.toString().getBytes());
+          sb.writeTo(out);
           out.flush();
         } finally {
           try {
@@ -252,14 +252,27 @@ public class LuceneJUnitResultFormatter 
       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));
   }
 }