This is an automated email from the ASF dual-hosted git repository.
yx9o 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 4870f418997 Move ShowStatusFromReadwriteSplittingRulesExecutor &
AlterReadwriteSplittingStorageUnitStatusExecutor to readwrite-splitting module.
(#30052)
4870f418997 is described below
commit 4870f418997d07c61fbcc4f1a49ef812be084f47
Author: Raigor <[email protected]>
AuthorDate: Wed Feb 7 21:37:20 2024 +0800
Move ShowStatusFromReadwriteSplittingRulesExecutor &
AlterReadwriteSplittingStorageUnitStatusExecutor to readwrite-splitting module.
(#30052)
* Move ShowStatusFromReadwriteSplittingRulesExecutor &
AlterReadwriteSplittingStorageUnitStatusExecutor to readwrite-splitting module.
* Update ShowStatusFromReadwriteSplittingRulesExecutorTest
---
...wStatusFromReadwriteSplittingRulesExecutor.java | 14 ++--
...eadwriteSplittingStorageUnitStatusExecutor.java | 3 +-
...stsql.handler.engine.query.DistSQLQueryExecutor | 1 +
...ql.handler.engine.update.DistSQLUpdateExecutor} | 3 +-
...tusFromReadwriteSplittingRulesExecutorTest.java | 77 ++++++++++++++++++++
.../required/DistSQLExecutorRequiredChecker.java | 2 +-
...stsql.handler.engine.query.DistSQLQueryExecutor | 1 -
...sql.handler.engine.update.DistSQLUpdateExecutor | 1 -
...tusFromReadwriteSplittingRulesExecutorTest.java | 85 ----------------------
9 files changed, 87 insertions(+), 100 deletions(-)
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/readwritesplitting/ShowStatusFromReadwriteSplittingRulesExecutor.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutor.java
similarity index 91%
rename from
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/readwritesplitting/ShowStatusFromReadwriteSplittingRulesExecutor.java
rename to
features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutor.java
index 070143888ad..6092231b2d5 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/readwritesplitting/ShowStatusFromReadwriteSplittingRulesExecutor.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutor.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.proxy.backend.handler.distsql.rql.readwritesplitting;
+package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
import com.google.common.base.Strings;
import lombok.Setter;
@@ -29,12 +29,10 @@ import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.RuleExpor
import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants;
import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
-import org.apache.shardingsphere.metadata.persist.MetaDataBasedPersistService;
import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource;
import org.apache.shardingsphere.mode.event.storage.StorageNodeRole;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.storage.service.StorageNodeStatusService;
-import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import
org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowStatusFromReadwriteSplittingRulesStatement;
import java.util.Arrays;
@@ -52,7 +50,6 @@ import java.util.stream.Collectors;
/**
* Show status from readwrite-splitting rules executor.
*/
-// TODO move to readwritesplitting module
@Setter
public final class ShowStatusFromReadwriteSplittingRulesExecutor implements
DistSQLQueryExecutor<ShowStatusFromReadwriteSplittingRulesStatement>,
DistSQLExecutorDatabaseAware {
@@ -66,10 +63,11 @@ public final class
ShowStatusFromReadwriteSplittingRulesExecutor implements Dist
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShowStatusFromReadwriteSplittingRulesStatement sqlStatement, final
ContextManager contextManager) {
Collection<String> allReadResources =
getAllReadResources(sqlStatement.getGroupName());
- Map<String, StorageNodeDataSource> persistentReadResources =
getPersistentReadResources(database.getName(),
contextManager.getMetaDataContexts().getPersistService());
+ Map<String, StorageNodeDataSource> persistentReadResources =
getPersistentReadResources(database.getName(), contextManager);
return buildRows(allReadResources, persistentReadResources);
}
+ @SuppressWarnings("unchecked")
private Collection<String> getAllReadResources(final String groupName) {
Collection<String> exportKeys =
Arrays.asList(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE,
ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE);
Map<String, Object> exportMap =
database.getRuleMetaData().findRules(ExportableRule.class).stream()
@@ -84,11 +82,11 @@ public final class
ShowStatusFromReadwriteSplittingRulesExecutor implements Dist
.map(this::deconstructString).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
}
- private Map<String, StorageNodeDataSource>
getPersistentReadResources(final String databaseName, final
MetaDataBasedPersistService persistService) {
- if (null == persistService || null == persistService.getRepository()
|| !(persistService.getRepository() instanceof ClusterPersistRepository)) {
+ private Map<String, StorageNodeDataSource>
getPersistentReadResources(final String databaseName, final ContextManager
contextManager) {
+ if (!contextManager.getInstanceContext().isCluster()) {
return Collections.emptyMap();
}
- Map<String, StorageNodeDataSource> storageNodes = new
StorageNodeStatusService(persistService.getRepository()).loadStorageNodes();
+ Map<String, StorageNodeDataSource> storageNodes = new
StorageNodeStatusService(contextManager.getMetaDataContexts().getPersistService().getRepository()).loadStorageNodes();
Map<String, StorageNodeDataSource> result = new HashMap<>();
storageNodes.entrySet().stream().filter(entry ->
StorageNodeRole.MEMBER == entry.getValue().getRole()).forEach(entry -> {
QualifiedDatabase qualifiedDatabase = new
QualifiedDatabase(entry.getKey());
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/readwritesplitting/AlterReadwriteSplittingStorageUnitStatusExecutor.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
similarity index 98%
rename from
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/readwritesplitting/AlterReadwriteSplittingStorageUnitStatusExecutor.java
rename to
features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
index 8958c79fe57..fca40a12425 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/readwritesplitting/AlterReadwriteSplittingStorageUnitStatusExecutor.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.readwritesplitting;
+package org.apache.shardingsphere.readwritesplitting.distsql.handler.update;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
@@ -52,7 +52,6 @@ import java.util.stream.Collectors;
/**
* Alter readwrite-splitting storage unit status executor.
*/
-// TODO move to readwritesplitting module
@DistSQLExecutorClusterModeRequired
@Setter
public final class AlterReadwriteSplittingStorageUnitStatusExecutor
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor
b/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor
index f8b8df89a7c..df30ab43299 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor
+++
b/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor
@@ -16,4 +16,5 @@
#
org.apache.shardingsphere.readwritesplitting.distsql.handler.query.ShowReadwriteSplittingRuleExecutor
+org.apache.shardingsphere.readwritesplitting.distsql.handler.query.ShowStatusFromReadwriteSplittingRulesExecutor
org.apache.shardingsphere.readwritesplitting.distsql.handler.query.ShowReadQueryLoadBalanceAlgorithmImplementationsExecutor
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor
b/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor
similarity index 77%
copy from
features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor
copy to
features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor
index f8b8df89a7c..653463b9a00 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor
+++
b/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor
@@ -15,5 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.readwritesplitting.distsql.handler.query.ShowReadwriteSplittingRuleExecutor
-org.apache.shardingsphere.readwritesplitting.distsql.handler.query.ShowReadQueryLoadBalanceAlgorithmImplementationsExecutor
+org.apache.shardingsphere.readwritesplitting.distsql.handler.update.AlterReadwriteSplittingStorageUnitStatusExecutor
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
new file mode 100644
index 00000000000..c34dd849830
--- /dev/null
+++
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
+
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
+import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import
org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowStatusFromReadwriteSplittingRulesStatement;
+import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class ShowStatusFromReadwriteSplittingRulesExecutorTest {
+
+ @Test
+ void assertGetRowData() {
+ ShowStatusFromReadwriteSplittingRulesExecutor executor = new
ShowStatusFromReadwriteSplittingRulesExecutor();
+ executor.setDatabase(mockDatabase());
+ Collection<LocalDataQueryResultRow> actual =
executor.getRows(mock(ShowStatusFromReadwriteSplittingRulesStatement.class),
mock(ContextManager.class, RETURNS_DEEP_STUBS));
+ assertThat(actual.size(), is(2));
+ Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
+ LocalDataQueryResultRow row = iterator.next();
+ assertThat(row.getCell(1), is("read_ds_0"));
+ assertThat(row.getCell(2), is("ENABLED"));
+ row = iterator.next();
+ assertThat(row.getCell(1), is("read_ds_1"));
+ assertThat(row.getCell(2), is("ENABLED"));
+ }
+
+ private ShardingSphereDatabase mockDatabase() {
+ ShardingSphereDatabase result = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
+ ReadwriteSplittingRule readwriteSplittingRule =
mock(ReadwriteSplittingRule.class);
+
when(readwriteSplittingRule.getExportData()).thenReturn(mockExportData());
+
when(result.getRuleMetaData().findRules(ExportableRule.class)).thenReturn(Collections.singletonList(readwriteSplittingRule));
+ return result;
+ }
+
+ private Map<String, Object> mockExportData() {
+ return
Collections.singletonMap(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE,
exportDataSources());
+ }
+
+ private Map<String, Map<String, String>> exportDataSources() {
+ Map<String, String> exportedDataSources = new LinkedHashMap<>(2, 1F);
+
exportedDataSources.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME,
"write_ds");
+
exportedDataSources.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES,
"read_ds_0,read_ds_1");
+ return Collections.singletonMap("readwrite_ds", exportedDataSources);
+ }
+}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java
index 6a3eed8cc5d..ff798aa4342 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java
@@ -50,7 +50,7 @@ public final class DistSQLExecutorRequiredChecker {
}
private void checkClusterMode(final ContextManager contextManager) {
-
ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().isCluster(),
() -> new UnsupportedSQLOperationException("Mode must be `Cluster`."));
+
ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().isCluster(),
() -> new UnsupportedSQLOperationException("Mode must be `Cluster`"));
}
private void checkCurrentRule(final SQLStatement sqlStatement, final
ContextManager contextManager, final ShardingSphereDatabase database,
diff --git
a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor
b/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor
index cf4065402a9..96f543ec8a1 100644
---
a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor
+++
b/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor
@@ -18,7 +18,6 @@
org.apache.shardingsphere.proxy.backend.handler.distsql.rql.ShowStorageUnitExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.rql.ShowRulesUsedStorageUnitExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.rql.ShowLogicalTableExecutor
-org.apache.shardingsphere.proxy.backend.handler.distsql.rql.readwritesplitting.ShowStatusFromReadwriteSplittingRulesExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowComputeNodesExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowComputeNodeInfoExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowComputeNodeModeExecutor
diff --git
a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor
b/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor
index b99508e07d9..eb0b26ad4a5 100644
---
a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor
+++
b/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor
@@ -21,7 +21,6 @@
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.UnlabelCom
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.SetInstanceStatusExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.ImportDatabaseConfigurationExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.ImportMetaDataExecutor
-org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.readwritesplitting.AlterReadwriteSplittingStorageUnitStatusExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.SetDistVariableExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.RefreshDatabaseMetaDataExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.LockClusterExecutor
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
deleted file mode 100644
index 3e8e79c0231..00000000000
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
-
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
-import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import
org.apache.shardingsphere.mode.repository.cluster.zookeeper.ZookeeperRepository;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.rql.readwritesplitting.ShowStatusFromReadwriteSplittingRulesExecutor;
-import
org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowStatusFromReadwriteSplittingRulesStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import org.apache.shardingsphere.test.mock.AutoMockExtension;
-import org.apache.shardingsphere.test.mock.StaticMockSettings;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(AutoMockExtension.class)
-@StaticMockSettings(ProxyContext.class)
-class ShowStatusFromReadwriteSplittingRulesExecutorTest {
-
- @Test
- void assertGetRowsWithEmptyResult() {
- ShowStatusFromReadwriteSplittingRulesExecutor executor = new
ShowStatusFromReadwriteSplittingRulesExecutor();
- ContextManager contextManager = mockContextManager();
-
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
-
executor.setDatabase(contextManager.getMetaDataContexts().getMetaData().getDatabase("readwrite_db"));
- Collection<LocalDataQueryResultRow> actual = executor.getRows(
- new ShowStatusFromReadwriteSplittingRulesStatement(new
DatabaseSegment(1, 1, new IdentifierValue("readwrite_db")), null),
contextManager);
- assertTrue(actual.isEmpty());
- }
-
- private ContextManager mockContextManager() {
- MetaDataPersistService persistService = new
MetaDataPersistService(mock(ZookeeperRepository.class));
- MetaDataContexts metaDataContexts = new
MetaDataContexts(persistService, mockMetaData());
- return new ContextManager(metaDataContexts,
mock(InstanceContext.class, RETURNS_DEEP_STUBS));
- }
-
- private ShardingSphereMetaData mockMetaData() {
- ShardingSphereDatabase database = new
ShardingSphereDatabase("readwrite_db",
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"),
- mock(ResourceMetaData.class, RETURNS_DEEP_STUBS),
- new
RuleMetaData(Collections.singletonList(mock(ShardingSphereRule.class))),
Collections.emptyMap());
- Map<String, ShardingSphereDatabase> databaseMap = new
LinkedHashMap<>();
- databaseMap.put("readwrite_db", database);
- return new ShardingSphereMetaData(databaseMap,
mock(ResourceMetaData.class),
- new RuleMetaData(Collections.emptyList()), new
ConfigurationProperties(new Properties()));
- }
-}