tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject tajo git commit: TAJO-1745: Add positive and negative test methods.
Date Wed, 19 Aug 2015 05:24:31 GMT
Repository: tajo
Updated Branches:
  refs/heads/branch-0.11.0 e31256249 -> cb23c10b6


TAJO-1745: Add positive and negative test methods.

Closes #681


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

Branch: refs/heads/branch-0.11.0
Commit: cb23c10b6474dd5f2f191b6562431b55c2ff4982
Parents: e312562
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Wed Aug 19 14:09:11 2015 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Wed Aug 19 14:20:22 2015 +0900

----------------------------------------------------------------------
 CHANGES                                         |   2 +
 .../java/org/apache/tajo/QueryTestCaseBase.java | 103 ++++++++++++++++++-
 .../tajo/engine/query/TestSelectQuery.java      |  10 ++
 .../TestSelectQuery/nagative/operations.sql     |   1 +
 .../queries/TestSelectQuery/nagative/tables.sql |   1 +
 .../TestSelectQuery/positive/operations.sql     |   1 +
 6 files changed, 116 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/cb23c10b/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 5a930c0..69bdb3a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -32,6 +32,8 @@ Release 0.11.0 - unreleased
 
   IMPROVEMENT
 
+    TAJO-1745: Add positive and negative test methods. (hyunsik)
+ 
     TAJO-1757: Add examples for TajoClient v2. (hyunsik)
 
     TAJO-1761: Separate an integration unit test kit into an independent 

http://git-wip-us.apache.org/repos/asf/tajo/blob/cb23c10b/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 c3c9b52..bfc7d7b 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
@@ -18,6 +18,9 @@
 
 package org.apache.tajo;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
 import com.google.protobuf.ServiceException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -29,7 +32,7 @@ import org.apache.tajo.annotation.Nullable;
 import org.apache.tajo.catalog.CatalogService;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.TableDesc;
-import org.apache.tajo.exception.UndefinedTableException;
+import org.apache.tajo.cli.tsql.InvalidStatementException;
 import org.apache.tajo.cli.tsql.ParsedResult;
 import org.apache.tajo.cli.tsql.SimpleParser;
 import org.apache.tajo.client.TajoClient;
@@ -37,6 +40,7 @@ import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.engine.parser.SQLAnalyzer;
 import org.apache.tajo.engine.query.QueryContext;
 import org.apache.tajo.exception.TajoException;
+import org.apache.tajo.exception.UndefinedTableException;
 import org.apache.tajo.master.GlobalEngine;
 import org.apache.tajo.plan.LogicalOptimizer;
 import org.apache.tajo.plan.LogicalPlan;
@@ -80,7 +84,10 @@ import static org.junit.Assert.*;
  *
  *   <li>src/test/resources/queries - This is the query directory. It contains sub
directories, each of which
  *   corresponds each test class. All query files in each sub directory can be used in the
corresponding test
- *   class.</li>
+ *   class. This directory also can include <code>positive</code> and <code>negative</code>
directories, each
+ *   of which include multiple files containing multiple queries. They are used by <code>runPositiveTests()</code>
and
+ *   <code>runNegativeTests()</code>, which test just successfully completed
and failed respectively
+ *   without compararing query results.</li>
  *
  *   <li>src/test/resources/results - This is the result directory. It contains sub
directories, each of which
  *   corresponds each test class. All result files in each sub directory can be used in the
corresponding test class.
@@ -100,6 +107,10 @@ import static org.junit.Assert.*;
  *             |
  *             |- queries
  *             |     |- TestJoinQuery
+ *             |              |- positive
+ *             |                    |- valid_join_conditions.sql
+ *             |              |- negative
+ *             |                    |- invalid_join_conditions.sql
  *             |              |- TestInnerJoin.sql
  *             |              |- table1_ddl.sql
  *             |              |- table2_ddl.sql
@@ -464,6 +475,62 @@ public class QueryTestCaseBase {
     public boolean sort() { return sort;}
   }
 
