Skip to content

Commit

Permalink
Rename RuleConfigurationChangedEventBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Dec 14, 2024
1 parent 5b09fb9 commit c57a8f8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
import java.util.Optional;

/**
* Rule configuration event builder.
* Rule configuration changed event builder.
*/
public final class RuleConfigurationEventBuilder {
public final class RuleConfigurationChangedEventBuilder {

/**
* Build rule changed event.
*
* @param databaseName database name
* @param event data changed event
* @return rule changed event
* @return built event
*/
public Optional<DispatchEvent> build(final String databaseName, final DataChangedEvent event) {
for (RuleNodePathProvider each : ShardingSphereServiceLoader.getServiceInstances(RuleNodePathProvider.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@

@ExtendWith(AutoMockExtension.class)
@StaticMockSettings(ShardingSphereServiceLoader.class)
class RuleConfigurationEventBuilderTest {
class RuleConfigurationChangedEventBuilderTest {

@Test
void assertBuildWithoutRuleNodePathProvider() {
when(ShardingSphereServiceLoader.getServiceInstances(RuleNodePathProvider.class)).thenReturn(Collections.emptyList());
assertFalse(new RuleConfigurationEventBuilder().build("foo_db", new DataChangedEvent("k", "v", Type.IGNORED)).isPresent());
assertFalse(new RuleConfigurationChangedEventBuilder().build("foo_db", new DataChangedEvent("k", "v", Type.IGNORED)).isPresent());
}

@ParameterizedTest(name = "{0}")
Expand All @@ -66,7 +66,7 @@ void assertBuild(final String name, final String eventKey, final String eventVal
RuleNodePathProvider ruleNodePathProvider = mock(RuleNodePathProvider.class, RETURNS_DEEP_STUBS);
when(ruleNodePathProvider.getRuleNodePath()).thenReturn(new RuleNodePath("fixture", Collections.singleton("named"), Collections.singleton("unique")));
when(ShardingSphereServiceLoader.getServiceInstances(RuleNodePathProvider.class)).thenReturn(Collections.singleton(ruleNodePathProvider));
Optional<DispatchEvent> actual = new RuleConfigurationEventBuilder().build("foo_db", new DataChangedEvent(eventKey, eventValue, type));
Optional<DispatchEvent> actual = new RuleConfigurationChangedEventBuilder().build("foo_db", new DataChangedEvent(eventKey, eventValue, type));
assertThat(actual.isPresent(), is(isEventPresent));
if (actual.isPresent()) {
if (dispatchEventClass == AlterNamedRuleItemEvent.class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.shardingsphere.metadata.persist.node.metadata.ViewMetaDataNode;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
import org.apache.shardingsphere.mode.event.builder.RuleConfigurationEventBuilder;
import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder;
import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent;
import org.apache.shardingsphere.mode.event.dispatch.datasource.node.AlterStorageNodeEvent;
import org.apache.shardingsphere.mode.event.dispatch.datasource.node.RegisterStorageNodeEvent;
Expand All @@ -51,7 +51,7 @@ public final class DatabaseMetaDataChangedListener implements DataChangedEventLi

private final EventBusContext eventBusContext;

private final RuleConfigurationEventBuilder eventBuilder = new RuleConfigurationEventBuilder();
private final RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = new RuleConfigurationChangedEventBuilder();

@Override
public void onChange(final DataChangedEvent event) {
Expand All @@ -78,7 +78,7 @@ private Optional<DispatchEvent> createDispatchEvent(final DataChangedEvent event
if (DataSourceMetaDataNode.isDataSourcesNode(key)) {
return createDataSourceChangedEvent(databaseName.get(), event);
}
return eventBuilder.build(databaseName.get(), event);
return ruleConfigChangedEventBuilder.build(databaseName.get(), event);
}

private Optional<DispatchEvent> createSchemaChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
import org.apache.shardingsphere.mode.event.builder.RuleConfigurationEventBuilder;
import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder;
import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent;
import org.apache.shardingsphere.mode.event.dispatch.datasource.node.AlterStorageNodeEvent;
import org.apache.shardingsphere.mode.event.dispatch.datasource.node.RegisterStorageNodeEvent;
Expand Down Expand Up @@ -76,9 +76,9 @@ void setUp() {

@SneakyThrows(ReflectiveOperationException.class)
private void setMockedBuilder() {
RuleConfigurationEventBuilder builder = mock(RuleConfigurationEventBuilder.class);
when(builder.build(eq("foo_db"), any(DataChangedEvent.class))).thenReturn(Optional.of(new AlterUniqueRuleItemEvent("foo_db", "key", "value", "type")));
Plugins.getMemberAccessor().set(DatabaseMetaDataChangedListener.class.getDeclaredField("eventBuilder"), listener, builder);
RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = mock(RuleConfigurationChangedEventBuilder.class);
when(ruleConfigChangedEventBuilder.build(eq("foo_db"), any(DataChangedEvent.class))).thenReturn(Optional.of(new AlterUniqueRuleItemEvent("foo_db", "key", "value", "type")));
Plugins.getMemberAccessor().set(DatabaseMetaDataChangedListener.class.getDeclaredField("ruleConfigChangedEventBuilder"), listener, ruleConfigChangedEventBuilder);
}

@ParameterizedTest(name = "{0}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.apache.shardingsphere.metadata.persist.service.config.database.DataSourceUnitPersistService;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
import org.apache.shardingsphere.mode.event.builder.RuleConfigurationEventBuilder;
import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder;
import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent;
import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent;
import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent;
Expand Down Expand Up @@ -64,7 +64,7 @@
*/
public final class StandaloneMetaDataManagerPersistService implements MetaDataManagerPersistService {

private final RuleConfigurationEventBuilder ruleConfigEventBuilder = new RuleConfigurationEventBuilder();
private final RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = new RuleConfigurationChangedEventBuilder();

private final MetaDataPersistService metaDataPersistService;

Expand Down Expand Up @@ -302,7 +302,7 @@ public void alterRuleConfiguration(final String databaseName, final RuleConfigur
}

private Optional<DispatchEvent> buildAlterRuleItemEvent(final String databaseName, final MetaDataVersion metaDataVersion, final Type type) {
return ruleConfigEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), type));
return ruleConfigChangedEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), type));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion;
import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.metadata.persist.service.metadata.DatabaseMetaDataPersistFacade;
import org.apache.shardingsphere.mode.event.builder.RuleConfigurationEventBuilder;
import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder;
import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent;
import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent;
import org.apache.shardingsphere.mode.metadata.MetaDataContextManager;
Expand Down Expand Up @@ -173,9 +173,9 @@ void assertAlterRuleConfiguration() throws SQLException {
Collection<MetaDataVersion> metaDataVersion = Collections.singleton(mock(MetaDataVersion.class));
when(metaDataPersistService.getDatabaseRulePersistService().persist("foo_db", Collections.singleton(ruleConfig))).thenReturn(metaDataVersion);
AlterRuleItemEvent event = mock(AlterRuleItemEvent.class);
RuleConfigurationEventBuilder ruleConfigurationEventBuilder = mock(RuleConfigurationEventBuilder.class);
when(ruleConfigurationEventBuilder.build(eq("foo_db"), any())).thenReturn(Optional.of(event));
setRuleConfigurationEventBuilder(ruleConfigurationEventBuilder);
RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = mock(RuleConfigurationChangedEventBuilder.class);
when(ruleConfigChangedEventBuilder.build(eq("foo_db"), any())).thenReturn(Optional.of(event));
setRuleConfigurationEventBuilder(ruleConfigChangedEventBuilder);
metaDataManagerPersistService.alterRuleConfiguration("foo_db", ruleConfig);
verify(metaDataPersistService.getMetaDataVersionPersistService()).switchActiveVersion(metaDataVersion);
verify(metaDataContextManager.getRuleItemManager()).alterRuleItem(event);
Expand All @@ -192,10 +192,10 @@ void assertRemoveRuleConfigurationItem() throws SQLException {
RuleConfiguration ruleConfig = mock(RuleConfiguration.class, RETURNS_DEEP_STUBS);
Collection<MetaDataVersion> metaDataVersion = Collections.singleton(mock(MetaDataVersion.class));
when(metaDataPersistService.getDatabaseRulePersistService().delete("foo_db", Collections.singleton(ruleConfig))).thenReturn(metaDataVersion);
RuleConfigurationEventBuilder ruleConfigurationEventBuilder = mock(RuleConfigurationEventBuilder.class);
RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = mock(RuleConfigurationChangedEventBuilder.class);
DropRuleItemEvent event = mock(DropRuleItemEvent.class);
when(ruleConfigurationEventBuilder.build(eq("foo_db"), any())).thenReturn(Optional.of(event));
setRuleConfigurationEventBuilder(ruleConfigurationEventBuilder);
when(ruleConfigChangedEventBuilder.build(eq("foo_db"), any())).thenReturn(Optional.of(event));
setRuleConfigurationEventBuilder(ruleConfigChangedEventBuilder);
metaDataManagerPersistService.removeRuleConfigurationItem("foo_db", ruleConfig);
verify(metaDataContextManager.getRuleItemManager()).dropRuleItem(event);
}
Expand Down Expand Up @@ -236,7 +236,7 @@ void assertDropTables() {
}

@SneakyThrows(ReflectiveOperationException.class)
private void setRuleConfigurationEventBuilder(final RuleConfigurationEventBuilder ruleConfigurationEventBuilder) {
Plugins.getMemberAccessor().set(StandaloneMetaDataManagerPersistService.class.getDeclaredField("ruleConfigEventBuilder"), metaDataManagerPersistService, ruleConfigurationEventBuilder);
private void setRuleConfigurationEventBuilder(final RuleConfigurationChangedEventBuilder ruleConfigurationEventBuilder) {
Plugins.getMemberAccessor().set(StandaloneMetaDataManagerPersistService.class.getDeclaredField("ruleConfigChangedEventBuilder"), metaDataManagerPersistService, ruleConfigurationEventBuilder);
}
}

0 comments on commit c57a8f8

Please sign in to comment.