asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject asterixdb git commit: Extract common code of [Optimizer|Smoke]ParserTest
Date Tue, 13 Dec 2016 02:18:22 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master 3072ef35e -> 8216bd88a


Extract common code of [Optimizer|Smoke]ParserTest

Change-Id: Iab916e71539ffac7b952ab6795614c00039ca7ff
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1379
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>


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

Branch: refs/heads/master
Commit: 8216bd88a75cffbbd7d08befdc1bbfe80a244ca5
Parents: 3072ef3
Author: Till Westmann <tillw@apache.org>
Authored: Mon Dec 12 14:40:00 2016 -0800
Committer: Till Westmann <tillw@apache.org>
Committed: Mon Dec 12 18:17:37 2016 -0800

----------------------------------------------------------------------
 .../asterix/test/sqlpp/OptimizerParserTest.java | 61 +++-----------
 .../asterix/test/sqlpp/ParserTestUtil.java      | 83 ++++++++++++++++++++
 .../asterix/test/sqlpp/SmokeParserTest.java     | 60 +++-----------
 3 files changed, 101 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8216bd88/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/OptimizerParserTest.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/OptimizerParserTest.java
b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/OptimizerParserTest.java
index ef17c9f..31103a8 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/OptimizerParserTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/OptimizerParserTest.java
@@ -26,10 +26,8 @@ import java.util.logging.Logger;
 import org.apache.asterix.test.base.AsterixTestHelper;
 import org.apache.asterix.test.common.TestHelper;
 import org.junit.AfterClass;
-import org.junit.Assume;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.internal.AssumptionViolatedException;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
@@ -39,17 +37,14 @@ public class OptimizerParserTest {
 
     private static final Logger LOGGER = Logger.getLogger(OptimizerParserTest.class.getName());
 
-    private static final String SEPARATOR = File.separator;
     private static final String EXTENSION_QUERY = "sqlpp";
     private static final String EXTENSION_RESULT = "ast";
     private static final String FILENAME_IGNORE = "ignore.txt";
     private static final String FILENAME_ONLY = "only.txt";
-    private static final String PATH_BASE = "src" + SEPARATOR + "test" + SEPARATOR + "resources"
+ SEPARATOR
-            + "optimizerts" + SEPARATOR;
-    private static final String PATH_QUERIES = PATH_BASE + "queries_sqlpp" + SEPARATOR;
-    private static final String PATH_EXPECTED = PATH_BASE + "results_parser_sqlpp" + SEPARATOR;
-    private static final String PATH_ACTUAL =
-            "target" + File.separator + "opt_parserts" + SEPARATOR + "results_parser_sqlpp"
+ SEPARATOR;
+    private static final String PATH_BASE = TestHelper.joinPath("src", "test", "resources",
"optimizerts");
+    private static final String PATH_QUERIES = TestHelper.joinPath(PATH_BASE, "queries_sqlpp");
+    private static final String PATH_EXPECTED = TestHelper.joinPath(PATH_BASE, "results_parser_sqlpp");
+    private static final String PATH_ACTUAL = TestHelper.joinPath("target", "opt_parserts",
"results_parser_sqlpp");
 
     private static final ArrayList<String> ignore = AsterixTestHelper.readFile(FILENAME_IGNORE,
PATH_BASE);
     private static final ArrayList<String> only = AsterixTestHelper.readFile(FILENAME_ONLY,
PATH_BASE);
@@ -68,24 +63,11 @@ public class OptimizerParserTest {
         }
     }
 
-    private static void suiteBuild(File dir, Collection<Object[]> testArgs, String
path) {
-        for (File file : dir.listFiles()) {
-            if (file.isDirectory() && !file.getName().startsWith(".")) {
-                suiteBuild(file, testArgs, path + file.getName() + SEPARATOR);
-            }
-            if (file.isFile() && file.getName().endsWith(EXTENSION_QUERY)) {
-                String resultFileName = AsterixTestHelper.extToResExt(file.getName(), EXTENSION_RESULT);
-                File expectedFile = new File(PATH_EXPECTED + path + resultFileName);
-                File actualFile = new File(PATH_ACTUAL + path + resultFileName);
-                testArgs.add(new Object[] { file, expectedFile, actualFile });
-            }
-        }
-    }
-
     @Parameters(name = "OptimizerParserTest {index}: {0}")
     public static Collection<Object[]> tests() {
-        Collection<Object[]> testArgs = new ArrayList<Object[]>();
-        suiteBuild(new File(PATH_QUERIES), testArgs, "");
+        Collection<Object[]> testArgs = new ArrayList<>();
+        ParserTestUtil.suiteBuild(new File(PATH_QUERIES), testArgs, "", File.separator, EXTENSION_QUERY,
+                EXTENSION_RESULT, PATH_EXPECTED, PATH_ACTUAL);
         return testArgs;
     }
 
