Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Test Framework to be able to run a single test. #391

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions framework/src/main/java/org/apache/drill/test/framework/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ public static List<DrillTestCase> 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<File> testDefFiles = searchFiles(testDefSourceFile, ".*.json");
for (File testDefFile : testDefFiles) {
// try {
Expand Down Expand Up @@ -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<DrillTestCase> drillTestCases)
throws IOException {
List<File> jsonFiles = searchFiles(singleTestFile.getParentFile(), ".*.json");
if (jsonFiles.isEmpty()) {
String updir = "";
while (jsonFiles.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you never encounter a test definition file in any of the upstream directories?

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<String> 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;
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test the following scenarios:

  1. -s .../dir contains test definition file and sudirs containing .json
  2. -s .../test_definition_file.json
  3. -s .../test_query.q
  4. -s .../dir without any test definition files in any of the dir and parent dirs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to specify the relative path to the test, including the file extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the "..." do?

  1. how is .json different from test definition file?
  2. are there any files besides test_definition_file.json in the directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Agirish. Yes. Previously we would say
-s Functional/p1tests
Now we can say
-s Functional/p1tests/is_null.q

}