18
18
package org .apache .shardingsphere .readwritesplitting .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
21
import org .apache .shardingsphere .infra .config .rule .scope .DatabaseRuleConfiguration ;
23
22
import org .apache .shardingsphere .infra .merge .result .impl .local .LocalDataQueryResultRow ;
24
23
import org .apache .shardingsphere .infra .rule .attribute .RuleAttributes ;
25
24
import org .apache .shardingsphere .infra .rule .attribute .exportable .constant .ExportableConstants ;
26
- import org .apache .shardingsphere .readwritesplitting .config .ReadwriteSplittingRuleConfiguration ;
27
- import org .apache .shardingsphere .readwritesplitting .config .rule .ReadwriteSplittingDataSourceGroupRuleConfiguration ;
28
- import org .apache .shardingsphere .readwritesplitting .distsql .statement .ShowReadwriteSplittingRulesStatement ;
29
25
import org .apache .shardingsphere .readwritesplitting .rule .ReadwriteSplittingRule ;
30
26
import org .apache .shardingsphere .readwritesplitting .rule .attribute .ReadwriteSplittingExportableRuleAttribute ;
31
- import org .apache .shardingsphere .test .it .distsql .handler .engine .query .DistSQLDatabaseRuleQueryExecutorTest ;
32
- import org .apache .shardingsphere .test .util .PropertiesBuilder ;
33
- import org .apache .shardingsphere .test .util .PropertiesBuilder .Property ;
34
- import org .junit .jupiter .api .extension .ExtensionContext ;
27
+ import org .apache .shardingsphere .test .it .distsql .handler .engine .query .DistSQLDatabaseRuleQueryExecutorAssert ;
28
+ import org .apache .shardingsphere .test .it .distsql .handler .engine .query .DistSQLRuleQueryExecutorSettings ;
29
+ import org .apache .shardingsphere .test .it .distsql .handler .engine .query .DistSQLRuleQueryExecutorTestCaseArgumentsProvider ;
35
30
import org .junit .jupiter .params .ParameterizedTest ;
36
- import org .junit .jupiter .params .provider .Arguments ;
37
- import org .junit .jupiter .params .provider .ArgumentsProvider ;
38
31
import org .junit .jupiter .params .provider .ArgumentsSource ;
39
32
40
33
import java .sql .SQLException ;
41
- import java .util .Arrays ;
42
34
import java .util .Collection ;
43
35
import java .util .Collections ;
44
36
import java .util .HashMap ;
45
37
import java .util .Map ;
46
- import java .util .stream .Stream ;
47
38
48
39
import static org .mockito .Mockito .mock ;
49
40
import static org .mockito .Mockito .when ;
50
41
51
- class ShowReadwriteSplittingRuleExecutorTest extends DistSQLDatabaseRuleQueryExecutorTest {
42
+ @ DistSQLRuleQueryExecutorSettings ("cases/show-readwrite-splitting-rule.xml" )
43
+ class ShowReadwriteSplittingRuleExecutorTest {
52
44
53
- ShowReadwriteSplittingRuleExecutorTest () {
54
- super (mockRule ());
45
+ @ ParameterizedTest (name = "DistSQL -> {0}" )
46
+ @ ArgumentsSource (DistSQLRuleQueryExecutorTestCaseArgumentsProvider .class )
47
+ void assertExecuteQuery (@ SuppressWarnings ("unused" ) final String distSQL , final DistSQLStatement sqlStatement ,
48
+ final DatabaseRuleConfiguration currentRuleConfig , final Collection <LocalDataQueryResultRow > expected ) throws SQLException {
49
+ new DistSQLDatabaseRuleQueryExecutorAssert (mockRule ()).assertQueryResultRows (currentRuleConfig , sqlStatement , expected );
55
50
}
56
51
57
52
private static ReadwriteSplittingRule mockRule () {
@@ -67,37 +62,4 @@ private static Map<String, Object> createExportedData() {
67
62
result .put (ExportableConstants .EXPORT_STATIC_READWRITE_SPLITTING_RULE , Collections .emptyMap ());
68
63
return result ;
69
64
}
70
-
71
- @ ParameterizedTest (name = "{0}" )
72
- @ ArgumentsSource (TestCaseArgumentsProvider .class )
73
- void assertExecuteQuery (final String name , final DatabaseRuleConfiguration ruleConfig , final DistSQLStatement sqlStatement ,
74
- final Collection <LocalDataQueryResultRow > expected ) throws SQLException {
75
- assertQueryResultRows (ruleConfig , sqlStatement , expected );
76
- }
77
-
78
- private static class TestCaseArgumentsProvider implements ArgumentsProvider {
79
-
80
- @ Override
81
- public Stream <? extends Arguments > provideArguments (final ExtensionContext extensionContext ) {
82
- return Stream .of (Arguments .arguments ("withNull" , createRuleConfiguration (), new ShowReadwriteSplittingRulesStatement (null , null ),
83
- Collections .singleton (new LocalDataQueryResultRow ("readwrite_ds" , "ds_primary" , "ds_slave_0,ds_slave_1" , "DYNAMIC" , "random" , "{\" read_weight\" :\" 2:1\" }" ))),
84
- Arguments .arguments ("withSpecifiedRuleName" , createRuleConfiguration (), new ShowReadwriteSplittingRulesStatement ("readwrite_ds" , null ),
85
- Collections .singleton (new LocalDataQueryResultRow ("readwrite_ds" , "ds_primary" , "ds_slave_0,ds_slave_1" , "DYNAMIC" , "random" , "{\" read_weight\" :\" 2:1\" }" ))),
86
- Arguments .arguments ("withoutLoadBalancer" , createRuleConfigurationWithoutLoadBalancer (), new ShowReadwriteSplittingRulesStatement ("readwrite_ds" , null ),
87
- Collections .singleton (new LocalDataQueryResultRow ("readwrite_ds" , "write_ds" , "read_ds_0,read_ds_1" , "DYNAMIC" , "" , "" ))));
88
- }
89
-
90
- private ReadwriteSplittingRuleConfiguration createRuleConfiguration () {
91
- ReadwriteSplittingDataSourceGroupRuleConfiguration dataSourceGroupConfig =
92
- new ReadwriteSplittingDataSourceGroupRuleConfiguration ("readwrite_ds" , "ds_primary" , Arrays .asList ("ds_slave_0" , "ds_slave_1" ), "test" );
93
- return new ReadwriteSplittingRuleConfiguration (
94
- Collections .singleton (dataSourceGroupConfig ), Collections .singletonMap ("test" , new AlgorithmConfiguration ("random" , PropertiesBuilder .build (new Property ("read_weight" , "2:1" )))));
95
- }
96
-
97
- private ReadwriteSplittingRuleConfiguration createRuleConfigurationWithoutLoadBalancer () {
98
- ReadwriteSplittingDataSourceGroupRuleConfiguration dataSourceGroupConfig =
99
- new ReadwriteSplittingDataSourceGroupRuleConfiguration ("readwrite_ds" , "write_ds" , Arrays .asList ("read_ds_0" , "read_ds_1" ), null );
100
- return new ReadwriteSplittingRuleConfiguration (Collections .singleton (dataSourceGroupConfig ), null );
101
- }
102
- }
103
65
}
0 commit comments