You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2014/04/30 10:27:24 UTC

svn commit: r1591214 - in /lucene/dev/branches/LUCENE-5622: lucene/ lucene/analysis/stempel/src/test/org/egothor/stemmer/ lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/ lucene/benchmark/src/test/org/apache/lucene/benchmark/ lucene/bench...

Author: dweiss
Date: Wed Apr 30 08:27:23 2014
New Revision: 1591214

URL: http://svn.apache.org/r1591214
Log:
Soft limit on the sysout bytes instead of a yes/no switch.

Added:
    lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleLimitSysouts.java   (with props)
Removed:
    lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleDisallowSysouts.java
Modified:
    lucene/dev/branches/LUCENE-5622/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java
    lucene/dev/branches/LUCENE-5622/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java
    lucene/dev/branches/LUCENE-5622/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMATypeAwareAnalyzerTest.java
    lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/BenchmarkTestCase.java
    lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
    lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java
    lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java
    lucene/dev/branches/LUCENE-5622/lucene/common-build.xml
    lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/codecs/compressing/TestFastCompressionMode.java
    lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java
    lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSameRandomnessLocalePassedOrNot.java
    lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.java
    lucene/dev/branches/LUCENE-5622/lucene/demo/src/test/org/apache/lucene/demo/TestDemo.java
    lucene/dev/branches/LUCENE-5622/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java
    lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java
    lucene/dev/branches/LUCENE-5622/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java

Modified: lucene/dev/branches/LUCENE-5622/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java Wed Apr 30 08:27:23 2014
@@ -72,7 +72,6 @@ import java.util.StringTokenizer;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
 
