hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1417236 - in /hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase: ClassTestFinder.java IntegrationTestsDriver.java
Date Tue, 04 Dec 2012 23:20:06 GMT
Author: stack
Date: Tue Dec  4 23:20:06 2012
New Revision: 1417236

URL: http://svn.apache.org/viewvc?rev=1417236&view=rev
Log:
HBASE-7249 add test name filter to IntegrationTestsDriver

Modified:
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java?rev=1417236&r1=1417235&r2=1417236&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java Tue Dec
 4 23:20:06 2012
@@ -50,7 +50,7 @@ public class ClassTestFinder extends Cla
     return new Class<?>[0];
   }
 
-  private static class TestFileNameFilter implements FileNameFilter {
+  public static class TestFileNameFilter implements FileNameFilter {
     private static final Pattern hadoopCompactRe =
         Pattern.compile("hbase-hadoop\\d?-compat");
 
@@ -68,7 +68,7 @@ public class ClassTestFinder extends Cla
    *  - one or more of its methods is annotated with org.junit.Test OR
    *  - the class is annotated with Suite.SuiteClasses
   * */
-  private static class TestClassFilter implements ClassFilter {
+  public static class TestClassFilter implements ClassFilter {
     private Class<?> categoryAnnotation = null;
     public TestClassFilter(Class<?> categoryAnnotation) {
       this.categoryAnnotation = categoryAnnotation;

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java?rev=1417236&r1=1417235&r2=1417236&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java
(original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java
Tue Dec  4 23:20:06 2012
@@ -21,6 +21,7 @@ package org.apache.hadoop.hbase;
 import java.io.IOException;
 import java.util.List;
 import java.util.Set;
+import java.util.regex.Pattern;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.hadoop.hbase.util.AbstractHBaseTool;
@@ -38,30 +39,55 @@ import org.apache.commons.logging.LogFac
  * already deployed distributed cluster.
  */
 public class IntegrationTestsDriver extends AbstractHBaseTool {
+  private static final String TESTS_ARG = "test";
   private static final Log LOG = LogFactory.getLog(IntegrationTestsDriver.class);
+  private IntegrationTestFilter intTestFilter = new IntegrationTestFilter();
 
   public static void main(String[] args) throws Exception {
     int ret = ToolRunner.run(new IntegrationTestsDriver(), args);
     System.exit(ret);
   }
 
+  private class IntegrationTestFilter extends ClassTestFinder.TestClassFilter {
+    private Pattern testFilterRe = Pattern.compile(".*");
+    public IntegrationTestFilter() {
+      super(IntegrationTests.class);
+    }
+
+    public void setPattern(String pattern) {
+      testFilterRe = Pattern.compile(pattern);
+    }
+
+    @Override
+    public boolean isCandidateClass(Class<?> c) {
+      return super.isCandidateClass(c) && testFilterRe.matcher(c.getName()).find();
+    }
+  }
+
   @Override
   protected void addOptions() {
+    addOptWithArg(TESTS_ARG, "a Java regular expression to filter tests on");
   }
 
   @Override
   protected void processOptions(CommandLine cmd) {
+    String testFilterString = cmd.getOptionValue(TESTS_ARG, null);
+    if (testFilterString != null) {
+      intTestFilter.setPattern(testFilterString);
+    }
   }
 
   /**
-   * Returns test classes annotated with @Category(IntegrationTests.class)
+   * Returns test classes annotated with @Category(IntegrationTests.class),
+   * according to the filter specific on the command line (if any).
    */
   private Class<?>[] findIntegrationTestClasses()
     throws ClassNotFoundException, LinkageError, IOException {
-     ClassTestFinder classFinder = new ClassTestFinder(IntegrationTests.class);
-     Set<Class<?>> classes = classFinder.findClasses(true);
-     return classes.toArray(new Class<?>[classes.size()]);
-   }
+    ClassTestFinder.TestFileNameFilter nameFilter = new ClassTestFinder.TestFileNameFilter();
+    ClassFinder classFinder = new ClassFinder(nameFilter, intTestFilter);
+    Set<Class<?>> classes = classFinder.findClasses(true);
+    return classes.toArray(new Class<?>[classes.size()]);
+  }
 
 
   @Override
@@ -78,4 +104,4 @@ public class IntegrationTestsDriver exte
     return result.wasSuccessful() ? 0 : 1;
   }
 
-}
\ No newline at end of file
+}



Mime
View raw message