You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/10/09 16:57:17 UTC

[GitHub] [shardingsphere] terrymanu commented on a diff in pull request #21431: Dynamic Loading SQL Parser Parameterized Test

terrymanu commented on code in PR #21431:
URL: https://github.com/apache/shardingsphere/pull/21431#discussion_r990811558


##########
.github/workflows/it.yml:
##########
@@ -226,3 +226,34 @@ jobs:
         run: |
           ./mvnw -B clean install -f test/integration-agent-test/plugins/metrics/pom.xml -Dspotless.apply.skip=true -Pit.env.metrics
           ./mvnw -B clean install -f test/integration-agent-test/plugins/opentelemetry/pom.xml -Dspotless.apply.skip=true -Pit.env.opentelemetry
+
+  dynamic-loading-test-case:
+    name: Dynamic Loading SQL Parser
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        database: [ MySQL, PostgreSQL ]
+        include:
+          - database: MySQL
+            url: https://github.com/mysql/mysql-server/tree/8.0/mysql-test/t
+          - database: PostgreSQL
+            url: https://github.com/postgres/postgres/tree/master/src/test/regress/sql
+    steps:
+      - uses: actions/checkout@v2
+      - name: Maven Resolve Ranges
+        run: ./mvnw versions:resolve-ranges -ntp -Dincludes='org.springframework:*,org.springframework.boot:*'
+      - uses: actions/cache@v2
+        with:
+          path: ~/.m2/repository
+          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+          restore-keys: |
+            ${{ runner.os }}-maven-
+      - uses: actions/setup-java@v2
+        with:
+          distribution: 'temurin'
+          java-version: 8
+      - name: Build Project
+        run: ./mvnw -B clean install -DskipITs -DskipTests
+      - name: Run Parameterized Test
+        run: |
+          ./mvnw -B clean install -f test/parser/pom.xml -Pit.dynamic.loading -Dspotless.apply.skip=true -Ddatabase=${{ matrix.database }} -Durl=${{ matrix.url }}

Review Comment:
   It is better to put business logic into java codes with junit, just keep GitHub action simple.
   It could be better to run in local `mvn install` too.



##########
pom.xml:
##########
@@ -691,6 +693,19 @@
                 <artifactId>caffeine</artifactId>
                 <version>${caffeine.version}</version>
             </dependency>
+
+            <dependency>
+                <groupId>org.jsoup</groupId>
+                <artifactId>jsoup</artifactId>
+                <version>${jsoup.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.testng</groupId>
+                <artifactId>testng</artifactId>
+                <version>${testng.version}</version>
+                <scope>compile</scope>
+            </dependency>

Review Comment:
   Is it necessary to import new testing framework?



##########
test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/engine/DynamicLoadingSQLParserParameterizedTest.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.shardingsphere.test.sql.parser.parameterized.engine;
+
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.apache.shardingsphere.sql.parser.api.SQLParserEngine;
+import org.apache.shardingsphere.sql.parser.api.SQLVisitorEngine;
+import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
+import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.testng.asserts.IAssert;
+import org.testng.asserts.SoftAssert;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Objects;
+import java.util.Properties;
+
+@RunWith(Parameterized.class)
+public final class DynamicLoadingSQLParserParameterizedTest extends SoftAssert {
+    
+    private static final String SQL_CASE_FILE_MARKER = "js-navigation-open Link--primary";
+    
+    private static final String SQL_CASE_MARKER = "blob-code blob-code-inner js-file-line";
+    
+    private static boolean inBracket;
+    
+    private static StringBuilder sqlCase;
+    
+    private static int sqlCaseId;
+    
+    private static String sqlCaseURL;
+    
+    private static String databaseType;
+
+    public DynamicLoadingSQLParserParameterizedTest() {
+        sqlCaseURL = System.getProperty("url");
+        databaseType = System.getProperty("database");
+    }
+    
+    private static String[] getSqlCaseFiles(final String sqlCaseURL) throws IOException {
+        Document document = Jsoup.connect(sqlCaseURL).get();
+        return document.getElementsByClass(SQL_CASE_FILE_MARKER).text().split("\\s+");
+    }
+    
+    private static Collection<Object[]> getTestParameters(final String databaseType) throws IOException {

Review Comment:
   What is the useful of parameter `databaseType`?



##########
pom.xml:
##########
@@ -691,6 +693,19 @@
                 <artifactId>caffeine</artifactId>
                 <version>${caffeine.version}</version>
             </dependency>
+
+            <dependency>
+                <groupId>org.jsoup</groupId>
+                <artifactId>jsoup</artifactId>
+                <version>${jsoup.version}</version>
+            </dependency>

Review Comment:
   How about using GitHub API to instead of jsoup to fetch sql text?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org