You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/07/13 11:48:49 UTC
[shardingsphere] branch master updated: Fixes #19084. (#19105)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 955ada55f67 Fixes #19084. (#19105)
955ada55f67 is described below
commit 955ada55f6762e604951387fef373a1dc86a49ef
Author: Raigor <ra...@gmail.com>
AuthorDate: Wed Jul 13 19:48:42 2022 +0800
Fixes #19084. (#19105)
---
.../query/ReadwriteSplittingRuleQueryResultSet.java | 15 ++++++---------
.../query/ReadwriteSplittingRuleQueryResultSetTest.java | 10 ++++++++++
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwrite [...]
index 65fd78b0115..219ee045cf3 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSet.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSet.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
import org.apache.shardingsphere.infra.distsql.constant.ExportableItemConstants;
@@ -44,8 +43,6 @@ import java.util.Optional;
*/
public final class ReadwriteSplittingRuleQueryResultSet implements DistSQLResultSet {
- private static final String DYNAMIC = "Dynamic";
-
private Iterator<Collection<Object>> data = Collections.emptyIterator();
private Map<String, Map<String, String>> exportableAutoAwareDataSource = Collections.emptyMap();
@@ -55,15 +52,15 @@ public final class ReadwriteSplittingRuleQueryResultSet implements DistSQLResult
@Override
public void init(final ShardingSphereDatabase database, final SQLStatement sqlStatement) {
Optional<ReadwriteSplittingRule> rule = database.getRuleMetaData().findSingleRule(ReadwriteSplittingRule.class);
- buildExportableMap(database);
- rule.ifPresent(optional -> data = buildData(optional).iterator());
+ rule.ifPresent(optional -> {
+ buildExportableMap(optional);
+ data = buildData(optional).iterator();
+ });
}
@SuppressWarnings("unchecked")
- private void buildExportableMap(final ShardingSphereDatabase database) {
- Optional<ReadwriteSplittingRule> rule = database.getRuleMetaData().findSingleRule(ReadwriteSplittingRule.class);
- Preconditions.checkState(rule.isPresent());
- Map<String, Object> exportedData = rule.get().getExportData();
+ private void buildExportableMap(final ReadwriteSplittingRule rule) {
+ Map<String, Object> exportedData = rule.getExportData();
exportableAutoAwareDataSource = (Map<String, Map<String, String>>) exportedData.get(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE);
exportableDataSourceMap = (Map<String, Map<String, String>>) exportedData.get(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE);
}
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readw [...]
index c46d5040ea0..edc53895deb 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java
@@ -40,6 +40,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;
@@ -48,6 +49,15 @@ import static org.mockito.Mockito.when;
public final class ReadwriteSplittingRuleQueryResultSetTest {
+ @Test
+ public void assertGetEmptyRule() {
+ ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
+ when(database.getRuleMetaData().findSingleRule(ReadwriteSplittingRule.class)).thenReturn(Optional.empty());
+ ReadwriteSplittingRuleQueryResultSet resultSet = new ReadwriteSplittingRuleQueryResultSet();
+ resultSet.init(database, mock(ShowReadwriteSplittingRulesStatement.class));
+ assertFalse(resultSet.next());
+ }
+
@Test
public void assertGetRowData() {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);