Github user navis commented on a diff in the pull request:
https://github.com/apache/tajo/pull/441#discussion_r26897619
--- Diff: tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java ---
@@ -317,6 +333,60 @@ public ResultSet executeQuery() throws Exception {
return executeFile(getMethodName() + ".sql");
}
+ private volatile Description current;
+
+ @Rule
+ public TestRule watcher = new TestWatcher() {
+ @Override
+ protected void starting(Description description) {
+ QueryTestCaseBase.this.current = description;
+ }
+ };
+
+ @Target({ElementType.METHOD})
+ @Retention(RetentionPolicy.RUNTIME)
+ protected static @interface SimpleTest {
+ String[] queries();
+ String[] cleanupTables() default {};
+ }
+
+ protected void runSimpleTests() throws Exception {
+ String methodName = getMethodName();
+ Method method = current.getTestClass().getMethod(methodName);
+ SimpleTest annotation = method.getAnnotation(SimpleTest.class);
+ if (annotation == null) {
+ throw new IllegalStateException("Cannot find test annotation");
+ }
+ String[] queries = annotation.queries();
+ try {
+ for (int i = 0; i < queries.length; i++) {
+ ResultSet result = client.executeQueryAndGetResult(queries[i]);
+ Path resultPath = StorageUtil.concatPath(
+ currentResultPath, methodName + "." + String.valueOf(i + 1) +
".result");
+ if (currentResultFS.exists(resultPath)) {
+ assertEquals("Result Verification",
+
FileUtil.readTextFromStream(currentResultFS.open(resultPath)),
resultSetToString(result).trim());
+ } else if (!isNull(result)) {
+ FileUtil.writeTextToStream(resultSetToString(result).trim(),
currentResultFS.create(resultPath));
--- End diff --
In the first patch, it was just else { FileUtils.write..} ,which is for
creating gold file for new test. In hive there are option
(-Dtest.overwrite=true) but I couldn't find something like that in Tajo. So
just I've made one if there is no result file expected.
Adding "isNull" to the clause in next patch was because I though some DDL
queries can be used in here, which has no output result. For example,
SimpleTest(queres= {"create table x ...", "select * from x.."}, cleanup="x")
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---