+  protected Collection<String> getBatchQueries(Collection<Path> paths) throws
IOException, InvalidStatementException {
+    List<String> queries = Lists.newArrayList();
+
+    for (Path p : paths) {
+      for (ParsedResult statement: SimpleParser.parseScript(FileUtil.readTextFile(new File(p.toUri()))))
{
+        queries.add(statement.getStatement());
+      }
+    }
+
+    return queries;
+  }
+
+  /**
+   * Run all positive tests
+   *
+   * @throws Exception
+   */
+  protected void runPositiveTests() throws Exception {
+    Collection<String> queries = getBatchQueries(getPositiveQueryFiles());
+
+    ResultSet result = null;
+    for (String query: queries) {
+      try {
+        result = client.executeQueryAndGetResult(query);
+      } catch (TajoException e) {
+        fail("Positive Test Failed: " + e.getMessage());
+      } finally {
+        if (result != null) {
+          result.close();
+        }
+      }
+    }
+  }
+
+  /**
+   * Run all negative tests
+   *
+   * @throws Exception
+   */
+  protected void runNegativeTests() throws Exception {
+    Collection<String> queries = getBatchQueries(getNegativeQueryFiles());
+
+    ResultSet result = null;
+    for (String query: queries) {
+      try {
+        result = client.executeQueryAndGetResult(query);
+        fail("Negative Test Failed: " + query);
+      } catch (TajoException e) {
+      } finally {
+        if (result != null) {
+          result.close();
+        }
+      }
+    }
+  }
+
   protected void runSimpleTests() throws Exception {
     String methodName = getMethodName();
     Method method = current.getTestClass().getMethod(methodName);
@@ -771,6 +838,38 @@ public class QueryTestCaseBase {
     assertEquals(message, expectedResult.trim(), actualResult.trim());
   }
 
+  private Collection<Path> getPositiveQueryFiles() throws IOException {
+    Path positiveQueryDir = StorageUtil.concatPath(currentQueryPath, "positive");
+    FileSystem fs = currentQueryPath.getFileSystem(testBase.getTestingCluster().getConfiguration());
+
+    if (!fs.exists(positiveQueryDir)) {
+      throw new IOException("Cannot find " + positiveQueryDir);
+    }
+
+    return Collections2.transform(Lists.newArrayList(fs.listStatus(positiveQueryDir)), new
Function<FileStatus, Path>(){
+      @Override
+      public Path apply(@Nullable FileStatus fileStatus) {
+        return fileStatus.getPath();
+      }
+    });
+  }
+
+  private Collection<Path> getNegativeQueryFiles() throws IOException {
+    Path positiveQueryDir = StorageUtil.concatPath(currentQueryPath, "nagative");
+    FileSystem fs = currentQueryPath.getFileSystem(testBase.getTestingCluster().getConfiguration());
+
+    if (!fs.exists(positiveQueryDir)) {
+      throw new IOException("Cannot find " + positiveQueryDir);
+    }
+
+    return Collections2.transform(Lists.newArrayList(fs.listStatus(positiveQueryDir)),new
Function<FileStatus, Path>(){
+      @Override
+      public Path apply(@Nullable FileStatus fileStatus) {
+        return fileStatus.getPath();
+      }
+    });
+  }
+
   private Path getQueryFilePath(String fileName) throws IOException {
     Path queryFilePath = StorageUtil.concatPath(currentQueryPath, fileName);
     FileSystem fs = currentQueryPath.getFileSystem(testBase.getTestingCluster().getConfiguration());

http://git-wip-us.apache.org/repos/asf/tajo/blob/cb23c10b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
index 27c2fcd..0fd6fcf 100644
--- a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
+++ b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
@@ -55,6 +55,16 @@ public class TestSelectQuery extends QueryTestCaseBase {
   }
 
   @Test
+  public final void testPositives() throws Exception {
+    runPositiveTests();
+  }
+
+  @Test
+  public final void testNegatives() throws Exception {
+    runNegativeTests();
+  }
+
+  @Test
   public final void testNonQualifiedNames() throws Exception {
     // select l_orderkey, l_partkey from lineitem;
     ResultSet res = executeQuery();

http://git-wip-us.apache.org/repos/asf/tajo/blob/cb23c10b/tajo-core-tests/src/test/resources/queries/TestSelectQuery/nagative/operations.sql
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/resources/queries/TestSelectQuery/nagative/operations.sql
b/tajo-core-tests/src/test/resources/queries/TestSelectQuery/nagative/operations.sql
new file mode 100644
index 0000000..0a0ed75
--- /dev/null
+++ b/tajo-core-tests/src/test/resources/queries/TestSelectQuery/nagative/operations.sql
@@ -0,0 +1 @@
+select 1 + col1;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/cb23c10b/tajo-core-tests/src/test/resources/queries/TestSelectQuery/nagative/tables.sql
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/resources/queries/TestSelectQuery/nagative/tables.sql
b/tajo-core-tests/src/test/resources/queries/TestSelectQuery/nagative/tables.sql
new file mode 100644
index 0000000..17d0403
--- /dev/null
+++ b/tajo-core-tests/src/test/resources/queries/TestSelectQuery/nagative/tables.sql
@@ -0,0 +1 @@
+select * from lineite;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/cb23c10b/tajo-core-tests/src/test/resources/queries/TestSelectQuery/positive/operations.sql
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/resources/queries/TestSelectQuery/positive/operations.sql
b/tajo-core-tests/src/test/resources/queries/TestSelectQuery/positive/operations.sql
new file mode 100644
index 0000000..5c00f4e
--- /dev/null
+++ b/tajo-core-tests/src/test/resources/queries/TestSelectQuery/positive/operations.sql
@@ -0,0 +1 @@
+select 1 + 2;
\ No newline at end of file


Mime
View raw message