Skip to content

Commit

Permalink
Po/refactor case executor (apache#9408)
Browse files Browse the repository at this point in the history
* merge untracked file

* Refactor the integration test case executor
Based on the Mac OS version to adapt to the embedded MySQL version
New embedded PostgreSQL support
Adjust the PostgreSQL initialization script

* Refactor the integration test case executor
Adapt the embedded database default version
Added embedded PostgreSQL support
Fixed PostgreSQL dropping index NPE
Refactor integration test parameterization parameters
Refactor database SQL initialization
Mark some test cases to ignore PostgreSQL tests

* Refactor the integration test case executor
Adapt the embedded database default version
Added embedded PostgreSQL support
Fixed PostgreSQL dropping index NPE
Refactor integration test parameterization parameters
Refactor database SQL initialization
Mark some test cases to ignore PostgreSQL tests
Enhanced embedded database startup failure retry

* Restore the configuration
  • Loading branch information
juaby authored Feb 9, 2021
1 parent 046f2c1 commit 1e6d100
Show file tree
Hide file tree
Showing 48 changed files with 1,352 additions and 1,232 deletions.
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@

<calcite.version>1.26.0</calcite.version>
<embedded-mysql.version>4.6.1</embedded-mysql.version>
<embedded-postgresql.version>2.10</embedded-postgresql.version>
<disruptor.version>3.4.2</disruptor.version>

<!-- Plugin versions -->
<apache-rat-plugin.version>0.12</apache-rat-plugin.version>
Expand Down Expand Up @@ -462,6 +464,18 @@
<version>${embedded-mysql.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.embed</groupId>
<artifactId>postgresql-embedded</artifactId>
<version>${embedded-postgresql.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>${disruptor.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.shardingsphere.infra.metadata.schema.refresher.type;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
Expand All @@ -36,17 +38,27 @@
public final class DropIndexStatementSchemaRefresher implements SchemaRefresher<DropIndexStatement> {

@Override
public void refresh(final ShardingSphereSchema schema,
public void refresh(final ShardingSphereSchema schema,
final Collection<String> routeDataSourceNames, final DropIndexStatement sqlStatement, final SchemaBuilderMaterials materials) {
Collection<String> indexNames = getIndexNames(sqlStatement);
Optional<SimpleTableSegment> simpleTableSegment = DropIndexStatementHandler.getSimpleTableSegment(sqlStatement);
String tableName = simpleTableSegment.map(tableSegment -> tableSegment.getTableName().getIdentifier().getValue()).orElse("");
TableMetaData tableMetaData = schema.get(tableName);
if (simpleTableSegment.isPresent()) {
indexNames.forEach(each -> tableMetaData.getIndexes().remove(each));
if (!Strings.isNullOrEmpty(tableName)) {
for (String each : indexNames) {
tableMetaData.getIndexes().remove(each);
}
return;
}
for (String each : indexNames) {
if (findLogicTableName(schema, each).isPresent()) {
Optional<String> logicTableNameOptional = findLogicTableName(schema, each);
if (logicTableNameOptional.isPresent()) {
String logicTableName = logicTableNameOptional.orElse("");
Preconditions.checkArgument(!Strings.isNullOrEmpty(logicTableName), "Cannot get the table name!");
if (null == tableMetaData) {
tableMetaData = schema.get(logicTableName);
}
Preconditions.checkNotNull(tableMetaData, "Cannot get the table metadata!");
tableMetaData.getIndexes().remove(each);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@
<groupId>com.wix</groupId>
<artifactId>wix-embedded-mysql</artifactId>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.embed</groupId>
<artifactId>postgresql-embedded</artifactId>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.engine.junit.ITRunnerWithParametersFactory;
import org.apache.shardingsphere.test.integration.engine.junit.ParallelParameterized;
import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
import org.apache.shardingsphere.test.integration.env.EnvironmentType;
Expand All @@ -33,7 +32,6 @@
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.UseParametersRunnerFactory;

import javax.sql.DataSource;
import javax.xml.bind.JAXBException;
Expand All @@ -44,7 +42,6 @@
import java.util.TimeZone;

@RunWith(ParallelParameterized.class)
@UseParametersRunnerFactory(ITRunnerWithParametersFactory.class)
@Getter(AccessLevel.PROTECTED)
public abstract class BaseIT {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

package org.apache.shardingsphere.test.integration.engine.it.dal;

import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.test.integration.cases.SQLCommandType;
import org.apache.shardingsphere.test.integration.cases.assertion.IntegrationTestCaseAssertion;
import org.apache.shardingsphere.test.integration.engine.param.ParameterizedArrayFactory;
import org.apache.shardingsphere.test.integration.engine.param.SQLExecuteType;
import org.apache.shardingsphere.test.integration.engine.param.domain.ParameterizedWrapper;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;

Expand All @@ -40,15 +39,21 @@

public final class GeneralDALIT extends BaseDALIT {

public GeneralDALIT(final String parentPath, final IntegrationTestCaseAssertion assertion, final String adapter, final String scenario,
final String databaseType, final SQLExecuteType sqlExecuteType, final String sql) throws IOException, JAXBException, SQLException, ParseException {
super(parentPath, assertion, adapter, scenario, DatabaseTypeRegistry.getActualDatabaseType(databaseType), sqlExecuteType, sql);
public GeneralDALIT(final ParameterizedWrapper parameterizedWrapper) throws IOException, JAXBException, SQLException, ParseException {
super(parameterizedWrapper.getTestCaseContext().getParentPath(),
parameterizedWrapper.getAssertion(),
parameterizedWrapper.getAdapter(),
parameterizedWrapper.getScenario(),
parameterizedWrapper.getDatabaseType(),
parameterizedWrapper.getSqlExecuteType(),
parameterizedWrapper.getTestCaseContext().getTestCase().getSql());
}

@Parameters(name = "{2}: {3} -> {4} -> {5} -> {6}")
@Parameters(name = "{0}")
public static Collection<Object[]> getParameters() {
return ParameterizedArrayFactory.getAssertionParameterizedArray(SQLCommandType.DAL).stream()
.filter(each -> "proxy".equals(each[2]) && SQLExecuteType.Literal == each[5]).collect(Collectors.toList());
.filter(each -> "proxy".equals(((ParameterizedWrapper) each[0]).getAdapter())
&& SQLExecuteType.Literal == ((ParameterizedWrapper) each[0]).getSqlExecuteType()).collect(Collectors.toList());
}

@SuppressWarnings("JUnitTestMethodWithNoAssertions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

package org.apache.shardingsphere.test.integration.engine.it.dcl;

import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.test.integration.cases.SQLCommandType;
import org.apache.shardingsphere.test.integration.cases.assertion.IntegrationTestCaseAssertion;
import org.apache.shardingsphere.test.integration.engine.param.SQLExecuteType;
import org.apache.shardingsphere.test.integration.engine.param.ParameterizedArrayFactory;
import org.apache.shardingsphere.test.integration.engine.param.domain.ParameterizedWrapper;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;

Expand All @@ -34,12 +33,17 @@

public final class GeneralDCLIT extends BaseDCLIT {

public GeneralDCLIT(final String parentPath, final IntegrationTestCaseAssertion assertion, final String adapter, final String scenario,
final String databaseType, final SQLExecuteType sqlExecuteType, final String sql) throws IOException, JAXBException, SQLException, ParseException {
super(parentPath, assertion, adapter, scenario, DatabaseTypeRegistry.getActualDatabaseType(databaseType), sqlExecuteType, sql);
public GeneralDCLIT(final ParameterizedWrapper parameterizedWrapper) throws IOException, JAXBException, SQLException, ParseException {
super(parameterizedWrapper.getTestCaseContext().getParentPath(),
parameterizedWrapper.getAssertion(),
parameterizedWrapper.getAdapter(),
parameterizedWrapper.getScenario(),
parameterizedWrapper.getDatabaseType(),
parameterizedWrapper.getSqlExecuteType(),
parameterizedWrapper.getTestCaseContext().getTestCase().getSql());
}

@Parameters(name = "{2}: {3} -> {4} -> {5} -> {6}")
@Parameters(name = "{0}")
public static Collection<Object[]> getParameters() {
return ParameterizedArrayFactory.getAssertionParameterizedArray(SQLCommandType.DCL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

package org.apache.shardingsphere.test.integration.engine.it.ddl;

import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.test.integration.cases.SQLCommandType;
import org.apache.shardingsphere.test.integration.cases.assertion.IntegrationTestCaseAssertion;
import org.apache.shardingsphere.test.integration.engine.param.SQLExecuteType;
import org.apache.shardingsphere.test.integration.engine.param.ParameterizedArrayFactory;
import org.apache.shardingsphere.test.integration.engine.param.domain.ParameterizedWrapper;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;

Expand All @@ -34,12 +33,17 @@

public final class GeneralDDLIT extends BaseDDLIT {

public GeneralDDLIT(final String parentPath, final IntegrationTestCaseAssertion assertion, final String adapter, final String scenario,
final String databaseType, final SQLExecuteType sqlExecuteType, final String sql) throws IOException, JAXBException, SQLException, ParseException {
super(parentPath, assertion, adapter, scenario, DatabaseTypeRegistry.getActualDatabaseType(databaseType), sqlExecuteType, sql);
public GeneralDDLIT(final ParameterizedWrapper parameterizedWrapper) throws IOException, JAXBException, SQLException, ParseException {
super(parameterizedWrapper.getTestCaseContext().getParentPath(),
parameterizedWrapper.getAssertion(),
parameterizedWrapper.getAdapter(),
parameterizedWrapper.getScenario(),
parameterizedWrapper.getDatabaseType(),
parameterizedWrapper.getSqlExecuteType(),
parameterizedWrapper.getTestCaseContext().getTestCase().getSql());
}

@Parameters(name = "{2}: {3} -> {4} -> {5} -> {6}")
@Parameters(name = "{0}")
public static Collection<Object[]> getParameters() {
return ParameterizedArrayFactory.getAssertionParameterizedArray(SQLCommandType.DDL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.apache.shardingsphere.test.integration.engine.it.dml;

import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.cases.SQLCommandType;
import org.apache.shardingsphere.test.integration.cases.assertion.IntegrationTestCaseAssertion;
import org.apache.shardingsphere.test.integration.engine.param.SQLExecuteType;
import org.apache.shardingsphere.test.integration.cases.value.SQLValue;
import org.apache.shardingsphere.test.integration.engine.param.ParameterizedArrayFactory;
import org.apache.shardingsphere.test.integration.engine.param.domain.ParameterizedWrapper;
import org.apache.shardingsphere.test.integration.env.IntegrationTestEnvironment;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
Expand All @@ -43,13 +43,18 @@ public final class AdditionalDMLIT extends BaseDMLIT {

private final IntegrationTestCaseAssertion assertion;

public AdditionalDMLIT(final String parentPath, final IntegrationTestCaseAssertion assertion, final String adapter, final String scenario,
final DatabaseType databaseType, final SQLExecuteType sqlExecuteType, final String sql) throws IOException, JAXBException, SQLException, ParseException {
super(parentPath, assertion, adapter, scenario, databaseType, sqlExecuteType, sql);
this.assertion = assertion;
public AdditionalDMLIT(final ParameterizedWrapper parameterizedWrapper) throws IOException, JAXBException, SQLException, ParseException {
super(parameterizedWrapper.getTestCaseContext().getParentPath(),
parameterizedWrapper.getAssertion(),
parameterizedWrapper.getAdapter(),
parameterizedWrapper.getScenario(),
parameterizedWrapper.getDatabaseType(),
parameterizedWrapper.getSqlExecuteType(),
parameterizedWrapper.getTestCaseContext().getTestCase().getSql());
this.assertion = parameterizedWrapper.getAssertion();
}

@Parameters(name = "{2} -> {3} -> {4} -> {5}")
@Parameters(name = "{0}")
public static Collection<Object[]> getParameters() {
return IntegrationTestEnvironment.getInstance().isRunAdditionalTestCases() ? ParameterizedArrayFactory.getAssertionParameterizedArray(SQLCommandType.DML) : Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

package org.apache.shardingsphere.test.integration.engine.it.dml;

import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.test.integration.cases.SQLCommandType;
import org.apache.shardingsphere.test.integration.cases.IntegrationTestCaseContext;
import org.apache.shardingsphere.test.integration.cases.assertion.IntegrationTestCaseAssertion;
import org.apache.shardingsphere.test.integration.cases.value.SQLValue;
import org.apache.shardingsphere.test.integration.engine.it.BatchIT;
import org.apache.shardingsphere.test.integration.engine.param.ParameterizedArrayFactory;
import org.apache.shardingsphere.test.integration.engine.param.domain.ParameterizedWrapper;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;

Expand All @@ -42,13 +42,16 @@ public final class BatchDMLIT extends BatchIT {

private final IntegrationTestCaseContext testCaseContext;

public BatchDMLIT(final IntegrationTestCaseContext testCaseContext, final String adapter,
final String scenario, final String databaseType, final String sql) throws IOException, JAXBException, SQLException {
super(testCaseContext, adapter, scenario, DatabaseTypeRegistry.getActualDatabaseType(databaseType), sql);
this.testCaseContext = testCaseContext;
public BatchDMLIT(final ParameterizedWrapper parameterizedWrapper) throws IOException, JAXBException, SQLException {
super(parameterizedWrapper.getTestCaseContext(),
parameterizedWrapper.getAdapter(),
parameterizedWrapper.getScenario(),
parameterizedWrapper.getDatabaseType(),
parameterizedWrapper.getTestCaseContext().getTestCase().getSql());
this.testCaseContext = parameterizedWrapper.getTestCaseContext();
}

@Parameters(name = "{1}: {2} -> {3} -> {4}")
@Parameters(name = "{0}")
public static Collection<Object[]> getParameters() {
return ParameterizedArrayFactory.getCaseParameterizedArray(SQLCommandType.DML);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.apache.shardingsphere.test.integration.engine.it.dml;

import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.test.integration.cases.SQLCommandType;
import org.apache.shardingsphere.test.integration.cases.assertion.IntegrationTestCaseAssertion;
import org.apache.shardingsphere.test.integration.engine.param.SQLExecuteType;
import org.apache.shardingsphere.test.integration.cases.value.SQLValue;
import org.apache.shardingsphere.test.integration.engine.param.ParameterizedArrayFactory;
import org.apache.shardingsphere.test.integration.engine.param.domain.ParameterizedWrapper;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;

Expand All @@ -41,13 +41,18 @@ public final class GeneralDMLIT extends BaseDMLIT {

private final IntegrationTestCaseAssertion assertion;

public GeneralDMLIT(final String parentPath, final IntegrationTestCaseAssertion assertion, final String adapter, final String scenario,
final String databaseType, final SQLExecuteType sqlExecuteType, final String sql) throws IOException, JAXBException, SQLException, ParseException {
super(parentPath, assertion, adapter, scenario, DatabaseTypeRegistry.getActualDatabaseType(databaseType), sqlExecuteType, sql);
this.assertion = assertion;
public GeneralDMLIT(final ParameterizedWrapper parameterizedWrapper) throws IOException, JAXBException, SQLException, ParseException {
super(parameterizedWrapper.getTestCaseContext().getParentPath(),
parameterizedWrapper.getAssertion(),
parameterizedWrapper.getAdapter(),
parameterizedWrapper.getScenario(),
parameterizedWrapper.getDatabaseType(),
parameterizedWrapper.getSqlExecuteType(),
parameterizedWrapper.getTestCaseContext().getTestCase().getSql());
this.assertion = parameterizedWrapper.getAssertion();
}

@Parameters(name = "{2}: {3} -> {4} -> {5} -> {6}")
@Parameters(name = "{0}")
public static Collection<Object[]> getParameters() {
return ParameterizedArrayFactory.getAssertionParameterizedArray(SQLCommandType.DML);
}
Expand Down
Loading

0 comments on commit 1e6d100

Please sign in to comment.