You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by so...@apache.org on 2022/09/28 04:13:26 UTC

[shardingsphere] branch master updated: init example generator test (#21221)

This is an automated email from the ASF dual-hosted git repository.

soulasuna pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 684eaa5d029 init example generator test (#21221)
684eaa5d029 is described below

commit 684eaa5d02978b54a3f63c8c3aa286bf4d590234
Author: Guocheng Tang <to...@apache.org>
AuthorDate: Wed Sep 28 12:13:17 2022 +0800

    init example generator test (#21221)
    
    * refactor: optimize push-down for projections.
    
    * init example generator test
    
    * run example test
    
    * run example test
    
    * add example test
    
    * update ci
    
    * update branch
    
    * update pull_request
    
    * add new line
    
    * update name
    
    * update name
    
    * add header
    
    Co-authored-by: boyjoy1127 <bo...@163.com>
---
 .github/workflows/ci-daily.yml                     | 23 --------
 .../{ci-daily.yml => ci-example-generator.yml}     | 64 +++++++---------------
 .github/workflows/ci.yml                           | 25 ---------
 .../docker-compose.yml                             | 28 ++++++++++
 .../mysql/init/init.sql                            | 19 +++++++
 .../generator/core/ExampleGeneratorFactory.java    | 39 ++++++++++++-
 .../src/main/resources/config.yaml                 |  2 +-
 .../template/jdbc/java/config/Configuration.ftl    |  2 +-
 .../template/jdbc/java/config/sharding.ftl         |  2 +-
 .../src/main/resources/template/jdbc/pom.ftl       | 27 +++++++++
 10 files changed, 133 insertions(+), 98 deletions(-)

diff --git a/.github/workflows/ci-daily.yml b/.github/workflows/ci-daily.yml
index 9240710a17e..2bdf5094e80 100644
--- a/.github/workflows/ci-daily.yml
+++ b/.github/workflows/ci-daily.yml
@@ -59,26 +59,3 @@ jobs:
         run: ./mvnw -B -ntp clean install
       - name: Build examples with Maven
         run: ./mvnw -B -f examples/pom.xml clean package
-  
-  shardingsphere-example-generator:
-    if: github.repository == 'apache/shardingsphere'
-    name: ShardingSphere example generator
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v3
-      - name: Set up JDK 8
-        uses: actions/setup-java@v2
-        with:
-          distribution: 'temurin'
-          java-version: 8
-      - name: Cache Maven Repos
-        uses: actions/cache@v2
-        with:
-          path: ~/.m2/repository
-          key: shardingsphere-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
-          restore-keys: |
-            ${{ runner.os }}-maven-
-      - name: Build Project
-        run: ./mvnw -B -ntp clean install -Dmaven.javadoc.skip=true -DskipITs -DskipTests -Dspotless.apply.skip=true
-      - name: Run Example generator
-        run: ./mvnw -B test -f examples/shardingsphere-example-generator/pom.xml -Pexample-generator
diff --git a/.github/workflows/ci-daily.yml b/.github/workflows/ci-example-generator.yml
similarity index 52%
copy from .github/workflows/ci-daily.yml
copy to .github/workflows/ci-example-generator.yml
index 9240710a17e..680e46ad563 100644
--- a/.github/workflows/ci-daily.yml
+++ b/.github/workflows/ci-example-generator.yml
@@ -18,52 +18,29 @@
 # This workflow will build a Java project with Maven
 # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
 
-name: Continuous Integration:Daily
+name: Example Generator Test
 
 on:
-  schedule:
-    - cron: '0 18 */1 * *'  # once a day. UTC time
+  push:
+    branches: [ master, dev ]
+  pull_request:
+    branches: [ master ]
 
 env:
   MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3  -Drat.skip=true -Dcheckstyle.skip=true
 
 jobs:
-  ci:
-    if: github.repository == 'apache/shardingsphere'
-    name: JDK ${{ matrix.java_version }} - on ${{ matrix.os }}
-    runs-on: ${{ matrix.os }}
-    timeout-minutes: 60
-    strategy:
-      fail-fast: false
-      matrix:
-        os: [ ubuntu-latest, macos-latest, windows-latest ]
-        java_version: [ 8, 17, 18 ]
-    steps:
-      - name: Support longpaths in Windows
-        if: matrix.os == 'windows-latest'
-        run: git config --global core.longpaths true
-      - uses: actions/checkout@v3
-      - name: Set up JDK ${{ matrix.java_version }}
-        uses: actions/setup-java@v2
-        with:
-          distribution: 'temurin'
-          java-version: ${{ matrix.java_version }}
-      - name: Cache Maven Repos
-        uses: actions/cache@v2
-        with:
-          path: ~/.m2/repository
-          key: shardingsphere-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
-          restore-keys: |
-            ${{ runner.os }}-maven-
-      - name: Build with Maven
-        run: ./mvnw -B -ntp clean install
-      - name: Build examples with Maven
-        run: ./mvnw -B -f examples/pom.xml clean package
-  
   shardingsphere-example-generator:
     if: github.repository == 'apache/shardingsphere'
-    name: ShardingSphere example generator
+    name: ${{ matrix.feature }}--${{ matrix.framework }}--${{ matrix.mode }}--${{ matrix.transaction }}
     runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        product: [ jdbc ]
+        mode: [ standalone ]
+        transaction: [ local ]
+        feature: [ sharding ]
+        framework: [ jdbc ]
     steps:
       - uses: actions/checkout@v3
       - name: Set up JDK 8
@@ -71,14 +48,11 @@ jobs:
         with:
           distribution: 'temurin'
           java-version: 8
-      - name: Cache Maven Repos
-        uses: actions/cache@v2
-        with:
-          path: ~/.m2/repository
-          key: shardingsphere-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
-          restore-keys: |
-            ${{ runner.os }}-maven-
       - name: Build Project
         run: ./mvnw -B -ntp clean install -Dmaven.javadoc.skip=true -DskipITs -DskipTests -Dspotless.apply.skip=true
-      - name: Run Example generator
-        run: ./mvnw -B test -f examples/shardingsphere-example-generator/pom.xml -Pexample-generator
+      - name: Example generator
+        run: ./mvnw -B test -f examples/shardingsphere-example-generator/pom.xml -Pexample-generator -Dproducts=${{ matrix.product }} -Dmodes=${{ matrix.mode }} -Dtransactions=${{ matrix.transaction }} -Dfeatures=${{ matrix.feature }} -Dframeworks=${{ matrix.framework }}
+      - name: Prepare The Docker Environment
+        run : docker-compose -f examples/shardingsphere-example-generator/docker-compose.yml up -d
+      - name: Example Test
+        run : ./mvnw -B test -f examples/shardingsphere-example-generator/target/generated-sources/shardingsphere-jdbc-sample/${{ matrix.feature }}--${{ matrix.framework }}--${{ matrix.mode }}--${{ matrix.transaction }}/pom.xml -Pexample-generator -Dexec.cleanupDaemonThreads=false 
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2d8cd443521..1a2f3c8c69c 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -84,31 +84,6 @@ jobs:
         run: ./mvnw -B -ntp clean install -Dmaven.javadoc.skip=true -Djacoco.skip=true 
       - name: Build examples with Maven
         run: ./mvnw -B -f examples/pom.xml clean package -DskipTests
-  
-  
-  shardingsphere-example-generator:
-    name: ShardingSphere example generator
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v3
-      - name: Maven resolve ranges
-        run: ./mvnw versions:resolve-ranges -ntp -Dincludes='org.springframework:*,org.springframework.boot:*'
-      - name: Cache Maven Repos
-        uses: actions/cache@v2
-        with:
-          path: ~/.m2/repository
-          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
-          restore-keys: |
-            ${{ runner.os }}-maven-
-      - name: Set up JDK 8
-        uses: actions/setup-java@v2
-        with:
-          distribution: 'temurin'
-          java-version: 8
-      - name: Build Project
-        run: ./mvnw -B -ntp clean install -Dmaven.javadoc.skip=true -DskipITs -DskipTests
-      - name: Run Example generator
-        run: ./mvnw -B test -f examples/shardingsphere-example-generator/pom.xml -Pexample-generator
 
   test-coverage-report:
     if: github.repository == 'apache/shardingsphere'
diff --git a/examples/shardingsphere-example-generator/docker-compose.yml b/examples/shardingsphere-example-generator/docker-compose.yml
new file mode 100644
index 00000000000..47a73604614
--- /dev/null
+++ b/examples/shardingsphere-example-generator/docker-compose.yml
@@ -0,0 +1,28 @@
+# 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.
+version: '3'
+services:
+  db:
+    image: 'docker.io/mysql:latest'
+    restart: always
+    container_name: mysql
+    volumes:
+      - ./mysql/init:/docker-entrypoint-initdb.d/
+    ports:
+      - '3306:3306'
+    environment:
+      TZ: Asia/Shanghai
+      MYSQL_ROOT_PASSWORD: "123456"
diff --git a/examples/shardingsphere-example-generator/mysql/init/init.sql b/examples/shardingsphere-example-generator/mysql/init/init.sql
new file mode 100644
index 00000000000..24f154e4905
--- /dev/null
+++ b/examples/shardingsphere-example-generator/mysql/init/init.sql
@@ -0,0 +1,19 @@
+-- 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.
+
+CREATE DATABASE demo_ds_0;
+CREATE DATABASE demo_ds_1;
+CREATE DATABASE demo_ds_2;
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGeneratorFactory.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGeneratorFactory.java
index afa389b9629..c572a147d99 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGeneratorFactory.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGeneratorFactory.java
@@ -17,20 +17,23 @@
 
 package org.apache.shardingsphere.example.generator.core;
 
+import com.google.common.collect.Lists;
 import freemarker.template.Configuration;
 import freemarker.template.TemplateException;
 import lombok.SneakyThrows;
 import org.apache.shardingsphere.example.generator.core.yaml.config.YamlExampleConfiguration;
 import org.apache.shardingsphere.example.generator.core.yaml.config.YamlExampleConfigurationValidator;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
 import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
+import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
 
 import java.io.File;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.List;
 import java.util.Objects;
+import java.util.Properties;
 
 /**
  * Example generator factory.
@@ -63,13 +66,45 @@ public final class ExampleGeneratorFactory {
      * @throws IOException IO exception
      */
     public void generate() throws TemplateException, IOException {
-        YamlExampleConfiguration exampleConfig = swapConfigToObject();
+        YamlExampleConfiguration exampleConfig = buildExampleConfiguration();
         YamlExampleConfigurationValidator.validate(exampleConfig);
         for (String each : exampleConfig.getProducts()) {
             TypedSPIRegistry.getRegisteredService(ExampleGenerator.class, each).generate(templateConfig, exampleConfig);
         }
     }
     
+    private YamlExampleConfiguration buildExampleConfiguration() {
+        YamlExampleConfiguration result = swapConfigToObject();
+        Properties props = new Properties();
+        for (String each : System.getProperties().stringPropertyNames()) {
+            props.setProperty(each, System.getProperty(each));
+        }
+        if (!props.isEmpty()) {
+            if (props.containsKey("products")) {
+                result.setProducts(getSysEnvByKey(props, "products"));
+            }
+            if (props.containsKey("modes")) {
+                result.setModes(getSysEnvByKey(props, "modes"));
+            }
+    
+            if (props.containsKey("transactions")) {
+                result.setTransactions(getSysEnvByKey(props, "transactions"));
+            }
+            if (props.containsKey("features")) {
+                result.setFeatures(getSysEnvByKey(props, "features"));
+            }
+    
+            if (props.containsKey("frameworks")) {
+                result.setFrameworks(getSysEnvByKey(props, "frameworks"));
+            }
+        }
+        return result;
+    }
+    
+    private List<String> getSysEnvByKey(final Properties props, final String key) {
+        return Lists.newArrayList(props.getProperty(key).split(","));
+    }
+    
     @SneakyThrows({URISyntaxException.class, IOException.class})
     private YamlExampleConfiguration swapConfigToObject() {
         URL url = ExampleGeneratorFactory.class.getResource(CONFIG_FILE);
diff --git a/examples/shardingsphere-example-generator/src/main/resources/config.yaml b/examples/shardingsphere-example-generator/src/main/resources/config.yaml
index 0c48058858f..7344a294724 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/config.yaml
+++ b/examples/shardingsphere-example-generator/src/main/resources/config.yaml
@@ -53,4 +53,4 @@ props:
   host: localhost
   port: 3306
   username: root
-  password: root
+  password: 123456
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl
index 99c94046657..5b38cd9c592 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl
@@ -93,7 +93,7 @@ public final class Configuration {
         return new ModeConfiguration("Cluster", new ClusterPersistRepositoryConfiguration("etcd", "governance-sharding-data-source", "localhost:2379", new Properties()), true);
     </#if>
     <#if mode=="standalone">
-        return new ModeConfiguration("Standalone", new StandalonePersistRepositoryConfiguration("H2", new Properties()), true);
+        return new ModeConfiguration("Standalone", new StandalonePersistRepositoryConfiguration("JDBC", new Properties()), true);
     </#if> 
     }
     
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/sharding.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/sharding.ftl
index adaef95a7a3..3cc34b037c8 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/sharding.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/sharding.ftl
@@ -32,7 +32,7 @@
     private static ShardingTableRuleConfiguration getOrderTableRuleConfiguration() {
         ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_order");
         result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("order_id", "snowflake"));
-        result.setAuditStrategy(new ShardingAuditStrategyConfiguration(Arrays.asList("sharding_key_required_auditor"), true));
+        // result.setAuditStrategy(new ShardingAuditStrategyConfiguration(Arrays.asList("sharding_key_required_auditor"), true));
         return result;
     }
     
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl
index a39b8ab897e..228ed21409f 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl
@@ -214,6 +214,33 @@
             <version>1.2.10</version>
         </dependency>
     </dependencies>
+
+    <profiles>
+        <profile>
+            <id>example-generator</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <version>3.0.0</version>
+                        <executions>
+                            <execution>
+                                <phase>test</phase>
+                                <goals>
+                                    <goal>java</goal>
+                                </goals>
+                                <configuration>
+                                    <#assign package = feature?replace('-', '')?replace(',', '.') />
+                                    <mainClass>org.apache.shardingsphere.example.${package}.${framework?replace('-', '.')}.ExampleMain</mainClass>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
     
     <build>
         <plugins>