Return-Path: X-Original-To: apmail-tajo-commits-archive@minotaur.apache.org Delivered-To: apmail-tajo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8EDAE187FF for ; Wed, 19 Aug 2015 05:24:32 +0000 (UTC) Received: (qmail 48977 invoked by uid 500); 19 Aug 2015 05:24:32 -0000 Delivered-To: apmail-tajo-commits-archive@tajo.apache.org Received: (qmail 48942 invoked by uid 500); 19 Aug 2015 05:24:32 -0000 Mailing-List: contact commits-help@tajo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tajo.apache.org Delivered-To: mailing list commits@tajo.apache.org Received: (qmail 48933 invoked by uid 99); 19 Aug 2015 05:24:32 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Aug 2015 05:24:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DEB64E0941; Wed, 19 Aug 2015 05:24:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hyunsik@apache.org To: commits@tajo.apache.org Message-Id: <6332cf88fdfd428793603f349b609e6a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: tajo git commit: TAJO-1745: Add positive and negative test methods. Date: Wed, 19 Aug 2015 05:24:31 +0000 (UTC) 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 Authored: Wed Aug 19 14:09:11 2015 +0900 Committer: Hyunsik Choi 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.*; * *
  • 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.
  • + * class. This directory also can include positive and negative directories, each + * of which include multiple files containing multiple queries. They are used by runPositiveTests() and + * runNegativeTests(), which test just successfully completed and failed respectively + * without compararing query results. * *
  • 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 getBatchQueries(Collection paths) throws IOException, InvalidStatementException { + List 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 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 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 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(){ + @Override + public Path apply(@Nullable FileStatus fileStatus) { + return fileStatus.getPath(); + } + }); + } + + private Collection 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(){ + @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