You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2025/02/20 09:45:42 UTC
(shardingsphere) branch master updated: Use DistSQLDatabaseRuleQueryExecutorAssert in ShowShardingAuditorsExecutorTest (#34718)
This is an automated email from the ASF dual-hosted git repository.
yx9o pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new b0d580cda9c Use DistSQLDatabaseRuleQueryExecutorAssert in ShowShardingAuditorsExecutorTest (#34718)
b0d580cda9c is described below
commit b0d580cda9c6c275ace9ae72803e828c21aab784
Author: ilyas ahsan <me...@gmail.com>
AuthorDate: Thu Feb 20 16:45:35 2025 +0700
Use DistSQLDatabaseRuleQueryExecutorAssert in ShowShardingAuditorsExecutorTest (#34718)
---
.../query/ShowShardingAuditorsExecutorTest.java | 46 +++++-----------------
.../show-sharding-auditors-current-config.yaml | 38 ++++++++++++++++++
.../resources/cases/show-sharding-auditors.xml | 27 +++++++++++++
3 files changed, 75 insertions(+), 36 deletions(-)
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAuditorsExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAuditorsExecutorTest.java
index 3614ce97828..47d4f3e3bca 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAuditorsExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingAuditorsExecutorTest.java
@@ -18,53 +18,27 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingAuditorsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
-import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorTest;
-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.DistSQLDatabaseRuleQueryExecutorAssert;
+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 ShowShardingAuditorsExecutorTest extends DistSQLDatabaseRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-sharding-auditors.xml")
+class ShowShardingAuditorsExecutorTest {
- ShowShardingAuditorsExecutorTest() {
- super(mock(ShardingRule.class));
- }
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final DatabaseRuleConfiguration 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 ShowShardingAuditorsStatement(null),
- Collections.singleton(new LocalDataQueryResultRow("sharding_key_required_auditor", "DML_SHARDING_CONDITIONS", "{\"key\":\"value\"}"))));
- }
-
- private ShardingRuleConfiguration createRuleConfiguration() {
- ShardingRuleConfiguration result = new ShardingRuleConfiguration();
- result.getAuditors().put("sharding_key_required_auditor", new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", PropertiesBuilder.build(new Property("key", "value"))));
- return result;
- }
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL, final DistSQLStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig, final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new DistSQLDatabaseRuleQueryExecutorAssert(mock(ShardingRule.class)).assertQueryResultRows(currentRuleConfig, sqlStatement, expected);
}
}
diff --git a/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-auditors-current-config.yaml b/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-auditors-current-config.yaml
new file mode 100644
index 00000000000..4166b4eb87b
--- /dev/null
+++ b/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-auditors-current-config.yaml
@@ -0,0 +1,38 @@
+#
+# 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:
+ - !SHARDING
+ tables:
+ t_order:
+ actualDataNodes: ds_${0..1}.t_order_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_inline
+ auditStrategy:
+ auditorNames:
+ - sharding_key_required_auditor
+ allowHintDisable: true
+ defaultAuditStrategy:
+ auditorNames:
+ - sharding_key_required_auditor
+ allowHintDisable: true
+
+ auditors:
+ sharding_key_required_auditor:
+ type: DML_SHARDING_CONDITIONS
diff --git a/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-auditors.xml b/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-auditors.xml
new file mode 100644
index 00000000000..4e0b55e669b
--- /dev/null
+++ b/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-auditors.xml
@@ -0,0 +1,27 @@
+<?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 SHARDING AUDITORS" current-rule-config-yaml-file="cases/show-sharding-auditors-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>
+ sharding_key_required_auditor|DML_SHARDING_CONDITIONS|
+ </expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>