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/11/17 16:58:56 UTC

svn commit: r1036088 - in /lucene/dev/trunk: lucene/ lucene/src/test/org/apache/lucene/util/ solr/ solr/contrib/analysis-extras/ solr/contrib/clustering/ solr/contrib/dataimporthandler/ solr/contrib/extraction/

Author: rmuir
Date: Wed Nov 17 15:58:55 2010
New Revision: 1036088

URL: http://svn.apache.org/viewvc?rev=1036088&view=rev
Log:
LUCENE-2768: add support to LuceneTestCase for @Nightly annotated tests

Modified:
    lucene/dev/trunk/lucene/common-build.xml
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/trunk/solr/build.xml
    lucene/dev/trunk/solr/common-build.xml
    lucene/dev/trunk/solr/contrib/analysis-extras/build.xml
    lucene/dev/trunk/solr/contrib/clustering/build.xml
    lucene/dev/trunk/solr/contrib/dataimporthandler/build.xml
    lucene/dev/trunk/solr/contrib/extraction/build.xml

Modified: lucene/dev/trunk/lucene/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/common-build.xml?rev=1036088&r1=1036087&r2=1036088&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/common-build.xml (original)
+++ lucene/dev/trunk/lucene/common-build.xml Wed Nov 17 15:58:55 2010
@@ -72,6 +72,7 @@
   <property name="tests.seed" value="random" />
   <property name="tests.userdir" value="."/>
   <property name="tests.loggingfile" value="/dev/null"/>
+  <property name="tests.nightly" value="false" />
     
   <property name="javac.deprecation" value="off"/>
   <property name="javac.debug" value="on"/>
@@ -462,7 +463,9 @@
               <sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
               <!-- logging config file -->
               <sysproperty key="java.util.logging.config.file" value="${tests.loggingfile}"/>
-	
+          <!-- set whether or not nightly tests should run -->
+          <sysproperty key="tests.nightly" value="${tests.nightly}"/>
+
 	      <!-- TODO: create propertyset for test properties, so each project can have its own set -->
               <sysproperty key="tests.multiplier" value="${tests.multiplier}"/>
 	      <sysproperty key="tempDir" file="@{tempDir}/@{threadNum}"/>

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java?rev=1036088&r1=1036087&r2=1036088&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java Wed Nov 17 15:58:55 2010
@@ -63,6 +63,10 @@ import org.junit.runners.model.Initializ
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -152,6 +156,8 @@ public abstract class LuceneTestCase ext
   static final int TEST_ITER = Integer.parseInt(System.getProperty("tests.iter", "1"));
   /** Get the random seed for tests */
   static final String TEST_SEED = System.getProperty("tests.seed", "random");
+  /** whether or not nightly tests should run */
+  static final boolean TEST_NIGHTLY = Boolean.parseBoolean(System.getProperty("tests.nightly", "false"));
   
   private static final Pattern codecWithParam = Pattern.compile("(.*)\\(\\s*(\\d+)\\s*\\)");
 
@@ -843,6 +849,14 @@ public abstract class LuceneTestCase ext
 
   private String name = "<unknown>";
   
