From 9455f8a45f1c2862aab517f52f3687f663c034e7 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sat, 14 Dec 2024 17:57:13 +0800 Subject: [PATCH] Rename RuleConfigurationChangedEventBuilder (#34056) --- ... RuleConfigurationChangedEventBuilder.java} | 6 +++--- ...eConfigurationChangedEventBuilderTest.java} | 6 +++--- .../type/DatabaseMetaDataChangedListener.java | 6 +++--- .../DatabaseMetaDataChangedListenerTest.java | 8 ++++---- ...tandaloneMetaDataManagerPersistService.java | 6 +++--- ...aloneMetaDataManagerPersistServiceTest.java | 18 +++++++++--------- 6 files changed, 25 insertions(+), 25 deletions(-) rename mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/{RuleConfigurationEventBuilder.java => RuleConfigurationChangedEventBuilder.java} (97%) rename mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/{RuleConfigurationEventBuilderTest.java => RuleConfigurationChangedEventBuilderTest.java} (95%) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilder.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilder.java similarity index 97% rename from mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilder.java rename to mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilder.java index fa071d22c41ee..9fe445fd099b4 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilder.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilder.java @@ -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 build(final String databaseName, final DataChangedEvent event) { for (RuleNodePathProvider each : ShardingSphereServiceLoader.getServiceInstances(RuleNodePathProvider.class)) { diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilderTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilderTest.java similarity index 95% rename from mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilderTest.java rename to mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilderTest.java index 01284e6a0ee7a..e9a1fbd1ea74d 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilderTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilderTest.java @@ -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}") @@ -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 actual = new RuleConfigurationEventBuilder().build("foo_db", new DataChangedEvent(eventKey, eventValue, type)); + Optional actual = new RuleConfigurationChangedEventBuilder().build("foo_db", new DataChangedEvent(eventKey, eventValue, type)); assertThat(actual.isPresent(), is(isEventPresent)); if (actual.isPresent()) { if (dispatchEventClass == AlterNamedRuleItemEvent.class) { diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java index 2e33d83316161..0342e18ec6cee 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java @@ -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; @@ -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) { @@ -78,7 +78,7 @@ private Optional 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 createSchemaChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java index a1a23a6aab3b3..1c663cfd84ca6 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java @@ -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; @@ -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}") diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java index 5e5482666b850..1518a07cc8486 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java @@ -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; @@ -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; @@ -302,7 +302,7 @@ public void alterRuleConfiguration(final String databaseName, final RuleConfigur } private Optional 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 diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java index 788bae7f66c42..7ba6f66770cd1 100644 --- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java +++ b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java @@ -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; @@ -173,9 +173,9 @@ void assertAlterRuleConfiguration() throws SQLException { Collection 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); @@ -192,10 +192,10 @@ void assertRemoveRuleConfigurationItem() throws SQLException { RuleConfiguration ruleConfig = mock(RuleConfiguration.class, RETURNS_DEEP_STUBS); Collection 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); } @@ -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); } }