-@SuppressSysoutChecks(bugUrl = "External tool.")
 public class TestCompile extends LuceneTestCase {
   
   public void testCompile() throws Exception {

Modified: lucene/dev/branches/LUCENE-5622/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java Wed Apr 30 08:27:23 2014
@@ -42,7 +42,6 @@ import java.util.Map;
 /**
  * Testcase for {@link UIMABaseAnalyzer}
  */
-@SuppressSysoutChecks(bugUrl = "UIMA logs via ju.logging")
 public class UIMABaseAnalyzerTest extends BaseTokenStreamTestCase {
 
   private UIMABaseAnalyzer analyzer;

Modified: lucene/dev/branches/LUCENE-5622/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMATypeAwareAnalyzerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMATypeAwareAnalyzerTest.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMATypeAwareAnalyzerTest.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMATypeAwareAnalyzerTest.java Wed Apr 30 08:27:23 2014
@@ -27,7 +27,6 @@ import org.junit.Test;
 /**
  * Testcase for {@link UIMATypeAwareAnalyzer}
  */
-@SuppressSysoutChecks(bugUrl = "UIMA logs via ju.logging")
 public class UIMATypeAwareAnalyzerTest extends BaseTokenStreamTestCase {
 
   private UIMATypeAwareAnalyzer analyzer;

Modified: lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/BenchmarkTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/BenchmarkTestCase.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/BenchmarkTestCase.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/BenchmarkTestCase.java Wed Apr 30 08:27:23 2014
@@ -31,7 +31,6 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
 /** Base class for all Benchmark unit tests. */
-@SuppressSysoutChecks(bugUrl = "Output expected.")
 public abstract class BenchmarkTestCase extends LuceneTestCase {
   private static File WORKDIR;
   

Modified: lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java Wed Apr 30 08:27:23 2014
@@ -67,7 +67,6 @@ import org.apache.lucene.util.LuceneTest
 /**
  * Test very simply that perf tasks - simple algorithms - are doing what they should.
  */
-@SuppressSysoutChecks(bugUrl = "Output expected.")
 public class TestPerfTasksLogic extends BenchmarkTestCase {
 
   @Override

Modified: lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java Wed Apr 30 08:27:23 2014
@@ -42,7 +42,6 @@ import org.apache.lucene.util.LuceneTest
 import conf.ConfLoader;
 
 /** Test very simply that perf tasks are parses as expected. */
-@SuppressSysoutChecks(bugUrl = "Output expected.")
 public class TestPerfTasksParse extends LuceneTestCase {
 
   static final String NEW_LINE = System.getProperty("line.separator");

Modified: lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java Wed Apr 30 08:27:23 2014
@@ -44,7 +44,6 @@ import java.nio.charset.StandardCharsets
  * this test will not work correctly, as it does not dynamically
  * generate its test trec topics/qrels!
  */
-@SuppressSysoutChecks(bugUrl = "Output expected.")
 public class TestQualityRun extends BenchmarkTestCase {
   
   @Override

Modified: lucene/dev/branches/LUCENE-5622/lucene/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/common-build.xml?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/common-build.xml (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/common-build.xml Wed Apr 30 08:27:23 2014
@@ -1008,7 +1008,6 @@
                 <propertyref prefix="tests.leavetmpdir" />
                 <propertyref prefix="tests.leaveTemporary" />
                 <propertyref prefix="tests.leavetemporary" />
-            	<propertyref prefix="tests.sysouts" />
                 <propertyref prefix="solr.test.leavetmpdir" />
             </syspropertyset>
 

Modified: lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/codecs/compressing/TestFastCompressionMode.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/codecs/compressing/TestFastCompressionMode.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/codecs/compressing/TestFastCompressionMode.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/codecs/compressing/TestFastCompressionMode.java Wed Apr 30 08:27:23 2014
@@ -24,5 +24,4 @@ public class TestFastCompressionMode ext
     super.setUp();
     mode = CompressionMode.FAST;
   }
-
 }

Modified: lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java Wed Apr 30 08:27:23 2014
@@ -18,7 +18,6 @@ package org.apache.lucene.util.junitcomp
  */
 
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.JUnitCore;
@@ -30,8 +29,7 @@ public class TestFailIfDirectoryNotClose
   public TestFailIfDirectoryNotClosed() {
     super(true);
   }
-  
-  @SuppressSysoutChecks(bugUrl = "Expected.")
+
   public static class Nested1 extends WithNestedTests.AbstractNestedTest {
     public void testDummy() throws Exception {
       Directory dir = newDirectory();

Modified: lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSameRandomnessLocalePassedOrNot.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSameRandomnessLocalePassedOrNot.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSameRandomnessLocalePassedOrNot.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSameRandomnessLocalePassedOrNot.java Wed Apr 30 08:27:23 2014
@@ -43,7 +43,6 @@ public class TestSameRandomnessLocalePas
     super(true);
   }
   
-  @SuppressSysoutChecks(bugUrl = "Expected.")
   public static class Nested extends WithNestedTests.AbstractNestedTest {
     public static String pickString;
     public static Locale defaultLocale;

Modified: lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.java Wed Apr 30 08:27:23 2014
@@ -30,7 +30,6 @@ import org.junit.runner.notification.Fai
  * console. 
  */
 public class TestSeedFromUncaught extends WithNestedTests {
-  @SuppressSysoutChecks(bugUrl = "Expected.")
   public static class ThrowInUncaught extends AbstractNestedTest {
     @Test
     public void testFoo() throws Exception {

Modified: lucene/dev/branches/LUCENE-5622/lucene/demo/src/test/org/apache/lucene/demo/TestDemo.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/demo/src/test/org/apache/lucene/demo/TestDemo.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/demo/src/test/org/apache/lucene/demo/TestDemo.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/demo/src/test/org/apache/lucene/demo/TestDemo.java Wed Apr 30 08:27:23 2014
@@ -25,7 +25,6 @@ import java.nio.charset.Charset;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
 
-@SuppressSysoutChecks(bugUrl = "Output expected.")
 public class TestDemo extends LuceneTestCase {
 
   private void testOneSearch(File indexPath, String query, int expectedHitCount) throws Exception {

Modified: lucene/dev/branches/LUCENE-5622/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java Wed Apr 30 08:27:23 2014
@@ -24,7 +24,6 @@ import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
 
-@SuppressSysoutChecks(bugUrl = "Output expected (external tool).")
 public class TestMultiPassIndexSplitter extends LuceneTestCase {
   IndexReader input;
   int NUM_DOCS = 11;

Modified: lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java Wed Apr 30 08:27:23 2014
@@ -230,6 +230,7 @@ import static com.carrotsearch.randomize
 @ThreadLeakFilters(defaultFilters = true, filters = {
     QuickPatchThreadsFilter.class
 })
+@TestRuleLimitSysouts.Limit(bytes = TestRuleLimitSysouts.DEFAULT_SYSOUT_BYTES_THRESHOLD)
 public abstract class LuceneTestCase extends Assert {
 
   // --------------------------------------------------------------------
@@ -248,13 +249,6 @@ public abstract class LuceneTestCase ext
 
   /** @see #ignoreAfterMaxFailures*/
   public static final String SYSPROP_FAILFAST = "tests.failfast";
-  
-  /**
-   * If true, enables assertions on writing to system streams.
-   * 
-   * @see TestRuleLimitSysouts
-   */
-  public static final String SYSPROP_SYSOUTS = "tests.sysouts";
 
   /**
    * Annotation for tests that should only be run during nightly builds.
@@ -356,8 +350,8 @@ public abstract class LuceneTestCase ext
   }
 
   /**
-   * Marks any suite which is known to print to {@link System#out} or {@link System#err},
-   * even when {@link #VERBOSE} is disabled.
+   * Ignore {@link TestRuleLimitSysouts} for any suite which is known to print 
+   * over the default limit of bytes to {@link System#out} or {@link System#err}.
    * 
    * @see TestRuleLimitSysouts
    */
@@ -369,7 +363,7 @@ public abstract class LuceneTestCase ext
     /** Point to JIRA entry. */
     public String bugUrl();
   }
-  
+
   // -----------------------------------------------------------------
   // Truly immutable fields and constants, initialized once and valid 
   // for all suites ever since.

Modified: lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java (original)
+++ lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java Wed Apr 30 08:27:23 2014
@@ -154,9 +154,6 @@ public final class RunListenerPrintRepro
     addVmOpt(b, "testcase", RandomizedContext.current().getTargetClass().getSimpleName());
     addVmOpt(b, "tests.method", testName);
     addVmOpt(b, "tests.seed", RandomizedContext.current().getRunnerSeedAsString());
-    
-    // Misc switches.
-    addVmOpt(b, SYSPROP_SYSOUTS, System.getProperty(SYSPROP_SYSOUTS));
 
     // Test groups and multipliers.
     if (RANDOM_MULTIPLIER > 1) addVmOpt(b, "tests.multiplier", RANDOM_MULTIPLIER);

Added: lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleLimitSysouts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleLimitSysouts.java?rev=1591214&view=auto
==============================================================================
--- lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleLimitSysouts.java (added)
+++ lucene/dev/branches/LUCENE-5622/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleLimitSysouts.java Wed Apr 30 08:27:23 2014
@@ -0,0 +1,236 @@
+package org.apache.lucene.util;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.nio.charset.Charset;
+import java.util.List;
+import java.util.Locale;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
+
+import com.carrotsearch.randomizedtesting.RandomizedTest;
+import com.carrotsearch.randomizedtesting.rules.TestRuleAdapter;
+
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Fails the suite if it prints over the given limit of bytes to either
+ * {@link System#out} or {@link System#err},
+ * unless the condition is not enforced (see {@link #isEnforced()}).
+ */
+public class TestRuleLimitSysouts extends TestRuleAdapter {
+  /**
+   * Max limit of bytes printed to either {@link System#out} or {@link System#err}. 
+   * This limit is enforced per-class (suite).
+   */
+  public final static int DEFAULT_SYSOUT_BYTES_THRESHOLD = 8 * 1024;
+
+  /**
+   * An annotation specifying the limit of bytes per class.
+   */
+  @Documented
+  @Inherited
+  @Retention(RetentionPolicy.RUNTIME)
+  @Target(ElementType.TYPE)
+  public static @interface Limit {
+    public int bytes();
+  }
+
+  private final static AtomicInteger bytesWritten = new AtomicInteger();
+
+  private final static DelegateStream capturedSystemOut;
+  private final static DelegateStream capturedSystemErr;
+  
+  /**
+   * We capture system output and error streams as early as possible because
+   * certain components (like the Java logging system) steal these references and
+   * never refresh them.
+   * 
+   * Also, for this exact reason, we cannot change delegate streams for every suite.
+   * This isn't as elegant as it should be, but there's no workaround for this.
+   */
+  static {
+    System.out.flush();
+    System.err.flush();
+
+    final String csn = Charset.defaultCharset().name();
+    capturedSystemOut = new DelegateStream(System.out, csn, bytesWritten);
+    capturedSystemErr = new DelegateStream(System.err, csn, bytesWritten);
+
+    System.setOut(capturedSystemOut.printStream);
+    System.setErr(capturedSystemErr.printStream);
+  }
+
+  /**
+   * Test failures from any tests or rules before.
+   */
+  private final TestRuleMarkFailure failureMarker;
+
+  /**
+   * Tracks the number of bytes written to an underlying stream by
+   * incrementing an {@link AtomicInteger}.
+   */
+  static class DelegateStream extends FilterOutputStream {
+    final PrintStream printStream;
+    final AtomicInteger bytesCounter;
+
+    public DelegateStream(OutputStream delegate, String charset, AtomicInteger bytesCounter) {
+      super(delegate);
+      try {
+        this.printStream = new PrintStream(this, true, charset);
+        this.bytesCounter = bytesCounter;
+      } catch (UnsupportedEncodingException e) {
+        throw new RuntimeException(e);
+      }
+    }
+
+    // Do override all three write() methods to make sure nothing slips through.
+
+    @Override
+    public void write(byte[] b) throws IOException {
+      if (b.length > 0) {
+        bytesCounter.addAndGet(b.length);
+      }
+      super.write(b);
+    }
+    
+    @Override
+    public void write(byte[] b, int off, int len) throws IOException {
+      if (len > 0) {
+        bytesCounter.addAndGet(len);
+      }
+      super.write(b, off, len);
+    }
+
+    @Override
+    public void write(int b) throws IOException {
+      bytesCounter.incrementAndGet();
+      super.write(b);
+    }
+  }
+
+  public TestRuleLimitSysouts(TestRuleMarkFailure failureMarker) {
+    this.failureMarker = failureMarker;
+  }
+
+  
+  /** */
+  @Override
+  protected void before() throws Throwable {
+    if (isEnforced()) {
+      checkCaptureStreams();
+    }
+    resetCaptureState();
+    validateClassAnnotations();
+  }
+
+  private void validateClassAnnotations() {
+    Class<?> target = RandomizedTest.getContext().getTargetClass();
+    if (target.isAnnotationPresent(Limit.class)) {
+      int bytes = target.getAnnotation(Limit.class).bytes();
+      if (bytes < 0 || bytes > 1 * 1024 * 1024) {
+        throw new AssertionError("The sysout limit is insane. Did you want to use "
+            + "@" + LuceneTestCase.SuppressSysoutChecks.class.getName() + " annotation to "
+            + "avoid sysout checks entirely?");
+      }
+    }
+  }
+
+  /**
+   * Ensures {@link System#out} and {@link System#err} point to delegate streams.
+   */
+  public static void checkCaptureStreams() {
+    // Make sure we still hold the right references to wrapper streams.
+    if (System.out != capturedSystemOut.printStream) {
+      throw new AssertionError("Something has changed System.out to: " + System.out.getClass().getName());
+    }
+    if (System.err != capturedSystemErr.printStream) {
+      throw new AssertionError("Something has changed System.err to: " + System.err.getClass().getName());
+    }
+  }
+
+  protected boolean isEnforced() {
+    Class<?> target = RandomizedTest.getContext().getTargetClass();
+
+    if (LuceneTestCase.VERBOSE || 
+        LuceneTestCase.INFOSTREAM ||
+        target.isAnnotationPresent(SuppressSysoutChecks.class)) {
+      return false;
+    }
+    
+    if (!target.isAnnotationPresent(Limit.class)) {
+      return false;
+    }
+
+    return true;
+  }
+
+  /**
+   * We're only interested in failing the suite if it was successful. Otherwise
+   * just propagate the original problem and don't bother.
+   */
+  @Override
+  protected void afterIfSuccessful() throws Throwable {
+    if (isEnforced()) {
+      checkCaptureStreams();
+  
+      // Flush any buffers.
+      capturedSystemOut.printStream.flush();
+      capturedSystemErr.printStream.flush();
+  
+      // Check for offenders, but only if everything was successful so far.
+      int limit = RandomizedTest.getContext().getTargetClass().getAnnotation(Limit.class).bytes();
+      if (bytesWritten.get() >= limit && failureMarker.wasSuccessful()) {
+        throw new AssertionError(String.format(Locale.ENGLISH, 
+            "The test or suite printed %d bytes to stdout and stderr," +
+            " even though the limit was set to %d bytes. Increase the limit with @%s, ignore it completely" +
+            " with @%s or run with -Dtests.verbose=true",
+            bytesWritten.get(),
+            limit,
+            Limit.class.getSimpleName(),
+            SuppressSysoutChecks.class.getSimpleName()));
+      }
+    }
+  }
+
+  /**
+   * Restore original streams.
+   */
+  @Override
+  protected void afterAlways(List<Throwable> errors) throws Throwable {
+    resetCaptureState();
+  }
+
+  private void resetCaptureState() {
+    capturedSystemOut.printStream.flush();
+    capturedSystemErr.printStream.flush();
+    bytesWritten.set(0);
+  }
+}
+

Modified: lucene/dev/branches/LUCENE-5622/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-5622/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java?rev=1591214&r1=1591213&r2=1591214&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-5622/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/branches/LUCENE-5622/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java Wed Apr 30 08:27:23 2014
@@ -119,7 +119,7 @@ import com.carrotsearch.randomizedtestin
     SolrIgnoredThreadsFilter.class,
     QuickPatchThreadsFilter.class
 })
-@SuppressSysoutChecks(bugUrl = "Solr dumps logs to console.")
+@SuppressSysoutChecks(bugUrl = "Solr dumps tons of logs to console.")
 public abstract class SolrTestCaseJ4 extends LuceneTestCase {
   private static String coreName = ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME;
   public static int DEFAULT_CONNECTION_TIMEOUT = 60000;  // default socket connection timeout in ms