This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 957b0b2c56e Use xml to test DistSQLGlobalRuleQueryExecutor (#33137)
957b0b2c56e is described below
commit 957b0b2c56e2382c55fc3f0b35afddacb168078e
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Oct 7 02:11:33 2024 +0800
Use xml to test DistSQLGlobalRuleQueryExecutor (#33137)
* Use xml to test DistSQLGlobalRuleQueryExecutor
* Use xml to test DistSQLGlobalRuleQueryExecutor
---
.../query/ShowAuthorityRuleExecutorTest.java | 47 +++----------
.../cases/show-authority-rule-current-config.yaml | 25 +++++++
.../test/resources/cases/show-authority-rule.xml | 25 +++++++
.../query/ShowGlobalClockRuleExecutorTest.java | 39 +++--------
.../show-global-clock-rule-current-config.yaml | 24 +++++++
.../resources/cases/show-global-clock-rule.xml | 25 +++++++
...faultSQLFederationRuleConfigurationBuilder.java | 2 +-
.../query/ShowSQLFederationRuleExecutor.java | 2 +-
.../query/ShowSQLFederationRuleExecutorTest.java | 40 +++--------
.../show-sql-federation-rule-current-config.yaml | 24 +++++++
.../resources/cases/show-sql-federation-rule.xml | 25 +++++++
.../handler/query/ShowSQLParserRuleExecutor.java | 4 +-
.../query/ShowSQLParserRuleExecutorTest.java | 40 +++--------
.../cases/show-sql-parser-rule-current-config.yaml | 25 +++++++
.../test/resources/cases/show-sql-parser-rule.xml | 25 +++++++
.../query/ShowSQLTranslatorRuleExecutorTest.java | 37 +++-------
.../show-sql-translator-rule-current-config.yaml | 21 ++++++
.../resources/cases/show-sql-translator-rule.xml | 25 +++++++
.../query/ShowTransactionRuleExecutorTest.java | 39 +++--------
.../show-transaction-rule-current-config.yaml | 23 +++++++
.../test/resources/cases/show-transaction-rule.xml | 25 +++++++
.../pipeline/framework/PipelineE2EExtension.java | 2 +-
.../DistSQLGlobalRuleQueryExecutorAssert.java | 71 ++++++++++++++++++++
.../query/DistSQLRuleQueryExecutorSettings.java | 37 ++++++++++
...RuleQueryExecutorTestCaseArgumentsProvider.java | 78 ++++++++++++++++++++++
.../jaxb/DistSQLRuleQueryExecutorTestCase.java | 46 +++++++++++++
.../jaxb/DistSQLRuleQueryExecutorTestCases.java | 36 ++++++++++
27 files changed, 625 insertions(+), 187 deletions(-)
diff --git
a/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutorTest.java
b/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutorTest.java
index 32989e38cd2..188395917d2 100644
---
a/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutorTest.java
+++
b/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutorTest.java
@@ -17,62 +17,37 @@
package org.apache.shardingsphere.authority.distsql.handler.query;
-import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
-import org.apache.shardingsphere.authority.config.UserConfiguration;
-import
org.apache.shardingsphere.authority.distsql.statement.ShowAuthorityRuleStatement;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
-import java.util.Properties;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-class ShowAuthorityRuleExecutorTest extends DistSQLGlobalRuleQueryExecutorTest
{
+@DistSQLRuleQueryExecutorSettings("cases/show-authority-rule.xml")
+class ShowAuthorityRuleExecutorTest {
- ShowAuthorityRuleExecutorTest() {
- super(mockRule());
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final GlobalRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLGlobalRuleQueryExecutorAssert(mockRule()).assertQueryResultRows(sqlStatement,
currentRuleConfig, expected);
}
- private static AuthorityRule mockRule() {
+ private AuthorityRule mockRule() {
AuthorityRule result = mock(AuthorityRule.class);
when(result.getGrantees()).thenReturn(Collections.singleton(new
Grantee("root", "localhost")));
return result;
}
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement, final
Collection<LocalDataQueryResultRow> expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ExtensionContext extensionContext) {
- return Stream.of(
- Arguments.arguments("normal", createRuleConfiguration(),
new ShowAuthorityRuleStatement(),
- Collections.singleton(new
LocalDataQueryResultRow("root@localhost", "ALL_PERMITTED", ""))));
- }
-
- private AuthorityRuleConfiguration createRuleConfiguration() {
- UserConfiguration userConfig = new UserConfiguration("root", "",
"localhost", null, false);
- AlgorithmConfiguration privilegeProvider = new
AlgorithmConfiguration("ALL_PERMITTED", new Properties());
- return new
AuthorityRuleConfiguration(Collections.singleton(userConfig),
privilegeProvider, Collections.emptyMap(), null);
- }
- }
}
diff --git
a/kernel/authority/distsql/handler/src/test/resources/cases/show-authority-rule-current-config.yaml
b/kernel/authority/distsql/handler/src/test/resources/cases/show-authority-rule-current-config.yaml
new file mode 100644
index 00000000000..a274ced7afb
--- /dev/null
+++
b/kernel/authority/distsql/handler/src/test/resources/cases/show-authority-rule-current-config.yaml
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+rules:
+ - !AUTHORITY
+ users:
+ - user: root@localhost
+ password:
+ admin: false
+ privilege:
+ type: ALL_PERMITTED
diff --git
a/kernel/authority/distsql/handler/src/test/resources/cases/show-authority-rule.xml
b/kernel/authority/distsql/handler/src/test/resources/cases/show-authority-rule.xml
new file mode 100644
index 00000000000..195f9e17ed1
--- /dev/null
+++
b/kernel/authority/distsql/handler/src/test/resources/cases/show-authority-rule.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW AUTHORITY RULE"
current-rule-config-yaml-file="cases/show-authority-rule-current-config.yaml">
+ <expected-query-result-rows>
+
<expected-query-result-row>root@localhost|ALL_PERMITTED|</expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>
diff --git
a/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/query/ShowGlobalClockRuleExecutorTest.java
b/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/query/ShowGlobalClockRuleExecutorTest.java
index f69b0f8f46e..f62bb376d84 100644
---
a/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/query/ShowGlobalClockRuleExecutorTest.java
+++
b/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/query/ShowGlobalClockRuleExecutorTest.java
@@ -18,46 +18,27 @@
package org.apache.shardingsphere.globalclock.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import
org.apache.shardingsphere.globalclock.config.GlobalClockRuleConfiguration;
-import
org.apache.shardingsphere.globalclock.distsql.statement.queryable.ShowGlobalClockRuleStatement;
import org.apache.shardingsphere.globalclock.rule.GlobalClockRule;
import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorTest;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorAssert;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class ShowGlobalClockRuleExecutorTest extends
DistSQLGlobalRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-global-clock-rule.xml")
+class ShowGlobalClockRuleExecutorTest {
- ShowGlobalClockRuleExecutorTest() {
- super(mock(GlobalClockRule.class));
- }
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement, final
Collection<LocalDataQueryResultRow> expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ExtensionContext extensionContext) {
- return Stream.of(
- Arguments.arguments("normal", new
GlobalClockRuleConfiguration("TSO", "local", false, PropertiesBuilder.build(new
Property("key", "value"))), new ShowGlobalClockRuleStatement(),
- Collections.singleton(new
LocalDataQueryResultRow("TSO", "local", "false", "{\"key\":\"value\"}"))));
- }
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final GlobalRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLGlobalRuleQueryExecutorAssert(mock(GlobalClockRule.class)).assertQueryResultRows(sqlStatement,
currentRuleConfig, expected);
}
}
diff --git
a/kernel/global-clock/distsql/handler/src/test/resources/cases/show-global-clock-rule-current-config.yaml
b/kernel/global-clock/distsql/handler/src/test/resources/cases/show-global-clock-rule-current-config.yaml
new file mode 100644
index 00000000000..e48ead638d2
--- /dev/null
+++
b/kernel/global-clock/distsql/handler/src/test/resources/cases/show-global-clock-rule-current-config.yaml
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+
+rules:
+ - !GLOBAL_CLOCK
+ type: TSO
+ provider: local
+ enabled: false
+ props:
+ k: v
diff --git
a/kernel/global-clock/distsql/handler/src/test/resources/cases/show-global-clock-rule.xml
b/kernel/global-clock/distsql/handler/src/test/resources/cases/show-global-clock-rule.xml
new file mode 100644
index 00000000000..fa7f956453e
--- /dev/null
+++
b/kernel/global-clock/distsql/handler/src/test/resources/cases/show-global-clock-rule.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW GLOBAL CLOCK RULE"
current-rule-config-yaml-file="cases/show-global-clock-rule-current-config.yaml">
+ <expected-query-result-rows>
+
<expected-query-result-row>TSO|local|false|{"k":"v"}</expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/DefaultSQLFederationRuleConfigurationBuilder.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/DefaultSQLFederationRuleConfigurationBuilder.java
index 060efaeeb79..b306529f63a 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/DefaultSQLFederationRuleConfigurationBuilder.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/DefaultSQLFederationRuleConfigurationBuilder.java
@@ -23,7 +23,7 @@ import
org.apache.shardingsphere.sqlfederation.config.SQLFederationRuleConfigura
import org.apache.shardingsphere.sqlfederation.constant.SQLFederationOrder;
/**
- * Default sql federation rule configuration builder.
+ * Default SQL federation rule configuration builder.
*/
public final class DefaultSQLFederationRuleConfigurationBuilder implements
DefaultGlobalRuleConfigurationBuilder<SQLFederationRuleConfiguration,
SQLFederationRuleBuilder> {
diff --git
a/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
b/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
index 7faa78fb525..e746bb7fb1e 100644
---
a/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
+++
b/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
@@ -48,7 +48,7 @@ public final class ShowSQLFederationRuleExecutor implements
DistSQLQueryExecutor
SQLFederationRuleConfiguration ruleConfig = rule.getConfiguration();
boolean sqlFederationEnabled = ruleConfig.isSqlFederationEnabled();
boolean allQueryUseSQLFederation =
ruleConfig.isAllQueryUseSQLFederation();
- String executionPlanCache = null == ruleConfig.getExecutionPlanCache()
? "" : ruleConfig.getExecutionPlanCache().toString();
+ String executionPlanCache =
String.valueOf(ruleConfig.getExecutionPlanCache());
return Collections.singleton(new
LocalDataQueryResultRow(sqlFederationEnabled, allQueryUseSQLFederation,
executionPlanCache));
}
diff --git
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
index a3e7ce3702b..030435b9978 100644
---
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
+++
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
@@ -20,45 +20,25 @@ package
org.apache.shardingsphere.sqlfederation.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.sql.parser.api.CacheOption;
-import
org.apache.shardingsphere.sqlfederation.config.SQLFederationRuleConfiguration;
-import
org.apache.shardingsphere.sqlfederation.distsql.statement.queryable.ShowSQLFederationRuleStatement;
import org.apache.shardingsphere.sqlfederation.rule.SQLFederationRule;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class ShowSQLFederationRuleExecutorTest extends
DistSQLGlobalRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-sql-federation-rule.xml")
+class ShowSQLFederationRuleExecutorTest {
- ShowSQLFederationRuleExecutorTest() {
- super(mock(SQLFederationRule.class));
- }
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement, final
Collection<LocalDataQueryResultRow> expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ExtensionContext extensionContext) {
- return Stream.of(
- Arguments.arguments("withCacheOption", new
SQLFederationRuleConfiguration(false, false, new CacheOption(2000, 65535L)),
new ShowSQLFederationRuleStatement(),
- Collections.singleton(new
LocalDataQueryResultRow(false, false, "initialCapacity: 2000, maximumSize:
65535"))),
- Arguments.arguments("withoutCacheOption", new
SQLFederationRuleConfiguration(true, true, null), new
ShowSQLFederationRuleStatement(),
- Collections.singleton(new
LocalDataQueryResultRow(true, true, ""))));
- }
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final GlobalRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLGlobalRuleQueryExecutorAssert(mock(SQLFederationRule.class)).assertQueryResultRows(sqlStatement,
currentRuleConfig, expected);
}
}
diff --git
a/kernel/sql-federation/distsql/handler/src/test/resources/cases/show-sql-federation-rule-current-config.yaml
b/kernel/sql-federation/distsql/handler/src/test/resources/cases/show-sql-federation-rule-current-config.yaml
new file mode 100644
index 00000000000..befbbab43eb
--- /dev/null
+++
b/kernel/sql-federation/distsql/handler/src/test/resources/cases/show-sql-federation-rule-current-config.yaml
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+
+rules:
+ - !SQL_FEDERATION
+ sqlFederationEnabled: false
+ allQueryUseSQLFederation: false
+ executionPlanCache:
+ initialCapacity: 2000
+ maximumSize: 65535
diff --git
a/kernel/sql-federation/distsql/handler/src/test/resources/cases/show-sql-federation-rule.xml
b/kernel/sql-federation/distsql/handler/src/test/resources/cases/show-sql-federation-rule.xml
new file mode 100644
index 00000000000..17c1143944e
--- /dev/null
+++
b/kernel/sql-federation/distsql/handler/src/test/resources/cases/show-sql-federation-rule.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW SQL_FEDERATION RULE"
current-rule-config-yaml-file="cases/show-sql-federation-rule-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>false|false|initialCapacity: 2000,
maximumSize: 65535</expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>
diff --git
a/kernel/sql-parser/distsql/handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutor.java
b/kernel/sql-parser/distsql/handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutor.java
index 7d0159a8bd6..0aa5e0fa9f6 100644
---
a/kernel/sql-parser/distsql/handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutor.java
+++
b/kernel/sql-parser/distsql/handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutor.java
@@ -46,9 +46,7 @@ public final class ShowSQLParserRuleExecutor implements
DistSQLQueryExecutor<Sho
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShowSQLParserRuleStatement sqlStatement, final ContextManager contextManager) {
SQLParserRuleConfiguration ruleConfig = rule.getConfiguration();
- return Collections.singleton(new LocalDataQueryResultRow(
- null == ruleConfig.getParseTreeCache() ? "" :
ruleConfig.getParseTreeCache().toString(),
- null == ruleConfig.getSqlStatementCache() ? "" :
ruleConfig.getSqlStatementCache().toString()));
+ return Collections.singleton(new
LocalDataQueryResultRow(String.valueOf(ruleConfig.getParseTreeCache()),
String.valueOf(ruleConfig.getSqlStatementCache())));
}
@Override
diff --git
a/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutorTest.java
b/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutorTest.java
index 5ea78f6ed5c..5724f72e9b9 100644
---
a/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutorTest.java
+++
b/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutorTest.java
@@ -20,45 +20,25 @@ package
org.apache.shardingsphere.parser.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
-import
org.apache.shardingsphere.parser.distsql.statement.queryable.ShowSQLParserRuleStatement;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import org.apache.shardingsphere.sql.parser.api.CacheOption;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class ShowSQLParserRuleExecutorTest extends DistSQLGlobalRuleQueryExecutorTest
{
+@DistSQLRuleQueryExecutorSettings("cases/show-sql-parser-rule.xml")
+class ShowSQLParserRuleExecutorTest {
- ShowSQLParserRuleExecutorTest() {
- super(mock(SQLParserRule.class));
- }
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement, final
Collection<LocalDataQueryResultRow> expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ExtensionContext extensionContext) {
- return Stream.of(
- Arguments.arguments("withCacheOption", new
SQLParserRuleConfiguration(new CacheOption(128, 1024L), new CacheOption(2000,
65535L)), new ShowSQLParserRuleStatement(),
- Collections.singleton(new
LocalDataQueryResultRow("initialCapacity: 128, maximumSize: 1024",
"initialCapacity: 2000, maximumSize: 65535"))),
- Arguments.arguments("withoutCacheOption", new
SQLParserRuleConfiguration(null, null), new ShowSQLParserRuleStatement(),
- Collections.singleton(new
LocalDataQueryResultRow("", ""))));
- }
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final GlobalRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLGlobalRuleQueryExecutorAssert(mock(SQLParserRule.class)).assertQueryResultRows(sqlStatement,
currentRuleConfig, expected);
}
}
diff --git
a/kernel/sql-parser/distsql/handler/src/test/resources/cases/show-sql-parser-rule-current-config.yaml
b/kernel/sql-parser/distsql/handler/src/test/resources/cases/show-sql-parser-rule-current-config.yaml
new file mode 100644
index 00000000000..336df465d25
--- /dev/null
+++
b/kernel/sql-parser/distsql/handler/src/test/resources/cases/show-sql-parser-rule-current-config.yaml
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+rules:
+ - !SQL_PARSER
+ parseTreeCache:
+ initialCapacity: 128
+ maximumSize: 1024
+ sqlStatementCache:
+ initialCapacity: 2000
+ maximumSize: 65535
diff --git
a/kernel/sql-parser/distsql/handler/src/test/resources/cases/show-sql-parser-rule.xml
b/kernel/sql-parser/distsql/handler/src/test/resources/cases/show-sql-parser-rule.xml
new file mode 100644
index 00000000000..34ceb602c9b
--- /dev/null
+++
b/kernel/sql-parser/distsql/handler/src/test/resources/cases/show-sql-parser-rule.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW SQL_PARSER RULE"
current-rule-config-yaml-file="cases/show-sql-parser-rule-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>initialCapacity: 128, maximumSize:
1024|initialCapacity: 2000, maximumSize: 65535</expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>
diff --git
a/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/query/ShowSQLTranslatorRuleExecutorTest.java
b/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/query/ShowSQLTranslatorRuleExecutorTest.java
index 1c17ef7cd74..b0f30212f5e 100644
---
a/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/query/ShowSQLTranslatorRuleExecutorTest.java
+++
b/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/query/ShowSQLTranslatorRuleExecutorTest.java
@@ -20,42 +20,25 @@ package
org.apache.shardingsphere.sqltranslator.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import
org.apache.shardingsphere.sqltranslator.config.SQLTranslatorRuleConfiguration;
-import
org.apache.shardingsphere.sqltranslator.distsql.statement.queryable.ShowSQLTranslatorRuleStatement;
import org.apache.shardingsphere.sqltranslator.rule.SQLTranslatorRule;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.Collections;
-import java.util.Properties;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class ShowSQLTranslatorRuleExecutorTest extends
DistSQLGlobalRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-sql-translator-rule.xml")
+class ShowSQLTranslatorRuleExecutorTest {
- ShowSQLTranslatorRuleExecutorTest() {
- super(mock(SQLTranslatorRule.class));
- }
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement, final
Collection<LocalDataQueryResultRow> expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ExtensionContext extensionContext) {
- return Stream.of(Arguments.arguments("normal", new
SQLTranslatorRuleConfiguration("NATIVE", new Properties(), true), new
ShowSQLTranslatorRuleStatement(),
- Collections.singleton(new
LocalDataQueryResultRow("NATIVE", "", "true"))));
- }
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final GlobalRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLGlobalRuleQueryExecutorAssert(mock(SQLTranslatorRule.class)).assertQueryResultRows(sqlStatement,
currentRuleConfig, expected);
}
}
diff --git
a/kernel/sql-translator/distsql/handler/src/test/resources/cases/show-sql-translator-rule-current-config.yaml
b/kernel/sql-translator/distsql/handler/src/test/resources/cases/show-sql-translator-rule-current-config.yaml
new file mode 100644
index 00000000000..4473586aa4b
--- /dev/null
+++
b/kernel/sql-translator/distsql/handler/src/test/resources/cases/show-sql-translator-rule-current-config.yaml
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+
+rules:
+ - !SQL_TRANSLATOR
+ type: NATIVE
+ useOriginalSQLWhenTranslatingFailed: true
diff --git
a/kernel/sql-translator/distsql/handler/src/test/resources/cases/show-sql-translator-rule.xml
b/kernel/sql-translator/distsql/handler/src/test/resources/cases/show-sql-translator-rule.xml
new file mode 100644
index 00000000000..0fe0ac1739b
--- /dev/null
+++
b/kernel/sql-translator/distsql/handler/src/test/resources/cases/show-sql-translator-rule.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW SQL_TRANSLATOR RULE"
current-rule-config-yaml-file="cases/show-sql-translator-rule-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>NATIVE||true</expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>
diff --git
a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/ShowTransactionRuleExecutorTest.java
b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/ShowTransactionRuleExecutorTest.java
index 694fb7e4448..19d03eb812b 100644
---
a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/ShowTransactionRuleExecutorTest.java
+++
b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/ShowTransactionRuleExecutorTest.java
@@ -20,44 +20,25 @@ package
org.apache.shardingsphere.transaction.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorTest;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
-import
org.apache.shardingsphere.transaction.distsql.statement.queryable.ShowTransactionRuleStatement;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
-import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class ShowTransactionRuleExecutorTest extends
DistSQLGlobalRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-transaction-rule.xml")
+class ShowTransactionRuleExecutorTest {
- ShowTransactionRuleExecutorTest() {
- super(mock(TransactionRule.class));
- }
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement, final
Collection<LocalDataQueryResultRow> expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ExtensionContext extensionContext) {
- return Stream.of(
- Arguments.arguments("normal", new
TransactionRuleConfiguration("XA", "Atomikos", PropertiesBuilder.build(new
Property("k", "v"))), new ShowTransactionRuleStatement(),
- Collections.singleton(new
LocalDataQueryResultRow("XA", "Atomikos", "{\"k\":\"v\"}"))));
- }
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final GlobalRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLGlobalRuleQueryExecutorAssert(mock(TransactionRule.class)).assertQueryResultRows(sqlStatement,
currentRuleConfig, expected);
}
}
diff --git
a/kernel/transaction/distsql/handler/src/test/resources/cases/show-transaction-rule-current-config.yaml
b/kernel/transaction/distsql/handler/src/test/resources/cases/show-transaction-rule-current-config.yaml
new file mode 100644
index 00000000000..4b9e06794f0
--- /dev/null
+++
b/kernel/transaction/distsql/handler/src/test/resources/cases/show-transaction-rule-current-config.yaml
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+
+rules:
+ - !TRANSACTION
+ defaultType: XA
+ providerType: Atomikos
+ props:
+ k: v
diff --git
a/kernel/transaction/distsql/handler/src/test/resources/cases/show-transaction-rule.xml
b/kernel/transaction/distsql/handler/src/test/resources/cases/show-transaction-rule.xml
new file mode 100644
index 00000000000..14d97a75f86
--- /dev/null
+++
b/kernel/transaction/distsql/handler/src/test/resources/cases/show-transaction-rule.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW TRANSACTION RULE"
current-rule-config-yaml-file="cases/show-transaction-rule-current-config.yaml">
+ <expected-query-result-rows>
+
<expected-query-result-row>XA|Atomikos|{"k":"v"}</expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>
diff --git
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/PipelineE2EExtension.java
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/PipelineE2EExtension.java
index e1c8e800706..3071d2ec79d 100644
---
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/PipelineE2EExtension.java
+++
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/PipelineE2EExtension.java
@@ -31,7 +31,7 @@ import java.lang.reflect.Method;
public final class PipelineE2EExtension implements BeforeEachCallback,
TestWatcher {
@Override
- public void beforeEach(final ExtensionContext context) throws Exception {
+ public void beforeEach(final ExtensionContext context) {
log.info("Before case: {}.{}({})",
context.getTestClass().map(Class::getSimpleName).orElse(""),
context.getTestMethod().map(Method::getName).orElse(""),
context.getDisplayName());
}
diff --git
a/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLGlobalRuleQueryExecutorAssert.java
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLGlobalRuleQueryExecutorAssert.java
new file mode 100644
index 00000000000..0a3e35d9a9b
--- /dev/null
+++
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLGlobalRuleQueryExecutorAssert.java
@@ -0,0 +1,71 @@
+/*
+ * 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.test.it.distsql.handler.engine.query;
+
+import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.distsql.handler.engine.DistSQLConnectionContext;
+import
org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecuteEngine;
+import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
+import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import org.apache.shardingsphere.infra.rule.scope.GlobalRule;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import static
org.apache.shardingsphere.test.matcher.ShardingSphereAssertionMatchers.deepEqual;
+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;
+
+/**
+ * DistSQL global rule query executor assert.
+ */
+@RequiredArgsConstructor
+public final class DistSQLGlobalRuleQueryExecutorAssert {
+
+ private final GlobalRule mockedRule;
+
+ /**
+ * Assert query result rows.
+ *
+ * @param sqlStatement SQL statement
+ * @param currentRuleConfig current rule configuration
+ * @param expected expected query result rows
+ * @throws SQLException SQL exception
+ */
+ public void assertQueryResultRows(final DistSQLStatement sqlStatement,
+ final GlobalRuleConfiguration
currentRuleConfig, final Collection<LocalDataQueryResultRow> expected) throws
SQLException {
+ DistSQLQueryExecuteEngine engine = new
DistSQLQueryExecuteEngine(sqlStatement, null,
mockContextManager(currentRuleConfig), mock(DistSQLConnectionContext.class));
+ engine.executeQuery();
+ Collection<LocalDataQueryResultRow> actual = new
ArrayList<>(engine.getRows());
+ assertThat(actual, deepEqual(new ArrayList<>(expected)));
+ }
+
+ private ContextManager mockContextManager(final GlobalRuleConfiguration
ruleConfig) {
+ ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
+ when(mockedRule.getConfiguration()).thenReturn(ruleConfig);
+
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new
RuleMetaData(Collections.singleton(mockedRule)));
+ return result;
+ }
+}
diff --git
a/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLRuleQueryExecutorSettings.java
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLRuleQueryExecutorSettings.java
new file mode 100644
index 00000000000..4749ec30c36
--- /dev/null
+++
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLRuleQueryExecutorSettings.java
@@ -0,0 +1,37 @@
+/*
+ * 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.test.it.distsql.handler.engine.query;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * DistSQL rule query executor settings.
+ */
+@Inherited
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DistSQLRuleQueryExecutorSettings {
+
+ /**
+ * Get test case XML file path.
+ *
+ * @return test case XML file path
+ */
+ String value();
+}
diff --git
a/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLRuleQueryExecutorTestCaseArgumentsProvider.java
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLRuleQueryExecutorTestCaseArgumentsProvider.java
new file mode 100644
index 00000000000..a7589df9e22
--- /dev/null
+++
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLRuleQueryExecutorTestCaseArgumentsProvider.java
@@ -0,0 +1,78 @@
+/*
+ * 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.test.it.distsql.handler.engine.query;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
+import lombok.SneakyThrows;
+import
org.apache.shardingsphere.distsql.parser.core.featured.DistSQLParserEngine;
+import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
+import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
+import
org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.jaxb.DistSQLRuleQueryExecutorTestCase;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.jaxb.DistSQLRuleQueryExecutorTestCases;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * DistSQL rule query executor test case arguments provider.
+ */
+public final class DistSQLRuleQueryExecutorTestCaseArgumentsProvider
implements ArgumentsProvider {
+
+ @SneakyThrows(JAXBException.class)
+ @Override
+ public Stream<Arguments> provideArguments(final ExtensionContext
extensionContext) {
+ DistSQLRuleQueryExecutorSettings settings =
extensionContext.getRequiredTestClass().getAnnotation(DistSQLRuleQueryExecutorSettings.class);
+ Preconditions.checkNotNull(settings, "Annotation
DistSQLRuleQueryExecutorSettings is required.");
+ DistSQLRuleQueryExecutorTestCases testCases =
(DistSQLRuleQueryExecutorTestCases)
JAXBContext.newInstance(DistSQLRuleQueryExecutorTestCases.class)
+
.createUnmarshaller().unmarshal(Thread.currentThread().getContextClassLoader().getResource(settings.value()));
+ return testCases.getTestCases().stream().map(each ->
Arguments.arguments(
+ each.getDistSQL(), getDistSQLStatement(each),
getCurrentRuleConfiguration(each),
getExpectedQueryResultRows(each))).collect(Collectors.toList()).stream();
+ }
+
+ private DistSQLStatement getDistSQLStatement(final
DistSQLRuleQueryExecutorTestCase testCase) {
+ return (DistSQLStatement) new
DistSQLParserEngine().parse(testCase.getDistSQL());
+ }
+
+ @SneakyThrows(IOException.class)
+ private RuleConfiguration getCurrentRuleConfiguration(final
DistSQLRuleQueryExecutorTestCase testCase) {
+ URL url =
Thread.currentThread().getContextClassLoader().getResource(testCase.getCurrentRuleConfigurationYAMLFile());
+ assertNotNull(url);
+ YamlRootConfiguration yamlRootConfig = YamlEngine.unmarshal(new
File(url.getFile()), YamlRootConfiguration.class);
+ return new
YamlRuleConfigurationSwapperEngine().swapToRuleConfiguration(yamlRootConfig.getRules().iterator().next());
+ }
+
+ private Collection<LocalDataQueryResultRow>
getExpectedQueryResultRows(final DistSQLRuleQueryExecutorTestCase testCase) {
+ return testCase.getExpectedQueryResultRows().stream().map(each -> new
LocalDataQueryResultRow(Splitter.on('|').trimResults().splitToStream(each).toArray())).collect(Collectors.toList());
+ }
+}
diff --git
a/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/jaxb/DistSQLRuleQueryExecutorTestCase.java
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/jaxb/DistSQLRuleQueryExecutorTestCase.java
new file mode 100644
index 00000000000..3c01a1f9f4b
--- /dev/null
+++
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/jaxb/DistSQLRuleQueryExecutorTestCase.java
@@ -0,0 +1,46 @@
+/*
+ * 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.test.it.distsql.handler.engine.query.jaxb;
+
+import lombok.Getter;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * DistSQL rule query executor test case.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@Getter
+public final class DistSQLRuleQueryExecutorTestCase {
+
+ @XmlAttribute(name = "dist-sql")
+ private String distSQL;
+
+ @XmlAttribute(name = "current-rule-config-yaml-file")
+ private String currentRuleConfigurationYAMLFile;
+
+ @XmlElementWrapper(name = "expected-query-result-rows")
+ @XmlElement(name = "expected-query-result-row")
+ private final List<String> expectedQueryResultRows = new LinkedList<>();
+}
diff --git
a/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/jaxb/DistSQLRuleQueryExecutorTestCases.java
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/jaxb/DistSQLRuleQueryExecutorTestCases.java
new file mode 100644
index 00000000000..d2368fa0aba
--- /dev/null
+++
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/jaxb/DistSQLRuleQueryExecutorTestCases.java
@@ -0,0 +1,36 @@
+/*
+ * 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.test.it.distsql.handler.engine.query.jaxb;
+
+import lombok.Getter;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * DistSQL rule query executor test cases.
+ */
+@XmlRootElement(name = "distsql-rule-query-executor-test-cases")
+@Getter
+public final class DistSQLRuleQueryExecutorTestCases {
+
+ @XmlElement(name = "test-case")
+ private final List<DistSQLRuleQueryExecutorTestCase> testCases = new
LinkedList<>();
+}