strongduanmu opened a new issue #10915:
URL: https://github.com/apache/shardingsphere/issues/10915
Hi community,
This issue is for #10887.
# Background
Currently `FederateStatementTest` and `FederatePrepareStatementTest` use
JUNIT to test SQL statements. In order to improve test coverage and code
elegance, we need to migrate the test scenarios of FederateStatementTest and
FederatePrepareStatementTest to `shardingsphere-integration-test`.
# Target
The goal of this issue is to migrate the
`SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ALIAS` statement to the
`shardingsphere-integration-test` module.
You can search for the
`SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ALIAS` keyword, and then
you will find the test cases in `FederateStatementTest` and
`FederatePrepareStatementTest`.
FederateStatementTest:
```java
private static final String
SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ALIAS = "select o.*, i.*
from"
+ " t_order_federate o, t_order_item_federate_sharding i where
o.order_id = i.item_id";
@Test
public void
assertQueryWithFederateInSingleAndShardingTableWithAliasByExecuteQuery() throws
SQLException {
assertQueryWithFederateInSingleAndShardingTableWithAlias(true);
}
@Test
public void
assertQueryWithFederateInSingleAndShardingTableWithAliasByExecute() throws
SQLException {
assertQueryWithFederateInSingleAndShardingTableWithAlias(false);
}
private void
assertQueryWithFederateInSingleAndShardingTableWithAlias(final boolean
executeQuery) throws SQLException {
ShardingSphereStatement statement = (ShardingSphereStatement)
getShardingSphereDataSource().getConnection().createStatement();
ResultSet resultSet = getResultSet(statement,
SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ALIAS, executeQuery);
assertNotNull(resultSet);
assertTrue(resultSet.next());
assertThat(resultSet.getInt(1), is(1000));
assertThat(resultSet.getInt(2), is(10));
assertThat(resultSet.getString(3), is("init"));
assertThat(resultSet.getInt(4), is(1000));
assertThat(resultSet.getInt(5), is(10000));
assertTrue(resultSet.next());
assertThat(resultSet.getInt(1), is(1001));
assertThat(resultSet.getInt(2), is(11));
assertThat(resultSet.getString(3), is("init"));
assertThat(resultSet.getInt(4), is(1001));
assertThat(resultSet.getInt(5), is(10001));
assertFalse(resultSet.next());
}
```
FederatePrepareStatementTest:
```java
private static final String
SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ALIAS =
"select o.*, i.* from t_order_federate o,
t_order_item_federate_sharding i "
+ "where o.order_id = i.item_id AND i.order_id = ?";
@Test
public void
assertQueryWithFederateInSingleAndShardingTableWithAliasByExecuteQuery() throws
SQLException {
assertQueryWithFederateInSingleAndShardingTableWithAlias(true);
}
@Test
public void
assertQueryWithFederateInSingleAndShardingTableWithAliasByExecute() throws
SQLException {
assertQueryWithFederateInSingleAndShardingTableWithAlias(false);
}
public void
assertQueryWithFederateInSingleAndShardingTableWithAlias(final boolean
executeQuery) throws SQLException {
ShardingSpherePreparedStatement preparedStatement =
(ShardingSpherePreparedStatement) getShardingSphereDataSource()
.getConnection().prepareStatement(SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ALIAS);
preparedStatement.setInt(1, 10001);
ResultSet resultSet = getResultSet(preparedStatement, executeQuery);
assertNotNull(resultSet);
assertTrue(resultSet.next());
assertThat(resultSet.getInt(1), is(1001));
assertThat(resultSet.getInt(2), is(11));
assertThat(resultSet.getString(3), is("init"));
assertThat(resultSet.getInt(4), is(1001));
assertThat(resultSet.getInt(5), is(10001));
assertFalse(resultSet.next());
}
```
# How to
In order to finish this task, you need to understand the
[documentation](https://shardingsphere.apache.org/document/current/en/features/test-engine/integration-test/)
of the integration test first, and PR #10913 also provides an example, which
you can refer to. BTW, if you have any questions, please leave a comment.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]