|
18 | 18 | package org.apache.shardingsphere.sharding.distsql.handler.query;
|
19 | 19 |
|
20 | 20 | 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; |
23 | 21 | import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
|
24 | 22 | 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; |
29 | 23 | 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; |
32 | 27 | import org.junit.jupiter.params.ParameterizedTest;
|
33 |
| -import org.junit.jupiter.params.provider.Arguments; |
34 |
| -import org.junit.jupiter.params.provider.ArgumentsProvider; |
35 | 28 | import org.junit.jupiter.params.provider.ArgumentsSource;
|
36 | 29 |
|
37 | 30 | import java.sql.SQLException;
|
38 | 31 | import java.util.Collection;
|
39 |
| -import java.util.Collections; |
40 |
| -import java.util.Properties; |
41 |
| -import java.util.stream.Stream; |
42 | 32 |
|
43 | 33 | import static org.mockito.Mockito.mock;
|
44 | 34 |
|
45 |
| -class ShowUnusedShardingKeyGeneratorExecutorTest extends DistSQLDatabaseRuleQueryExecutorTest { |
| 35 | +@DistSQLRuleQueryExecutorSettings("cases/show-unused-sharding-key-generator.xml") |
| 36 | +class ShowUnusedShardingKeyGeneratorExecutorTest { |
46 | 37 |
|
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); |
89 | 43 | }
|
90 | 44 | }
|
0 commit comments