Skip to content

Commit

Permalink
Remove useless BroadcastRule.databaseName
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Oct 30, 2024
1 parent 68755bd commit 1cc49c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,16 @@ public final class BroadcastRule implements DatabaseRule {

private final BroadcastRuleConfiguration configuration;

private final String databaseName;

private final Collection<String> tables;

private final Collection<String> dataSourceNames;

private final RuleAttributes attributes;

public BroadcastRule(final BroadcastRuleConfiguration config, final String databaseName, final Map<String, DataSource> dataSources, final Collection<ShardingSphereRule> builtRules) {
public BroadcastRule(final BroadcastRuleConfiguration config, final Map<String, DataSource> dataSources, final Collection<ShardingSphereRule> builtRules) {
configuration = config;
this.databaseName = databaseName;
dataSourceNames = getAggregatedDataSourceNames(dataSources, builtRules);
tables = createBroadcastTables(config.getTables());
tables = new CaseInsensitiveSet<>(config.getTables());
attributes = new RuleAttributes(new BroadcastDataNodeRuleAttribute(dataSourceNames, tables), new BroadcastTableNamesRuleAttribute(tables));
}

Expand Down Expand Up @@ -86,10 +83,6 @@ private Collection<String> getAggregatedDataSourceNames(final Collection<String>
return result;
}

private Collection<String> createBroadcastTables(final Collection<String> broadcastTables) {
return new CaseInsensitiveSet<>(broadcastTables);
}

/**
* Get broadcast rule table names.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public final class BroadcastRuleBuilder implements DatabaseRuleBuilder<Broadcast
@Override
public BroadcastRule build(final BroadcastRuleConfiguration ruleConfig, final String databaseName, final DatabaseType protocolType,
final ResourceMetaData resourceMetaData, final Collection<ShardingSphereRule> builtRules, final ComputeNodeInstanceContext computeNodeInstanceContext) {
return new BroadcastRule(ruleConfig, databaseName, resourceMetaData.getDataSourceMap(), builtRules);
return new BroadcastRule(ruleConfig, resourceMetaData.getDataSourceMap(), builtRules);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BroadcastSqlRouterTest {
void assertCreateBroadcastRouteContextWithMultiDataSource() throws SQLException {
BroadcastRuleConfiguration currentConfig = mock(BroadcastRuleConfiguration.class);
when(currentConfig.getTables()).thenReturn(Collections.singleton("t_order"));
BroadcastRule broadcastRule = new BroadcastRule(currentConfig, DefaultDatabase.LOGIC_NAME, createMultiDataSourceMap(), Collections.emptyList());
BroadcastRule broadcastRule = new BroadcastRule(currentConfig, createMultiDataSourceMap(), Collections.emptyList());
RouteContext routeContext = new BroadcastSQLRouter().createRouteContext(createQueryContext(), mock(RuleMetaData.class), mockDatabaseWithMultipleResources(), broadcastRule,
new ConfigurationProperties(new Properties()));
List<RouteUnit> routeUnits = new ArrayList<>(routeContext.getRouteUnits());
Expand All @@ -92,7 +92,7 @@ void assertCreateBroadcastRouteContextWithMultiDataSource() throws SQLException
void assertCreateBroadcastRouteContextWithSingleDataSource() throws SQLException {
BroadcastRuleConfiguration currentConfig = mock(BroadcastRuleConfiguration.class);
when(currentConfig.getTables()).thenReturn(Collections.singleton("t_order"));
BroadcastRule broadcastRule = new BroadcastRule(currentConfig, DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tmp_ds", new MockedDataSource(mockConnection())), Collections.emptyList());
BroadcastRule broadcastRule = new BroadcastRule(currentConfig, Collections.singletonMap("tmp_ds", new MockedDataSource(mockConnection())), Collections.emptyList());
broadcastRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().put("t_order", Collections.singletonList(createDataNode("tmp_ds")));
ShardingSphereDatabase database = mockSingleDatabase();
RouteContext routeContext = new BroadcastSQLRouter().createRouteContext(
Expand All @@ -108,7 +108,7 @@ void assertCreateBroadcastRouteContextWithSingleDataSource() throws SQLException
void assertDecorateBroadcastRouteContextWithSingleDataSource() {
BroadcastRuleConfiguration currentConfig = mock(BroadcastRuleConfiguration.class);
when(currentConfig.getTables()).thenReturn(Collections.singleton("t_order"));
BroadcastRule broadcastRule = new BroadcastRule(currentConfig, DefaultDatabase.LOGIC_NAME, Collections.singletonMap("foo_ds", new MockedDataSource()), Collections.emptyList());
BroadcastRule broadcastRule = new BroadcastRule(currentConfig, Collections.singletonMap("foo_ds", new MockedDataSource()), Collections.emptyList());
RouteContext routeContext = new RouteContext();
routeContext.getRouteUnits().add(new RouteUnit(new RouteMapper("foo_ds", "foo_ds"), Lists.newArrayList()));
BroadcastSQLRouter sqlRouter = (BroadcastSQLRouter) OrderedSPILoader.getServices(SQLRouter.class, Collections.singleton(broadcastRule)).get(broadcastRule);
Expand Down

0 comments on commit 1cc49c5

Please sign in to comment.