Integration Test

    It is used to define the SQL to be tested and the assertion data of the test results.

    Each case defines one SQL, which can define multiple database execution types.

    Test environment

    It is used to set up the database and ShardingSphere-Proxy environment for running test cases. The environment is classified into environment preparation mode, database type, and scenario.

    Environment preparation mode is divided into Native and Docker, and Embed type will be supported in the future.

    • Native environment is used for test cases to run directly in the test environment provided by the developer, suitable for debugging scenarios;
    • Docker environment is directly built when Maven runs the Docker-Compose plug-in. It is suitable for cloud compilation environment and testing ShardingSphere-Proxy, such as GitHub Action;
    • Embed environment is built when the test framework automatically builds embedded MySQL. It is suitable for the local environment test of ShardingSphere-JDBC.

    Currently, the Native environment is adopted by default, and ShardingSphere-JDBC + H2 database is used to run test cases. Maven’s parameter specifies how the Docker environment is run. In the future, ShardingSphere-JDBC + MySQL of the Embed environment will be adopted to replace the default environment type used when Native executes test cases.

    Database types currently support MySQL, PostgreSQL, SQLServer, and Oracle, and test cases can be executed using ShardingSphere-JDBC or ShardingSphere-Proxy.

    Scenarios are used to test the supporting rules of ShardingSphere. Currently, data sharding and read/write splitting and other related scenarios are supported, and the combination of scenarios will be improved continuously in the future.

    It is used to read test cases in batches and execute and assert test results line by line.

    The test engine arranges test cases and environments to test as many scenarios as possible with the fewest test cases.

    • Database types: H2, MySQL, PostgreSQL, SQLServer, and Oracle;

    • Access port types: ShardingSphere-JDBC and ShardingSphere-Proxy;

    • SQL execution modes: Statement and PreparedStatement;

    • JDBC execution modes: execute and executeQuery/executeUpdate;

    • Scenarios: database shards, table shards, read/write splitting and sharding + read/write splitting

    Therefore, one SQL will drive Database type (5) * Access port type (2) * SQL execution mode (2) * JDBC execution mode (2) * Scenario (4) = 160 test cases to be run to achieve the pursuit of high quality.

    User Guide

    Module path:shardingsphere-test/shardingsphere-test-e2e/shardingsphere-test-e2e-test-suite

    Test case configuration

    SQL test case is in resources/cases/${SQL-TYPE}/${SQL-TYPE}-integration-test-cases.xml.

    The case file format is as follows:

    1. Find the file dataset\${SCENARIO_NAME}\${DATABASE_TYPE}\${dataset_file}.xml in the same level directory;
    2. Find the file dataset\${SCENARIO_NAME}\${dataset_file}.xml in the same level directory;
    3. Find the file dataset\${dataset_file}.xml in the same level directory;

    The assertion file format is as follows:

    ${SCENARIO-TYPE} Refers to the scenario name used to identify a unique scenario during the test engine run. refers to the database types.

    Native environment configuration

    Directory: src/test/resources/env/${SCENARIO-TYPE}

    • scenario-env.properties: data source configuration;
    • rules.yaml: rule configuration;
    • databases.xml: name of the real database;
    • dataset.xml: initialize the data;
    • init-sql\${DATABASE-TYPE}\init.sql: initialize the database and table structure;
    • authority.xml: to be supplemented.

    Docker environment configuration

    Directory: src/test/resources/docker/${SCENARIO-TYPE}

    • docker-compose.yml: Docker-Compose config files, used for Docker environment startup;
    • : rule configuration。

    **The Docker environment configuration provides a remote debugging port for ShardingSphere-Proxy. You can find the second exposed port for remote debugging in shardingsphere-proxy of the docker-comemage. yml file. **

    Run the test engine

    Configure the running environment of the test engine

    Control the test engine by configuring src/test/resources/env/engine-env.properties.

    All attribute values can be dynamically injected via Maven command line -D.

    Run debugging mode

    • Standard test engine Run org.apache.shardingsphere.test.integration.engine.${SQL-TYPE}.General${SQL-TYPE}IT to start the test engines of different SQL types.

    • Batch test engine Run org.apache.shardingsphere.test.integration.engine.dml.BatchDMLIT to start the batch test engine for the test addBatch() provided for DML statements.

    Run Docker mode

    Run the above command to build a Docker mirror used for integration testing. If you only modify the test code, you can reuse the existing test mirror without rebuilding it. Skip the mirror building and run the integration testing directly with the following command:

    Notice

    1. To test Oracle, add an Oracle driver dependency to pom.xml.