Skip to content

Commit 4df9222

Browse files
Use DistSQLDatabaseRuleQueryExecutorAssert in ShowUnusedShardingKeyGeneratorExecutorTest (#34938)
* Use DistSQLDatabaseRuleQueryExecutorAssert in ShowShardingTableRulesUsedAuditorExecutorTest * Use DistSQLDatabaseRuleQueryExecutorAssert in ShowUnusedShardingKeyGeneratorExecutorTest
1 parent 230e103 commit 4df9222

File tree

3 files changed

+76
-56
lines changed

3 files changed

+76
-56
lines changed

features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingKeyGeneratorExecutorTest.java

+10-56
Original file line numberDiff line numberDiff line change
@@ -18,73 +18,27 @@
1818
package org.apache.shardingsphere.sharding.distsql.handler.query;
1919

2020
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
21-
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
22-
import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
2321
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
2422
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
25-
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
26-
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
27-
import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
28-
import org.apache.shardingsphere.sharding.distsql.statement.ShowUnusedShardingKeyGeneratorsStatement;
2923
import org.apache.shardingsphere.sharding.rule.ShardingRule;
30-
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorTest;
31-
import org.junit.jupiter.api.extension.ExtensionContext;
24+
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorAssert;
25+
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
26+
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
3227
import org.junit.jupiter.params.ParameterizedTest;
33-
import org.junit.jupiter.params.provider.Arguments;
34-
import org.junit.jupiter.params.provider.ArgumentsProvider;
3528
import org.junit.jupiter.params.provider.ArgumentsSource;
3629

3730
import java.sql.SQLException;
3831
import java.util.Collection;
39-
import java.util.Collections;
40-
import java.util.Properties;
41-
import java.util.stream.Stream;
4232

4333
import static org.mockito.Mockito.mock;
4434

45-
class ShowUnusedShardingKeyGeneratorExecutorTest extends DistSQLDatabaseRuleQueryExecutorTest {
35+
@DistSQLRuleQueryExecutorSettings("cases/show-unused-sharding-key-generator.xml")
36+
class ShowUnusedShardingKeyGeneratorExecutorTest {
4637

47-
ShowUnusedShardingKeyGeneratorExecutorTest() {
48-
super(mock(ShardingRule.class));
49-
}
50-
51-
@ParameterizedTest(name = "{0}")
52-
@ArgumentsSource(TestCaseArgumentsProvider.class)
53-
void assertExecuteQuery(final String name, final DatabaseRuleConfiguration ruleConfig, final DistSQLStatement sqlStatement,
54-
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
55-
assertQueryResultRows(ruleConfig, sqlStatement, expected);
56-
}
57-
58-
private static class TestCaseArgumentsProvider implements ArgumentsProvider {
59-
60-
@Override
61-
public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
62-
return Stream.of(Arguments.arguments("normal", createRuleConfiguration(), new ShowUnusedShardingKeyGeneratorsStatement(null),
63-
Collections.singleton(new LocalDataQueryResultRow("uuid_key_generator", "UUID", ""))));
64-
}
65-
66-
private ShardingRuleConfiguration createRuleConfiguration() {
67-
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
68-
result.getKeyGenerators().put("snowflake_key_generator", new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
69-
result.getKeyGenerators().put("uuid_key_generator", new AlgorithmConfiguration("UUID", null));
70-
result.getTables().add(createShardingTableRuleConfiguration());
71-
result.getTables().add(new ShardingTableRuleConfiguration("bar_table", null));
72-
result.getAutoTables().add(createShardingAutoTableRuleConfiguration());
73-
result.getAutoTables().add(new ShardingAutoTableRuleConfiguration("bar_auto_table", null));
74-
result.setDefaultKeyGenerateStrategy(new KeyGenerateStrategyConfiguration(null, "snowflake_key_generator"));
75-
return result;
76-
}
77-
78-
private ShardingTableRuleConfiguration createShardingTableRuleConfiguration() {
79-
ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("foo_tbl", null);
80-
result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("foo_col", "snowflake_key_generator"));
81-
return result;
82-
}
83-
84-
private ShardingAutoTableRuleConfiguration createShardingAutoTableRuleConfiguration() {
85-
ShardingAutoTableRuleConfiguration result = new ShardingAutoTableRuleConfiguration("foo_auto_table", null);
86-
result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("foo_col", "snowflake_key_generator"));
87-
return result;
88-
}
38+
@ParameterizedTest(name = "DistSQL -> {0}")
39+
@ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
40+
void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL, final DistSQLStatement sqlStatement,
41+
final ShardingRuleConfiguration currentRuleConfig, final Collection<LocalDataQueryResultRow> expected) throws SQLException {
42+
new DistSQLDatabaseRuleQueryExecutorAssert(mock(ShardingRule.class)).assertQueryResultRows(currentRuleConfig, sqlStatement, expected);
8943
}
9044
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
rules:
19+
- !SHARDING
20+
tables:
21+
t_order:
22+
actualDataNodes: ds_${0..1}.t_order_${0..1}
23+
tableStrategy:
24+
standard:
25+
shardingColumn: order_id
26+
shardingAlgorithmName: t_order_inline
27+
keyGenerateStrategy:
28+
column: order_id
29+
keyGeneratorName: snowflake
30+
auditStrategy:
31+
auditorNames:
32+
- sharding_key_required_auditor
33+
allowHintDisable: true
34+
35+
keyGenerators:
36+
snowflake:
37+
type: SNOWFLAKE
38+
uuid:
39+
type: UUID
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<distsql-rule-query-executor-test-cases>
20+
<test-case dist-sql="SHOW UNUSED SHARDING KEY GENERATORS" current-rule-config-yaml-file="cases/show-unused-sharding-key-generator-current-config.yaml">
21+
<expected-query-result-rows>
22+
<expected-query-result-row>
23+
uuid|UUID|
24+
</expected-query-result-row>
25+
</expected-query-result-rows>
26+
</test-case>
27+
</distsql-rule-query-executor-test-cases>

0 commit comments

Comments
 (0)