From af8f1d41cf1f6ec31aebcbd3b251109fa0baeed7 Mon Sep 17 00:00:00 2001 From: Robert Hou Date: Wed, 3 Jan 2018 19:29:40 -0800 Subject: [PATCH] Enhance Test Framework to be able to run a single test. The -s option can now support a mixture of test suites and individual query files, separated by commas. If the individual query file does not have a json definition file in the same directory, the Test Framework will check the parent directories until it finds at least one JSON file, at which time it assumes that one of those JSON files can be used. --- .../apache/drill/test/framework/Utils.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/framework/src/main/java/org/apache/drill/test/framework/Utils.java b/framework/src/main/java/org/apache/drill/test/framework/Utils.java index c1eae590c..598c6024f 100755 --- a/framework/src/main/java/org/apache/drill/test/framework/Utils.java +++ b/framework/src/main/java/org/apache/drill/test/framework/Utils.java @@ -195,6 +195,12 @@ public static List getDrillTestCases() throws IOException { LOG.error("Directory " + testDefSourceFile.getAbsolutePath() + " does not exist!"); System.exit(-1); } + if (testDefSourceFile.isFile()) { + // Single test execution + singleTestCase(testDefSourceFile, testGroups, drillTestCases); + continue; + } + List testDefFiles = searchFiles(testDefSourceFile, ".*.json"); for (File testDefFile : testDefFiles) { // try { @@ -747,4 +753,60 @@ public static String removeNewLines(String input) { return builder.toString(); } + /* Get DrillTestCase for a single query file */ + public static void singleTestCase(File singleTestFile, + String[] testGroups, + List drillTestCases) + throws IOException { + List jsonFiles = searchFiles(singleTestFile.getParentFile(), ".*.json"); + if (jsonFiles.isEmpty()) { + String updir = ""; + while (jsonFiles.isEmpty()) { + updir = updir + "/.."; + File singleTestFileParent = new File(singleTestFile.getParent() + updir); + jsonFiles = searchFiles(singleTestFileParent, ".*.json"); + } + } + for (File jsonFile : jsonFiles) { + TestCaseModeler modeler; + try { + modeler = getTestCaseModeler(jsonFile.getAbsolutePath()); + } catch (JsonParseException e) { + LOG.warn("Caught exception parsing " + jsonFile + ". This test will not be executed.", e); + continue; + } + + String queryFileExtension = modeler.matrices.get(0).inputFile; + Pattern pattern = Pattern.compile(queryFileExtension + "$"); + Matcher matcher = pattern.matcher(singleTestFile.getName()); + if (matcher.find()) { + List categories = modeler.categories; + boolean foundTests = false; + for (String testGroup : testGroups) { + if (categories != null && !categories.contains(testGroup)) { + continue; + } else { + foundTests = true; + break; + } + } + if (!foundTests) {continue;} + String expectedFileExtension = modeler.matrices.get(0).expectedFile; + boolean skipSuite = false; + if (modeler.dependencies != null) { + for (String dependency : modeler.dependencies) { + if (TestDriver.cmdParam.excludeDependenciesAsList().contains(dependency)) { + skipSuite = true; + } + } + } + if (skipSuite) {continue;} + String expectedFileName = getExpectedFile(singleTestFile.getAbsolutePath(), + queryFileExtension, expectedFileExtension); + drillTestCases.add(new DrillTestCase(modeler, singleTestFile.getAbsolutePath(), expectedFileName)); + break; + } + } + } + }