1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase;
20
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.Set;
24 import java.util.regex.Pattern;
25
26 import org.apache.commons.cli.CommandLine;
27 import org.apache.hadoop.hbase.util.AbstractHBaseTool;
28 import org.apache.hadoop.util.ToolRunner;
29 import org.junit.internal.TextListener;
30 import org.junit.runner.JUnitCore;
31 import org.junit.runner.Result;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36
37
38
39
40
41 public class IntegrationTestsDriver extends AbstractHBaseTool {
42 private static final String TESTS_ARG = "test";
43 private static final Log LOG = LogFactory.getLog(IntegrationTestsDriver.class);
44 private IntegrationTestFilter intTestFilter = new IntegrationTestFilter();
45
46 public static void main(String[] args) throws Exception {
47 int ret = ToolRunner.run(new IntegrationTestsDriver(), args);
48 System.exit(ret);
49 }
50
51 private class IntegrationTestFilter extends ClassTestFinder.TestClassFilter {
52 private Pattern testFilterRe = Pattern.compile(".*");
53 public IntegrationTestFilter() {
54 super(IntegrationTests.class);
55 }
56
57 public void setPattern(String pattern) {
58 testFilterRe = Pattern.compile(pattern);
59 }
60
61 @Override
62 public boolean isCandidateClass(Class<?> c) {
63 return super.isCandidateClass(c) && testFilterRe.matcher(c.getName()).find();
64 }
65 }
66
67 @Override
68 protected void addOptions() {
69 addOptWithArg(TESTS_ARG, "a Java regular expression to filter tests on");
70 }
71
72 @Override
73 protected void processOptions(CommandLine cmd) {
74 String testFilterString = cmd.getOptionValue(TESTS_ARG, null);
75 if (testFilterString != null) {
76 intTestFilter.setPattern(testFilterString);
77 }
78 }
79
80
81
82
83
84 private Class<?>[] findIntegrationTestClasses()
85 throws ClassNotFoundException, LinkageError, IOException {
86 ClassTestFinder.TestFileNameFilter nameFilter = new ClassTestFinder.TestFileNameFilter();
87 ClassFinder classFinder = new ClassFinder(nameFilter, intTestFilter);
88 Set<Class<?>> classes = classFinder.findClasses(true);
89 return classes.toArray(new Class<?>[classes.size()]);
90 }
91
92
93 @Override
94 protected int doWork() throws Exception {
95
96 IntegrationTestingUtility.setUseDistributedCluster(conf);
97 Class<?>[] classes = findIntegrationTestClasses();
98 LOG.info("Found " + classes.length + " integration tests to run");
99
100 JUnitCore junit = new JUnitCore();
101 junit.addListener(new TextListener(System.out));
102 Result result = junit.run(classes);
103
104 return result.wasSuccessful() ? 0 : 1;
105 }
106
107 }