You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by ji...@apache.org on 2016/03/04 03:02:33 UTC

tajo git commit: TAJO-2088: Change QueryTestCaseBase.runSimpleTests() to return a set of TajoResultSetBase.

Repository: tajo
Updated Branches:
  refs/heads/master 1138784fb -> 0d94efe0f


TAJO-2088: Change QueryTestCaseBase.runSimpleTests() to return a set of TajoResultSetBase.

Closes #971


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/0d94efe0
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/0d94efe0
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/0d94efe0

Branch: refs/heads/master
Commit: 0d94efe0fbaea5a8d9eb042b912d0713af62bc16
Parents: 1138784
Author: Jihoon Son <ji...@apache.org>
Authored: Fri Mar 4 11:01:50 2016 +0900
Committer: Jihoon Son <ji...@apache.org>
Committed: Fri Mar 4 11:02:05 2016 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 ++
 .../java/org/apache/tajo/QueryTestCaseBase.java | 34 +++++++++++++++++---
 2 files changed, 33 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/0d94efe0/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 21fd2b0..50e1de0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -201,6 +201,9 @@ Release 0.12.0 - unreleased
 
   TASKS
 
+    TAJO-2088: Change QueryTestCaseBase.runSimpleTests() to return a set of 
+    TajoResultSetBase. (jihoon)
+
     TAJO-2033: Printing out query status with progress bar in TSQL.
     (Dongkyu Hwangbo via jihoon)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/0d94efe0/tajo-cluster-tests/src/test/java/org/apache/tajo/QueryTestCaseBase.java
----------------------------------------------------------------------
diff --git a/tajo-cluster-tests/src/test/java/org/apache/tajo/QueryTestCaseBase.java b/tajo-cluster-tests/src/test/java/org/apache/tajo/QueryTestCaseBase.java
index eb40562..e1d01c0 100644
--- a/tajo-cluster-tests/src/test/java/org/apache/tajo/QueryTestCaseBase.java
+++ b/tajo-cluster-tests/src/test/java/org/apache/tajo/QueryTestCaseBase.java
@@ -44,6 +44,7 @@ import org.apache.tajo.exception.TajoException;
 import org.apache.tajo.exception.UndefinedTableException;
 import org.apache.tajo.jdbc.FetchResultSet;
 import org.apache.tajo.jdbc.TajoMemoryResultSet;
+import org.apache.tajo.jdbc.TajoResultSetBase;
 import org.apache.tajo.master.GlobalEngine;
 import org.apache.tajo.parser.sql.SQLAnalyzer;
 import org.apache.tajo.plan.LogicalOptimizer;
@@ -469,6 +470,7 @@ public class QueryTestCaseBase {
     boolean withExplainGlobal() default false;
     boolean parameterized() default false;
     boolean sort() default false;
+    boolean resultClose() default true;
   }
 
   private static class DummyQuerySpec implements QuerySpec {
@@ -489,17 +491,25 @@ public class QueryTestCaseBase {
     private final boolean withExplainGlobal;
     private final boolean parameterized;
     private final boolean sort;
-    public DummyOption(boolean explain, boolean withExplainGlobal, boolean parameterized, boolean sort) {
+    private final boolean resultClose;
+    public DummyOption(boolean explain, boolean withExplainGlobal, boolean parameterized, boolean sort,
+                       boolean resultClose) {
       this.explain = explain;
       this.withExplainGlobal = withExplainGlobal;
       this.parameterized = parameterized;
       this.sort = sort;
+      this.resultClose = resultClose;
     }
     public Class<? extends Annotation> annotationType() { return Option.class; }
     public boolean withExplain() { return explain;}
     public boolean withExplainGlobal() { return withExplainGlobal;}
     public boolean parameterized() { return parameterized;}
     public boolean sort() { return sort;}
+
+    @Override
+    public boolean resultClose() {
+      return resultClose;
+    }
   }
 
   protected Collection<String> getBatchQueries(Collection<Path> paths) throws IOException, InvalidStatementException {
@@ -558,7 +568,7 @@ public class QueryTestCaseBase {
     }
   }
 
-  protected void runSimpleTests() throws Exception {
+  protected Optional<TajoResultSetBase[]> runSimpleTests() throws Exception {
     String methodName = getMethodName();
     Method method = current.getTestClass().getMethod(methodName);
     SimpleTest annotation = method.getAnnotation(SimpleTest.class);
@@ -570,7 +580,7 @@ public class QueryTestCaseBase {
     QuerySpec[] queries = annotation.queries();
     Option defaultOption = method.getAnnotation(Option.class);
     if (defaultOption == null) {
-      defaultOption = new DummyOption(false, false, false, false);
+      defaultOption = new DummyOption(false, false, false, false, true);
     }
 
     boolean fromFile = false;
@@ -589,6 +599,7 @@ public class QueryTestCaseBase {
       for (String prepare : prepares) {
         client.executeQueryAndGetResult(prepare).close();
       }
+      List<TajoResultSetBase> resultSetBases = new ArrayList<>();
       for (int i = 0; i < queries.length; i++) {
         QuerySpec spec = queries[i];
         Option option = spec.override() ? spec.option() : defaultOption;
@@ -620,6 +631,7 @@ public class QueryTestCaseBase {
 
         testingCluster.getConfiguration().set(TajoConf.ConfVars.$TEST_PLAN_SHAPE_FIX_ENABLED.varname, "false");
         ResultSet result = client.executeQueryAndGetResult(spec.value());
+        resultSetBases.add((TajoResultSetBase) result);
 
         // result test
         String fileName = methodName + (fromFile ? "" : "." + (i + 1)) + ".result";
@@ -633,7 +645,15 @@ public class QueryTestCaseBase {
           LOG.info("New test output for " + current.getDisplayName() + " is written to " + resultPath);
           // should be copied to src directory
         }
-        result.close();
+        if (option.resultClose()) {
+          result.close();
+        }
+      }
+
+      if (resultSetBases.size() > 0) {
+        return Optional.of(resultSetBases.toArray(new TajoResultSetBase[resultSetBases.size()]));
+      } else {
+        return Optional.empty();
       }
     } finally {
       for (String cleanup : annotation.cleanup()) {
@@ -646,6 +666,12 @@ public class QueryTestCaseBase {
     }
   }
 
+  protected void closeResultSets(ResultSet... resultSets) throws SQLException {
+    for (ResultSet rs : resultSets) {
+      rs.close();
+    }
+  }
+
   private boolean isNull(ResultSet result) throws SQLException {
     return result.getMetaData().getColumnCount() == 0;
   }