This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 2ec095dffac Move generic RQL executor to distsql-handler module
(#30060)
2ec095dffac is described below
commit 2ec095dffac76e7f434b91a8c425acc0f3e118ba
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Feb 8 00:22:28 2024 +0800
Move generic RQL executor to distsql-handler module (#30060)
---
.../query}/rql/ShowLogicalTableExecutor.java | 2 +-
.../rql/ShowRulesUsedStorageUnitExecutor.java | 3 +-
.../engine/query}/rql/ShowStorageUnitExecutor.java | 9 +-
.../query}/rql/ShowLogicalTableExecutorTest.java | 2 +-
.../rql/ShowRulesUsedStorageUnitExecutorTest.java | 77 ++++++++++
.../query}/rql/ShowStorageUnitExecutorTest.java | 83 ++++-------
.../FixtureInUsedStorageUnitRetriever.java} | 20 ++-
.../UnregisterStorageUnitExecutorTest.java | 6 +-
.../FixtureStorageUnitDefinitionProcessor.java | 7 +-
.../DistSQLHandlerFixtureRule.java} | 6 +-
...ler.engine.query.rql.InUsedStorageUnitRetriever | 18 +++
...stsql.handler.engine.query.DistSQLQueryExecutor | 6 +-
.../rql/ShowRulesUsedStorageUnitExecutorTest.java | 162 ---------------------
13 files changed, 153 insertions(+), 248 deletions(-)
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowLogicalTableExecutor.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowLogicalTableExecutor.java
similarity index 97%
rename from
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowLogicalTableExecutor.java
rename to
infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowLogicalTableExecutor.java
index db848ca2b49..8dffee9a311 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowLogicalTableExecutor.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowLogicalTableExecutor.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.handler.distsql.rql;
+package org.apache.shardingsphere.distsql.handler.engine.query.rql;
import lombok.Setter;
import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitExecutor.java
similarity index 95%
rename from
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java
rename to
infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitExecutor.java
index ddf31bc8769..48b6f13d9cc 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitExecutor.java
@@ -15,13 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.handler.distsql.rql;
+package org.apache.shardingsphere.distsql.handler.engine.query.rql;
import com.google.common.base.CaseFormat;
import lombok.Setter;
import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
import
org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
-import
org.apache.shardingsphere.distsql.handler.engine.query.rql.InUsedStorageUnitRetriever;
import
org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowStorageUnitExecutor.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowStorageUnitExecutor.java
similarity index 95%
rename from
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowStorageUnitExecutor.java
rename to
infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowStorageUnitExecutor.java
index 2043eb2695a..3646f4724f5 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowStorageUnitExecutor.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowStorageUnitExecutor.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.handler.distsql.rql;
+package org.apache.shardingsphere.distsql.handler.engine.query.rql;
import lombok.Setter;
import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
@@ -60,7 +60,7 @@ public final class ShowStorageUnitExecutor implements
DistSQLQueryExecutor<ShowS
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShowStorageUnitsStatement sqlStatement, final ContextManager contextManager) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- for (Entry<String, StorageUnit> entry :
getToBeShownStorageUnits(database, sqlStatement).entrySet()) {
+ for (Entry<String, StorageUnit> entry :
getToBeShownStorageUnits(sqlStatement).entrySet()) {
ConnectionProperties connectionProps =
entry.getValue().getConnectionProperties();
DataSourcePoolProperties dataSourcePoolProps =
getDataSourcePoolProperties(entry.getValue());
Map<String, Object> poolProps =
dataSourcePoolProps.getPoolPropertySynonyms().getStandardProperties();
@@ -81,9 +81,8 @@ public final class ShowStorageUnitExecutor implements
DistSQLQueryExecutor<ShowS
return result;
}
- private Map<String, StorageUnit> getToBeShownStorageUnits(final
ShardingSphereDatabase database, final ShowStorageUnitsStatement sqlStatement) {
+ private Map<String, StorageUnit> getToBeShownStorageUnits(final
ShowStorageUnitsStatement sqlStatement) {
Map<String, StorageUnit> result = new
LinkedHashMap<>(database.getResourceMetaData().getStorageUnits().size(), 1F);
- Map<String, StorageUnit> storageUnits =
database.getResourceMetaData().getStorageUnits();
Optional<Integer> usageCount = sqlStatement.getUsageCount();
if (usageCount.isPresent()) {
Map<String, Collection<Class<? extends ShardingSphereRule>>>
inUsedStorageUnits =
database.getRuleMetaData().getInUsedStorageUnitNameAndRulesMap();
@@ -94,7 +93,7 @@ public final class ShowStorageUnitExecutor implements
DistSQLQueryExecutor<ShowS
}
}
} else {
- result.putAll(storageUnits);
+ result.putAll(database.getResourceMetaData().getStorageUnits());
}
return result;
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowLogicalTableExecutorTest.java
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowLogicalTableExecutorTest.java
similarity index 98%
rename from
proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowLogicalTableExecutorTest.java
rename to
infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowLogicalTableExecutorTest.java
index 734ed660092..a99be0b1637 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowLogicalTableExecutorTest.java
+++
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowLogicalTableExecutorTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.handler.distsql.rql;
+package org.apache.shardingsphere.distsql.handler.engine.query.rql;
import
org.apache.shardingsphere.distsql.statement.rql.resource.ShowLogicalTablesStatement;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
diff --git
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitExecutorTest.java
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitExecutorTest.java
new file mode 100644
index 00000000000..d3c991aaa7b
--- /dev/null
+++
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitExecutorTest.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.distsql.handler.engine.query.rql;
+
+import
org.apache.shardingsphere.distsql.handler.fixture.DistSQLHandlerFixtureRule;
+import
org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+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.mode.manager.ContextManager;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment;
+import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class ShowRulesUsedStorageUnitExecutorTest {
+
+ private final ShowRulesUsedStorageUnitExecutor executor = new
ShowRulesUsedStorageUnitExecutor();
+
+ @Test
+ void assertGetRowData() {
+ executor.setDatabase(mockDatabase());
+ ShowRulesUsedStorageUnitStatement sqlStatement = new
ShowRulesUsedStorageUnitStatement("foo_ds", mock(DatabaseSegment.class));
+ Collection<LocalDataQueryResultRow> rowData =
executor.getRows(sqlStatement, mock(ContextManager.class));
+ assertThat(rowData.size(), is(1));
+ Iterator<LocalDataQueryResultRow> actual = rowData.iterator();
+ LocalDataQueryResultRow row = actual.next();
+ assertThat(row.getCell(1), is("dist_s_q_l_handler_fixture"));
+ assertThat(row.getCell(2), is("foo_tbl"));
+ }
+
+ private ShardingSphereDatabase mockDatabase() {
+ ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
+ when(result.getRuleMetaData()).thenReturn(new
RuleMetaData(Collections.singleton(new DistSQLHandlerFixtureRule())));
+ when(result.getResourceMetaData()).thenReturn(new
ResourceMetaData(Collections.singletonMap("foo_ds", new MockedDataSource())));
+ return result;
+ }
+
+ @Test
+ void assertGetEmptyRowData() {
+ executor.setDatabase(mockEmptyDatabase());
+ ShowRulesUsedStorageUnitStatement sqlStatement = new
ShowRulesUsedStorageUnitStatement("empty_ds", mock(DatabaseSegment.class));
+ assertTrue(executor.getRows(sqlStatement,
mock(ContextManager.class)).isEmpty());
+ }
+
+ private ShardingSphereDatabase mockEmptyDatabase() {
+ ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
+ when(result.getRuleMetaData()).thenReturn(new
RuleMetaData(Collections.emptyList()));
+ when(result.getResourceMetaData()).thenReturn(new
ResourceMetaData(Collections.singletonMap("empty_ds", new MockedDataSource())));
+ return result;
+ }
+}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowStorageUnitExecutorTest.java
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowStorageUnitExecutorTest.java
similarity index 58%
rename from
proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowStorageUnitExecutorTest.java
rename to
infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowStorageUnitExecutorTest.java
index b31dcc09f02..a28259c2dad 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowStorageUnitExecutorTest.java
+++
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowStorageUnitExecutorTest.java
@@ -15,38 +15,31 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.handler.distsql.rql;
+package org.apache.shardingsphere.distsql.handler.engine.query.rql;
import
org.apache.shardingsphere.distsql.statement.rql.resource.ShowStorageUnitsStatement;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
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.mode.manager.ContextManager;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
-import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.mockito.junit.jupiter.MockitoSettings;
-import org.mockito.quality.Strictness;
-import javax.sql.DataSource;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -54,46 +47,17 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
-@MockitoSettings(strictness = Strictness.LENIENT)
class ShowStorageUnitExecutorTest {
- @Mock
+ private final ShowStorageUnitExecutor executor = new
ShowStorageUnitExecutor();
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
@BeforeEach
void setUp() {
- ResourceMetaData resourceMetaData = new
ResourceMetaData(createDataSources());
- RuleMetaData metaData = new
RuleMetaData(Collections.singleton(createShardingRule()));
- when(database.getResourceMetaData()).thenReturn(resourceMetaData);
- when(database.getRuleMetaData()).thenReturn(metaData);
- }
-
- private ShardingRule createShardingRule() {
- ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
- ShardingTableRuleConfiguration shardingTableRuleConfig =
createTableRuleConfiguration("order", "ds_${0..1}.order_${0..1}");
- shardingTableRuleConfig.setKeyGenerateStrategy(new
KeyGenerateStrategyConfiguration("id", "increment"));
- shardingRuleConfig.getTables().add(shardingTableRuleConfig);
- shardingRuleConfig.getKeyGenerators().put("increment",
mock(AlgorithmConfiguration.class));
- return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(InstanceContext.class));
- }
-
- private ShardingTableRuleConfiguration createTableRuleConfiguration(final
String logicTableName, final String actualDataNodes) {
- ShardingTableRuleConfiguration result = new
ShardingTableRuleConfiguration(logicTableName, actualDataNodes);
- result.setDatabaseShardingStrategy(new
StandardShardingStrategyConfiguration("order_id", "database_inline"));
- result.setTableShardingStrategy(new
StandardShardingStrategyConfiguration("order_id", "table_inline"));
- return result;
- }
-
- private Collection<String> createDataSourceNames() {
- return Arrays.asList("ds_0", "ds_1", "ds_2");
- }
-
- private Map<String, DataSource> createDataSources() {
- Map<String, DataSource> result = new HashMap<>();
- for (String each : createDataSourceNames()) {
- result.put(each, createDataSource(each));
- }
- return result;
+ when(database.getResourceMetaData()).thenReturn(new
ResourceMetaData(Stream.of("ds_0", "ds_1",
"ds_2").collect(Collectors.toMap(each -> each, this::createDataSource))));
+ executor.setDatabase(database);
}
private MockedDataSource createDataSource(final String dataSourceName) {
@@ -107,17 +71,14 @@ class ShowStorageUnitExecutorTest {
}
@Test
- void assertAllStorageUnit() {
- ShowStorageUnitExecutor executor = new ShowStorageUnitExecutor();
- executor.setDatabase(database);
- ShowStorageUnitsStatement showStorageUnitsStatement = new
ShowStorageUnitsStatement(mock(DatabaseSegment.class), null);
+ void assertGetRowsWithAllStorageUnits() {
Map<Integer, String> nameMap = new HashMap<>(3, 1F);
nameMap.put(0, "ds_2");
nameMap.put(1, "ds_1");
nameMap.put(2, "ds_0");
- Collection<LocalDataQueryResultRow> actual =
executor.getRows(showStorageUnitsStatement, mock(ContextManager.class));
- Iterator<LocalDataQueryResultRow> rowData = actual.iterator();
+ Collection<LocalDataQueryResultRow> actual = executor.getRows(new
ShowStorageUnitsStatement(mock(DatabaseSegment.class), null),
mock(ContextManager.class));
assertThat(actual.size(), is(3));
+ Iterator<LocalDataQueryResultRow> rowData = actual.iterator();
int index = 0;
while (rowData.hasNext()) {
LocalDataQueryResultRow data = rowData.next();
@@ -138,11 +99,10 @@ class ShowStorageUnitExecutorTest {
}
@Test
- void assertUnusedStorageUnit() {
- ShowStorageUnitExecutor executor = new ShowStorageUnitExecutor();
- executor.setDatabase(database);
- ShowStorageUnitsStatement showStorageUnitsStatement = new
ShowStorageUnitsStatement(mock(DatabaseSegment.class), 0);
- Collection<LocalDataQueryResultRow> actual =
executor.getRows(showStorageUnitsStatement, mock(ContextManager.class));
+ void assertGetRowsWithUnusedStorageUnits() {
+ RuleMetaData metaData = mockUnusedStorageUnitsRuleMetaData();
+ when(database.getRuleMetaData()).thenReturn(metaData);
+ Collection<LocalDataQueryResultRow> actual = executor.getRows(new
ShowStorageUnitsStatement(mock(DatabaseSegment.class), 0),
mock(ContextManager.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> rowData = actual.iterator();
LocalDataQueryResultRow data = rowData.next();
@@ -159,4 +119,13 @@ class ShowStorageUnitExecutorTest {
assertThat(data.getCell(11), is(""));
assertThat(data.getCell(12),
is("{\"openedConnections\":[],\"closed\":false}"));
}
+
+ private RuleMetaData mockUnusedStorageUnitsRuleMetaData() {
+ RuleMetaData result = mock(RuleMetaData.class);
+ Map<String, Collection<Class<? extends ShardingSphereRule>>>
inUsedStorageUnitNameAndRulesMap = new HashMap<>(2, 1F);
+ inUsedStorageUnitNameAndRulesMap.put("ds_0",
Collections.singleton(ShardingSphereRule.class));
+ inUsedStorageUnitNameAndRulesMap.put("ds_1",
Collections.singleton(ShardingSphereRule.class));
+
when(result.getInUsedStorageUnitNameAndRulesMap()).thenReturn(inUsedStorageUnitNameAndRulesMap);
+ return result;
+ }
}
diff --git
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/fixture/FixtureStorageUnitDefinitionProcessor.java
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/fixture/FixtureInUsedStorageUnitRetriever.java
similarity index 50%
copy from
infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/fixture/FixtureStorageUnitDefinitionProcessor.java
copy to
infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/fixture/FixtureInUsedStorageUnitRetriever.java
index e742686fe71..06918dc0e22 100644
---
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/fixture/FixtureStorageUnitDefinitionProcessor.java
+++
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/fixture/FixtureInUsedStorageUnitRetriever.java
@@ -15,20 +15,24 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.distsql.handler.executor.rdl.resource.fixture;
+package org.apache.shardingsphere.distsql.handler.engine.query.rql.fixture;
-import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.resource.StorageUnitDefinitionProcessor;
-import
org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.UnregisterStorageUnitStatement;
+import
org.apache.shardingsphere.distsql.handler.engine.query.rql.InUsedStorageUnitRetriever;
+import
org.apache.shardingsphere.distsql.handler.fixture.DistSQLHandlerFixtureRule;
+import
org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
-public final class FixtureStorageUnitDefinitionProcessor implements
StorageUnitDefinitionProcessor<FixtureUnregisterStorageUnitRule> {
+import java.util.Collection;
+import java.util.Collections;
+
+public final class FixtureInUsedStorageUnitRetriever implements
InUsedStorageUnitRetriever<DistSQLHandlerFixtureRule> {
@Override
- public boolean ignoreUsageCheckOnUnregister(final
UnregisterStorageUnitStatement sqlStatement) {
- return sqlStatement.isIgnoreSingleTables();
+ public Collection<String> getInUsedResources(final
ShowRulesUsedStorageUnitStatement sqlStatement, final DistSQLHandlerFixtureRule
rule) {
+ return Collections.singleton("foo_tbl");
}
@Override
- public Class<FixtureUnregisterStorageUnitRule> getRuleClass() {
- return FixtureUnregisterStorageUnitRule.class;
+ public Class<DistSQLHandlerFixtureRule> getType() {
+ return DistSQLHandlerFixtureRule.class;
}
}
diff --git
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutorTest.java
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutorTest.java
index 23864012259..151ad7fd2ca 100644
---
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutorTest.java
+++
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutorTest.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.distsql.handler.executor.rdl.resource;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.StorageUnitInUsedException;
+import
org.apache.shardingsphere.distsql.handler.fixture.DistSQLHandlerFixtureRule;
import
org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.UnregisterStorageUnitStatement;
import
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.DistSQLException;
@@ -31,7 +32,6 @@ import
org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import
org.apache.shardingsphere.distsql.handler.executor.rdl.resource.fixture.FixtureUnregisterStorageUnitRule;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -116,13 +116,13 @@ class UnregisterStorageUnitExecutorTest {
@Test
void assertExecuteUpdateWithStorageUnitInUsedWithoutIgnoredTables() {
- when(database.getRuleMetaData()).thenReturn(new
RuleMetaData(Collections.singleton(new FixtureUnregisterStorageUnitRule())));
+ when(database.getRuleMetaData()).thenReturn(new
RuleMetaData(Collections.singleton(new DistSQLHandlerFixtureRule())));
assertThrows(StorageUnitInUsedException.class, () ->
executor.executeUpdate(new
UnregisterStorageUnitStatement(Collections.singleton("foo_ds"), false, false),
mock(ContextManager.class)));
}
@Test
void assertExecuteUpdateWithStorageUnitInUsedWithIgnoredTables() throws
SQLException {
- when(database.getRuleMetaData()).thenReturn(new
RuleMetaData(Collections.singleton(new FixtureUnregisterStorageUnitRule())));
+ when(database.getRuleMetaData()).thenReturn(new
RuleMetaData(Collections.singleton(new DistSQLHandlerFixtureRule())));
UnregisterStorageUnitStatement sqlStatement = new
UnregisterStorageUnitStatement(Collections.singleton("foo_ds"), true, false);
executor.executeUpdate(sqlStatement, contextManager);
verify(modeContextManager).unregisterStorageUnits("foo_db",
sqlStatement.getStorageUnitNames());
diff --git
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/fixture/FixtureStorageUnitDefinitionProcessor.java
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/fixture/FixtureStorageUnitDefinitionProcessor.java
index e742686fe71..33c30fa0fc7 100644
---
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/fixture/FixtureStorageUnitDefinitionProcessor.java
+++
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/fixture/FixtureStorageUnitDefinitionProcessor.java
@@ -18,9 +18,10 @@
package
org.apache.shardingsphere.distsql.handler.executor.rdl.resource.fixture;
import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.resource.StorageUnitDefinitionProcessor;
+import
org.apache.shardingsphere.distsql.handler.fixture.DistSQLHandlerFixtureRule;
import
org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.UnregisterStorageUnitStatement;
-public final class FixtureStorageUnitDefinitionProcessor implements
StorageUnitDefinitionProcessor<FixtureUnregisterStorageUnitRule> {
+public final class FixtureStorageUnitDefinitionProcessor implements
StorageUnitDefinitionProcessor<DistSQLHandlerFixtureRule> {
@Override
public boolean ignoreUsageCheckOnUnregister(final
UnregisterStorageUnitStatement sqlStatement) {
@@ -28,7 +29,7 @@ public final class FixtureStorageUnitDefinitionProcessor
implements StorageUnitD
}
@Override
- public Class<FixtureUnregisterStorageUnitRule> getRuleClass() {
- return FixtureUnregisterStorageUnitRule.class;
+ public Class<DistSQLHandlerFixtureRule> getRuleClass() {
+ return DistSQLHandlerFixtureRule.class;
}
}
diff --git
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/fixture/FixtureUnregisterStorageUnitRule.java
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/DistSQLHandlerFixtureRule.java
similarity index 91%
rename from
infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/fixture/FixtureUnregisterStorageUnitRule.java
rename to
infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/DistSQLHandlerFixtureRule.java
index 346fd5bf23d..cde6be16d0c 100644
---
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/fixture/FixtureUnregisterStorageUnitRule.java
+++
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/DistSQLHandlerFixtureRule.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.distsql.handler.executor.rdl.resource.fixture;
+package org.apache.shardingsphere.distsql.handler.fixture;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNode;
@@ -30,11 +30,11 @@ import java.util.Optional;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public final class FixtureUnregisterStorageUnitRule implements
ShardingSphereRule, DataNodeContainedRule {
+public final class DistSQLHandlerFixtureRule implements ShardingSphereRule,
DataNodeContainedRule {
@Override
public RuleConfiguration getConfiguration() {
- return null;
+ return mock(RuleConfiguration.class);
}
@Override
diff --git
a/infra/distsql-handler/src/test/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.InUsedStorageUnitRetriever
b/infra/distsql-handler/src/test/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.InUsedStorageUnitRetriever
new file mode 100644
index 00000000000..098510cba97
--- /dev/null
+++
b/infra/distsql-handler/src/test/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.rql.InUsedStorageUnitRetriever
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.distsql.handler.engine.query.rql.fixture.FixtureInUsedStorageUnitRetriever
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 96f543ec8a1..f840821531f 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
@@ -15,9 +15,9 @@
# limitations under the License.
#
-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.distsql.handler.engine.query.rql.ShowStorageUnitExecutor
+org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitExecutor
+org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowLogicalTableExecutor
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/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutorTest.java
deleted file mode 100644
index 4b3cedaf351..00000000000
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutorTest.java
+++ /dev/null
@@ -1,162 +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.rql;
-
-import
org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
-import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import org.apache.shardingsphere.encrypt.rule.EncryptRule;
-import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-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.mask.api.config.MaskRuleConfiguration;
-import
org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
-import org.apache.shardingsphere.mask.rule.MaskRule;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
-import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
-import org.apache.shardingsphere.sharding.rule.ShardingRule;
-import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class ShowRulesUsedStorageUnitExecutorTest {
-
- @Test
- void assertGetRowData() {
- ShowRulesUsedStorageUnitExecutor executor = new
ShowRulesUsedStorageUnitExecutor();
- executor.setDatabase(mockDatabase());
- ShowRulesUsedStorageUnitStatement sqlStatement =
mock(ShowRulesUsedStorageUnitStatement.class);
-
when(sqlStatement.getStorageUnitName()).thenReturn(Optional.of("foo_ds"));
- Collection<LocalDataQueryResultRow> rowData =
executor.getRows(sqlStatement, mock(ContextManager.class));
- assertThat(rowData.size(), is(7));
- Iterator<LocalDataQueryResultRow> actual = rowData.iterator();
- LocalDataQueryResultRow row = actual.next();
- assertThat(row.getCell(1), is("sharding"));
- assertThat(row.getCell(2), is("sharding_auto_table"));
- row = actual.next();
- assertThat(row.getCell(1), is("sharding"));
- assertThat(row.getCell(2), is("sharding_table"));
- row = actual.next();
- assertThat(row.getCell(1), is("readwrite_splitting"));
- assertThat(row.getCell(2), is("readwrite_splitting_source"));
- row = actual.next();
- assertThat(row.getCell(1), is("readwrite_splitting"));
- assertThat(row.getCell(2), is("readwrite_splitting_source"));
- row = actual.next();
- assertThat(row.getCell(1), is("encrypt"));
- assertThat(row.getCell(2), is("encrypt_table"));
- row = actual.next();
- assertThat(row.getCell(1), is("shadow"));
- assertThat(row.getCell(2), is("shadow_source"));
- row = actual.next();
- assertThat(row.getCell(1), is("mask"));
- assertThat(row.getCell(2), is("mask_table"));
- assertFalse(actual.hasNext());
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
- RuleMetaData ruleMetaData = new RuleMetaData(
- Arrays.asList(mockShardingRule(),
mockReadwriteSplittingRule(), mockEncryptRule(), mockShadowRule(),
mockMaskRule()));
- when(result.getRuleMetaData()).thenReturn(ruleMetaData);
- ResourceMetaData resourceMetaData = new
ResourceMetaData(Collections.singletonMap("foo_ds", new MockedDataSource()));
- when(result.getResourceMetaData()).thenReturn(resourceMetaData);
- return result;
- }
-
- private ShardingRule mockShardingRule() {
- ShardingRule result = mock(ShardingRule.class);
- ShardingRuleConfiguration config =
mock(ShardingRuleConfiguration.class);
- when(config.getTables()).thenReturn(Collections.singleton(new
ShardingTableRuleConfiguration("sharding_table", null)));
- when(config.getAutoTables()).thenReturn(Collections.singleton(new
ShardingAutoTableRuleConfiguration("sharding_auto_table", null)));
- when(result.getConfiguration()).thenReturn(config);
- return result;
- }
-
- private ReadwriteSplittingRule mockReadwriteSplittingRule() {
- ReadwriteSplittingRule result = mock(ReadwriteSplittingRule.class);
- ReadwriteSplittingRuleConfiguration config =
mock(ReadwriteSplittingRuleConfiguration.class);
- when(config.getDataSources())
- .thenReturn(Collections.singleton(new
ReadwriteSplittingDataSourceRuleConfiguration("readwrite_splitting_source",
"foo_ds", Arrays.asList("foo_ds", "bar_ds"), "")));
- when(result.getConfiguration()).thenReturn(config);
- return result;
- }
-
- private EncryptRule mockEncryptRule() {
- EncryptRule result = mock(EncryptRule.class);
- EncryptRuleConfiguration config = mock(EncryptRuleConfiguration.class);
- when(config.getTables()).thenReturn(Collections.singleton(new
EncryptTableRuleConfiguration("encrypt_table", Collections.emptyList())));
- when(result.getConfiguration()).thenReturn(config);
- return result;
- }
-
- private ShadowRule mockShadowRule() {
- ShadowRule result = mock(ShadowRule.class);
- ShadowRuleConfiguration config = mock(ShadowRuleConfiguration.class);
- when(config.getDataSources()).thenReturn(Collections.singletonList(new
ShadowDataSourceConfiguration("shadow_source", "foo_ds", "shadow_ds")));
- when(result.getConfiguration()).thenReturn(config);
- return result;
- }
-
- private MaskRule mockMaskRule() {
- MaskRule result = mock(MaskRule.class);
- MaskRuleConfiguration config = mock(MaskRuleConfiguration.class);
- when(config.getTables()).thenReturn(Collections.singleton(new
MaskTableRuleConfiguration("mask_table", Collections.emptyList())));
- when(result.getConfiguration()).thenReturn(config);
- return result;
- }
-
- @Test
- void assertGetEmptyRowData() {
- ShowRulesUsedStorageUnitExecutor executor = new
ShowRulesUsedStorageUnitExecutor();
- executor.setDatabase(mockEmptyDatabase());
- ShowRulesUsedStorageUnitStatement sqlStatement =
mock(ShowRulesUsedStorageUnitStatement.class);
-
when(sqlStatement.getStorageUnitName()).thenReturn(Optional.of("empty_ds"));
- Collection<LocalDataQueryResultRow> rowData =
executor.getRows(sqlStatement, mock(ContextManager.class));
- assertTrue(rowData.isEmpty());
- }
-
- private ShardingSphereDatabase mockEmptyDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
- when(result.getRuleMetaData()).thenReturn(new
RuleMetaData(Collections.emptyList()));
- ResourceMetaData resourceMetaData = new
ResourceMetaData(Collections.singletonMap("empty_ds", new MockedDataSource()));
- when(result.getResourceMetaData()).thenReturn(resourceMetaData);
- return result;
- }
-}