+  /**
+   * Annotation for tests that should only be run during nightly builds.
+   */
+  @Documented
+  @Inherited
+  @Retention(RetentionPolicy.RUNTIME)
+  public @interface Nightly {}
+  
   /** optionally filters the tests to be run by TEST_METHOD */
   public static class LuceneTestCaseRunner extends BlockJUnit4ClassRunner {
     private List<FrameworkMethod> testMethods;
@@ -856,7 +870,7 @@ public abstract class LuceneTestCase ext
       for (Method m : getTestClass().getJavaClass().getMethods()) {
         // check if the current test's class has methods annotated with @Ignore
         final Ignore ignored = m.getAnnotation(Ignore.class);
-        if (ignored != null) {
+        if (ignored != null && !m.getName().equals("alwaysIgnoredTestMethod")) {
           System.err.println("NOTE: Ignoring test method '" + m.getName() + "': " + ignored.value());
         }
         // add methods starting with "test"
@@ -872,6 +886,34 @@ public abstract class LuceneTestCase ext
           testMethods.add(new FrameworkMethod(m));
         }
       }
+      
+      if (testMethods.isEmpty()) {
+        throw new RuntimeException("No runnable methods!");
+      }
+      
+      if (TEST_NIGHTLY == false) {
+        if (getTestClass().getJavaClass().isAnnotationPresent(Nightly.class)) {
+          /* the test class is annotated with nightly, remove all methods */
+          String className = getTestClass().getJavaClass().getSimpleName();
+          System.err.println("NOTE: Ignoring nightly-only test class '" + className + "'");
+          testMethods.clear();
+        } else {
+          /* remove all nightly-only methods */
+          for (int i = 0; i < testMethods.size(); i++) {
+            final FrameworkMethod m = testMethods.get(i);
+            if (m.getAnnotation(Nightly.class) != null) {
+              System.err.println("NOTE: Ignoring nightly-only test method '" + m.getName() + "'");
+              testMethods.remove(i--);
+            }
+          }
+        }
+        /* dodge a possible "no-runnable methods" exception by adding a fake ignored test */
+        if (testMethods.isEmpty()) {
+          try {
+            testMethods.add(new FrameworkMethod(LuceneTestCase.class.getMethod("alwaysIgnoredTestMethod")));
+          } catch (Exception e) { throw new RuntimeException(e); }
+        }
+      }
       return testMethods;
     }
 
@@ -901,4 +943,7 @@ public abstract class LuceneTestCase ext
       }
     }
   }
+  
+  @Ignore("just a hack")
+  public final void alwaysIgnoredTestMethod() {}
 }

Modified: lucene/dev/trunk/solr/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/build.xml?rev=1036088&r1=1036087&r2=1036088&view=diff
==============================================================================
--- lucene/dev/trunk/solr/build.xml (original)
+++ lucene/dev/trunk/solr/build.xml Wed Nov 17 15:58:55 2010
@@ -436,6 +436,8 @@
       <sysproperty key="jetty.testMode" value="1"/>
       <sysproperty key="tempDir" file="@{tempDir}/@{threadNum}"/>
       <sysproperty key="testmethod" value="${testmethod}"/>
+      <!-- set whether or not nightly tests should run -->
+      <sysproperty key="tests.nightly" value="${tests.nightly}"/>
       <!-- TODO: why is this unconditionally set to "" above? disable for now
          <jvmarg line="${dir.prop}"/>
       -->

Modified: lucene/dev/trunk/solr/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/common-build.xml?rev=1036088&r1=1036087&r2=1036088&view=diff
==============================================================================
--- lucene/dev/trunk/solr/common-build.xml (original)
+++ lucene/dev/trunk/solr/common-build.xml Wed Nov 17 15:58:55 2010
@@ -61,6 +61,7 @@
   <property name="tests.timezone" value="random" />
   <property name="tests.iter" value="1" />
   <property name="tests.seed" value="random" />
+  <property name="tests.nightly" value="false" />
 
   <condition property="dir.prop" value="-Dsolr.directoryFactory=solr.StandardDirectoryFactory">
     <isset property="use.fsdir"/>

Modified: lucene/dev/trunk/solr/contrib/analysis-extras/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/analysis-extras/build.xml?rev=1036088&r1=1036087&r2=1036088&view=diff
==============================================================================
--- lucene/dev/trunk/solr/contrib/analysis-extras/build.xml (original)
+++ lucene/dev/trunk/solr/contrib/analysis-extras/build.xml Wed Nov 17 15:58:55 2010
@@ -148,6 +148,8 @@
       <sysproperty key="tests.multiplier" value="${tests.multiplier}"/>
       <sysproperty key="tests.seed" value="${tests.seed}"/>
       <sysproperty key="tests.iter" value="${tests.iter}"/>
