This is an automated email from the ASF dual-hosted git repository. jianglongtao 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 48fff97bf01 fix IllegalStateException for 19449 (#19610) 48fff97bf01 is described below commit 48fff97bf011b551879c6db91e8f91e8d8cbf497 Author: Da Xiang Huang <localhos...@foxmail.com> AuthorDate: Fri Jul 29 23:00:32 2022 +0800 fix IllegalStateException for 19449 (#19610) * fix IllegalStateException for 19449 * add test * revert the order of imports --- .../handler/query/DatabaseDiscoveryRuleQueryResultSet.java | 6 ++++-- .../handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQuer [...] index 23a3f0a17b1..6f24c7f2204 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java @@ -17,7 +17,6 @@ package org.apache.shardingsphere.dbdiscovery.distsql.handler.query; -import com.google.common.base.Preconditions; import com.google.gson.Gson; import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration; import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration; @@ -67,7 +66,10 @@ public final class DatabaseDiscoveryRuleQueryResultSet implements DistSQLResultS @Override public void init(final ShardingSphereDatabase database, final SQLStatement sqlStatement) { Optional<DatabaseDiscoveryRule> rule = database.getRuleMetaData().findSingleRule(DatabaseDiscoveryRule.class); - Preconditions.checkState(rule.isPresent()); + if (!rule.isPresent()) { + dataSourceRules = Collections.emptyIterator(); + return; + } DatabaseDiscoveryRuleConfiguration ruleConfig = (DatabaseDiscoveryRuleConfiguration) rule.get().getConfiguration(); dataSourceRules = ruleConfig.getDataSources().iterator(); discoveryTypes = ruleConfig.getDiscoveryTypes(); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRule [...] index 1fcf43a52dc..940596878d3 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java @@ -38,6 +38,7 @@ import java.util.Optional; import java.util.Properties; import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @@ -60,6 +61,15 @@ public final class DatabaseDiscoveryRuleQueryResultSetTest { assertColumns(resultSet.getColumnNames()); assertRowData(new ArrayList<>(resultSet.getRowData())); } + + @Test + public void assertInitWithNullDatabaseDiscoveryRule() { + ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); + DistSQLResultSet resultSet = new DatabaseDiscoveryRuleQueryResultSet(); + resultSet.init(database, mock(ShowDatabaseDiscoveryRulesStatement.class)); + assertColumns(resultSet.getColumnNames()); + assertFalse(resultSet.next()); + } private DatabaseDiscoveryRuleConfiguration createRuleConfiguration() { DatabaseDiscoveryDataSourceRuleConfiguration databaseDiscoveryDataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration(