This is an automated email from the ASF dual-hosted git repository.
stoty pushed a commit to branch 5.1
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/5.1 by this push:
new c73004b62f PHOENIX-7429 End2EndTestDriver should not extend
AbstractHBaseTool (#2003)
c73004b62f is described below
commit c73004b62f6435b6c964f067ea64613d4f8e5892
Author: Istvan Toth <[email protected]>
AuthorDate: Tue Oct 15 15:26:24 2024 +0200
PHOENIX-7429 End2EndTestDriver should not extend AbstractHBaseTool (#2003)
---
bin/end2endTest.py | 36 +++++--
.../apache/phoenix/end2end/End2EndTestDriver.java | 103 ++++++++++++++++-----
pom.xml | 1 +
3 files changed, 108 insertions(+), 32 deletions(-)
diff --git a/bin/end2endTest.py b/bin/end2endTest.py
index 40954d1e3c..7de0a0423f 100755
--- a/bin/end2endTest.py
+++ b/bin/end2endTest.py
@@ -31,17 +31,37 @@ import phoenix_utils
phoenix_utils.setPath()
-phoenix_jar_path = os.getenv(phoenix_utils.phoenix_class_path,
phoenix_utils.phoenix_test_jar_path)
+# Get the cached classpath
+base_dir = os.path.join(phoenix_utils.current_dir, '..')
+phoenix_target_dir = os.path.join(base_dir, 'phoenix-core', 'target')
-# HBase configuration folder path (where hbase-site.xml reside) for
-# HBase/Phoenix client side property override
-hbase_library_path = os.getenv('HBASE_LIBRARY_DIR', '')
+cp_file_path = os.path.join(phoenix_target_dir, 'cached_classpath.txt')
+cp_components = []
+with open(cp_file_path, 'r') as cp_file:
+ cp_components.append(cp_file.read())
+cached_classpath = ":".join(cp_components)
-print("Current ClassPath=%s:%s:%s" % (phoenix_utils.hbase_conf_dir,
phoenix_jar_path,
- hbase_library_path))
+# Get the hbase classpath from HBASE_HOME
+hbase_classpath = ''
+if os.getenv('HBASE_HOME'):
+ hbase_bin_dir = os.path.join(os.getenv('HBASE_HOME'), "bin")
+ hbase_classpath = subprocess.check_output(
+ [os.path.join(hbase_bin_dir, "hbase"), "--internal-classpath",
"classpath"]).decode().strip()
+else:
+ print("HBASE_HOME is not set, using HBase jars from cached_classpath.txt")
+ # Set whatever config dir phoenix_utlils has decided instead
+ hbase_classpath = phoenix_utils.hbase_conf_dir
-java_cmd = "java -cp " + phoenix_utils.hbase_conf_dir + os.pathsep +
phoenix_jar_path + os.pathsep + \
- hbase_library_path + " org.apache.phoenix.end2end.End2EndTestDriver " + \
+# The internal classpath returned by `hbase classpath`, and the cached
classpath have a lot of the
+# same files. If HBASE_HOME is set, then the jars from it come before the
cached jars, so those
+# take precedence. Otherwise we use the HBase jars from the cached classpath.
+# If HBASE_HOME is specified, then the cached classpath would only be used for
Junit.
+
+print("Current ClassPath=%s:%s:%s" %
+ (hbase_classpath, phoenix_utils.phoenix_test_jar_path, cached_classpath))
+
+java_cmd = "java -cp " + hbase_classpath + os.pathsep +
phoenix_utils.phoenix_test_jar_path \
+ + os.pathsep + cached_classpath + "
org.apache.phoenix.end2end.End2EndTestDriver " + \
' '.join(sys.argv[1:])
os.execl("/bin/sh", "/bin/sh", "-c", java_cmd)
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/End2EndTestDriver.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/End2EndTestDriver.java
index 76174f5857..875eee6f0d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/End2EndTestDriver.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/End2EndTestDriver.java
@@ -27,13 +27,22 @@ import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.hbase.ClassFinder;
import org.apache.hadoop.hbase.ClassFinder.FileNameFilter;
import org.apache.hadoop.hbase.ClassTestFinder;
+import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.IntegrationTestingUtility;
-import org.apache.hadoop.hbase.util.AbstractHBaseTool;
+import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
-import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.Option;
+import
org.apache.phoenix.thirdparty.com.google.common.annotations.VisibleForTesting;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.CommandLine;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.CommandLineParser;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.DefaultParser;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.HelpFormatter;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.Options;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.ParseException;
import org.junit.internal.TextListener;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
@@ -46,20 +55,66 @@ import org.slf4j.LoggerFactory;
* This class drives the End2End tests suite execution against an
* already deployed distributed cluster.
*/
-public class End2EndTestDriver extends AbstractHBaseTool {
+public class End2EndTestDriver extends Configured implements Tool {
private static final Logger LOGGER =
LoggerFactory.getLogger(End2EndTestDriver.class);
- private static final String SHORT_REGEX_ARG = "r";
- private static final String SKIP_TESTS = "n";
-
+
+ private static Option SHORT_REGEX_OPTION = new Option("r", true, "Java
regex to use selecting tests to run: e.g. .*TestBig.*" +
+ " will select all tests that include TestBig in their name.
Default: " +
+ ".*end2end.*");
+ private static Option SKIP_TESTS_OPTION = new Option("n", false, "Print
list of End2End test suits without running them.");
+
private End2EndTestFilter end2endTestFilter = new End2EndTestFilter();
private boolean skipTests = false;
-
public static void main(String[] args) throws Exception {
int ret = ToolRunner.run(new End2EndTestDriver(), args);
System.exit(ret);
}
+
+ @Override
+ public int run(String[] args) throws Exception {
+ try {
+ parseOptions(args);
+ } catch (IllegalStateException e) {
+ printHelpAndExit(e.getMessage(), getOptions());
+ return -1;
+ }
+ setConf(HBaseConfiguration.addHbaseResources(getConf()));
+ return doWork();
+ }
+
+
+ /**
+ * Parses the commandline arguments, throws IllegalStateException if
mandatory arguments are
+ * missing.
+ * @param args supplied command line arguments
+ * @return the parsed command line
+ */
+ @VisibleForTesting
+ public CommandLine parseOptions(String[] args) {
+
+ final Options options = getOptions();
+
+ CommandLineParser parser = DefaultParser.builder().
+ setAllowPartialMatching(false).
+ setStripLeadingAndTrailingQuotes(false).
+ build();
+ CommandLine cmdLine = null;
+ try {
+ cmdLine = parser.parse(options, args);
+ } catch (ParseException e) {
+ printHelpAndExit("Error parsing command line options: " +
e.getMessage(), options);
+ }
+
+ String testFilterString = cmdLine.getOptionValue(SHORT_REGEX_OPTION);
+ if (testFilterString != null) {
+ end2endTestFilter.setPattern(testFilterString);
+ }
+ skipTests = cmdLine.hasOption(SKIP_TESTS_OPTION);
+
+ return cmdLine;
+ }
public static class End2EndFileNameFilter implements FileNameFilter {
@@ -72,6 +127,7 @@ public class End2EndTestDriver extends AbstractHBaseTool {
public class End2EndTestFilter extends ClassTestFinder.TestClassFilter {
private Pattern testFilterRe = Pattern.compile(".*end2end.*");
+
public End2EndTestFilter() {
super();
}
@@ -105,23 +161,22 @@ public class End2EndTestDriver extends AbstractHBaseTool {
}
}
- @Override
- protected void addOptions() {
- addOptWithArg(SHORT_REGEX_ARG,
- "Java regex to use selecting tests to run: e.g. .*TestBig.*" +
- " will select all tests that include TestBig in their name. Default:
" +
- ".*end2end.*");
- addOptNoArg(SKIP_TESTS,
- "Print list of End2End test suits without running them.");
+ private Options getOptions() {
+ final Options options = new Options();
+ options.addOption(SHORT_REGEX_OPTION);
+ options.addOption(SKIP_TESTS_OPTION);
+ return options;
}
- @Override
- protected void processOptions(CommandLine cmd) {
- String testFilterString = cmd.getOptionValue(SHORT_REGEX_ARG, null);
- if (testFilterString != null) {
- end2endTestFilter.setPattern(testFilterString);
- }
- skipTests = cmd.hasOption(SKIP_TESTS);
+ private void printHelpAndExit(String errorMessage, Options options) {
+ System.err.println(errorMessage);
+ printHelpAndExit(options, 1);
+ }
+
+ private void printHelpAndExit(Options options, int exitCode) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp("help", options);
+ System.exit(exitCode);
}
/**
@@ -193,10 +248,9 @@ public class End2EndTestDriver extends AbstractHBaseTool {
};
- @Override
protected int doWork() throws Exception {
//this is called from the command line, so we should set to use the
distributed cluster
- IntegrationTestingUtility.setUseDistributedCluster(conf);
+ IntegrationTestingUtility.setUseDistributedCluster(getConf());
Class<?>[] classes = findEnd2EndTestClasses();
System.out.println("Found " + classes.length + " end2end tests to run:");
for (Class<?> aClass : classes) {
@@ -210,4 +264,5 @@ public class End2EndTestDriver extends AbstractHBaseTool {
return result.wasSuccessful() ? 0 : 1;
}
+
}
diff --git a/pom.xml b/pom.xml
index 295858735e..ee62b6c9ae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -549,6 +549,7 @@
<reason>Use shaded version in phoenix-thirdparty</reason>
<bannedImports>
<bannedImport>org.apache.commons.cli.**</bannedImport>
+
<bannedImport>org.apache.hbase.thirdparty.org.apache.commons.cli.**</bannedImport>
</bannedImports>
</RestrictImports>
<RestrictImports>