HBASE-7249 add test name filter to IntegrationTestsDriver
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1417230 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f7f190a684
commit
2e5618b053
|
@ -50,7 +50,7 @@ public class ClassTestFinder extends ClassFinder {
|
|||
return new Class<?>[0];
|
||||
}
|
||||
|
||||
private static class TestFileNameFilter implements FileNameFilter, ResourcePathFilter {
|
||||
public static class TestFileNameFilter implements FileNameFilter, ResourcePathFilter {
|
||||
private static final Pattern hadoopCompactRe =
|
||||
Pattern.compile("hbase-hadoop\\d?-compat");
|
||||
|
||||
|
@ -73,7 +73,7 @@ public class ClassTestFinder extends ClassFinder {
|
|||
* - 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;
|
||||
|
|
|
@ -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.LogFactory;
|
|||
* 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, nameFilter, intTestFilter);
|
||||
Set<Class<?>> classes = classFinder.findClasses(true);
|
||||
return classes.toArray(new Class<?>[classes.size()]);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -669,10 +669,11 @@ If you have an already-setup HBase cluster, you can launch the integration tests
|
|||
run test-compile first. The configuration will be picked by the bin/hbase script.
|
||||
<programlisting>mvn test-compile</programlisting>
|
||||
Then launch the tests with:
|
||||
<programlisting>bin/hbase [--config config_dir] org.apache.hadoop.hbase.IntegrationTestsDriver</programlisting>
|
||||
<programlisting>bin/hbase [--config config_dir] org.apache.hadoop.hbase.IntegrationTestsDriver [-test=class_regex]</programlisting>
|
||||
|
||||
This execution will launch the tests under <code>hbase-it/src/test</code>, having <code>@Category(IntegrationTests.class)</code> annotation,
|
||||
and a name starting with <code>IntegrationTests</code>. It uses Junit to run the tests. Currently there is no support for running integration tests against a distributed cluster using maven (see <link xlink:href="https://issues.apache.org/jira/browse/HBASE-6201">HBASE-6201</link>).
|
||||
and a name starting with <code>IntegrationTests</code>. If specified, class_regex will be used to filter test classes. The regex is checked against full class name; so, part of class name can be used.
|
||||
IntegrationTestsDriver uses Junit to run the tests. Currently there is no support for running integration tests against a distributed cluster using maven (see <link xlink:href="https://issues.apache.org/jira/browse/HBASE-6201">HBASE-6201</link>).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
|
Loading…
Reference in New Issue