diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/changed/BroadcastTableChangedProcessor.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/changed/BroadcastTableChangedProcessor.java index dd278cac2c1bc..5145b941137b4 100644 --- a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/changed/BroadcastTableChangedProcessor.java +++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/changed/BroadcastTableChangedProcessor.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.broadcast.metadata.nodepath.BroadcastRuleNodePathProvider; import org.apache.shardingsphere.broadcast.rule.BroadcastRule; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import java.util.LinkedHashSet; @@ -36,7 +36,7 @@ public final class BroadcastTableChangedProcessor implements RuleItemConfigurati @SuppressWarnings("unchecked") @Override - public BroadcastRuleConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public BroadcastRuleConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new BroadcastRuleConfiguration(YamlEngine.unmarshal(yamlContent, LinkedHashSet.class)); } @@ -46,13 +46,13 @@ public BroadcastRuleConfiguration findRuleConfiguration(final ShardingSphereData } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final BroadcastRuleConfiguration currentRuleConfig, final BroadcastRuleConfiguration toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final BroadcastRuleConfiguration currentRuleConfig, final BroadcastRuleConfiguration toBeChangedItemConfig) { currentRuleConfig.getTables().clear(); currentRuleConfig.getTables().addAll(toBeChangedItemConfig.getTables()); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final BroadcastRuleConfiguration currentRuleConfig) { + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final BroadcastRuleConfiguration currentRuleConfig) { currentRuleConfig.getTables().clear(); } diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/changed/BroadcastTableChangedProcessorTest.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/changed/BroadcastTableChangedProcessorTest.java index 408499af607a2..8c28e1eafb9c6 100644 --- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/changed/BroadcastTableChangedProcessorTest.java +++ b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/changed/BroadcastTableChangedProcessorTest.java @@ -22,8 +22,8 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.junit.jupiter.api.Test; @@ -44,8 +44,8 @@ class BroadcastTableChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - BroadcastRuleConfiguration actual = processor.swapRuleItemConfiguration(event, "- foo_tbl"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + BroadcastRuleConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, "- foo_tbl"); assertThat(actual.getTables(), is(Collections.singleton("foo_tbl"))); } @@ -65,18 +65,18 @@ private ShardingSphereDatabase mockDatabase(final BroadcastRuleConfiguration rul @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); BroadcastRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); BroadcastRuleConfiguration toBeChangedItemConfig = new BroadcastRuleConfiguration(new LinkedList<>(Collections.singleton("bar_tbl"))); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getTables(), is(Collections.singletonList("bar_tbl"))); } @Test void assertDropRuleItemConfiguration() { - DropRuleItemEvent event = mock(DropRuleItemEvent.class); + DropRuleItem dropRuleItem = mock(DropRuleItem.class); BroadcastRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getTables().isEmpty()); } diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessor.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessor.java index 57b652ab7ceb1..6101bcc4eb647 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessor.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessor.java @@ -24,10 +24,10 @@ import org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptTableRuleConfiguration; import org.apache.shardingsphere.encrypt.yaml.swapper.rule.YamlEncryptTableRuleConfigurationSwapper; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import java.util.LinkedHashMap; @@ -39,7 +39,7 @@ public final class EncryptTableChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public EncryptTableRuleConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public EncryptTableRuleConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new YamlEncryptTableRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlEncryptTableRuleConfiguration.class)); } @@ -50,15 +50,15 @@ public EncryptRuleConfiguration findRuleConfiguration(final ShardingSphereDataba } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final EncryptRuleConfiguration currentRuleConfig, final EncryptTableRuleConfiguration toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final EncryptRuleConfiguration currentRuleConfig, final EncryptTableRuleConfiguration toBeChangedItemConfig) { // TODO refactor DistSQL to only persist config currentRuleConfig.getTables().removeIf(each -> each.getName().equals(toBeChangedItemConfig.getName())); currentRuleConfig.getTables().add(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final EncryptRuleConfiguration currentRuleConfig) { - currentRuleConfig.getTables().removeIf(each -> each.getName().equals(((DropNamedRuleItemEvent) event).getItemName())); + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final EncryptRuleConfiguration currentRuleConfig) { + currentRuleConfig.getTables().removeIf(each -> each.getName().equals(((DropNamedRuleItem) dropRuleItem).getItemName())); } @Override diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessorTest.java index dbf7962be265d..857b7fa7a7785 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessorTest.java @@ -29,9 +29,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -53,8 +53,8 @@ class EncryptTableChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - EncryptTableRuleConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + EncryptTableRuleConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new EncryptTableRuleConfiguration("foo_tbl", Collections.singletonList(new EncryptColumnRuleConfiguration("foo_col", new EncryptColumnItemRuleConfiguration("foo_col_cipher", "foo_algo")))))); } @@ -88,11 +88,11 @@ private ShardingSphereDatabase mockDatabase(final EncryptRuleConfiguration ruleC @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); EncryptRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); EncryptTableRuleConfiguration toBeChangedItemConfig = new EncryptTableRuleConfiguration("foo_tbl", Collections.singleton(new EncryptColumnRuleConfiguration("foo_col", new EncryptColumnItemRuleConfiguration("bar_col_cipher", "bar_algo")))); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getTables().size(), is(1)); assertThat(new ArrayList<>(currentRuleConfig.getTables()).get(0).getColumns().size(), is(1)); assertThat(new ArrayList<>(new ArrayList<>(currentRuleConfig.getTables()).get(0).getColumns()).get(0).getCipher().getName(), is("bar_col_cipher")); @@ -101,10 +101,10 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_tbl"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_tbl"); EncryptRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getTables().isEmpty()); } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptorChangedProcessorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptorChangedProcessorTest.java index c25d3ae25c3d9..e830f32f3c98b 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptorChangedProcessorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptorChangedProcessorTest.java @@ -22,9 +22,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -59,11 +59,11 @@ private ShardingSphereDatabase mockDatabase() { @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("bar_algo"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("bar_algo"); EncryptRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); AlgorithmConfiguration toBeChangedItemConfig = new AlgorithmConfiguration("BAR_FIXTURE", new Properties()); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getEncryptors().size(), is(2)); assertThat(currentRuleConfig.getEncryptors().get("foo_algo").getType(), is("FOO_FIXTURE")); assertThat(currentRuleConfig.getEncryptors().get("bar_algo").getType(), is("BAR_FIXTURE")); @@ -71,10 +71,10 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_algo"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_algo"); EncryptRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getEncryptors().isEmpty()); } diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/changed/MaskTableChangedProcessor.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/changed/MaskTableChangedProcessor.java index 8ee7950c8c106..eab4b8c0bc494 100644 --- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/changed/MaskTableChangedProcessor.java +++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/changed/MaskTableChangedProcessor.java @@ -25,9 +25,9 @@ import org.apache.shardingsphere.mask.rule.MaskRule; import org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskTableRuleConfiguration; import org.apache.shardingsphere.mask.yaml.swapper.rule.YamlMaskTableRuleConfigurationSwapper; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import java.util.LinkedHashMap; @@ -39,7 +39,7 @@ public final class MaskTableChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public MaskTableRuleConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public MaskTableRuleConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new YamlMaskTableRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlMaskTableRuleConfiguration.class)); } @@ -49,15 +49,15 @@ public MaskRuleConfiguration findRuleConfiguration(final ShardingSphereDatabase } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final MaskRuleConfiguration currentRuleConfig, final MaskTableRuleConfiguration toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final MaskRuleConfiguration currentRuleConfig, final MaskTableRuleConfiguration toBeChangedItemConfig) { // TODO refactor DistSQL to only persist config currentRuleConfig.getTables().removeIf(each -> each.getName().equals(toBeChangedItemConfig.getName())); currentRuleConfig.getTables().add(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final MaskRuleConfiguration currentRuleConfig) { - currentRuleConfig.getTables().removeIf(each -> each.getName().equals(((DropNamedRuleItemEvent) event).getItemName())); + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final MaskRuleConfiguration currentRuleConfig) { + currentRuleConfig.getTables().removeIf(each -> each.getName().equals(((DropNamedRuleItem) dropRuleItem).getItemName())); } @Override diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskAlgorithmChangedProcessorTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskAlgorithmChangedProcessorTest.java index 8334615594173..2a2ef3b39d230 100644 --- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskAlgorithmChangedProcessorTest.java +++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskAlgorithmChangedProcessorTest.java @@ -22,9 +22,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.mask.config.MaskRuleConfiguration; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -59,11 +59,11 @@ private ShardingSphereDatabase mockDatabase() { @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("bar_algo"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("bar_algo"); MaskRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); AlgorithmConfiguration toBeChangedItemConfig = new AlgorithmConfiguration("BAR_FIXTURE", new Properties()); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getMaskAlgorithms().size(), is(2)); assertThat(currentRuleConfig.getMaskAlgorithms().get("foo_algo").getType(), is("FOO_FIXTURE")); assertThat(currentRuleConfig.getMaskAlgorithms().get("bar_algo").getType(), is("BAR_FIXTURE")); @@ -71,10 +71,10 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_algo"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_algo"); MaskRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getMaskAlgorithms().isEmpty()); } diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskTableChangedProcessorTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskTableChangedProcessorTest.java index 9844e0c5ddc41..aa5b5811cda63 100644 --- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskTableChangedProcessorTest.java +++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskTableChangedProcessorTest.java @@ -27,9 +27,9 @@ import org.apache.shardingsphere.mask.rule.MaskRule; import org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskColumnRuleConfiguration; import org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskTableRuleConfiguration; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -51,8 +51,8 @@ class MaskTableChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - MaskTableRuleConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + MaskTableRuleConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new MaskTableRuleConfiguration("foo_tbl", Collections.singletonList(new MaskColumnRuleConfiguration("foo_col", "foo_algo"))))); } @@ -82,21 +82,21 @@ private ShardingSphereDatabase mockDatabase(final MaskRuleConfiguration ruleConf @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_tbl"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("foo_tbl"); MaskRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); MaskTableRuleConfiguration toBeChangedItemConfig = new MaskTableRuleConfiguration("foo_tbl", Collections.singleton(mock(MaskColumnRuleConfiguration.class))); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getTables().size(), is(1)); assertThat(new ArrayList<>(currentRuleConfig.getTables()).get(0).getColumns().size(), is(1)); } @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_tbl"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_tbl"); MaskRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getTables().isEmpty()); } diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java index da07516749626..b0c7d3c530fa1 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java @@ -20,10 +20,10 @@ import com.google.common.base.Strings; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.config.rule.ReadwriteSplittingDataSourceGroupRuleConfiguration; @@ -43,9 +43,9 @@ public final class ReadwriteSplittingDataSourceChangedProcessor RuleItemConfigurationChangedProcessor { @Override - public ReadwriteSplittingDataSourceGroupRuleConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public ReadwriteSplittingDataSourceGroupRuleConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { YamlReadwriteSplittingDataSourceGroupRuleConfiguration yamlDataSourceGroupRuleConfig = YamlEngine.unmarshal(yamlContent, YamlReadwriteSplittingDataSourceGroupRuleConfiguration.class); - return new ReadwriteSplittingDataSourceGroupRuleConfiguration(((AlterNamedRuleItemEvent) event).getItemName(), yamlDataSourceGroupRuleConfig.getWriteDataSourceName(), + return new ReadwriteSplittingDataSourceGroupRuleConfiguration(((AlterNamedRuleItem) alterRuleItem).getItemName(), yamlDataSourceGroupRuleConfig.getWriteDataSourceName(), yamlDataSourceGroupRuleConfig.getReadDataSourceNames(), getTransactionalReadQueryStrategy(yamlDataSourceGroupRuleConfig), yamlDataSourceGroupRuleConfig.getLoadBalancerName()); } @@ -62,7 +62,7 @@ public ReadwriteSplittingRuleConfiguration findRuleConfiguration(final ShardingS } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ReadwriteSplittingRuleConfiguration currentRuleConfig, + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ReadwriteSplittingDataSourceGroupRuleConfiguration toBeChangedItemConfig) { // TODO refactor DistSQL to only persist config currentRuleConfig.getDataSourceGroups().removeIf(each -> each.getName().equals(toBeChangedItemConfig.getName())); @@ -70,8 +70,8 @@ public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final Re } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ReadwriteSplittingRuleConfiguration currentRuleConfig) { - currentRuleConfig.getDataSourceGroups().removeIf(each -> each.getName().equals(((DropNamedRuleItemEvent) event).getItemName())); + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ReadwriteSplittingRuleConfiguration currentRuleConfig) { + currentRuleConfig.getDataSourceGroups().removeIf(each -> each.getName().equals(((DropNamedRuleItem) dropRuleItem).getItemName())); } @Override diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessorTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessorTest.java index 1ed47ee1cf18e..f0d2f66585aed 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessorTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.config.rule.ReadwriteSplittingDataSourceGroupRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule; @@ -50,17 +50,17 @@ class ReadwriteSplittingDataSourceChangedProcessorTest { @Test void assertSwapRuleItemConfigurationWithoutTransactionalReadQueryStrategy() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo"); - ReadwriteSplittingDataSourceGroupRuleConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent(null)); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("foo"); + ReadwriteSplittingDataSourceGroupRuleConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent(null)); assertThat(actual, deepEqual(new ReadwriteSplittingDataSourceGroupRuleConfiguration("foo", "write_ds", Collections.singletonList("read_ds"), "foo_balancer"))); } @Test void assertSwapRuleItemConfigurationWithTransactionalReadQueryStrategy() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo"); - ReadwriteSplittingDataSourceGroupRuleConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent(TransactionalReadQueryStrategy.PRIMARY)); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("foo"); + ReadwriteSplittingDataSourceGroupRuleConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent(TransactionalReadQueryStrategy.PRIMARY)); assertThat(actual, deepEqual(new ReadwriteSplittingDataSourceGroupRuleConfiguration( "foo", "write_ds", Collections.singletonList("read_ds"), TransactionalReadQueryStrategy.PRIMARY, "foo_balancer"))); } @@ -90,21 +90,21 @@ private ShardingSphereDatabase mockDatabase(final ReadwriteSplittingRuleConfigur @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("foo"); ReadwriteSplittingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); ReadwriteSplittingDataSourceGroupRuleConfiguration toBeChangedItemConfig = new ReadwriteSplittingDataSourceGroupRuleConfiguration( "foo", "write_ds", Collections.singletonList("read_ds"), TransactionalReadQueryStrategy.FIXED, "foo_balancer"); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(new ArrayList<>(currentRuleConfig.getDataSourceGroups()).get(0).getTransactionalReadQueryStrategy(), is(TransactionalReadQueryStrategy.FIXED)); } @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo"); ReadwriteSplittingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getDataSourceGroups().isEmpty()); } diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingLoadBalancerChangedProcessorTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingLoadBalancerChangedProcessorTest.java index 065bc88043019..92b132b24a9b1 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingLoadBalancerChangedProcessorTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingLoadBalancerChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration; import org.junit.jupiter.api.Test; @@ -59,11 +59,11 @@ private ShardingSphereDatabase mockDatabase() { @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("bar_algo"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("bar_algo"); ReadwriteSplittingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); AlgorithmConfiguration toBeChangedItemConfig = new AlgorithmConfiguration("BAR_FIXTURE", new Properties()); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getLoadBalancers().size(), is(2)); assertThat(currentRuleConfig.getLoadBalancers().get("foo_algo").getType(), is("FOO_FIXTURE")); assertThat(currentRuleConfig.getLoadBalancers().get("bar_algo").getType(), is("BAR_FIXTURE")); @@ -71,10 +71,10 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_algo"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_algo"); ReadwriteSplittingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getLoadBalancers().isEmpty()); } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessor.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessor.java index a8f365ad203f1..24e11c2fdd3ee 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessor.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessor.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.shadow.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -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.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.metadata.nodepath.ShadowRuleNodePathProvider; @@ -31,7 +31,7 @@ public final class DefaultShadowAlgorithmNameChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public String swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public String swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return yamlContent; } @@ -41,12 +41,12 @@ public ShadowRuleConfiguration findRuleConfiguration(final ShardingSphereDatabas } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShadowRuleConfiguration currentRuleConfig, final String toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShadowRuleConfiguration currentRuleConfig, final String toBeChangedItemConfig) { currentRuleConfig.setDefaultShadowAlgorithmName(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShadowRuleConfiguration currentRuleConfig) { + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShadowRuleConfiguration currentRuleConfig) { currentRuleConfig.setDefaultShadowAlgorithmName(null); } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowDataSourceChangedProcessor.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowDataSourceChangedProcessor.java index aec21bea9f0ca..d49863e4e9aa8 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowDataSourceChangedProcessor.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowDataSourceChangedProcessor.java @@ -18,11 +18,11 @@ package org.apache.shardingsphere.shadow.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.config.datasource.ShadowDataSourceConfiguration; @@ -36,9 +36,9 @@ public final class ShadowDataSourceChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public ShadowDataSourceConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public ShadowDataSourceConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { YamlShadowDataSourceConfiguration yamlConfig = YamlEngine.unmarshal(yamlContent, YamlShadowDataSourceConfiguration.class); - return new ShadowDataSourceConfiguration(((AlterNamedRuleItemEvent) event).getItemName(), yamlConfig.getProductionDataSourceName(), yamlConfig.getShadowDataSourceName()); + return new ShadowDataSourceConfiguration(((AlterNamedRuleItem) alterRuleItem).getItemName(), yamlConfig.getProductionDataSourceName(), yamlConfig.getShadowDataSourceName()); } @Override @@ -47,15 +47,15 @@ public ShadowRuleConfiguration findRuleConfiguration(final ShardingSphereDatabas } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShadowRuleConfiguration currentRuleConfig, final ShadowDataSourceConfiguration toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShadowRuleConfiguration currentRuleConfig, final ShadowDataSourceConfiguration toBeChangedItemConfig) { // TODO refactor DistSQL to only persist config currentRuleConfig.getDataSources().removeIf(each -> each.getName().equals(toBeChangedItemConfig.getName())); currentRuleConfig.getDataSources().add(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShadowRuleConfiguration currentRuleConfig) { - currentRuleConfig.getDataSources().removeIf(each -> each.getName().equals(((DropNamedRuleItemEvent) event).getItemName())); + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShadowRuleConfiguration currentRuleConfig) { + currentRuleConfig.getDataSources().removeIf(each -> each.getName().equals(((DropNamedRuleItem) dropRuleItem).getItemName())); } @Override diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowTableChangedProcessor.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowTableChangedProcessor.java index 819a7acd54d9f..acf835f74c27d 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowTableChangedProcessor.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowTableChangedProcessor.java @@ -18,11 +18,11 @@ package org.apache.shardingsphere.shadow.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.config.table.ShadowTableConfiguration; @@ -37,7 +37,7 @@ public final class ShadowTableChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public ShadowTableConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public ShadowTableConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new YamlShadowTableConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlShadowTableConfiguration.class)); } @@ -47,13 +47,13 @@ public ShadowRuleConfiguration findRuleConfiguration(final ShardingSphereDatabas } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShadowRuleConfiguration currentRuleConfig, final ShadowTableConfiguration toBeChangedItemConfig) { - currentRuleConfig.getTables().put(((AlterNamedRuleItemEvent) event).getItemName(), toBeChangedItemConfig); + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShadowRuleConfiguration currentRuleConfig, final ShadowTableConfiguration toBeChangedItemConfig) { + currentRuleConfig.getTables().put(((AlterNamedRuleItem) alterRuleItem).getItemName(), toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShadowRuleConfiguration currentRuleConfig) { - currentRuleConfig.getTables().remove(((DropNamedRuleItemEvent) event).getItemName()); + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShadowRuleConfiguration currentRuleConfig) { + currentRuleConfig.getTables().remove(((DropNamedRuleItem) dropRuleItem).getItemName()); } @Override diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessorTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessorTest.java index 755655258cc8c..1a2d198f99095 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessorTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessorTest.java @@ -20,9 +20,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.junit.jupiter.api.Test; @@ -43,8 +43,8 @@ class DefaultShadowAlgorithmNameChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - String actual = processor.swapRuleItemConfiguration(event, "foo_algo"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + String actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, "foo_algo"); assertThat(actual, is("foo_algo")); } @@ -64,19 +64,19 @@ private ShardingSphereDatabase mockDatabase(final ShadowRuleConfiguration ruleCo @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); ShadowRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); String toBeChangedItemConfig = "bar_algo"; - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getDefaultShadowAlgorithmName(), is("bar_algo")); } @Test void assertDropRuleItemConfiguration() { - DropRuleItemEvent event = mock(DropRuleItemEvent.class); + DropRuleItem dropRuleItem = mock(DropRuleItem.class); ShadowRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); currentRuleConfig.setDefaultShadowAlgorithmName("foo_algo"); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropRuleItem, currentRuleConfig); assertNull(currentRuleConfig.getDefaultShadowAlgorithmName()); } diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowAlgorithmChangedProcessorTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowAlgorithmChangedProcessorTest.java index a17e8711b0f59..c169b465c2a55 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowAlgorithmChangedProcessorTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowAlgorithmChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration; import org.junit.jupiter.api.Test; @@ -56,11 +56,11 @@ private ShardingSphereDatabase mockDatabase() { @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("bar_algo"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("bar_algo"); ShadowRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); AlgorithmConfiguration toBeChangedItemConfig = new AlgorithmConfiguration("BAR_FIXTURE", new Properties()); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getShadowAlgorithms().size(), is(2)); assertThat(currentRuleConfig.getShadowAlgorithms().get("foo_algo").getType(), is("FOO_FIXTURE")); assertThat(currentRuleConfig.getShadowAlgorithms().get("bar_algo").getType(), is("BAR_FIXTURE")); @@ -68,10 +68,10 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_algo"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_algo"); ShadowRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getShadowAlgorithms().isEmpty()); } diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowDataSourceChangedProcessorTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowDataSourceChangedProcessorTest.java index 26644475dc777..3cc3662b9c0a4 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowDataSourceChangedProcessorTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowDataSourceChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.config.datasource.ShadowDataSourceConfiguration; import org.apache.shardingsphere.shadow.rule.ShadowRule; @@ -48,9 +48,9 @@ class ShadowDataSourceChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_ds"); - ShadowDataSourceConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("foo_ds"); + ShadowDataSourceConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new ShadowDataSourceConfiguration("foo_ds", "prod_ds", "shadow_ds"))); } @@ -77,10 +77,10 @@ private ShardingSphereDatabase mockDatabase(final ShadowRuleConfiguration ruleCo @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); ShadowRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); ShadowDataSourceConfiguration toBeChangedItemConfig = new ShadowDataSourceConfiguration("foo_ds", "new_prod_ds", "new_shadow_ds"); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getDataSources().size(), is(1)); assertThat(new ArrayList<>(currentRuleConfig.getDataSources()).get(0).getProductionDataSourceName(), is("new_prod_ds")); assertThat(new ArrayList<>(currentRuleConfig.getDataSources()).get(0).getShadowDataSourceName(), is("new_shadow_ds")); @@ -88,10 +88,10 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_tbl"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_tbl"); ShadowRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getTables().isEmpty()); } diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowTableChangedProcessorTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowTableChangedProcessorTest.java index 8766a5aaafd1b..a934d87bdd9ac 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowTableChangedProcessorTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/changed/ShadowTableChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.config.table.ShadowTableConfiguration; import org.apache.shardingsphere.shadow.rule.ShadowRule; @@ -47,8 +47,8 @@ class ShadowTableChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - ShadowTableConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + ShadowTableConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new ShadowTableConfiguration(Collections.singletonList("foo_ds"), Collections.singletonList("foo_algo")))); } @@ -75,11 +75,11 @@ private ShardingSphereDatabase mockDatabase(final ShadowRuleConfiguration ruleCo @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_tbl"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("foo_tbl"); ShadowRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); ShadowTableConfiguration toBeChangedItemConfig = new ShadowTableConfiguration(Collections.singletonList("bar_ds"), Collections.singletonList("bar_algo")); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getTables().size(), is(1)); assertThat(currentRuleConfig.getTables().get("foo_tbl").getDataSourceNames(), is(Collections.singletonList("bar_ds"))); assertThat(currentRuleConfig.getTables().get("foo_tbl").getShadowAlgorithmNames(), is(Collections.singletonList("bar_algo"))); @@ -87,10 +87,10 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_tbl"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_tbl"); ShadowRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getTables().isEmpty()); } diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultDatabaseShardingStrategyChangedProcessor.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultDatabaseShardingStrategyChangedProcessor.java index 7050e71236937..6d18cf0fe4b4d 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultDatabaseShardingStrategyChangedProcessor.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultDatabaseShardingStrategyChangedProcessor.java @@ -18,9 +18,9 @@ package org.apache.shardingsphere.sharding.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration; @@ -35,7 +35,7 @@ public final class DefaultDatabaseShardingStrategyChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public ShardingStrategyConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public ShardingStrategyConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new YamlShardingStrategyConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlShardingStrategyConfiguration.class)); } @@ -45,12 +45,12 @@ public ShardingRuleConfiguration findRuleConfiguration(final ShardingSphereDatab } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig, final ShardingStrategyConfiguration toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShardingRuleConfiguration currentRuleConfig, final ShardingStrategyConfiguration toBeChangedItemConfig) { currentRuleConfig.setDefaultDatabaseShardingStrategy(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig) { + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShardingRuleConfiguration currentRuleConfig) { currentRuleConfig.setDefaultDatabaseShardingStrategy(null); } diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultKeyGenerateStrategyChangedProcessor.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultKeyGenerateStrategyChangedProcessor.java index fb8efef752a91..ea63593d7f9ad 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultKeyGenerateStrategyChangedProcessor.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultKeyGenerateStrategyChangedProcessor.java @@ -18,9 +18,9 @@ package org.apache.shardingsphere.sharding.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration; @@ -35,7 +35,7 @@ public final class DefaultKeyGenerateStrategyChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public KeyGenerateStrategyConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public KeyGenerateStrategyConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new YamlKeyGenerateStrategyConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlKeyGenerateStrategyConfiguration.class)); } @@ -45,12 +45,12 @@ public ShardingRuleConfiguration findRuleConfiguration(final ShardingSphereDatab } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig, final KeyGenerateStrategyConfiguration toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShardingRuleConfiguration currentRuleConfig, final KeyGenerateStrategyConfiguration toBeChangedItemConfig) { currentRuleConfig.setDefaultKeyGenerateStrategy(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig) { + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShardingRuleConfiguration currentRuleConfig) { currentRuleConfig.setDefaultKeyGenerateStrategy(null); } diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingAuditorStrategyChangedProcessor.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingAuditorStrategyChangedProcessor.java index f9f51c42726fe..bb3df192e2ab6 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingAuditorStrategyChangedProcessor.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingAuditorStrategyChangedProcessor.java @@ -18,9 +18,9 @@ package org.apache.shardingsphere.sharding.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration; @@ -35,7 +35,7 @@ public final class DefaultShardingAuditorStrategyChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public ShardingAuditStrategyConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public ShardingAuditStrategyConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new YamlShardingAuditStrategyConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlShardingAuditStrategyConfiguration.class)); } @@ -45,12 +45,12 @@ public ShardingRuleConfiguration findRuleConfiguration(final ShardingSphereDatab } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig, final ShardingAuditStrategyConfiguration toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShardingRuleConfiguration currentRuleConfig, final ShardingAuditStrategyConfiguration toBeChangedItemConfig) { currentRuleConfig.setDefaultAuditStrategy(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig) { + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShardingRuleConfiguration currentRuleConfig) { currentRuleConfig.setDefaultAuditStrategy(null); } diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingColumnChangedProcessor.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingColumnChangedProcessor.java index fb6abbdbf4d11..32e4f748ba98d 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingColumnChangedProcessor.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingColumnChangedProcessor.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.sharding.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -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.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.metadata.nodepath.ShardingRuleNodePathProvider; @@ -31,7 +31,7 @@ public final class DefaultShardingColumnChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public String swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public String swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return yamlContent; } @@ -41,12 +41,12 @@ public ShardingRuleConfiguration findRuleConfiguration(final ShardingSphereDatab } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig, final String toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShardingRuleConfiguration currentRuleConfig, final String toBeChangedItemConfig) { currentRuleConfig.setDefaultShardingColumn(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig) { + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShardingRuleConfiguration currentRuleConfig) { currentRuleConfig.setDefaultShardingColumn(null); } diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultTableShardingStrategyChangedProcessor.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultTableShardingStrategyChangedProcessor.java index c272c476bb91a..75901a5abab7b 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultTableShardingStrategyChangedProcessor.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/DefaultTableShardingStrategyChangedProcessor.java @@ -18,9 +18,9 @@ package org.apache.shardingsphere.sharding.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration; @@ -35,7 +35,7 @@ public final class DefaultTableShardingStrategyChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public ShardingStrategyConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public ShardingStrategyConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new YamlShardingStrategyConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlShardingStrategyConfiguration.class)); } @@ -45,12 +45,12 @@ public ShardingRuleConfiguration findRuleConfiguration(final ShardingSphereDatab } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig, final ShardingStrategyConfiguration toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShardingRuleConfiguration currentRuleConfig, final ShardingStrategyConfiguration toBeChangedItemConfig) { currentRuleConfig.setDefaultTableShardingStrategy(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig) { + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShardingRuleConfiguration currentRuleConfig) { currentRuleConfig.setDefaultTableShardingStrategy(null); } diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAutoTableChangedProcessor.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAutoTableChangedProcessor.java index 672449bbc1470..6474b8fadff4e 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAutoTableChangedProcessor.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAutoTableChangedProcessor.java @@ -18,11 +18,11 @@ package org.apache.shardingsphere.sharding.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; @@ -37,7 +37,7 @@ public final class ShardingAutoTableChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public ShardingAutoTableRuleConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public ShardingAutoTableRuleConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new YamlShardingAutoTableRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlShardingAutoTableRuleConfiguration.class)); } @@ -47,14 +47,14 @@ public ShardingRuleConfiguration findRuleConfiguration(final ShardingSphereDatab } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig, final ShardingAutoTableRuleConfiguration toBeChangedItemConfig) { - currentRuleConfig.getAutoTables().removeIf(each -> each.getLogicTable().equals(((AlterNamedRuleItemEvent) event).getItemName())); + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShardingRuleConfiguration currentRuleConfig, final ShardingAutoTableRuleConfiguration toBeChangedItemConfig) { + currentRuleConfig.getAutoTables().removeIf(each -> each.getLogicTable().equals(((AlterNamedRuleItem) alterRuleItem).getItemName())); currentRuleConfig.getAutoTables().add(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig) { - currentRuleConfig.getAutoTables().removeIf(each -> each.getLogicTable().equals(((DropNamedRuleItemEvent) event).getItemName())); + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShardingRuleConfiguration currentRuleConfig) { + currentRuleConfig.getAutoTables().removeIf(each -> each.getLogicTable().equals(((DropNamedRuleItem) dropRuleItem).getItemName())); } @Override diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessor.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessor.java index 3a31029c7fe8a..f54ef5851d5fc 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessor.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessor.java @@ -18,9 +18,9 @@ package org.apache.shardingsphere.sharding.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheConfiguration; @@ -35,7 +35,7 @@ public final class ShardingCacheChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public ShardingCacheConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public ShardingCacheConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new YamlShardingCacheConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlShardingCacheConfiguration.class)); } @@ -45,12 +45,12 @@ public ShardingRuleConfiguration findRuleConfiguration(final ShardingSphereDatab } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig, final ShardingCacheConfiguration toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShardingRuleConfiguration currentRuleConfig, final ShardingCacheConfiguration toBeChangedItemConfig) { currentRuleConfig.setShardingCache(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig) { + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShardingRuleConfiguration currentRuleConfig) { currentRuleConfig.setShardingCache(null); } diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableChangedProcessor.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableChangedProcessor.java index 0029fa907dd15..6065236c3a358 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableChangedProcessor.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableChangedProcessor.java @@ -18,11 +18,11 @@ package org.apache.shardingsphere.sharding.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -37,7 +37,7 @@ public final class ShardingTableChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public ShardingTableRuleConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public ShardingTableRuleConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new YamlShardingTableRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlTableRuleConfiguration.class)); } @@ -47,14 +47,14 @@ public ShardingRuleConfiguration findRuleConfiguration(final ShardingSphereDatab } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig, final ShardingTableRuleConfiguration toBeChangedItemConfig) { - currentRuleConfig.getTables().removeIf(each -> each.getLogicTable().equals(((AlterNamedRuleItemEvent) event).getItemName())); + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShardingRuleConfiguration currentRuleConfig, final ShardingTableRuleConfiguration toBeChangedItemConfig) { + currentRuleConfig.getTables().removeIf(each -> each.getLogicTable().equals(((AlterNamedRuleItem) alterRuleItem).getItemName())); currentRuleConfig.getTables().add(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig) { - currentRuleConfig.getTables().removeIf(each -> each.getLogicTable().equals(((DropNamedRuleItemEvent) event).getItemName())); + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShardingRuleConfiguration currentRuleConfig) { + currentRuleConfig.getTables().removeIf(each -> each.getLogicTable().equals(((DropNamedRuleItem) dropRuleItem).getItemName())); } @Override diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableReferenceChangedProcessor.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableReferenceChangedProcessor.java index cc70702e9992e..cf6ee35c658ff 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableReferenceChangedProcessor.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableReferenceChangedProcessor.java @@ -18,10 +18,10 @@ package org.apache.shardingsphere.sharding.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration; @@ -35,7 +35,7 @@ public final class ShardingTableReferenceChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public ShardingTableReferenceRuleConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public ShardingTableReferenceRuleConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return YamlShardingTableReferenceRuleConfigurationConverter.convertToObject(yamlContent); } @@ -45,14 +45,14 @@ public ShardingRuleConfiguration findRuleConfiguration(final ShardingSphereDatab } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig, final ShardingTableReferenceRuleConfiguration toBeChangedItemConfig) { - currentRuleConfig.getBindingTableGroups().removeIf(each -> each.getName().equals(((AlterNamedRuleItemEvent) event).getItemName())); + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final ShardingRuleConfiguration currentRuleConfig, final ShardingTableReferenceRuleConfiguration toBeChangedItemConfig) { + currentRuleConfig.getBindingTableGroups().removeIf(each -> each.getName().equals(((AlterNamedRuleItem) alterRuleItem).getItemName())); currentRuleConfig.getBindingTableGroups().add(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final ShardingRuleConfiguration currentRuleConfig) { - currentRuleConfig.getBindingTableGroups().removeIf(each -> each.getName().equals(((DropNamedRuleItemEvent) event).getItemName())); + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final ShardingRuleConfiguration currentRuleConfig) { + currentRuleConfig.getBindingTableGroups().removeIf(each -> each.getName().equals(((DropNamedRuleItem) dropRuleItem).getItemName())); } @Override diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultDatabaseShardingStrategyChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultDatabaseShardingStrategyChangedProcessorTest.java index 4d43303d33572..77c7598baf98e 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultDatabaseShardingStrategyChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultDatabaseShardingStrategyChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.HintShardingStrategyConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration; @@ -50,8 +50,8 @@ class DefaultDatabaseShardingStrategyChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - ShardingStrategyConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + ShardingStrategyConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new NoneShardingStrategyConfiguration())); } @@ -77,18 +77,18 @@ private ShardingSphereDatabase mockDatabase(final ShardingRuleConfiguration rule @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); ShardingStrategyConfiguration toBeChangedItemConfig = new HintShardingStrategyConfiguration("foo_algo"); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getDefaultDatabaseShardingStrategy().getShardingAlgorithmName(), is("foo_algo")); } @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertNull(currentRuleConfig.getDefaultDatabaseShardingStrategy()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultKeyGenerateStrategyChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultKeyGenerateStrategyChangedProcessorTest.java index bc349b7c70e73..6f0bfc116bd72 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultKeyGenerateStrategyChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultKeyGenerateStrategyChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -47,8 +47,8 @@ class DefaultKeyGenerateStrategyChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - KeyGenerateStrategyConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + KeyGenerateStrategyConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new KeyGenerateStrategyConfiguration("foo_col", "foo_algo"))); } @@ -75,18 +75,18 @@ private ShardingSphereDatabase mockDatabase(final ShardingRuleConfiguration rule @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); KeyGenerateStrategyConfiguration toBeChangedItemConfig = new KeyGenerateStrategyConfiguration("foo_col", "bar_algo"); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getDefaultKeyGenerateStrategy().getKeyGeneratorName(), is("bar_algo")); } @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertNull(currentRuleConfig.getDefaultKeyGenerateStrategy()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingAuditorStrategyChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingAuditorStrategyChangedProcessorTest.java index 42182a26faa4e..fbd78abd4495c 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingAuditorStrategyChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingAuditorStrategyChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -48,8 +48,8 @@ class DefaultShardingAuditorStrategyChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - ShardingAuditStrategyConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + ShardingAuditStrategyConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new ShardingAuditStrategyConfiguration(Collections.singletonList("foo_algo"), true))); } @@ -75,19 +75,19 @@ private ShardingSphereDatabase mockDatabase(final ShardingRuleConfiguration rule @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); ShardingAuditStrategyConfiguration toBeChangedItemConfig = new ShardingAuditStrategyConfiguration(Collections.singleton("bar_algo"), true); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getDefaultAuditStrategy().getAuditorNames(), is(Collections.singleton("bar_algo"))); assertTrue(currentRuleConfig.getDefaultAuditStrategy().isAllowHintDisable()); } @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertNull(currentRuleConfig.getDefaultAuditStrategy()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingColumnChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingColumnChangedProcessorTest.java index 5d020a2b62ed3..c023a85e6fa5d 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingColumnChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultShardingColumnChangedProcessorTest.java @@ -20,9 +20,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.junit.jupiter.api.Test; @@ -43,8 +43,8 @@ class DefaultShardingColumnChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - String actual = processor.swapRuleItemConfiguration(event, "foo_col"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + String actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, "foo_col"); assertThat(actual, is("foo_col")); } @@ -64,19 +64,19 @@ private ShardingSphereDatabase mockDatabase(final ShardingRuleConfiguration rule @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); String toBeChangedItemConfig = "bar_col"; - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getDefaultShardingColumn(), is("bar_col")); } @Test void assertDropRuleItemConfiguration() { - DropRuleItemEvent event = mock(DropRuleItemEvent.class); + DropRuleItem dropRuleItem = mock(DropRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); currentRuleConfig.setDefaultShardingColumn("foo_col"); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropRuleItem, currentRuleConfig); assertNull(currentRuleConfig.getDefaultShardingColumn()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultTableShardingStrategyChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultTableShardingStrategyChangedProcessorTest.java index c5039f9443fc7..72c6624cde1ee 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultTableShardingStrategyChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/DefaultTableShardingStrategyChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.HintShardingStrategyConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration; @@ -50,8 +50,8 @@ class DefaultTableShardingStrategyChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - ShardingStrategyConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + ShardingStrategyConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new NoneShardingStrategyConfiguration())); } @@ -77,18 +77,18 @@ private ShardingSphereDatabase mockDatabase(final ShardingRuleConfiguration rule @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); ShardingStrategyConfiguration toBeChangedItemConfig = new HintShardingStrategyConfiguration("foo_algo"); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getDefaultTableShardingStrategy().getShardingAlgorithmName(), is("foo_algo")); } @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertNull(currentRuleConfig.getDefaultTableShardingStrategy()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/KeyGeneratorChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/KeyGeneratorChangedProcessorTest.java index a2cd6e36d27c1..aba58d8dee8cc 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/KeyGeneratorChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/KeyGeneratorChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.junit.jupiter.api.Test; @@ -56,11 +56,11 @@ private ShardingSphereDatabase mockDatabase() { @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("bar_algo"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("bar_algo"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); AlgorithmConfiguration toBeChangedItemConfig = new AlgorithmConfiguration("BAR_FIXTURE", new Properties()); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getKeyGenerators().size(), is(2)); assertThat(currentRuleConfig.getKeyGenerators().get("foo_algo").getType(), is("FOO_FIXTURE")); assertThat(currentRuleConfig.getKeyGenerators().get("bar_algo").getType(), is("BAR_FIXTURE")); @@ -68,10 +68,10 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_algo"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_algo"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getKeyGenerators().isEmpty()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAlgorithmChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAlgorithmChangedProcessorTest.java index d3ae6c720b971..abea0fa847ff9 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAlgorithmChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAlgorithmChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.junit.jupiter.api.Test; @@ -56,11 +56,11 @@ private ShardingSphereDatabase mockDatabase() { @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("bar_algo"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("bar_algo"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); AlgorithmConfiguration toBeChangedItemConfig = new AlgorithmConfiguration("BAR_FIXTURE", new Properties()); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getShardingAlgorithms().size(), is(2)); assertThat(currentRuleConfig.getShardingAlgorithms().get("foo_algo").getType(), is("FOO_FIXTURE")); assertThat(currentRuleConfig.getShardingAlgorithms().get("bar_algo").getType(), is("BAR_FIXTURE")); @@ -68,10 +68,10 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_algo"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_algo"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getShardingAlgorithms().isEmpty()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAuditorChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAuditorChangedProcessorTest.java index 5ba4bb81f848b..f45b928c86846 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAuditorChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAuditorChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.junit.jupiter.api.Test; @@ -56,11 +56,11 @@ private ShardingSphereDatabase mockDatabase() { @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("bar_algo"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("bar_algo"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); AlgorithmConfiguration toBeChangedItemConfig = new AlgorithmConfiguration("BAR_FIXTURE", new Properties()); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getAuditors().size(), is(2)); assertThat(currentRuleConfig.getAuditors().get("foo_algo").getType(), is("FOO_FIXTURE")); assertThat(currentRuleConfig.getAuditors().get("bar_algo").getType(), is("BAR_FIXTURE")); @@ -68,10 +68,10 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_algo"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_algo"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getAuditors().isEmpty()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAutoTableChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAutoTableChangedProcessorTest.java index 80bac9209f826..34721acdee7f2 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAutoTableChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAutoTableChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -48,8 +48,8 @@ class ShardingAutoTableChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - ShardingAutoTableRuleConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + ShardingAutoTableRuleConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new ShardingAutoTableRuleConfiguration("foo_tbl", "foo_ds"))); } @@ -76,21 +76,21 @@ private ShardingSphereDatabase mockDatabase(final ShardingRuleConfiguration rule @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_tbl"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("foo_tbl"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); ShardingAutoTableRuleConfiguration toBeChangedItemConfig = new ShardingAutoTableRuleConfiguration("foo_tbl", "bar_ds"); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getAutoTables().size(), is(1)); assertThat(new ArrayList<>(currentRuleConfig.getAutoTables()).get(0).getActualDataSources(), is("bar_ds")); } @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_tbl"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_tbl"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getAutoTables().isEmpty()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessorTest.java index fe25dfde0ab50..8bb32d9ded14c 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheConfiguration; import org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheOptionsConfiguration; @@ -50,8 +50,8 @@ class ShardingCacheChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - ShardingCacheConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + ShardingCacheConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new ShardingCacheConfiguration(1, new ShardingCacheOptionsConfiguration(true, 128, 1024)))); } @@ -82,10 +82,10 @@ private ShardingSphereDatabase mockDatabase(final ShardingRuleConfiguration rule @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); ShardingCacheConfiguration toBeChangedItemConfig = new ShardingCacheConfiguration(2, new ShardingCacheOptionsConfiguration(false, 1280, 10240)); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getShardingCache().getAllowedMaxSqlLength(), is(2)); assertFalse(currentRuleConfig.getShardingCache().getRouteCache().isSoftValues()); assertThat(currentRuleConfig.getShardingCache().getRouteCache().getInitialCapacity(), is(1280)); @@ -94,9 +94,9 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertNull(currentRuleConfig.getShardingCache()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableChangedProcessorTest.java index 671e450b48404..2d6f291e635b1 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableChangedProcessorTest.java @@ -21,9 +21,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -48,8 +48,8 @@ class ShardingTableChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - ShardingTableRuleConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + ShardingTableRuleConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new ShardingTableRuleConfiguration("foo_tbl", "foo_ds.foo_tbl"))); } @@ -76,21 +76,21 @@ private ShardingSphereDatabase mockDatabase(final ShardingRuleConfiguration rule @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_tbl"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("foo_tbl"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); ShardingTableRuleConfiguration toBeChangedItemConfig = new ShardingTableRuleConfiguration("foo_tbl", "bar_ds.bar_tbl"); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getTables().size(), is(1)); assertThat(new ArrayList<>(currentRuleConfig.getTables()).get(0).getActualDataNodes(), is("bar_ds.bar_tbl")); } @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_tbl"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_tbl"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getTables().isEmpty()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableReferenceChangedProcessorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableReferenceChangedProcessorTest.java index b78b740bffa78..b44f822dcfc49 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableReferenceChangedProcessorTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingTableReferenceChangedProcessorTest.java @@ -20,9 +20,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -46,8 +46,8 @@ class ShardingTableReferenceChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - ShardingTableReferenceRuleConfiguration actual = processor.swapRuleItemConfiguration(event, "foo_ref:foo_tbl_0,foo_tbl_1"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + ShardingTableReferenceRuleConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, "foo_ref:foo_tbl_0,foo_tbl_1"); assertThat(actual, deepEqual(new ShardingTableReferenceRuleConfiguration("foo_ref", "foo_tbl_0,foo_tbl_1"))); } @@ -67,11 +67,11 @@ private ShardingSphereDatabase mockDatabase(final ShardingRuleConfiguration rule @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_ref"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("foo_ref"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); ShardingTableReferenceRuleConfiguration toBeChangedItemConfig = new ShardingTableReferenceRuleConfiguration("foo_ref", "bar_tbl_0,bar_tbl_1"); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getBindingTableGroups().size(), is(1)); assertThat(new ArrayList<>(currentRuleConfig.getBindingTableGroups()).get(0).getName(), is("foo_ref")); assertThat(new ArrayList<>(currentRuleConfig.getBindingTableGroups()).get(0).getReference(), is("bar_tbl_0,bar_tbl_1")); @@ -79,10 +79,10 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_ref"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_ref"); ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getBindingTableGroups().isEmpty()); } diff --git a/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/processor/AlgorithmChangedProcessor.java b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/processor/AlgorithmChangedProcessor.java index 16bccca49accd..2a811a20314b8 100644 --- a/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/processor/AlgorithmChangedProcessor.java +++ b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/processor/AlgorithmChangedProcessor.java @@ -25,10 +25,10 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import java.util.Map; @@ -44,7 +44,7 @@ public abstract class AlgorithmChangedProcessor imp private final Class ruleClass; @Override - public final AlgorithmConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public final AlgorithmConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new YamlAlgorithmConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlAlgorithmConfiguration.class)); } @@ -55,13 +55,13 @@ public final T findRuleConfiguration(final ShardingSphereDatabase database) { } @Override - public final void changeRuleItemConfiguration(final AlterRuleItemEvent event, final T currentRuleConfig, final AlgorithmConfiguration toBeChangedItemConfig) { - getAlgorithmConfigurations(currentRuleConfig).put(((AlterNamedRuleItemEvent) event).getItemName(), toBeChangedItemConfig); + public final void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final T currentRuleConfig, final AlgorithmConfiguration toBeChangedItemConfig) { + getAlgorithmConfigurations(currentRuleConfig).put(((AlterNamedRuleItem) alterRuleItem).getItemName(), toBeChangedItemConfig); } @Override - public final void dropRuleItemConfiguration(final DropRuleItemEvent event, final T currentRuleConfig) { - getAlgorithmConfigurations(currentRuleConfig).remove(((DropNamedRuleItemEvent) event).getItemName()); + public final void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final T currentRuleConfig) { + getAlgorithmConfigurations(currentRuleConfig).remove(((DropNamedRuleItem) dropRuleItem).getItemName()); } protected abstract T createEmptyRuleConfiguration(); diff --git a/infra/algorithm/core/src/test/java/org/apache/shardingsphere/infra/algorithm/core/processor/AlgorithmChangedProcessorTest.java b/infra/algorithm/core/src/test/java/org/apache/shardingsphere/infra/algorithm/core/processor/AlgorithmChangedProcessorTest.java index d6c3dae120418..3e2021b195a71 100644 --- a/infra/algorithm/core/src/test/java/org/apache/shardingsphere/infra/algorithm/core/processor/AlgorithmChangedProcessorTest.java +++ b/infra/algorithm/core/src/test/java/org/apache/shardingsphere/infra/algorithm/core/processor/AlgorithmChangedProcessorTest.java @@ -25,9 +25,9 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -48,8 +48,8 @@ class AlgorithmChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - AlgorithmConfiguration actual = processor.swapRuleItemConfiguration(event, createYAMLContent()); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + AlgorithmConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, createYAMLContent()); assertThat(actual, deepEqual(new AlgorithmConfiguration("foo_algo", new Properties()))); } @@ -73,12 +73,12 @@ private ShardingSphereDatabase mockDatabase(final AlgorithmChangedProcessorFixtu @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("bar_algo"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + when(alterNamedRuleItem.getItemName()).thenReturn("bar_algo"); AlgorithmChangedProcessorFixtureRuleConfiguration currentRuleConfig = new AlgorithmChangedProcessorFixtureRuleConfiguration(); currentRuleConfig.getAlgorithmConfigurations().put("foo_algo", new AlgorithmConfiguration("FOO_FIXTURE", new Properties())); AlgorithmConfiguration toBeChangedItemConfig = new AlgorithmConfiguration("BAR_FIXTURE", new Properties()); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getAlgorithmConfigurations().size(), is(2)); assertThat(currentRuleConfig.getAlgorithmConfigurations().get("foo_algo").getType(), is("FOO_FIXTURE")); assertThat(currentRuleConfig.getAlgorithmConfigurations().get("bar_algo").getType(), is("BAR_FIXTURE")); @@ -86,11 +86,11 @@ void assertChangeRuleItemConfiguration() { @Test void assertDropRuleItemConfiguration() { - DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class); - when(event.getItemName()).thenReturn("foo_algo"); + DropNamedRuleItem dropNamedRuleItem = mock(DropNamedRuleItem.class); + when(dropNamedRuleItem.getItemName()).thenReturn("foo_algo"); AlgorithmChangedProcessorFixtureRuleConfiguration currentRuleConfig = new AlgorithmChangedProcessorFixtureRuleConfiguration(); currentRuleConfig.getAlgorithmConfigurations().put("foo_algo", new AlgorithmConfiguration("FOO_FIXTURE", new Properties())); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropNamedRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getAlgorithmConfigurations().isEmpty()); } } diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/changed/DefaultDataSourceChangedProcessor.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/changed/DefaultDataSourceChangedProcessor.java index 13a63a23a03f5..276c4104d820d 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/changed/DefaultDataSourceChangedProcessor.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/changed/DefaultDataSourceChangedProcessor.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.single.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -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.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.single.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.metadata.nodepath.SingleRuleNodePathProvider; @@ -31,7 +31,7 @@ public final class DefaultDataSourceChangedProcessor implements RuleItemConfigurationChangedProcessor { @Override - public String swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public String swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return yamlContent; } @@ -41,12 +41,12 @@ public SingleRuleConfiguration findRuleConfiguration(final ShardingSphereDatabas } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final SingleRuleConfiguration currentRuleConfig, final String toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final SingleRuleConfiguration currentRuleConfig, final String toBeChangedItemConfig) { currentRuleConfig.setDefaultDataSource(toBeChangedItemConfig); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final SingleRuleConfiguration currentRuleConfig) { + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final SingleRuleConfiguration currentRuleConfig) { currentRuleConfig.setDefaultDataSource(null); } diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/changed/SingleTableChangedProcessor.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/changed/SingleTableChangedProcessor.java index 099c95af387ca..70015c5b7d250 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/changed/SingleTableChangedProcessor.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/changed/SingleTableChangedProcessor.java @@ -18,9 +18,9 @@ package org.apache.shardingsphere.single.rule.changed; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.single.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.metadata.nodepath.SingleRuleNodePathProvider; @@ -35,7 +35,7 @@ public final class SingleTableChangedProcessor implements RuleItemConfigurationC @SuppressWarnings("unchecked") @Override - public SingleRuleConfiguration swapRuleItemConfiguration(final AlterRuleItemEvent event, final String yamlContent) { + public SingleRuleConfiguration swapRuleItemConfiguration(final AlterRuleItem alterRuleItem, final String yamlContent) { return new SingleRuleConfiguration(YamlEngine.unmarshal(yamlContent, LinkedHashSet.class), null); } @@ -45,13 +45,13 @@ public SingleRuleConfiguration findRuleConfiguration(final ShardingSphereDatabas } @Override - public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final SingleRuleConfiguration currentRuleConfig, final SingleRuleConfiguration toBeChangedItemConfig) { + public void changeRuleItemConfiguration(final AlterRuleItem alterRuleItem, final SingleRuleConfiguration currentRuleConfig, final SingleRuleConfiguration toBeChangedItemConfig) { currentRuleConfig.getTables().clear(); currentRuleConfig.getTables().addAll(toBeChangedItemConfig.getTables()); } @Override - public void dropRuleItemConfiguration(final DropRuleItemEvent event, final SingleRuleConfiguration currentRuleConfig) { + public void dropRuleItemConfiguration(final DropRuleItem dropRuleItem, final SingleRuleConfiguration currentRuleConfig) { currentRuleConfig.getTables().clear(); } diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/changed/DefaultDataSourceChangedProcessorTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/changed/DefaultDataSourceChangedProcessorTest.java index 1902e210c4299..0ac65fe4370ce 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/changed/DefaultDataSourceChangedProcessorTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/changed/DefaultDataSourceChangedProcessorTest.java @@ -20,9 +20,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.single.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.rule.SingleRule; import org.junit.jupiter.api.Test; @@ -44,8 +44,8 @@ class DefaultDataSourceChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - String actual = processor.swapRuleItemConfiguration(event, "foo_ds"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + String actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, "foo_ds"); assertThat(actual, is("foo_ds")); } @@ -65,18 +65,18 @@ private ShardingSphereDatabase mockDatabase(final SingleRuleConfiguration ruleCo @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); SingleRuleConfiguration currentRuleConfig = new SingleRuleConfiguration(Collections.emptyList(), "foo_ds"); String toBeChangedItemConfig = "bar_ds"; - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getDefaultDataSource(), is(Optional.of("bar_ds"))); } @Test void assertDropRuleItemConfiguration() { - DropRuleItemEvent event = mock(DropRuleItemEvent.class); + DropRuleItem dropRuleItem = mock(DropRuleItem.class); SingleRuleConfiguration currentRuleConfig = new SingleRuleConfiguration(Collections.emptyList(), "foo_ds"); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropRuleItem, currentRuleConfig); assertFalse(currentRuleConfig.getDefaultDataSource().isPresent()); } } diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/changed/SingleTableChangedProcessorTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/changed/SingleTableChangedProcessorTest.java index bd258dbb129ab..dc6abf3934972 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/changed/SingleTableChangedProcessorTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/changed/SingleTableChangedProcessorTest.java @@ -20,9 +20,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.single.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.rule.SingleRule; import org.junit.jupiter.api.Test; @@ -44,8 +44,8 @@ class SingleTableChangedProcessorTest { @Test void assertSwapRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); - SingleRuleConfiguration actual = processor.swapRuleItemConfiguration(event, "- foo_tbl"); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); + SingleRuleConfiguration actual = processor.swapRuleItemConfiguration(alterNamedRuleItem, "- foo_tbl"); assertThat(actual.getTables(), is(Collections.singleton("foo_tbl"))); } @@ -65,18 +65,18 @@ private ShardingSphereDatabase mockDatabase(final SingleRuleConfiguration ruleCo @Test void assertChangeRuleItemConfiguration() { - AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); + AlterNamedRuleItem alterNamedRuleItem = mock(AlterNamedRuleItem.class); SingleRuleConfiguration currentRuleConfig = new SingleRuleConfiguration(new LinkedList<>(Collections.singleton("foo_tbl")), null); SingleRuleConfiguration toBeChangedItemConfig = new SingleRuleConfiguration(new LinkedList<>(Collections.singleton("bar_tbl")), null); - processor.changeRuleItemConfiguration(event, currentRuleConfig, toBeChangedItemConfig); + processor.changeRuleItemConfiguration(alterNamedRuleItem, currentRuleConfig, toBeChangedItemConfig); assertThat(currentRuleConfig.getTables(), is(Collections.singletonList("bar_tbl"))); } @Test void assertDropRuleItemConfiguration() { - DropRuleItemEvent event = mock(DropRuleItemEvent.class); + DropRuleItem dropRuleItem = mock(DropRuleItem.class); SingleRuleConfiguration currentRuleConfig = new SingleRuleConfiguration(new LinkedList<>(Collections.singleton("foo_tbl")), null); - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropRuleItem, currentRuleConfig); assertTrue(currentRuleConfig.getTables().isEmpty()); } } diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RuleItemConfigurationChangedProcessor.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RuleItemConfigurationChangedProcessor.java index 0a147aef73bd9..d12f0fa1684c4 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RuleItemConfigurationChangedProcessor.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RuleItemConfigurationChangedProcessor.java @@ -19,10 +19,10 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; /** * Rule item configuration changed processor. @@ -36,11 +36,11 @@ public interface RuleItemConfigurationChangedProcessor build(final String databaseName, final String activeVersionKey, final String activeVersion, final Type changedType) { + for (RuleNodePathProvider each : ShardingSphereServiceLoader.getServiceInstances(RuleNodePathProvider.class)) { + Optional result = build(each.getRuleNodePath(), databaseName, activeVersionKey, activeVersion, changedType); + if (result.isPresent()) { + return result; + } + } + return Optional.empty(); + } + + private Optional build(final RuleNodePath ruleNodePath, final String databaseName, final String activeVersionKey, final String activeVersion, final Type changedType) { + if (!ruleNodePath.getRoot().isValidatedPath(activeVersionKey) || Type.DELETED != changedType && Strings.isNullOrEmpty(activeVersion)) { + return Optional.empty(); + } + for (Entry entry : ruleNodePath.getNamedItems().entrySet()) { + Optional itemName; + if (Type.ADDED == changedType || Type.UPDATED == changedType) { + itemName = entry.getValue().getNameByActiveVersion(activeVersionKey); + } else { + itemName = entry.getValue().getNameByItemPath(activeVersionKey); + } + if (itemName.isPresent()) { + return Optional.of(create(databaseName, itemName.get(), activeVersionKey, activeVersion, changedType, ruleNodePath.getRoot().getRuleType() + "." + entry.getKey())); + } + } + for (Entry entry : ruleNodePath.getUniqueItems().entrySet()) { + if (entry.getValue().isActiveVersionPath(activeVersionKey)) { + return Optional.of(create(databaseName, activeVersionKey, activeVersion, changedType, ruleNodePath.getRoot().getRuleType() + "." + entry.getKey())); + } + } + return Optional.empty(); + } + + private RuleItemChanged create(final String databaseName, final String itemName, final String activeVersionKey, final String activeVersion, final Type changedType, final String type) { + return Type.ADDED == changedType || Type.UPDATED == changedType + ? new AlterNamedRuleItem(databaseName, itemName, activeVersionKey, activeVersion, type) + : new DropNamedRuleItem(databaseName, itemName, type); + } + + private RuleItemChanged create(final String databaseName, final String activeVersionKey, final String activeVersion, final Type changedType, final String type) { + return Type.ADDED == changedType || Type.UPDATED == changedType + ? new AlterUniqueRuleItem(databaseName, activeVersionKey, activeVersion, type) + : new DropUniqueRuleItem(databaseName, type); + } +} diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/RuleItemManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/RuleItemManager.java index 4af0ebe9bc295..6d3adafe72378 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/RuleItemManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/RuleItemManager.java @@ -19,11 +19,11 @@ import com.google.common.base.Preconditions; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; @@ -50,20 +50,20 @@ public RuleItemManager(final AtomicReference metaDataContexts, /** * Alter with rule item. * - * @param event alter rule item event + * @param alterRuleItem alter rule item * @throws SQLException SQL Exception */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public void alterRuleItem(final AlterRuleItemEvent event) throws SQLException { - Preconditions.checkArgument(event.getActiveVersion().equals(metaDataPersistService.getMetaDataVersionPersistService() - .getActiveVersionByFullPath(event.getActiveVersionKey())), "Invalid active version: {} of key: {}", event.getActiveVersion(), event.getActiveVersionKey()); - RuleItemConfigurationChangedProcessor processor = TypedSPILoader.getService(RuleItemConfigurationChangedProcessor.class, event.getType()); + public void alterRuleItem(final AlterRuleItem alterRuleItem) throws SQLException { + Preconditions.checkArgument(alterRuleItem.getActiveVersion().equals(metaDataPersistService.getMetaDataVersionPersistService() + .getActiveVersionByFullPath(alterRuleItem.getActiveVersionKey())), "Invalid active version: {} of key: {}", + alterRuleItem.getActiveVersion(), alterRuleItem.getActiveVersionKey()); + RuleItemConfigurationChangedProcessor processor = TypedSPILoader.getService(RuleItemConfigurationChangedProcessor.class, alterRuleItem.getType()); String yamlContent = metaDataPersistService.getMetaDataVersionPersistService() - .getVersionPathByActiveVersion(event.getActiveVersionKey(), event.getActiveVersion()); - String databaseName = event.getDatabaseName(); + .getVersionPathByActiveVersion(alterRuleItem.getActiveVersionKey(), alterRuleItem.getActiveVersion()); + String databaseName = alterRuleItem.getDatabaseName(); RuleConfiguration currentRuleConfig = processor.findRuleConfiguration(metaDataContexts.get().getMetaData().getDatabase(databaseName)); synchronized (this) { - processor.changeRuleItemConfiguration(event, currentRuleConfig, processor.swapRuleItemConfiguration(event, yamlContent)); + processor.changeRuleItemConfiguration(alterRuleItem, currentRuleConfig, processor.swapRuleItemConfiguration(alterRuleItem, yamlContent)); ruleConfigManager.alterRuleConfiguration(databaseName, currentRuleConfig); } } @@ -71,17 +71,16 @@ public void alterRuleItem(final AlterRuleItemEvent event) throws SQLException { /** * Drop with rule item. * - * @param event drop rule item event + * @param dropRuleItem drop rule item * @throws SQLException SQL Exception */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public void dropRuleItem(final DropRuleItemEvent event) throws SQLException { - String databaseName = event.getDatabaseName(); + public void dropRuleItem(final DropRuleItem dropRuleItem) throws SQLException { + String databaseName = dropRuleItem.getDatabaseName(); Preconditions.checkState(metaDataContexts.get().getMetaData().containsDatabase(databaseName), "No database '%s' exists.", databaseName); - RuleItemConfigurationChangedProcessor processor = TypedSPILoader.getService(RuleItemConfigurationChangedProcessor.class, event.getType()); + RuleItemConfigurationChangedProcessor processor = TypedSPILoader.getService(RuleItemConfigurationChangedProcessor.class, dropRuleItem.getType()); RuleConfiguration currentRuleConfig = processor.findRuleConfiguration(metaDataContexts.get().getMetaData().getDatabase(databaseName)); synchronized (this) { - processor.dropRuleItemConfiguration(event, currentRuleConfig); + processor.dropRuleItemConfiguration(dropRuleItem, currentRuleConfig); ruleConfigManager.dropRuleConfiguration(databaseName, currentRuleConfig); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriber.java index de4bcd1c403fc..9db8351b9dd3a 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriber.java @@ -19,11 +19,21 @@ import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; +import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterUniqueRuleItemEvent; +import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; +import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropUniqueRuleItemEvent; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.DispatchEventSubscriber; import org.apache.shardingsphere.mode.metadata.manager.RuleItemManager; +import org.apache.shardingsphere.mode.spi.item.AlterNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.AlterUniqueRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropNamedRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropUniqueRuleItem; import java.sql.SQLException; @@ -47,7 +57,8 @@ public RuleItemChangedSubscriber(final ContextManager contextManager) { */ @Subscribe public void renew(final AlterRuleItemEvent event) throws SQLException { - ruleItemManager.alterRuleItem(event); + // TODO remove the event and this subscriber + ruleItemManager.alterRuleItem(convertToAlterRuleItem(event)); } /** @@ -58,6 +69,25 @@ public void renew(final AlterRuleItemEvent event) throws SQLException { */ @Subscribe public void renew(final DropRuleItemEvent event) throws SQLException { - ruleItemManager.dropRuleItem(event); + // TODO remove the event and this subscriber + ruleItemManager.dropRuleItem(convertToDropRuleItem(event)); + } + + private AlterRuleItem convertToAlterRuleItem(final AlterRuleItemEvent event) { + if (event instanceof AlterNamedRuleItemEvent) { + AlterNamedRuleItemEvent alterNamedRuleItemEvent = (AlterNamedRuleItemEvent) event; + return new AlterNamedRuleItem(alterNamedRuleItemEvent.getDatabaseName(), alterNamedRuleItemEvent.getItemName(), event.getActiveVersionKey(), event.getActiveVersion(), event.getType()); + } + AlterUniqueRuleItemEvent alterUniqueRuleItemEvent = (AlterUniqueRuleItemEvent) event; + return new AlterUniqueRuleItem(alterUniqueRuleItemEvent.getDatabaseName(), alterUniqueRuleItemEvent.getActiveVersionKey(), event.getActiveVersion(), event.getType()); + } + + private DropRuleItem convertToDropRuleItem(final DropRuleItemEvent event) { + if (event instanceof DropNamedRuleItemEvent) { + DropNamedRuleItemEvent dropNamedRuleItemEvent = (DropNamedRuleItemEvent) event; + return new DropNamedRuleItem(dropNamedRuleItemEvent.getDatabaseName(), dropNamedRuleItemEvent.getItemName(), event.getType()); + } + DropUniqueRuleItemEvent dropUniqueRuleItemEvent = (DropUniqueRuleItemEvent) event; + return new DropUniqueRuleItem(dropUniqueRuleItemEvent.getDatabaseName(), event.getType()); } } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriberTest.java index a4b209a94270a..5f04a35b00a69 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriberTest.java @@ -17,9 +17,13 @@ package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; +import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; +import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -29,6 +33,7 @@ import java.sql.SQLException; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -47,15 +52,15 @@ void setUp() { @Test void assertRenewWithAlterRuleItemEvent() throws SQLException { - AlterRuleItemEvent event = mock(AlterRuleItemEvent.class); + AlterRuleItemEvent event = mock(AlterNamedRuleItemEvent.class); subscriber.renew(event); - verify(contextManager.getMetaDataContextManager().getRuleItemManager()).alterRuleItem(event); + verify(contextManager.getMetaDataContextManager().getRuleItemManager()).alterRuleItem(any(AlterRuleItem.class)); } @Test void assertRenewWithDropRuleItemEvent() throws SQLException { - DropRuleItemEvent event = mock(DropRuleItemEvent.class); + DropRuleItemEvent event = mock(DropNamedRuleItemEvent.class); subscriber.renew(event); - verify(contextManager.getMetaDataContextManager().getRuleItemManager()).dropRuleItem(event); + verify(contextManager.getMetaDataContextManager().getRuleItemManager()).dropRuleItem(any(DropRuleItem.class)); } } 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 ce64a55aaf50a..7d067d5e4ce60 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 @@ -34,19 +34,18 @@ import org.apache.shardingsphere.infra.spi.type.ordered.cache.OrderedServicesCache; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; 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.dispatch.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; import org.apache.shardingsphere.mode.metadata.MetaDataContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; +import org.apache.shardingsphere.mode.metadata.manager.RuleItemChangedBuilder; import org.apache.shardingsphere.mode.metadata.manager.SwitchingResource; import org.apache.shardingsphere.mode.metadata.refresher.util.TableRefreshUtils; import org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.mode.spi.PersistRepository; +import org.apache.shardingsphere.mode.spi.item.RuleItemChanged; import org.apache.shardingsphere.single.config.SingleRuleConfiguration; import java.sql.SQLException; @@ -68,12 +67,12 @@ public final class StandaloneMetaDataManagerPersistService implements MetaDataMa private final MetaDataContextManager metaDataContextManager; - private final RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder; + private final RuleItemChangedBuilder ruleItemChangedBuilder; public StandaloneMetaDataManagerPersistService(final PersistRepository repository, final MetaDataContextManager metaDataContextManager) { metaDataPersistService = new MetaDataPersistService(repository); this.metaDataContextManager = metaDataContextManager; - ruleConfigChangedEventBuilder = new RuleConfigurationChangedEventBuilder(); + ruleItemChangedBuilder = new RuleItemChangedBuilder(); } @Override @@ -294,16 +293,16 @@ public void alterRuleConfiguration(final String databaseName, final RuleConfigur metaDataPersistService.getMetaDataVersionPersistService().switchActiveVersion(metaDataVersions); for (MetaDataVersion each : metaDataVersions) { // TODO double check here, when ruleItemEvent not existed or not AlterRuleItemEvent @haoran - Optional ruleItemEvent = buildAlterRuleItemEvent(databaseName, each, Type.UPDATED); - if (ruleItemEvent.isPresent() && ruleItemEvent.get() instanceof AlterRuleItemEvent) { - metaDataContextManager.getRuleItemManager().alterRuleItem((AlterRuleItemEvent) ruleItemEvent.get()); + Optional ruleItemChanged = buildAlterRuleItemChanged(databaseName, each, Type.UPDATED); + if (ruleItemChanged.isPresent() && ruleItemChanged.get() instanceof AlterRuleItem) { + metaDataContextManager.getRuleItemManager().alterRuleItem((AlterRuleItem) ruleItemChanged.get()); } } clearServiceCache(); } - private Optional buildAlterRuleItemEvent(final String databaseName, final MetaDataVersion metaDataVersion, final Type type) { - return ruleConfigChangedEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), type)); + private Optional buildAlterRuleItemChanged(final String databaseName, final MetaDataVersion metaDataVersion, final Type type) { + return ruleItemChangedBuilder.build(databaseName, metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), type); } @Override @@ -313,10 +312,10 @@ public void removeRuleConfigurationItem(final String databaseName, final RuleCon } Collection metaDataVersions = metaDataPersistService.getDatabaseRulePersistService().delete(databaseName, Collections.singleton(toBeRemovedRuleConfig)); for (MetaDataVersion metaDataVersion : metaDataVersions) { - Optional ruleItemEvent = buildAlterRuleItemEvent(databaseName, metaDataVersion, Type.DELETED); + Optional ruleItemChanged = buildAlterRuleItemChanged(databaseName, metaDataVersion, Type.DELETED); // TODO double check here, when ruleItemEvent not existed or not AlterRuleItemEvent @haoran - if (ruleItemEvent.isPresent() && ruleItemEvent.get() instanceof DropRuleItemEvent) { - metaDataContextManager.getRuleItemManager().dropRuleItem((DropRuleItemEvent) ruleItemEvent.get()); + if (ruleItemChanged.isPresent() && ruleItemChanged.get() instanceof DropRuleItem) { + metaDataContextManager.getRuleItemManager().dropRuleItem((DropRuleItem) ruleItemChanged.get()); } } clearServiceCache(); 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 cfb6314040c97..d86ffedcd0dc6 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,11 +30,11 @@ 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.dispatch.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; +import org.apache.shardingsphere.mode.metadata.manager.RuleItemChangedBuilder; import org.apache.shardingsphere.mode.spi.PersistRepository; +import org.apache.shardingsphere.mode.spi.item.AlterRuleItem; +import org.apache.shardingsphere.mode.spi.item.DropRuleItem; import org.apache.shardingsphere.single.config.SingleRuleConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -172,13 +172,13 @@ void assertAlterRuleConfiguration() throws SQLException { RuleConfiguration ruleConfig = mock(RuleConfiguration.class, RETURNS_DEEP_STUBS); Collection metaDataVersion = Collections.singleton(mock(MetaDataVersion.class)); when(metaDataPersistService.getDatabaseRulePersistService().persist("foo_db", Collections.singleton(ruleConfig))).thenReturn(metaDataVersion); - AlterRuleItemEvent event = mock(AlterRuleItemEvent.class); - RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = mock(RuleConfigurationChangedEventBuilder.class); - when(ruleConfigChangedEventBuilder.build(eq("foo_db"), any())).thenReturn(Optional.of(event)); - setRuleConfigurationEventBuilder(ruleConfigChangedEventBuilder); + AlterRuleItem alterRuleItem = mock(AlterRuleItem.class); + RuleItemChangedBuilder ruleItemChangedBuilder = mock(RuleItemChangedBuilder.class); + when(ruleItemChangedBuilder.build(eq("foo_db"), any(), any(), any())).thenReturn(Optional.of(alterRuleItem)); + setRuleConfigurationEventBuilder(ruleItemChangedBuilder); metaDataManagerPersistService.alterRuleConfiguration("foo_db", ruleConfig); verify(metaDataPersistService.getMetaDataVersionPersistService()).switchActiveVersion(metaDataVersion); - verify(metaDataContextManager.getRuleItemManager()).alterRuleItem(event); + verify(metaDataContextManager.getRuleItemManager()).alterRuleItem(any(AlterRuleItem.class)); } @Test @@ -192,12 +192,12 @@ 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); - RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = mock(RuleConfigurationChangedEventBuilder.class); - DropRuleItemEvent event = mock(DropRuleItemEvent.class); - when(ruleConfigChangedEventBuilder.build(eq("foo_db"), any())).thenReturn(Optional.of(event)); - setRuleConfigurationEventBuilder(ruleConfigChangedEventBuilder); + RuleItemChangedBuilder ruleItemChangedBuilder = mock(RuleItemChangedBuilder.class); + DropRuleItem dropRuleItem = mock(DropRuleItem.class); + when(ruleItemChangedBuilder.build(eq("foo_db"), any(), any(), any())).thenReturn(Optional.of(dropRuleItem)); + setRuleConfigurationEventBuilder(ruleItemChangedBuilder); metaDataManagerPersistService.removeRuleConfigurationItem("foo_db", ruleConfig); - verify(metaDataContextManager.getRuleItemManager()).dropRuleItem(event); + verify(metaDataContextManager.getRuleItemManager()).dropRuleItem(any(DropRuleItem.class)); } @Test @@ -236,7 +236,7 @@ void assertDropTables() { } @SneakyThrows(ReflectiveOperationException.class) - private void setRuleConfigurationEventBuilder(final RuleConfigurationChangedEventBuilder ruleConfigurationEventBuilder) { - Plugins.getMemberAccessor().set(StandaloneMetaDataManagerPersistService.class.getDeclaredField("ruleConfigChangedEventBuilder"), metaDataManagerPersistService, ruleConfigurationEventBuilder); + private void setRuleConfigurationEventBuilder(final RuleItemChangedBuilder ruleItemChangedBuilder) { + Plugins.getMemberAccessor().set(StandaloneMetaDataManagerPersistService.class.getDeclaredField("ruleItemChangedBuilder"), metaDataManagerPersistService, ruleItemChangedBuilder); } }