Skip to content

Commit

Permalink
Refactor method name form config to configuration (#30878)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Apr 13, 2024
1 parent 1c47a97 commit 4cf296f
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ private EncryptRuleConfiguration createValidConfiguration() {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
void assertCheckWhenConfigInvalidCipherColumn() {
EncryptRuleConfiguration config = createInvalidCipherColumnConfig();
EncryptRuleConfiguration config = createInvalidCipherColumnConfiguration();
RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
assertThrows(UnregisteredAlgorithmException.class, () -> checker.check("test", config, Collections.emptyMap(), Collections.emptyList()));
}

private EncryptRuleConfiguration createInvalidCipherColumnConfig() {
private EncryptRuleConfiguration createInvalidCipherColumnConfiguration() {
EncryptRuleConfiguration result = mock(EncryptRuleConfiguration.class);
when(result.getEncryptors()).thenReturn(Collections.emptyMap());
EncryptColumnRuleConfiguration columnRuleConfig = new EncryptColumnRuleConfiguration("user_id", new EncryptColumnItemRuleConfiguration("user_cipher", "aes_encryptor"));
Expand All @@ -74,12 +74,12 @@ private EncryptRuleConfiguration createInvalidCipherColumnConfig() {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
void assertCheckWhenConfigInvalidAssistColumn() {
EncryptRuleConfiguration config = createInvalidAssistColumnConfig();
EncryptRuleConfiguration config = createInvalidAssistColumnConfiguration();
RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
assertThrows(UnregisteredAlgorithmException.class, () -> checker.check("test", config, Collections.emptyMap(), Collections.emptyList()));
}

private EncryptRuleConfiguration createInvalidAssistColumnConfig() {
private EncryptRuleConfiguration createInvalidAssistColumnConfiguration() {
EncryptRuleConfiguration result = mock(EncryptRuleConfiguration.class);
when(result.getEncryptors()).thenReturn(Collections.emptyMap());
EncryptColumnRuleConfiguration columnRuleConfig = new EncryptColumnRuleConfiguration("user_id", new EncryptColumnItemRuleConfiguration("user_cipher", "aes_encryptor"));
Expand All @@ -92,12 +92,12 @@ private EncryptRuleConfiguration createInvalidAssistColumnConfig() {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
void assertCheckWhenConfigInvalidLikeColumn() {
EncryptRuleConfiguration config = createInvalidLikeColumnConfig();
EncryptRuleConfiguration config = createInvalidLikeColumnConfiguration();
RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
assertThrows(UnregisteredAlgorithmException.class, () -> checker.check("test", config, Collections.emptyMap(), Collections.emptyList()));
}

private EncryptRuleConfiguration createInvalidLikeColumnConfig() {
private EncryptRuleConfiguration createInvalidLikeColumnConfiguration() {
EncryptRuleConfiguration result = mock(EncryptRuleConfiguration.class);
when(result.getEncryptors()).thenReturn(Collections.emptyMap());
EncryptColumnRuleConfiguration columnRuleConfig = new EncryptColumnRuleConfiguration("user_id", new EncryptColumnItemRuleConfiguration("user_cipher", "aes_encryptor"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void setUp() {
@Test
void assertCheckSQLStatementWithDuplicateEncryptRule() {
EncryptRule rule = mock(EncryptRule.class);
when(rule.getConfiguration()).thenReturn(getCurrentRuleConfig());
when(rule.getConfiguration()).thenReturn(getCurrentRuleConfiguration());
executor.setRule(rule);
assertThrows(DuplicateRuleException.class, () -> executor.checkBeforeUpdate(createSQLStatement(false, "MD5")));
}
Expand All @@ -72,7 +72,7 @@ void assertCheckSQLStatementWithoutToBeCreatedEncryptors() {
@Test
void assertCheckSQLStatementWithConflictColumnNames() {
EncryptRule rule = mock(EncryptRule.class);
when(rule.getConfiguration()).thenReturn(getCurrentRuleConfig());
when(rule.getConfiguration()).thenReturn(getCurrentRuleConfiguration());
executor.setRule(rule);
assertThrows(InvalidRuleConfigurationException.class, () -> executor.checkBeforeUpdate(createConflictColumnNameSQLStatement()));
}
Expand Down Expand Up @@ -122,7 +122,7 @@ private CreateEncryptRuleStatement createConflictColumnNameSQLStatement() {
return new CreateEncryptRuleStatement(false, Collections.singleton(ruleSegment));
}

private EncryptRuleConfiguration getCurrentRuleConfig() {
private EncryptRuleConfiguration getCurrentRuleConfiguration() {
Collection<EncryptTableRuleConfiguration> rules = new LinkedList<>();
rules.add(new EncryptTableRuleConfiguration("t_user", Collections.emptyList()));
rules.add(new EncryptTableRuleConfiguration("t_order", Collections.emptyList()));
Expand All @@ -133,7 +133,7 @@ private EncryptRuleConfiguration getCurrentRuleConfig() {
void assertCreateAESEncryptRuleWithPropertiesNotExists() {
CreateEncryptRuleStatement sqlStatement = createWrongAESEncryptorSQLStatement();
EncryptRule rule = mock(EncryptRule.class);
when(rule.getConfiguration()).thenReturn(getCurrentRuleConfig());
when(rule.getConfiguration()).thenReturn(getCurrentRuleConfiguration());
executor.setRule(rule);
assertThrows(AlgorithmInitializationException.class, () -> executor.checkBeforeUpdate(sqlStatement));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void assertCheckBeforeUpdateWithoutToBeAlteredRules() {
@Test
void assertCheckBeforeUpdateWithoutToBeAlteredAlgorithm() {
MaskRule rule = mock(MaskRule.class);
when(rule.getConfiguration()).thenReturn(createCurrentRuleConfig());
when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration());
executor.setRule(rule);
assertThrows(MissingRequiredRuleException.class, () -> executor.checkBeforeUpdate(createSQLStatement("INVALID_TYPE")));
}
Expand All @@ -74,14 +74,14 @@ void assertCheckBeforeUpdateWithIncompleteDataType() {
MaskRuleSegment ruleSegment = new MaskRuleSegment("t_mask", Collections.singleton(columnSegment));
AlterMaskRuleStatement statement = new AlterMaskRuleStatement(Collections.singleton(ruleSegment));
MaskRule rule = mock(MaskRule.class);
when(rule.getConfiguration()).thenReturn(createCurrentRuleConfig());
when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration());
executor.setRule(rule);
assertThrows(MissingRequiredRuleException.class, () -> executor.checkBeforeUpdate(statement));
}

@Test
void assertUpdate() {
MaskRuleConfiguration currentRuleConfig = createCurrentRuleConfig();
MaskRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration();
MaskColumnSegment columnSegment = new MaskColumnSegment("order_id",
new AlgorithmSegment("MD5", new Properties()));
MaskRuleSegment ruleSegment = new MaskRuleSegment("t_order", Collections.singleton(columnSegment));
Expand All @@ -104,7 +104,7 @@ private AlterMaskRuleStatement createSQLStatement(final String algorithmName) {
return new AlterMaskRuleStatement(Collections.singleton(ruleSegment));
}

private MaskRuleConfiguration createCurrentRuleConfig() {
private MaskRuleConfiguration createCurrentRuleConfiguration() {
Collection<MaskTableRuleConfiguration> tableRuleConfigs = new LinkedList<>();
tableRuleConfigs.add(new MaskTableRuleConfiguration("t_order", Collections.emptyList()));
return new MaskRuleConfiguration(tableRuleConfigs, new HashMap<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void setUp() {
@Test
void assertCheckSQLStatementWithDuplicateMaskRule() {
MaskRule rule = mock(MaskRule.class);
when(rule.getConfiguration()).thenReturn(getCurrentRuleConfig());
when(rule.getConfiguration()).thenReturn(getCurrentRuleConfiguration());
executor.setRule(rule);
assertThrows(DuplicateRuleException.class, () -> executor.checkBeforeUpdate(createDuplicatedSQLStatement(false, "MD5")));
}
Expand All @@ -68,7 +68,7 @@ void assertCheckSQLStatementWithInvalidAlgorithm() {

@Test
void assertCreateMaskRule() {
MaskRuleConfiguration currentRuleConfig = getCurrentRuleConfig();
MaskRuleConfiguration currentRuleConfig = getCurrentRuleConfiguration();
CreateMaskRuleStatement sqlStatement = createSQLStatement(false, "MD5");
MaskRule rule = mock(MaskRule.class);
when(rule.getConfiguration()).thenReturn(currentRuleConfig);
Expand All @@ -82,7 +82,7 @@ void assertCreateMaskRule() {

@Test
void assertCreateMaskRuleWithIfNotExists() {
MaskRuleConfiguration currentRuleConfig = getCurrentRuleConfig();
MaskRuleConfiguration currentRuleConfig = getCurrentRuleConfiguration();
MaskRule rule = mock(MaskRule.class);
CreateMaskRuleStatement sqlStatement = createSQLStatement(true, "MD5");
when(rule.getConfiguration()).thenReturn(currentRuleConfig);
Expand Down Expand Up @@ -116,7 +116,7 @@ private CreateMaskRuleStatement createDuplicatedSQLStatement(final boolean ifNot
return new CreateMaskRuleStatement(ifNotExists, rules);
}

private MaskRuleConfiguration getCurrentRuleConfig() {
private MaskRuleConfiguration getCurrentRuleConfiguration() {
Collection<MaskTableRuleConfiguration> rules = new LinkedList<>();
rules.add(new MaskTableRuleConfiguration("t_mask", Collections.emptyList()));
rules.add(new MaskTableRuleConfiguration("t_order", Collections.emptyList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ private ReadwriteSplittingRuleConfiguration createInvalidConfiguration() {
@Test
void assertCheckWhenConfigInvalidWriteDataSource() {
ReadwriteSplittingRuleConfiguration config = mock(ReadwriteSplittingRuleConfiguration.class);
List<ReadwriteSplittingDataSourceRuleConfiguration> configs = Arrays.asList(createDataSourceRuleConfig(
"write_ds_0", Arrays.asList("read_ds_0", "read_ds_1")), createDataSourceRuleConfig("write_ds_2", Arrays.asList("read_ds_0", "read_ds_1")));
List<ReadwriteSplittingDataSourceRuleConfiguration> configs = Arrays.asList(createDataSourceRuleConfiguration(
"write_ds_0", Arrays.asList("read_ds_0", "read_ds_1")), createDataSourceRuleConfiguration("write_ds_2", Arrays.asList("read_ds_0", "read_ds_1")));
when(config.getDataSources()).thenReturn(configs);
RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
assertThrows(DataSourceNameNotExistedException.class, () -> checker.check("test", config, mockDataSources(), Collections.emptyList()));
Expand All @@ -80,8 +80,8 @@ void assertCheckWhenConfigInvalidWriteDataSource() {
@Test
void assertCheckWhenConfigInvalidReadDataSource() {
ReadwriteSplittingRuleConfiguration config = mock(ReadwriteSplittingRuleConfiguration.class);
List<ReadwriteSplittingDataSourceRuleConfiguration> configs = Arrays.asList(createDataSourceRuleConfig(
"write_ds_0", Arrays.asList("read_ds_0", "read_ds_0")), createDataSourceRuleConfig("write_ds_1", Arrays.asList("read_ds_0", "read_ds_0")));
List<ReadwriteSplittingDataSourceRuleConfiguration> configs = Arrays.asList(createDataSourceRuleConfiguration(
"write_ds_0", Arrays.asList("read_ds_0", "read_ds_0")), createDataSourceRuleConfiguration("write_ds_1", Arrays.asList("read_ds_0", "read_ds_0")));
when(config.getDataSources()).thenReturn(configs);
RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
assertThrows(DuplicateDataSourceException.class, () -> checker.check("test", config, mockDataSources(), Collections.emptyList()));
Expand All @@ -91,7 +91,7 @@ void assertCheckWhenConfigInvalidReadDataSource() {
@Test
void assertCheckWeightLoadBalanceInvalidDataSourceName() {
ReadwriteSplittingRuleConfiguration config = mock(ReadwriteSplittingRuleConfiguration.class);
Collection<ReadwriteSplittingDataSourceRuleConfiguration> configs = Collections.singleton(createDataSourceRuleConfig("write_ds_0", Arrays.asList("read_ds_0", "read_ds_1")));
Collection<ReadwriteSplittingDataSourceRuleConfiguration> configs = Collections.singleton(createDataSourceRuleConfiguration("write_ds_0", Arrays.asList("read_ds_0", "read_ds_1")));
when(config.getDataSources()).thenReturn(configs);
AlgorithmConfiguration algorithm = new AlgorithmConfiguration("WEIGHT", PropertiesBuilder.build(new Property("read_ds_2", "1"), new Property("read_ds_1", "2")));
when(config.getLoadBalancers()).thenReturn(Collections.singletonMap("weight_ds", algorithm));
Expand All @@ -102,7 +102,7 @@ void assertCheckWeightLoadBalanceInvalidDataSourceName() {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
void assertCheckWhenConfigOtherRulesDatasource() {
ReadwriteSplittingRuleConfiguration config = createContainsOtherRulesDatasourceConfig();
ReadwriteSplittingRuleConfiguration config = createContainsOtherRulesDatasourceConfiguration();
RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
ShardingSphereRule rule = mock(ShardingSphereRule.class);
DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class, RETURNS_DEEP_STUBS);
Expand All @@ -111,7 +111,7 @@ void assertCheckWhenConfigOtherRulesDatasource() {
checker.check("test", config, mockDataSources(), Collections.singleton(rule));
}

private ReadwriteSplittingRuleConfiguration createContainsOtherRulesDatasourceConfig() {
private ReadwriteSplittingRuleConfiguration createContainsOtherRulesDatasourceConfiguration() {
ReadwriteSplittingRuleConfiguration result = mock(ReadwriteSplittingRuleConfiguration.class);
ReadwriteSplittingDataSourceRuleConfiguration dataSourceConfig = mock(ReadwriteSplittingDataSourceRuleConfiguration.class);
when(dataSourceConfig.getName()).thenReturn("readwrite_ds");
Expand All @@ -121,7 +121,7 @@ private ReadwriteSplittingRuleConfiguration createContainsOtherRulesDatasourceCo
return result;
}

private ReadwriteSplittingDataSourceRuleConfiguration createDataSourceRuleConfig(final String writeDataSource, final List<String> readDataSources) {
private ReadwriteSplittingDataSourceRuleConfiguration createDataSourceRuleConfiguration(final String writeDataSource, final List<String> readDataSources) {
ReadwriteSplittingDataSourceRuleConfiguration result = mock(ReadwriteSplittingDataSourceRuleConfiguration.class);
when(result.getName()).thenReturn("readwrite_ds");
when(result.getWriteDataSourceName()).thenReturn(writeDataSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public ShardingRule(final ShardingRuleConfiguration ruleConfig, final Map<String
shardingTables.putAll(createShardingAutoTables(ruleConfig.getAutoTables(), ruleConfig.getDefaultKeyGenerateStrategy()));
validateUniqueActualDataNodesInTableRules();
bindingTableRules.putAll(createBindingTableRules(ruleConfig.getBindingTableGroups()));
defaultDatabaseShardingStrategyConfig = createDefaultDatabaseShardingStrategyConfig(ruleConfig);
defaultTableShardingStrategyConfig = createDefaultTableShardingStrategyConfig(ruleConfig);
defaultDatabaseShardingStrategyConfig = createDefaultDatabaseShardingStrategyConfiguration(ruleConfig);
defaultTableShardingStrategyConfig = createDefaultTableShardingStrategyConfiguration(ruleConfig);
defaultAuditStrategy = null == ruleConfig.getDefaultAuditStrategy() ? new ShardingAuditStrategyConfiguration(Collections.emptyList(), true) : ruleConfig.getDefaultAuditStrategy();
defaultKeyGenerateAlgorithm = null == ruleConfig.getDefaultKeyGenerateStrategy()
? TypedSPILoader.getService(KeyGenerateAlgorithm.class, null)
Expand All @@ -155,12 +155,12 @@ private void validateUniqueActualDataNodesInTableRules() {
});
}

private ShardingStrategyConfiguration createDefaultDatabaseShardingStrategyConfig(final ShardingRuleConfiguration ruleConfig) {
private ShardingStrategyConfiguration createDefaultDatabaseShardingStrategyConfiguration(final ShardingRuleConfiguration ruleConfig) {
Optional.ofNullable(ruleConfig.getDefaultDatabaseShardingStrategy()).ifPresent(optional -> checkManualShardingAlgorithm(optional.getShardingAlgorithmName(), "default"));
return null == ruleConfig.getDefaultDatabaseShardingStrategy() ? new NoneShardingStrategyConfiguration() : ruleConfig.getDefaultDatabaseShardingStrategy();
}

private ShardingStrategyConfiguration createDefaultTableShardingStrategyConfig(final ShardingRuleConfiguration ruleConfig) {
private ShardingStrategyConfiguration createDefaultTableShardingStrategyConfiguration(final ShardingRuleConfiguration ruleConfig) {
Optional.ofNullable(ruleConfig.getDefaultTableShardingStrategy()).ifPresent(optional -> checkManualShardingAlgorithm(optional.getShardingAlgorithmName(), "default"));
return null == ruleConfig.getDefaultTableShardingStrategy() ? new NoneShardingStrategyConfiguration() : ruleConfig.getDefaultTableShardingStrategy();
}
Expand Down
Loading

0 comments on commit 4cf296f

Please sign in to comment.