asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Till Westmann (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: Extract common code of [Optimizer|Smoke]ParserTest
Date Sat, 10 Dec 2016 00:35:41 GMT
Till Westmann has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/1379

Change subject: Extract common code of [Optimizer|Smoke]ParserTest
......................................................................

Extract common code of [Optimizer|Smoke]ParserTest

Change-Id: Iab916e71539ffac7b952ab6795614c00039ca7ff
---
M asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/OptimizerParserTest.java
A asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestUtil.java
M asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/SmokeParserTest.java
3 files changed, 95 insertions(+), 94 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/79/1379/1

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..4353545 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
@@ -24,12 +24,9 @@
 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;
@@ -48,8 +45,8 @@
             + "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_ACTUAL = "target" + File.separator + "opt_parserts"
+ SEPARATOR
+            + "results_parser_sqlpp" + SEPARATOR;
 
     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 +65,11 @@
         }
     }
 
-    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, "", SEPARATOR, EXTENSION_QUERY,
EXTENSION_RESULT,
+                PATH_EXPECTED, PATH_ACTUAL);
         return testArgs;
     }
 
@@ -103,32 +87,7 @@
 
     @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, SEPARATOR.charAt(0));
     }
 }
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..d8a852c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestUtil.java
@@ -0,0 +1,81 @@
+/*
+ * 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, path + file.getName() + separator, separator,
extensionQuery,
+                        extensionResult, pathExpected, pathActual);
+            }
+            if (file.isFile() && file.getName().endsWith(extensionQuery)) {
+                String resultFileName = AsterixTestHelper.extToResExt(file.getName(), extensionResult);
+                File expectedFile = new File(pathExpected + path + resultFileName);
+                File actualFile = new File(pathActual + separator + 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, char sep)
+            throws Exception {
+        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;
+            }
+        }
+    }
+}
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..b8c3107 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
@@ -24,12 +24,9 @@
 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;
@@ -67,24 +64,11 @@
         }
     }
 
-    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, "", SEPARATOR, EXTENSION_QUERY,
EXTENSION_RESULT,
+                PATH_EXPECTED, PATH_ACTUAL);
         return testArgs;
     }
 
@@ -102,32 +86,9 @@
 
     @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, SEPARATOR
+                .charAt(0));
     }
+
 }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1379
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iab916e71539ffac7b952ab6795614c00039ca7ff
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <tillw@apache.org>

Mime
View raw message