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 7da9f0e9fed Use parameterized GlobalRuleDefinitionExecutorAssert to
instead of GlobalRuleDefinitionExecutorTest (#37144)
7da9f0e9fed is described below
commit 7da9f0e9fed7a5dc4e751bab8ddb9ca31eb55353
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Nov 19 23:22:05 2025 +0800
Use parameterized GlobalRuleDefinitionExecutorAssert to instead of
GlobalRuleDefinitionExecutorTest (#37144)
---
.../update/AlterGlobalClockRuleExecutorTest.java | 39 +++-----
.../alter-global-clock-rule-current-config.yaml | 23 +++++
.../alter-global-clock-rule-expected-config.yaml | 23 +++++
.../resources/cases/alter-global-clock-rule.xml | 23 +++++
.../update/AlterSQLFederationRuleExecutorTest.java | 45 ++-------
.../alter-sql-federation-rule-expected-config.yaml | 24 +++++
.../resources/cases/alter-sql-federation-rule.xml | 35 +++++++
.../update/AlterSQLParserRuleExecutorTest.java | 47 ++--------
.../alter-sql-parser-rule-expected-config.yaml | 25 +++++
.../test/resources/cases/alter-sql-parser-rule.xml | 29 ++++++
.../update/AlterSQLTranslatorRuleExecutorTest.java | 44 ++-------
.../alter-sql-translator-rule-current-config.yaml | 21 +++++
.../alter-sql-translator-rule-expected-config.yaml | 23 +++++
.../resources/cases/alter-sql-translator-rule.xml | 26 ++++++
.../update/AlterTransactionRuleExecutorTest.java | 51 ++---------
.../alter-transaction-rule-empty-current.yaml | 22 +++++
.../alter-transaction-rule-expected-config.yaml | 23 +++++
...ter-transaction-rule-local-expected-config.yaml | 22 +++++
.../alter-transaction-rule-normal-current.yaml | 22 +++++
.../resources/cases/alter-transaction-rule.xml | 35 +++++++
.../DistSQLGlobalRuleDefinitionExecutorAssert.java | 76 +++++++++++++++
.../DistSQLRuleDefinitionExecutorSettings.java | 37 ++++++++
...efinitionExecutorTestCaseArgumentsProvider.java | 102 +++++++++++++++++++++
.../DistSQLRuleDefinitionExecutorTestCase.java | 44 +++++++++
.../DistSQLRuleDefinitionExecutorTestCases.java | 36 ++++++++
25 files changed, 718 insertions(+), 179 deletions(-)
diff --git
a/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutorTest.java
b/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutorTest.java
index e931a171ef7..655c34b3883 100644
---
a/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutorTest.java
+++
b/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutorTest.java
@@ -18,45 +18,28 @@
package org.apache.shardingsphere.globalclock.distsql.handler.update;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import
org.apache.shardingsphere.globalclock.config.GlobalClockRuleConfiguration;
-import
org.apache.shardingsphere.globalclock.distsql.statement.updatable.AlterGlobalClockRuleStatement;
-import org.apache.shardingsphere.globalclock.rule.GlobalClockRule;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.GlobalRuleDefinitionExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import org.apache.shardingsphere.globalclock.rule.GlobalClockRule;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLGlobalRuleDefinitionExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLRuleDefinitionExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider;
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 org.junit.jupiter.params.support.ParameterDeclarations;
import java.sql.SQLException;
-import java.util.Properties;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class AlterGlobalClockRuleExecutorTest extends
GlobalRuleDefinitionExecutorTest {
+@DistSQLRuleDefinitionExecutorSettings("cases/alter-global-clock-rule.xml")
+class AlterGlobalClockRuleExecutorTest {
- AlterGlobalClockRuleExecutorTest() {
- super(mock(GlobalClockRule.class));
- }
+ private final DistSQLGlobalRuleDefinitionExecutorAssert executorAssert =
new DistSQLGlobalRuleDefinitionExecutorAssert(mock(GlobalClockRule.class));
@ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteUpdate(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement, final RuleConfiguration
matchedRuleConfig) throws SQLException {
- assertExecuteUpdate(ruleConfig, sqlStatement, matchedRuleConfig, null);
- }
-
- private static final class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ParameterDeclarations parameters, final ExtensionContext context) {
- return Stream.of(Arguments.arguments("normal",
- new GlobalClockRuleConfiguration("TSO", "local", false,
new Properties()),
- new AlterGlobalClockRuleStatement("TSO", "redis", true,
new Properties()),
- new GlobalClockRuleConfiguration("TSO", "redis", true, new
Properties())));
- }
+
@ArgumentsSource(DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteUpdate(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement,
+ final RuleConfiguration matchedRuleConfig, final
Class<? extends Exception> expectedException) throws SQLException {
+ executorAssert.assertExecuteUpdate(ruleConfig, sqlStatement,
matchedRuleConfig, expectedException);
}
}
diff --git
a/kernel/global-clock/distsql/handler/src/test/resources/cases/alter-global-clock-rule-current-config.yaml
b/kernel/global-clock/distsql/handler/src/test/resources/cases/alter-global-clock-rule-current-config.yaml
new file mode 100644
index 00000000000..9c77c75a33c
--- /dev/null
+++
b/kernel/global-clock/distsql/handler/src/test/resources/cases/alter-global-clock-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:
+ - !GLOBAL_CLOCK
+ type: TSO
+ provider: local
+ enabled: false
+ props: {}
diff --git
a/kernel/global-clock/distsql/handler/src/test/resources/cases/alter-global-clock-rule-expected-config.yaml
b/kernel/global-clock/distsql/handler/src/test/resources/cases/alter-global-clock-rule-expected-config.yaml
new file mode 100644
index 00000000000..7e8228e18d3
--- /dev/null
+++
b/kernel/global-clock/distsql/handler/src/test/resources/cases/alter-global-clock-rule-expected-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:
+ - !GLOBAL_CLOCK
+ type: TSO
+ provider: redis
+ enabled: true
+ props: {}
diff --git
a/kernel/global-clock/distsql/handler/src/test/resources/cases/alter-global-clock-rule.xml
b/kernel/global-clock/distsql/handler/src/test/resources/cases/alter-global-clock-rule.xml
new file mode 100644
index 00000000000..c7475794f76
--- /dev/null
+++
b/kernel/global-clock/distsql/handler/src/test/resources/cases/alter-global-clock-rule.xml
@@ -0,0 +1,23 @@
+<?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-definition-executor-test-cases>
+ <test-case dist-sql="ALTER GLOBAL CLOCK RULE (TYPE="TSO",
PROVIDER="redis", ENABLED=TRUE, PROPERTIES())"
+
current-rule-config-yaml-file="cases/alter-global-clock-rule-current-config.yaml"
+
expected-rule-config-yaml-file="cases/alter-global-clock-rule-expected-config.yaml"/>
+</distsql-rule-definition-executor-test-cases>
diff --git
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutorTest.java
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutorTest.java
index 8ac10e58488..7aa565aefb8 100644
---
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutorTest.java
+++
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutorTest.java
@@ -20,55 +20,26 @@ package
org.apache.shardingsphere.sqlfederation.distsql.handler.update;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
-import org.apache.shardingsphere.sqlfederation.config.SQLFederationCacheOption;
-import
org.apache.shardingsphere.sqlfederation.config.SQLFederationRuleConfiguration;
-import
org.apache.shardingsphere.sqlfederation.distsql.segment.CacheOptionSegment;
-import
org.apache.shardingsphere.sqlfederation.distsql.statement.updatable.AlterSQLFederationRuleStatement;
import org.apache.shardingsphere.sqlfederation.rule.SQLFederationRule;
-import
org.apache.shardingsphere.sqlfederation.rule.builder.DefaultSQLFederationRuleConfigurationBuilder;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.GlobalRuleDefinitionExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLGlobalRuleDefinitionExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLRuleDefinitionExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider;
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 org.junit.jupiter.params.support.ParameterDeclarations;
import java.sql.SQLException;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class AlterSQLFederationRuleExecutorTest extends
GlobalRuleDefinitionExecutorTest {
+@DistSQLRuleDefinitionExecutorSettings("cases/alter-sql-federation-rule.xml")
+class AlterSQLFederationRuleExecutorTest {
- AlterSQLFederationRuleExecutorTest() {
- super(mock(SQLFederationRule.class));
- }
+ private final DistSQLGlobalRuleDefinitionExecutorAssert executorAssert =
new DistSQLGlobalRuleDefinitionExecutorAssert(mock(SQLFederationRule.class));
@ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
+
@ArgumentsSource(DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider.class)
void assertExecuteUpdate(final String name, final GlobalRuleConfiguration
ruleConfig,
final DistSQLStatement sqlStatement, final
RuleConfiguration matchedRuleConfig, final Class<? extends Exception>
expectedException) throws SQLException {
- assertExecuteUpdate(ruleConfig, sqlStatement, matchedRuleConfig,
expectedException);
- }
-
- private static final class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ParameterDeclarations parameters, final ExtensionContext context) {
- return Stream.of(
- Arguments.arguments("normal",
- new
DefaultSQLFederationRuleConfigurationBuilder().build(),
- new AlterSQLFederationRuleStatement(true, true,
new CacheOptionSegment(64, 512L)),
- new SQLFederationRuleConfiguration(true, true, new
SQLFederationCacheOption(64, 512L)), null),
-
Arguments.arguments("withNotExistedDistributedTransactionType",
- new
DefaultSQLFederationRuleConfigurationBuilder().build(),
- new AlterSQLFederationRuleStatement(null, null,
null),
- new SQLFederationRuleConfiguration(false, false,
new SQLFederationCacheOption(2000, 65535L)), null),
- Arguments.arguments("withNotExistedXATransactionProvider",
- new
DefaultSQLFederationRuleConfigurationBuilder().build(),
- new AlterSQLFederationRuleStatement(null, null,
new CacheOptionSegment(null, null)),
- new SQLFederationRuleConfiguration(false, false,
new SQLFederationCacheOption(2000, 65535L)), null));
- }
+ executorAssert.assertExecuteUpdate(ruleConfig, sqlStatement,
matchedRuleConfig, expectedException);
}
}
diff --git
a/kernel/sql-federation/distsql/handler/src/test/resources/cases/alter-sql-federation-rule-expected-config.yaml
b/kernel/sql-federation/distsql/handler/src/test/resources/cases/alter-sql-federation-rule-expected-config.yaml
new file mode 100644
index 00000000000..46b233e59b3
--- /dev/null
+++
b/kernel/sql-federation/distsql/handler/src/test/resources/cases/alter-sql-federation-rule-expected-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: true
+ allQueryUseSQLFederation: true
+ executionPlanCache:
+ initialCapacity: 64
+ maximumSize: 512
diff --git
a/kernel/sql-federation/distsql/handler/src/test/resources/cases/alter-sql-federation-rule.xml
b/kernel/sql-federation/distsql/handler/src/test/resources/cases/alter-sql-federation-rule.xml
new file mode 100644
index 00000000000..e3418301d6d
--- /dev/null
+++
b/kernel/sql-federation/distsql/handler/src/test/resources/cases/alter-sql-federation-rule.xml
@@ -0,0 +1,35 @@
+<?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-definition-executor-test-cases>
+ <test-case dist-sql="ALTER SQL_FEDERATION RULE
(SQL_FEDERATION_ENABLED=TRUE, ALL_QUERY_USE_SQL_FEDERATION=TRUE,
EXECUTION_PLAN_CACHE(INITIAL_CAPACITY=64, MAXIMUM_SIZE=512))"
+
current-rule-config-yaml-file="cases/show-sql-federation-rule-current-config.yaml"
+
expected-rule-config-yaml-file="cases/alter-sql-federation-rule-expected-config.yaml"/>
+ <test-case dist-sql="ALTER SQL_FEDERATION RULE ()"
+
current-rule-config-yaml-file="cases/show-sql-federation-rule-current-config.yaml"
+
expected-rule-config-yaml-file="cases/show-sql-federation-rule-current-config.yaml"/>
+ <test-case dist-sql="ALTER SQL_FEDERATION RULE (EXECUTION_PLAN_CACHE())"
+
current-rule-config-yaml-file="cases/show-sql-federation-rule-current-config.yaml"
+
expected-rule-config-yaml-file="cases/show-sql-federation-rule-current-config.yaml"/>
+ <test-case dist-sql="ALTER SQL_FEDERATION RULE
(EXECUTION_PLAN_CACHE(INITIAL_CAPACITY=0, MAXIMUM_SIZE=512))"
+
current-rule-config-yaml-file="cases/show-sql-federation-rule-current-config.yaml"
+
expected-exception="org.apache.shardingsphere.sqlfederation.compiler.exception.InvalidExecutionPlanCacheConfigException"/>
+ <test-case dist-sql="ALTER SQL_FEDERATION RULE
(EXECUTION_PLAN_CACHE(INITIAL_CAPACITY=64, MAXIMUM_SIZE=0))"
+
current-rule-config-yaml-file="cases/show-sql-federation-rule-current-config.yaml"
+
expected-exception="org.apache.shardingsphere.sqlfederation.compiler.exception.InvalidExecutionPlanCacheConfigException"/>
+</distsql-rule-definition-executor-test-cases>
diff --git
a/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
b/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
index 02e719c82ba..ffcfbb31824 100644
---
a/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
+++
b/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
@@ -20,53 +20,26 @@ package
org.apache.shardingsphere.parser.distsql.handler.update;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
-import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
-import org.apache.shardingsphere.parser.distsql.segment.CacheOptionSegment;
-import
org.apache.shardingsphere.parser.distsql.statement.updatable.AlterSQLParserRuleStatement;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import
org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
-import org.apache.shardingsphere.sql.parser.engine.api.CacheOption;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.GlobalRuleDefinitionExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLGlobalRuleDefinitionExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLRuleDefinitionExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider;
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 org.junit.jupiter.params.support.ParameterDeclarations;
import java.sql.SQLException;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class AlterSQLParserRuleExecutorTest extends GlobalRuleDefinitionExecutorTest {
+@DistSQLRuleDefinitionExecutorSettings("cases/alter-sql-parser-rule.xml")
+class AlterSQLParserRuleExecutorTest {
- AlterSQLParserRuleExecutorTest() {
- super(mock(SQLParserRule.class));
- }
+ private final DistSQLGlobalRuleDefinitionExecutorAssert executorAssert =
new DistSQLGlobalRuleDefinitionExecutorAssert(mock(SQLParserRule.class));
@ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteUpdate(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement, final RuleConfiguration
matchedRuleConfig) throws SQLException {
- assertExecuteUpdate(ruleConfig, sqlStatement, matchedRuleConfig, null);
- }
-
- private static final class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ParameterDeclarations parameters, final ExtensionContext context) {
- return Stream.of(Arguments.arguments("normal",
- new DefaultSQLParserRuleConfigurationBuilder().build(),
- new AlterSQLParserRuleStatement(new CacheOptionSegment(64,
512L), new CacheOptionSegment(1000, 1000L)),
- new SQLParserRuleConfiguration(new CacheOption(64, 512L),
new CacheOption(1000, 1000L))),
- Arguments.arguments("withNullStatement",
- new
DefaultSQLParserRuleConfigurationBuilder().build(),
- new AlterSQLParserRuleStatement(null, null),
- new SQLParserRuleConfiguration(new
CacheOption(128, 1024L), new CacheOption(2000, 65535L))),
- Arguments.arguments("wthNullCacheOptionSegment",
- new
DefaultSQLParserRuleConfigurationBuilder().build(),
- new AlterSQLParserRuleStatement(new
CacheOptionSegment(null, null), new CacheOptionSegment(null, null)),
- new SQLParserRuleConfiguration(new
CacheOption(128, 1024L), new CacheOption(2000, 65535L))));
- }
+
@ArgumentsSource(DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteUpdate(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement,
+ final RuleConfiguration matchedRuleConfig, final
Class<? extends Exception> expectedException) throws SQLException {
+ executorAssert.assertExecuteUpdate(ruleConfig, sqlStatement,
matchedRuleConfig, expectedException);
}
}
diff --git
a/kernel/sql-parser/distsql/handler/src/test/resources/cases/alter-sql-parser-rule-expected-config.yaml
b/kernel/sql-parser/distsql/handler/src/test/resources/cases/alter-sql-parser-rule-expected-config.yaml
new file mode 100644
index 00000000000..f9209044452
--- /dev/null
+++
b/kernel/sql-parser/distsql/handler/src/test/resources/cases/alter-sql-parser-rule-expected-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: 64
+ maximumSize: 512
+ sqlStatementCache:
+ initialCapacity: 1000
+ maximumSize: 1000
diff --git
a/kernel/sql-parser/distsql/handler/src/test/resources/cases/alter-sql-parser-rule.xml
b/kernel/sql-parser/distsql/handler/src/test/resources/cases/alter-sql-parser-rule.xml
new file mode 100644
index 00000000000..4d6059592bd
--- /dev/null
+++
b/kernel/sql-parser/distsql/handler/src/test/resources/cases/alter-sql-parser-rule.xml
@@ -0,0 +1,29 @@
+<?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-definition-executor-test-cases>
+ <test-case dist-sql="ALTER SQL_PARSER RULE
(PARSE_TREE_CACHE(INITIAL_CAPACITY=64, MAXIMUM_SIZE=512),
SQL_STATEMENT_CACHE(INITIAL_CAPACITY=1000, MAXIMUM_SIZE=1000))"
+
current-rule-config-yaml-file="cases/show-sql-parser-rule-current-config.yaml"
+
expected-rule-config-yaml-file="cases/alter-sql-parser-rule-expected-config.yaml"/>
+ <test-case dist-sql="ALTER SQL_PARSER RULE ()"
+
current-rule-config-yaml-file="cases/show-sql-parser-rule-current-config.yaml"
+
expected-rule-config-yaml-file="cases/show-sql-parser-rule-current-config.yaml"/>
+ <test-case dist-sql="ALTER SQL_PARSER RULE (PARSE_TREE_CACHE(),
SQL_STATEMENT_CACHE())"
+
current-rule-config-yaml-file="cases/show-sql-parser-rule-current-config.yaml"
+
expected-rule-config-yaml-file="cases/show-sql-parser-rule-current-config.yaml"/>
+</distsql-rule-definition-executor-test-cases>
diff --git
a/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java
b/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java
index 34860a1bb51..d83b6f20f32 100644
---
a/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java
+++
b/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java
@@ -17,53 +17,29 @@
package org.apache.shardingsphere.sqltranslator.distsql.handler.update;
-import org.apache.shardingsphere.distsql.segment.AlgorithmSegment;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
-import
org.apache.shardingsphere.sqltranslator.config.SQLTranslatorRuleConfiguration;
-import
org.apache.shardingsphere.sqltranslator.distsql.statement.updateable.AlterSQLTranslatorRuleStatement;
import org.apache.shardingsphere.sqltranslator.rule.SQLTranslatorRule;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.GlobalRuleDefinitionExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLGlobalRuleDefinitionExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLRuleDefinitionExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider;
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 org.junit.jupiter.params.support.ParameterDeclarations;
import java.sql.SQLException;
-import java.util.Properties;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class AlterSQLTranslatorRuleExecutorTest extends
GlobalRuleDefinitionExecutorTest {
+@DistSQLRuleDefinitionExecutorSettings("cases/alter-sql-translator-rule.xml")
+class AlterSQLTranslatorRuleExecutorTest {
- AlterSQLTranslatorRuleExecutorTest() {
- super(mock(SQLTranslatorRule.class));
- }
+ private final DistSQLGlobalRuleDefinitionExecutorAssert executorAssert =
new DistSQLGlobalRuleDefinitionExecutorAssert(mock(SQLTranslatorRule.class));
@ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteUpdate(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement, final RuleConfiguration
matchedRuleConfig) throws SQLException {
- assertExecuteUpdate(ruleConfig, sqlStatement, matchedRuleConfig, null);
- }
-
- private static final class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ParameterDeclarations parameters, final ExtensionContext context) {
- return
Stream.of(Arguments.arguments("withTrueOriginalSQLWhenTranslatingFailed",
- new SQLTranslatorRuleConfiguration("DISTSQL:FIXTURE", new
Properties(), true),
- new AlterSQLTranslatorRuleStatement(new
AlgorithmSegment("DISTSQL:FIXTURE", PropertiesBuilder.build(new Property("foo",
"bar"))), true),
- new SQLTranslatorRuleConfiguration("DISTSQL:FIXTURE",
PropertiesBuilder.build(new Property("foo", "bar")), true)),
-
Arguments.arguments("withNullOriginalSQLWhenTranslatingFailed",
- new
SQLTranslatorRuleConfiguration("DISTSQL:FIXTURE", new Properties(), true),
- new AlterSQLTranslatorRuleStatement(new
AlgorithmSegment("DISTSQL:FIXTURE", PropertiesBuilder.build(new Property("foo",
"bar"))), null),
- new
SQLTranslatorRuleConfiguration("DISTSQL:FIXTURE", PropertiesBuilder.build(new
Property("foo", "bar")), true)));
- }
+
@ArgumentsSource(DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteUpdate(final String name, final GlobalRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement,
+ final RuleConfiguration matchedRuleConfig, final
Class<? extends Exception> expectedException) throws SQLException {
+ executorAssert.assertExecuteUpdate(ruleConfig, sqlStatement,
matchedRuleConfig, expectedException);
}
}
diff --git
a/kernel/sql-translator/distsql/handler/src/test/resources/cases/alter-sql-translator-rule-current-config.yaml
b/kernel/sql-translator/distsql/handler/src/test/resources/cases/alter-sql-translator-rule-current-config.yaml
new file mode 100644
index 00000000000..644f0528eec
--- /dev/null
+++
b/kernel/sql-translator/distsql/handler/src/test/resources/cases/alter-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: DISTSQL:FIXTURE
+ useOriginalSQLWhenTranslatingFailed: true
diff --git
a/kernel/sql-translator/distsql/handler/src/test/resources/cases/alter-sql-translator-rule-expected-config.yaml
b/kernel/sql-translator/distsql/handler/src/test/resources/cases/alter-sql-translator-rule-expected-config.yaml
new file mode 100644
index 00000000000..92e87875bff
--- /dev/null
+++
b/kernel/sql-translator/distsql/handler/src/test/resources/cases/alter-sql-translator-rule-expected-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:
+ - !SQL_TRANSLATOR
+ type: DISTSQL:FIXTURE
+ useOriginalSQLWhenTranslatingFailed: true
+ props:
+ foo: bar
diff --git
a/kernel/sql-translator/distsql/handler/src/test/resources/cases/alter-sql-translator-rule.xml
b/kernel/sql-translator/distsql/handler/src/test/resources/cases/alter-sql-translator-rule.xml
new file mode 100644
index 00000000000..48fdd5bdb3d
--- /dev/null
+++
b/kernel/sql-translator/distsql/handler/src/test/resources/cases/alter-sql-translator-rule.xml
@@ -0,0 +1,26 @@
+<?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-definition-executor-test-cases>
+ <test-case dist-sql="ALTER SQL_TRANSLATOR RULE
(TYPE(NAME="DISTSQL:FIXTURE",
PROPERTIES("foo"="bar")),
USE_ORIGINAL_SQL_WHEN_TRANSLATING_FAILED=TRUE)"
+
current-rule-config-yaml-file="cases/alter-sql-translator-rule-current-config.yaml"
+
expected-rule-config-yaml-file="cases/alter-sql-translator-rule-expected-config.yaml"/>
+ <test-case dist-sql="ALTER SQL_TRANSLATOR RULE
(TYPE(NAME="DISTSQL:FIXTURE",
PROPERTIES("foo"="bar")))"
+
current-rule-config-yaml-file="cases/alter-sql-translator-rule-current-config.yaml"
+
expected-rule-config-yaml-file="cases/alter-sql-translator-rule-expected-config.yaml"/>
+</distsql-rule-definition-executor-test-cases>
diff --git
a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleExecutorTest.java
b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleExecutorTest.java
index 30db5ca585e..9c5827aa0ee 100644
---
a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleExecutorTest.java
+++
b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleExecutorTest.java
@@ -20,61 +20,26 @@ package
org.apache.shardingsphere.transaction.distsql.handler.update;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
-import
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.InvalidRuleConfigurationException;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.GlobalRuleDefinitionExecutorTest;
-import
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
-import
org.apache.shardingsphere.transaction.distsql.segment.TransactionProviderSegment;
-import
org.apache.shardingsphere.transaction.distsql.statement.updatable.AlterTransactionRuleStatement;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLGlobalRuleDefinitionExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLRuleDefinitionExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider;
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 org.junit.jupiter.params.support.ParameterDeclarations;
import java.sql.SQLException;
-import java.util.Properties;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class AlterTransactionRuleExecutorTest extends
GlobalRuleDefinitionExecutorTest {
+@DistSQLRuleDefinitionExecutorSettings("cases/alter-transaction-rule.xml")
+class AlterTransactionRuleExecutorTest {
- AlterTransactionRuleExecutorTest() {
- super(mock(TransactionRule.class));
- }
+ private final DistSQLGlobalRuleDefinitionExecutorAssert executorAssert =
new DistSQLGlobalRuleDefinitionExecutorAssert(mock(TransactionRule.class));
@ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
+
@ArgumentsSource(DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider.class)
void assertExecuteUpdate(final String name, final GlobalRuleConfiguration
ruleConfig,
final DistSQLStatement sqlStatement, final
RuleConfiguration matchedRuleConfig, final Class<? extends Exception>
expectedException) throws SQLException {
- assertExecuteUpdate(ruleConfig, sqlStatement, matchedRuleConfig,
expectedException);
- }
-
- private static final class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ParameterDeclarations parameters, final ExtensionContext context) {
- return Stream.of(
- Arguments.arguments("withInvalidTransactionType",
- new TransactionRuleConfiguration("", "", new
Properties()),
- new AlterTransactionRuleStatement("Invalid", new
TransactionProviderSegment("", new Properties())),
- null, InvalidRuleConfigurationException.class),
-
Arguments.arguments("withNotExistedDistributedTransactionType",
- new TransactionRuleConfiguration("", "", new
Properties()),
- new AlterTransactionRuleStatement("BASE", new
TransactionProviderSegment("", new Properties())),
- null, InvalidRuleConfigurationException.class),
- Arguments.arguments("withNotExistedXATransactionProvider",
- new TransactionRuleConfiguration("", "", new
Properties()),
- new AlterTransactionRuleStatement("XA", new
TransactionProviderSegment("Invalid", new Properties())),
- null, InvalidRuleConfigurationException.class),
- Arguments.arguments("normal",
- new TransactionRuleConfiguration("XA", "Atomikos",
new Properties()),
- new AlterTransactionRuleStatement("XA", new
TransactionProviderSegment("Atomikos", PropertiesBuilder.build(new
Property("k", "v")))),
- new TransactionRuleConfiguration("XA", "Atomikos",
PropertiesBuilder.build(new Property("k", "v"))), null));
- }
+ executorAssert.assertExecuteUpdate(ruleConfig, sqlStatement,
matchedRuleConfig, expectedException);
}
}
diff --git
a/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule-empty-current.yaml
b/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule-empty-current.yaml
new file mode 100644
index 00000000000..583856e1130
--- /dev/null
+++
b/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule-empty-current.yaml
@@ -0,0 +1,22 @@
+#
+# 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: ''
+ providerType: ''
+ props: {}
diff --git
a/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule-expected-config.yaml
b/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule-expected-config.yaml
new file mode 100644
index 00000000000..4b9e06794f0
--- /dev/null
+++
b/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule-expected-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/alter-transaction-rule-local-expected-config.yaml
b/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule-local-expected-config.yaml
new file mode 100644
index 00000000000..a64fb77a815
--- /dev/null
+++
b/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule-local-expected-config.yaml
@@ -0,0 +1,22 @@
+#
+# 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: LOCAL
+ providerType: Atomikos
+ props: {}
diff --git
a/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule-normal-current.yaml
b/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule-normal-current.yaml
new file mode 100644
index 00000000000..8c8a71a4118
--- /dev/null
+++
b/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule-normal-current.yaml
@@ -0,0 +1,22 @@
+#
+# 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: {}
diff --git
a/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule.xml
b/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule.xml
new file mode 100644
index 00000000000..58ca7dd7247
--- /dev/null
+++
b/kernel/transaction/distsql/handler/src/test/resources/cases/alter-transaction-rule.xml
@@ -0,0 +1,35 @@
+<?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-definition-executor-test-cases>
+ <test-case dist-sql="ALTER TRANSACTION RULE (DEFAULT="Invalid",
TYPE(NAME="", PROPERTIES()))"
+
current-rule-config-yaml-file="cases/alter-transaction-rule-empty-current.yaml"
+
expected-exception="org.apache.shardingsphere.infra.exception.kernel.metadata.rule.InvalidRuleConfigurationException"/>
+ <test-case dist-sql="ALTER TRANSACTION RULE (DEFAULT="BASE",
TYPE(NAME="", PROPERTIES()))"
+
current-rule-config-yaml-file="cases/alter-transaction-rule-empty-current.yaml"
+
expected-exception="org.apache.shardingsphere.infra.exception.kernel.metadata.rule.InvalidRuleConfigurationException"/>
+ <test-case dist-sql="ALTER TRANSACTION RULE (DEFAULT="XA",
TYPE(NAME="Invalid", PROPERTIES()))"
+
current-rule-config-yaml-file="cases/alter-transaction-rule-empty-current.yaml"
+
expected-exception="org.apache.shardingsphere.infra.exception.kernel.metadata.rule.InvalidRuleConfigurationException"/>
+ <test-case dist-sql="ALTER TRANSACTION RULE (DEFAULT="XA",
TYPE(NAME="Atomikos", PROPERTIES("k"="v")))"
+
current-rule-config-yaml-file="cases/alter-transaction-rule-normal-current.yaml"
+
expected-rule-config-yaml-file="cases/alter-transaction-rule-expected-config.yaml"/>
+ <test-case dist-sql="ALTER TRANSACTION RULE (DEFAULT="LOCAL",
TYPE(NAME="Atomikos", PROPERTIES()))"
+
current-rule-config-yaml-file="cases/alter-transaction-rule-empty-current.yaml"
+
expected-rule-config-yaml-file="cases/alter-transaction-rule-local-expected-config.yaml"/>
+</distsql-rule-definition-executor-test-cases>
diff --git
a/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/DistSQLGlobalRuleDefinitionExecutorAssert.java
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/DistSQLGlobalRuleDefinitionExecutorAssert.java
new file mode 100644
index 00000000000..cfe5c729b8a
--- /dev/null
+++
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/DistSQLGlobalRuleDefinitionExecutorAssert.java
@@ -0,0 +1,76 @@
+/*
+ * 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.update;
+
+import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecuteEngine;
+import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import
org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
+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
org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService;
+
+import java.sql.SQLException;
+import java.util.Collections;
+
+import static
org.apache.shardingsphere.test.infra.framework.matcher.ShardingSphereArgumentVerifyMatchers.deepEq;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * DistSQL global rule definition executor assert.
+ */
+@RequiredArgsConstructor
+public final class DistSQLGlobalRuleDefinitionExecutorAssert {
+
+ private final GlobalRule mockedRule;
+
+ /**
+ * Assert execute update.
+ *
+ * @param ruleConfig global rule configuration
+ * @param sqlStatement SQL statement
+ * @param matchedRuleConfig persisted rule configuration
+ * @param expectedException expected exception
+ * @throws SQLException SQL exception
+ */
+ public void assertExecuteUpdate(final GlobalRuleConfiguration ruleConfig,
+ final DistSQLStatement sqlStatement, final
RuleConfiguration matchedRuleConfig, final Class<? extends Exception>
expectedException) throws SQLException {
+ ContextManager contextManager = mockContextManager(ruleConfig);
+ DistSQLUpdateExecuteEngine engine = new
DistSQLUpdateExecuteEngine(sqlStatement, null, contextManager);
+ if (null != expectedException) {
+ assertThrows(expectedException, engine::executeUpdate);
+ return;
+ }
+ engine.executeUpdate();
+ MetaDataManagerPersistService metaDataManagerPersistService =
contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService();
+
verify(metaDataManagerPersistService).alterGlobalRuleConfiguration(deepEq(matchedRuleConfig));
+ }
+
+ 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/update/DistSQLRuleDefinitionExecutorSettings.java
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/DistSQLRuleDefinitionExecutorSettings.java
new file mode 100644
index 00000000000..242e01286ec
--- /dev/null
+++
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/DistSQLRuleDefinitionExecutorSettings.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.update;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * DistSQL rule definition executor settings.
+ */
+@Inherited
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DistSQLRuleDefinitionExecutorSettings {
+
+ /**
+ * 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/update/DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider.java
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider.java
new file mode 100644
index 00000000000..3e6afd17919
--- /dev/null
+++
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider.java
@@ -0,0 +1,102 @@
+/*
+ * 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.update;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+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.config.rule.scope.GlobalRuleConfiguration;
+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.update.jaxb.DistSQLRuleDefinitionExecutorTestCase;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.update.jaxb.DistSQLRuleDefinitionExecutorTestCases;
+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.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * DistSQL rule definition executor test case arguments provider.
+ */
+public final class DistSQLRuleDefinitionExecutorTestCaseArgumentsProvider
implements ArgumentsProvider {
+
+ @SneakyThrows(JAXBException.class)
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext
extensionContext) {
+ DistSQLRuleDefinitionExecutorSettings settings =
extensionContext.getRequiredTestClass().getAnnotation(DistSQLRuleDefinitionExecutorSettings.class);
+ Preconditions.checkNotNull(settings, "Annotation
DistSQLRuleDefinitionExecutorSettings is required.");
+ DistSQLRuleDefinitionExecutorTestCases testCases =
(DistSQLRuleDefinitionExecutorTestCases)
JAXBContext.newInstance(DistSQLRuleDefinitionExecutorTestCases.class)
+
.createUnmarshaller().unmarshal(Thread.currentThread().getContextClassLoader().getResource(settings.value()));
+ return testCases.getTestCases().stream().map(each ->
Arguments.arguments(each.getDistSQL(), getCurrentRuleConfiguration(each),
+ getDistSQLStatement(each), getExpectedRuleConfiguration(each),
getExpectedException(each))).collect(Collectors.toList()).stream();
+ }
+
+ private DistSQLStatement getDistSQLStatement(final
DistSQLRuleDefinitionExecutorTestCase testCase) {
+ return (DistSQLStatement) new
DistSQLParserEngine().parse(testCase.getDistSQL());
+ }
+
+ private GlobalRuleConfiguration getCurrentRuleConfiguration(final
DistSQLRuleDefinitionExecutorTestCase testCase) {
+ RuleConfiguration result =
swapRuleConfiguration(testCase.getCurrentRuleConfigurationYAMLFile());
+ Preconditions.checkState(result instanceof GlobalRuleConfiguration,
"Current rule configuration is not a global rule configuration.");
+ return (GlobalRuleConfiguration) result;
+ }
+
+ private RuleConfiguration getExpectedRuleConfiguration(final
DistSQLRuleDefinitionExecutorTestCase testCase) {
+ if
(Strings.isNullOrEmpty(testCase.getExpectedRuleConfigurationYAMLFile())) {
+ return null;
+ }
+ return
swapRuleConfiguration(testCase.getExpectedRuleConfigurationYAMLFile());
+ }
+
+ @SneakyThrows(ReflectiveOperationException.class)
+ @SuppressWarnings("unchecked")
+ private Class<? extends Exception> getExpectedException(final
DistSQLRuleDefinitionExecutorTestCase testCase) {
+ if (Strings.isNullOrEmpty(testCase.getExpectedException())) {
+ return null;
+ }
+ Class<?> result = Class.forName(testCase.getExpectedException());
+ Preconditions.checkState(Exception.class.isAssignableFrom(result),
"Expected exception must be an exception type.");
+ return (Class<? extends Exception>) result;
+ }
+
+ @SneakyThrows(IOException.class)
+ private RuleConfiguration swapRuleConfiguration(final String yamlFile) {
+ YamlRootConfiguration yamlRootConfig =
YamlEngine.unmarshal(getYAMLFile(yamlFile), YamlRootConfiguration.class);
+ Preconditions.checkState(!yamlRootConfig.getRules().isEmpty(), "Rule
configuration YAML file `%s` is empty.", yamlFile);
+ return new
YamlRuleConfigurationSwapperEngine().swapToRuleConfiguration(yamlRootConfig.getRules().iterator().next());
+ }
+
+ private File getYAMLFile(final String yamlFile) {
+ URL url =
Thread.currentThread().getContextClassLoader().getResource(yamlFile);
+ assertNotNull(url);
+ return new File(url.getFile());
+ }
+}
diff --git
a/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/jaxb/DistSQLRuleDefinitionExecutorTestCase.java
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/jaxb/DistSQLRuleDefinitionExecutorTestCase.java
new file mode 100644
index 00000000000..b62b8524769
--- /dev/null
+++
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/jaxb/DistSQLRuleDefinitionExecutorTestCase.java
@@ -0,0 +1,44 @@
+/*
+ * 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.update.jaxb;
+
+import lombok.Getter;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+
+/**
+ * DistSQL rule definition executor test case.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@Getter
+public final class DistSQLRuleDefinitionExecutorTestCase {
+
+ @XmlAttribute(name = "dist-sql")
+ private String distSQL;
+
+ @XmlAttribute(name = "current-rule-config-yaml-file")
+ private String currentRuleConfigurationYAMLFile;
+
+ @XmlAttribute(name = "expected-rule-config-yaml-file")
+ private String expectedRuleConfigurationYAMLFile;
+
+ @XmlAttribute(name = "expected-exception")
+ private String expectedException;
+}
diff --git
a/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/jaxb/DistSQLRuleDefinitionExecutorTestCases.java
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/jaxb/DistSQLRuleDefinitionExecutorTestCases.java
new file mode 100644
index 00000000000..517aabffbe7
--- /dev/null
+++
b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/update/jaxb/DistSQLRuleDefinitionExecutorTestCases.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.update.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 definition executor test cases.
+ */
+@XmlRootElement(name = "distsql-rule-definition-executor-test-cases")
+@Getter
+public final class DistSQLRuleDefinitionExecutorTestCases {
+
+ @XmlElement(name = "test-case")
+ private final List<DistSQLRuleDefinitionExecutorTestCase> testCases = new
LinkedList<>();
+}