+      <!-- set whether or not nightly tests should run -->
+      <sysproperty key="tests.nightly" value="${tests.nightly}"/>
       <sysproperty key="jetty.testMode" value="1"/>
       <sysproperty key="tempDir" file="${junit.output.dir}"/>
       <sysproperty key="testmethod" value="${testmethod}"/>

Modified: lucene/dev/trunk/solr/contrib/clustering/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/clustering/build.xml?rev=1036088&r1=1036087&r2=1036088&view=diff
==============================================================================
--- lucene/dev/trunk/solr/contrib/clustering/build.xml (original)
+++ lucene/dev/trunk/solr/contrib/clustering/build.xml Wed Nov 17 15:58:55 2010
@@ -116,6 +116,8 @@
       <sysproperty key="tests.multiplier" value="${tests.multiplier}"/>
       <sysproperty key="tests.seed" value="${tests.seed}"/>
       <sysproperty key="tests.iter" value="${tests.iter}"/>
+      <!-- set whether or not nightly tests should run -->
+      <sysproperty key="tests.nightly" value="${tests.nightly}"/>
       <sysproperty key="jetty.testMode" value="1"/>
       <sysproperty key="tempDir" file="${junit.output.dir}"/>
       <sysproperty key="testmethod" value="${testmethod}"/>

Modified: lucene/dev/trunk/solr/contrib/dataimporthandler/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/build.xml?rev=1036088&r1=1036087&r2=1036088&view=diff
==============================================================================
--- lucene/dev/trunk/solr/contrib/dataimporthandler/build.xml (original)
+++ lucene/dev/trunk/solr/contrib/dataimporthandler/build.xml Wed Nov 17 15:58:55 2010
@@ -168,6 +168,8 @@
       <sysproperty key="tests.multiplier" value="${tests.multiplier}"/>
       <sysproperty key="tests.iter" value="${tests.iter}"/>
       <sysproperty key="tests.seed" value="${tests.seed}"/>
+      <!-- set whether or not nightly tests should run -->
+      <sysproperty key="tests.nightly" value="${tests.nightly}"/>
       <sysproperty key="jetty.testMode" value="1"/>
       <sysproperty key="tempDir" file="${tempDir}"/>
       <sysproperty key="testmethod" value="${testmethod}"/>
@@ -226,6 +228,8 @@
       <sysproperty key="tests.multiplier" value="${tests.multiplier}"/>
       <sysproperty key="tests.iter" value="${tests.iter}"/>
       <sysproperty key="tests.seed" value="${tests.seed}"/>
+      <!-- set whether or not nightly tests should run -->
+      <sysproperty key="tests.nightly" value="${tests.nightly}"/>
       <sysproperty key="jetty.testMode" value="1"/>
       <sysproperty key="tempDir" file="${tempDir}"/>
       <sysproperty key="testmethod" value="${testmethod}"/>

Modified: lucene/dev/trunk/solr/contrib/extraction/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/extraction/build.xml?rev=1036088&r1=1036087&r2=1036088&view=diff
==============================================================================
--- lucene/dev/trunk/solr/contrib/extraction/build.xml (original)
+++ lucene/dev/trunk/solr/contrib/extraction/build.xml Wed Nov 17 15:58:55 2010
@@ -117,6 +117,8 @@
       <sysproperty key="tests.multiplier" value="${tests.multiplier}"/>
       <sysproperty key="tests.iter" value="${tests.iter}"/>
       <sysproperty key="tests.seed" value="${tests.seed}"/>
+      <!-- set whether or not nightly tests should run -->
+      <sysproperty key="tests.nightly" value="${tests.nightly}"/>
       <sysproperty key="jetty.testMode" value="1"/>
       <sysproperty key="tempDir" file="${tempDir}"/>
       <sysproperty key="testmethod" value="${testmethod}"/>