Skip to content

Commit

Permalink
Refactor DistSQL RDL IT (apache#21068)
Browse files Browse the repository at this point in the history
* Refactor DistSQL RDL integration-test

* Revise

* Modify it.yaml

* Fix error

* Modify

* newline

* Newline

* New line

* Add MYSQL

* Fix it case

* Add TODO

* ADD todo
  • Loading branch information
zhaojinchao95 authored Sep 20, 2022
1 parent 801bbc8 commit 00b6e98
Show file tree
Hide file tree
Showing 44 changed files with 641 additions and 508 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
matrix:
adapter: [ proxy, jdbc ]
database: [ MySQL, PostgreSQL ]
scenario: [ empty_rules ]
scenario: [ empty_rules, rdl_empty_rules ]
steps:
- uses: actions/checkout@v2
- name: Cache Maven Repos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public final class IntegrationTestCaseAssertion {
@XmlElement(name = "initial-sql")
private IntegrationTestCaseAssertionSQL initialSQL;

@XmlElement(name = "assertion-sql")
private IntegrationTestCaseAssertionSQL assertionSQL;

@XmlElement(name = "destroy-sql")
private IntegrationTestCaseAssertionSQL destroySQL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;

Expand All @@ -48,7 +47,6 @@ public BaseRDLIT(final AssertionParameterizedArray parameterizedArray) {

@Before
public final void init() throws Exception {
assertNotNull("Init SQL is required", getAssertion().getInitialSQL());
try (Connection connection = getTargetDataSource().getConnection()) {
executeInitSQLs(connection);
}
Expand All @@ -64,7 +62,7 @@ public final void tearDown() throws Exception {
}

private void executeInitSQLs(final Connection connection) throws SQLException {
if (null == getAssertion().getInitialSQL().getSql()) {
if (null == getAssertion().getInitialSQL() || null == getAssertion().getInitialSQL().getSql()) {
return;
}
for (String each : Splitter.on(";").trimResults().splitToList(getAssertion().getInitialSQL().getSql())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.text.ParseException;
import java.util.Collection;

import static org.junit.Assert.assertNotNull;

@ParallelRuntimeStrategy(ParallelLevel.SCENARIO)
public final class GeneralRDLIT extends BaseRDLIT {

Expand All @@ -46,12 +48,22 @@ public static Collection<AssertionParameterizedArray> getParameters() {

@Test
public void assertExecute() throws SQLException, ParseException {
assertNotNull("Assertion SQL is required", getAssertion().getAssertionSQL());
try (Connection connection = getTargetDataSource().getConnection()) {
try (
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(getSQL())) {
assertResultSet(resultSet);
try (Statement statement = connection.createStatement()) {
executeSQLCase(statement);
assertResultSet(statement);
}
}
}

private void executeSQLCase(final Statement statement) throws SQLException, ParseException {
statement.execute(getSQL());
}

private void assertResultSet(final Statement statement) throws SQLException {
try (ResultSet resultSet = statement.executeQuery(getAssertion().getAssertionSQL().getSql())) {
assertResultSet(resultSet);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ private Collection<AssertionParameterizedArray> getAssertionParameterizedArray(f
}

private boolean filterScenarios(final String scenario, final Collection<String> scenarios, final Class<? extends SQLStatement> sqlStatementClass) {
if (sqlStatementClass == RDLStatement.class || sqlStatementClass == RALStatement.class) {
if (sqlStatementClass == RALStatement.class) {
return "empty_rules".equals(scenario);
}
if (sqlStatementClass == RDLStatement.class) {
return "rdl_empty_rules".equals(scenario);
}
if ("empty_rules".equals(scenario)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@
<initial-sql sql="CREATE TABLE t_broadcast_table_for_ddl(id int, description varchar(10))" affected-table="t_broadcast_table_for_ddl" />
</assertion>
</test-case>

<test-case sql="DROP INDEX t_broadcast_table_for_ddl_index ON t_broadcast_table_for_ddl" db-types="MySQL,SQLServer,Oracle" scenario-types="db,tbl,dbtbl_with_readwrite_splitting,readwrite_splitting">
<assertion expected-data-file="unchanged_broadcast_table.xml">
<initial-sql sql="CREATE TABLE t_broadcast_table_for_ddl(id int, description varchar(10));CREATE INDEX t_broadcast_table_for_ddl_index ON t_broadcast_table_for_ddl(description)" affected-table="t_broadcast_table_for_ddl" />
</assertion>
</test-case>

<!-- TODO Fix me #20932 -->
<!-- <test-case sql="DROP INDEX t_broadcast_table_for_ddl_index ON t_broadcast_table_for_ddl" db-types="MySQL,SQLServer,Oracle" scenario-types="db,tbl,dbtbl_with_readwrite_splitting,readwrite_splitting">-->
<!-- <assertion expected-data-file="unchanged_broadcast_table.xml">-->
<!-- <initial-sql sql="CREATE TABLE t_broadcast_table_for_ddl(id int, description varchar(10));CREATE INDEX t_broadcast_table_for_ddl_index ON t_broadcast_table_for_ddl(description)" affected-table="t_broadcast_table_for_ddl" />-->
<!-- </assertion>-->
<!-- </test-case>-->

<!-- TODO Fix me #20932 -->
<!-- <test-case sql="DROP INDEX t_broadcast_table_for_ddl_index" db-types="PostgreSQL" scenario-types="db,tbl,dbtbl_with_readwrite_splitting,readwrite_splitting">-->
Expand Down Expand Up @@ -230,6 +231,7 @@
<!-- </assertion>-->
<!-- </test-case>-->

<!-- TODO Fix me #20932 -->
<!-- <test-case sql="DROP INDEX t_user_details_index" db-types="PostgreSQL" scenario-types="encrypt,dbtbl_with_readwrite_splitting_and_encrypt,sharding_and_encrypt,encrypt_and_readwrite_splitting">-->
<!-- <assertion expected-data-file="unchanged_table.xml">-->
<!-- <initial-sql sql="CREATE TABLE t_user_details (user_id INT NOT NULL, address_id INT NOT NULL, number_plain VARCHAR(45) NULL, number_cipher VARCHAR(45) NULL, description varchar(10));CREATE INDEX t_user_details_index ON t_user_details(description)" affected-table="t_user_details" />-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<initial-sql sql="SET READWRITE_SPLITTING HINT SOURCE = write;CLEAR HINT"/>
</assertion>
</test-case>

<test-case sql="SHOW SHARDING HINT STATUS">
<assertion expected-data-file="default_sharding_hint.xml"/>
<assertion expected-data-file="set_database_value_hint.xml">
Expand All @@ -49,26 +49,26 @@
<initial-sql sql="ADD SHARDING HINT TABLE_VALUE t_user_item= 100;CLEAR HINT"/>
</assertion>
</test-case>

<test-case sql="show variable transaction_type">
<assertion expected-data-file="default_transaction_type.xml"/>
</test-case>

<test-case sql="show variable transaction_type">
<assertion expected-data-file="transaction_type.xml">
<initial-sql sql="set variable transaction_type = 'XA'"/>
<destroy-sql sql="set variable transaction_type = 'LOCAL'"/>
</assertion>
</test-case>

<test-case sql="show variable cached_connections">
<assertion expected-data-file="cached_connections.xml"/>
</test-case>

<test-case sql="preview select * from t_user_item">
<assertion expected-data-file="preview_sql.xml"/>
</test-case>

<test-case
sql="PREVIEW SELECT * FROM t_single_table s INNER JOIN t_user_item i ON s.single_id = i.item_id WHERE i.user_id = 1">
<assertion expected-data-file="preview_federation_select.xml"/>
Expand Down
Loading

0 comments on commit 00b6e98

Please sign in to comment.