@@ -103,32 +85,7 @@ public class OptimizerParserTest {
 
     @Test
     public void test() throws Exception {
-        try {
-            String queryFileShort = queryFile.getPath().substring(PATH_QUERIES.length()).replace(SEPARATOR.charAt(0),
-                    '/');
-            if (!only.isEmpty()) {
-                boolean toRun = TestHelper.isInPrefixList(only, queryFileShort);
-                if (!toRun) {
-                    LOGGER.info("SKIP TEST: \"" + queryFile.getPath()
-                            + "\" \"only.txt\" not empty and not in \"only.txt\".");
-                }
-                Assume.assumeTrue(toRun);
-            }
-            boolean skipped = TestHelper.isInPrefixList(ignore, queryFileShort);
-            if (skipped) {
-                LOGGER.info("SKIP TEST: \"" + queryFile.getPath() + "\" in \"ignore.txt\".");
-            }
-            Assume.assumeTrue(!skipped);
-
-            LOGGER.info("RUN TEST: \"" + queryFile.getPath() + "\"");
-            parserTestExecutor.testSQLPPParser(queryFile, actualFile, expectedFile);
-        } catch (Exception e) {
-            if (!(e instanceof AssumptionViolatedException)) {
-                LOGGER.severe("Test \"" + queryFile.getPath() + "\" FAILED!");
-                throw new Exception("Test \"" + queryFile.getPath() + "\" FAILED!", e);
-            } else {
-                throw e;
-            }
-        }
+        ParserTestUtil.runTest(LOGGER, parserTestExecutor, PATH_QUERIES, queryFile, expectedFile,
actualFile, ignore,
+                only, File.separator);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8216bd88/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestUtil.java
b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestUtil.java
new file mode 100644
index 0000000..5e60af3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestUtil.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.asterix.test.sqlpp;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.asterix.test.base.AsterixTestHelper;
+import org.apache.asterix.test.common.TestHelper;
+import org.junit.Assume;
+import org.junit.internal.AssumptionViolatedException;
+
+class ParserTestUtil {
+
+    static void suiteBuild(File dir, Collection<Object[]> testArgs, String path, String
separator,
+            String extensionQuery, String extensionResult, String pathExpected, String pathActual)
{
+        for (File file : dir.listFiles()) {
+            if (file.isDirectory() && !file.getName().startsWith(".")) {
+                suiteBuild(file, testArgs, TestHelper.joinPath(path, file.getName()), separator,
extensionQuery,
+                        extensionResult, pathExpected, pathActual);
+            }
+            if (file.isFile() && file.getName().endsWith(extensionQuery)) {
+                String resultFileName = AsterixTestHelper.extToResExt(file.getName(), extensionResult);
+                File expectedFile = new File(TestHelper.joinPath(pathExpected, path, resultFileName));
+                File actualFile = new File(
+                        TestHelper.joinPath(pathActual, path.replace(separator, "_"), resultFileName));
+                testArgs.add(new Object[] { file, expectedFile, actualFile });
+            }
+        }
+    }
+
+    protected static void runTest(Logger logger, ParserTestExecutor parserTestExecutor, String
pathQueries,
+            File queryFile, File expectedFile, File actualFile, List<String> ignore,
List<String> only,
+            String separator) throws Exception {
+        final char sep = separator.charAt(0);
+        try {
+            String queryFileShort = queryFile.getPath().substring(pathQueries.length()).replace(sep,
'/');
+            if (!only.isEmpty()) {
+                boolean toRun = TestHelper.isInPrefixList(only, queryFileShort);
+                if (!toRun) {
+                    logger.info("SKIP TEST: \"" + queryFile.getPath()
+                            + "\" \"only.txt\" not empty and not in \"only.txt\".");
+                }
+                Assume.assumeTrue(toRun);
+            }
+            boolean skipped = TestHelper.isInPrefixList(ignore, queryFileShort);
+            if (skipped) {
+                logger.info("SKIP TEST: \"" + queryFile.getPath() + "\" in \"ignore.txt\".");
+            }
+            Assume.assumeTrue(!skipped);
+
+            logger.info("RUN TEST: \"" + queryFile.getPath() + "\"");
+            parserTestExecutor.testSQLPPParser(queryFile, actualFile, expectedFile);
+
+        } catch (Exception e) {
+            if (!(e instanceof AssumptionViolatedException)) {
+                final String msg = "Test \"" + queryFile.getPath() + "\" FAILED!";
+                logger.severe(msg);
+                throw new Exception(msg, e);
+            } else {
+                throw e;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8216bd88/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/SmokeParserTest.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/SmokeParserTest.java
b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/SmokeParserTest.java
index dd727c3..8fe9370 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/SmokeParserTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/SmokeParserTest.java
@@ -26,10 +26,8 @@ import java.util.logging.Logger;
 import org.apache.asterix.test.base.AsterixTestHelper;
 import org.apache.asterix.test.common.TestHelper;
 import org.junit.AfterClass;
-import org.junit.Assume;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.internal.AssumptionViolatedException;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
@@ -39,16 +37,14 @@ public class SmokeParserTest {
 
     private static final Logger LOGGER = Logger.getLogger(SmokeParserTest.class.getName());
 
-    private static final String SEPARATOR = File.separator;
     private static final String EXTENSION_QUERY = "sqlpp";
     private static final String EXTENSION_RESULT = "ast";
     private static final String FILENAME_IGNORE = "ignore.txt";
     private static final String FILENAME_ONLY = "only.txt";
-    private static final String PATH_BASE = "src" + SEPARATOR + "test" + SEPARATOR + "resources"
+ SEPARATOR
-            + "parserts" + SEPARATOR;
-    private static final String PATH_QUERIES = PATH_BASE + "queries_sqlpp" + SEPARATOR;
-    private static final String PATH_EXPECTED = PATH_BASE + "results_parser_sqlpp" + SEPARATOR;
-    private static final String PATH_ACTUAL = "target" + File.separator + "parserts" + SEPARATOR;
+    private static final String PATH_BASE = TestHelper.joinPath("src", "test", "resources",
"parserts");
+    private static final String PATH_QUERIES = TestHelper.joinPath(PATH_BASE, "queries_sqlpp");
+    private static final String PATH_EXPECTED = TestHelper.joinPath(PATH_BASE, "results_parser_sqlpp");
+    private static final String PATH_ACTUAL = TestHelper.joinPath("target", "parserts");
 
     private static final ArrayList<String> ignore = AsterixTestHelper.readFile(FILENAME_IGNORE,
PATH_BASE);
     private static final ArrayList<String> only = AsterixTestHelper.readFile(FILENAME_ONLY,
PATH_BASE);
@@ -67,24 +63,11 @@ public class SmokeParserTest {
         }
     }
 
-    private static void suiteBuild(File dir, Collection<Object[]> testArgs, String
path) {
-        for (File file : dir.listFiles()) {
-            if (file.isDirectory() && !file.getName().startsWith(".")) {
-                suiteBuild(file, testArgs, path + file.getName() + SEPARATOR);
-            }
-            if (file.isFile() && file.getName().endsWith(EXTENSION_QUERY)) {
-                String resultFileName = AsterixTestHelper.extToResExt(file.getName(), EXTENSION_RESULT);
-                File expectedFile = new File(PATH_EXPECTED + path + resultFileName);
-                File actualFile = new File(PATH_ACTUAL + SEPARATOR + path.replace(SEPARATOR,
"_") + resultFileName);
-                testArgs.add(new Object[] { file, expectedFile, actualFile });
-            }
-        }
-    }
-
     @Parameters(name = "SmokeParserTest {index}: {0}")
     public static Collection<Object[]> tests() {
-        Collection<Object[]> testArgs = new ArrayList<Object[]>();
-        suiteBuild(new File(PATH_QUERIES), testArgs, "");
+        Collection<Object[]> testArgs = new ArrayList<>();
+        ParserTestUtil.suiteBuild(new File(PATH_QUERIES), testArgs, "", File.separator, EXTENSION_QUERY,
+                EXTENSION_RESULT, PATH_EXPECTED, PATH_ACTUAL);
         return testArgs;
     }
 
@@ -102,32 +85,7 @@ public class SmokeParserTest {
 
     @Test
     public void test() throws Exception {
-        try {
-            String queryFileShort = queryFile.getPath().substring(PATH_QUERIES.length()).replace(SEPARATOR.charAt(0),
-                    '/');
-            if (!only.isEmpty()) {
-                boolean toRun = TestHelper.isInPrefixList(only, queryFileShort);
-                if (!toRun) {
-                    LOGGER.info("SKIP TEST: \"" + queryFile.getPath()
-                            + "\" \"only.txt\" not empty and not in \"only.txt\".");
-                }
-                Assume.assumeTrue(toRun);
-            }
-            boolean skipped = TestHelper.isInPrefixList(ignore, queryFileShort);
-            if (skipped) {
-                LOGGER.info("SKIP TEST: \"" + queryFile.getPath() + "\" in \"ignore.txt\".");
-            }
-            Assume.assumeTrue(!skipped);
-
-            LOGGER.info("RUN TEST: \"" + queryFile.getPath() + "\"");
-            parserTestExecutor.testSQLPPParser(queryFile, actualFile, expectedFile);
-        } catch (Exception e) {
-            if (!(e instanceof AssumptionViolatedException)) {
-                LOGGER.severe("Test \"" + queryFile.getPath() + "\" FAILED!");
-                throw new Exception("Test \"" + queryFile.getPath() + "\" FAILED!", e);
-            } else {
-                throw e;
-            }
-        }
+        ParserTestUtil.runTest(LOGGER, parserTestExecutor, PATH_QUERIES, queryFile, expectedFile,
actualFile, ignore,
+                only, File.separator);
     }
 }


Mime
View raw message