tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject tajo git commit: TAJO-2088: Change QueryTestCaseBase.runSimpleTests() to return a set of TajoResultSetBase.
Date Fri, 04 Mar 2016 02:12:31 GMT
Repository: tajo
Updated Branches:
  refs/heads/branch-0.11.2 cd1b133a5 -> d75bcd58f


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


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

Branch: refs/heads/branch-0.11.2
Commit: d75bcd58f504a40f0484c8934ee346b22551f5da
Parents: cd1b133
Author: Jihoon Son <jihoonson@apache.org>
Authored: Fri Mar 4 11:11:59 2016 +0900
Committer: Jihoon Son <jihoonson@apache.org>
Committed: Fri Mar 4 11:11:59 2016 +0900

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


http://git-wip-us.apache.org/repos/asf/tajo/blob/d75bcd58/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 90db2c8..ef2ad47 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,9 @@ Release 0.11.2 - unreleased
 
   TASKS
 
+    TAJO-2088: Change QueryTestCaseBase.runSimpleTests() to return a set of 
+    TajoResultSetBase. (jihoon)
+
     TAJO-2076: Add backward compatibility testing with hadoop on travis. (jinho)
 
     TAJO-2074: Upgrade hadoop and netty. (jinho)

http://git-wip-us.apache.org/repos/asf/tajo/blob/d75bcd58/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 179ed36..c62f583 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
@@ -19,6 +19,7 @@
 package org.apache.tajo;
 
 import com.google.common.base.Function;
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.Lists;
@@ -44,6 +45,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 +471,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 +492,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 +569,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 +581,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 +600,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 +632,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 +646,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.absent();
       }
     } finally {
       for (String cleanup : annotation.cleanup()) {
@@ -646,6 +667,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;
   }


Mime
View raw message