diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java index 8acad8f35c21b..fc973540b40e7 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java @@ -20,7 +20,7 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.instance.InstanceContext; -import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; @@ -58,13 +58,14 @@ public Map> getDataSourceMapper() { @Override public void updateStatus(final DataSourceStatusChangedEvent event) { StorageNodeDataSourceChangedEvent dataSourceEvent = (StorageNodeDataSourceChangedEvent) event; - QualifiedDatabase qualifiedDatabase = dataSourceEvent.getQualifiedDatabase(); - ReadwriteSplittingDataSourceRule dataSourceRule = dataSourceRules.get(qualifiedDatabase.getGroupName()); - ShardingSpherePreconditions.checkNotNull(dataSourceRule, () -> new ReadwriteSplittingDataSourceRuleNotFoundException(qualifiedDatabase.getGroupName(), qualifiedDatabase.getDatabaseName())); + QualifiedDataSource qualifiedDataSource = dataSourceEvent.getQualifiedDataSource(); + ReadwriteSplittingDataSourceRule dataSourceRule = dataSourceRules.get(qualifiedDataSource.getGroupName()); + ShardingSpherePreconditions.checkNotNull(dataSourceRule, + () -> new ReadwriteSplittingDataSourceRuleNotFoundException(qualifiedDataSource.getGroupName(), qualifiedDataSource.getDatabaseName())); if (DataSourceState.DISABLED == dataSourceEvent.getDataSource().getStatus()) { - dataSourceRule.disableDataSource(dataSourceEvent.getQualifiedDatabase().getDataSourceName()); + dataSourceRule.disableDataSource(dataSourceEvent.getQualifiedDataSource().getDataSourceName()); } else { - dataSourceRule.enableDataSource(dataSourceEvent.getQualifiedDatabase().getDataSourceName()); + dataSourceRule.enableDataSource(dataSourceEvent.getQualifiedDataSource().getDataSourceName()); } } @@ -76,7 +77,7 @@ public void cleanStorageNodeDataSource(final String groupName) { private void deleteStorageNodeDataSources(final ReadwriteSplittingDataSourceRule rule) { rule.getReadwriteSplittingGroup().getReadDataSources() - .forEach(each -> instanceContext.getEventBusContext().post(new StorageNodeDataSourceDeletedEvent(new QualifiedDatabase(databaseName, rule.getName(), each)))); + .forEach(each -> instanceContext.getEventBusContext().post(new StorageNodeDataSourceDeletedEvent(new QualifiedDataSource(databaseName, rule.getName(), each)))); } @Override diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java index c7619a8c496a9..860097fc3a6f3 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.instance.InstanceContext; -import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource; @@ -71,7 +71,7 @@ private void assertDataSourceRule(final ReadwriteSplittingDataSourceRule actual) void assertUpdateRuleStatusWithNotExistDataSource() { ReadwriteSplittingRule readwriteSplittingRule = createReadwriteSplittingRule(); readwriteSplittingRule.getAttributes().getAttribute(StaticDataSourceRuleAttribute.class).updateStatus(new StorageNodeDataSourceChangedEvent( - new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED))); + new QualifiedDataSource("readwrite_splitting_db.readwrite.read_ds"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED))); assertThat(readwriteSplittingRule.getSingleDataSourceRule().getDisabledDataSourceNames(), is(Collections.singleton("read_ds"))); } @@ -79,7 +79,7 @@ void assertUpdateRuleStatusWithNotExistDataSource() { void assertUpdateRuleStatus() { ReadwriteSplittingRule readwriteSplittingRule = createReadwriteSplittingRule(); readwriteSplittingRule.getAttributes().getAttribute(StaticDataSourceRuleAttribute.class).updateStatus(new StorageNodeDataSourceChangedEvent( - new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED))); + new QualifiedDataSource("readwrite_splitting_db.readwrite.read_ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED))); assertThat(readwriteSplittingRule.getSingleDataSourceRule().getDisabledDataSourceNames(), is(Collections.singleton("read_ds_0"))); } @@ -87,10 +87,10 @@ void assertUpdateRuleStatus() { void assertUpdateRuleStatusWithEnable() { ReadwriteSplittingRule readwriteSplittingRule = createReadwriteSplittingRule(); readwriteSplittingRule.getAttributes().getAttribute(StaticDataSourceRuleAttribute.class).updateStatus(new StorageNodeDataSourceChangedEvent( - new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED))); + new QualifiedDataSource("readwrite_splitting_db.readwrite.read_ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED))); assertThat(readwriteSplittingRule.getSingleDataSourceRule().getDisabledDataSourceNames(), is(Collections.singleton("read_ds_0"))); readwriteSplittingRule.getAttributes().getAttribute(StaticDataSourceRuleAttribute.class).updateStatus(new StorageNodeDataSourceChangedEvent( - new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.ENABLED))); + new QualifiedDataSource("readwrite_splitting_db.readwrite.read_ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.ENABLED))); assertThat(readwriteSplittingRule.getSingleDataSourceRule().getDisabledDataSourceNames(), is(Collections.emptySet())); } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDatabase.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDataSource.java similarity index 92% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDatabase.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDataSource.java index f3225c81bdfc8..6f5e4ab24c785 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDatabase.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDataSource.java @@ -24,11 +24,11 @@ import java.util.List; /** - * Qualified database. + * Qualified data source. */ @RequiredArgsConstructor @Getter -public final class QualifiedDatabase { +public final class QualifiedDataSource { private static final String DELIMITER = "."; @@ -38,7 +38,7 @@ public final class QualifiedDatabase { private final String dataSourceName; - public QualifiedDatabase(final String value) { + public QualifiedDataSource(final String value) { List values = Splitter.on(DELIMITER).splitToList(value); databaseName = values.get(0); groupName = values.get(1); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDatabaseTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDataSourceTest.java similarity index 84% rename from infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDatabaseTest.java rename to infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDataSourceTest.java index 81d194e0e65b3..dc859bc87789d 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDatabaseTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/QualifiedDataSourceTest.java @@ -22,13 +22,14 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class QualifiedDatabaseTest { +class QualifiedDataSourceTest { @Test - void assertNewQualifiedDatabaseWithDatabaseNameAndDataSourceName() { - QualifiedDatabase actual = new QualifiedDatabase("test_db.test_group_name.test_ds"); + void assertNew() { + QualifiedDataSource actual = new QualifiedDataSource("test_db.test_group_name.test_ds"); assertThat(actual.getDatabaseName(), is("test_db")); assertThat(actual.getGroupName(), is("test_group_name")); assertThat(actual.getDataSourceName(), is("test_ds")); + assertThat(actual.toString(), is("test_db.test_group_name.test_ds")); } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSourceChangedEvent.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSourceChangedEvent.java index 6fb312f659354..2d8f683ebef2d 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSourceChangedEvent.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSourceChangedEvent.java @@ -19,7 +19,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent; /** @@ -29,7 +29,7 @@ @Getter public final class StorageNodeDataSourceChangedEvent implements DataSourceStatusChangedEvent { - private final QualifiedDatabase qualifiedDatabase; + private final QualifiedDataSource qualifiedDataSource; private final StorageNodeDataSource dataSource; } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSourceDeletedEvent.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSourceDeletedEvent.java index 4185a516dd02d..01a97b31d6965 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSourceDeletedEvent.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSourceDeletedEvent.java @@ -19,7 +19,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; /** * Storage node data source deleted event. @@ -28,5 +28,5 @@ @Getter public final class StorageNodeDataSourceDeletedEvent { - private final QualifiedDatabase qualifiedDatabase; + private final QualifiedDataSource qualifiedDataSource; } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/node/StorageNode.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/node/StorageNode.java index c7a6ec4e70dac..de51b0fad2356 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/node/StorageNode.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/node/StorageNode.java @@ -19,7 +19,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import java.util.Optional; import java.util.regex.Matcher; @@ -60,19 +60,19 @@ public static String getStorageNodesDataSourcePath(final String dataSourcePath) * @param database cluster database * @return status path of storage node */ - public static String getStorageNodeDataSourcePath(final QualifiedDatabase database) { + public static String getStorageNodeDataSourcePath(final QualifiedDataSource database) { return String.join("/", getRootPath(), database.toString()); } /** - * Extract qualified database. + * Extract qualified data source. * * @param storageNodePath storage node path - * @return extracted qualified database + * @return extracted qualified data source */ - public static Optional extractQualifiedDatabase(final String storageNodePath) { + public static Optional extractQualifiedDataSource(final String storageNodePath) { Pattern pattern = Pattern.compile(getRootPath() + "/(\\S+)$", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(storageNodePath); - return matcher.find() ? Optional.of(new QualifiedDatabase(matcher.group(1))) : Optional.empty(); + return matcher.find() ? Optional.of(new QualifiedDataSource(matcher.group(1))) : Optional.empty(); } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/StorageNodeStatusService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/StorageNodeStatusService.java index f352bf30c113f..5366328cc7245 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/StorageNodeStatusService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/storage/service/StorageNodeStatusService.java @@ -19,7 +19,7 @@ import com.google.common.base.Strings; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource; @@ -68,7 +68,7 @@ public Map loadStorageNodes() { */ public void changeMemberStorageNodeStatus(final String databaseName, final String groupName, final String storageUnitName, final DataSourceState dataSourceState) { StorageNodeDataSource storageNodeDataSource = new StorageNodeDataSource(StorageNodeRole.MEMBER, dataSourceState); - repository.persist(StorageNode.getStorageNodeDataSourcePath(new QualifiedDatabase(databaseName, groupName, storageUnitName)), + repository.persist(StorageNode.getStorageNodeDataSourcePath(new QualifiedDataSource(databaseName, groupName, storageUnitName)), YamlEngine.marshal(new YamlStorageNodeDataSourceSwapper().swapToYamlConfiguration(storageNodeDataSource))); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/StorageNodeChangedEvent.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/StorageNodeChangedEvent.java index dc3804b0abe87..5f0b5047fe27a 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/StorageNodeChangedEvent.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/StorageNodeChangedEvent.java @@ -20,7 +20,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.rule.event.GovernanceEvent; -import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource; /** @@ -30,7 +30,7 @@ @Getter public final class StorageNodeChangedEvent implements GovernanceEvent { - private final QualifiedDatabase qualifiedDatabase; + private final QualifiedDataSource qualifiedDataSource; private final StorageNodeDataSource dataSource; } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriber.java index f76e8aefb5f7c..9e053a2f8190d 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriber.java @@ -42,6 +42,6 @@ public StorageNodeStatusSubscriber(final ClusterPersistRepository repository, fi */ @Subscribe public void delete(final StorageNodeDataSourceDeletedEvent event) { - repository.delete(StorageNode.getStorageNodeDataSourcePath(event.getQualifiedDatabase())); + repository.delete(StorageNode.getStorageNodeDataSourcePath(event.getQualifiedDataSource())); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java index 7de3c72c5cfd1..ef4d87d70b8a6 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.watcher; import com.google.common.base.Strings; -import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.infra.rule.event.GovernanceEvent; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher; @@ -55,9 +55,9 @@ public Optional createGovernanceEvent(final DataChangedEvent ev if (Strings.isNullOrEmpty(event.getValue())) { return Optional.empty(); } - Optional qualifiedDatabase = StorageNode.extractQualifiedDatabase(event.getKey()); - if (qualifiedDatabase.isPresent()) { - QualifiedDatabase database = qualifiedDatabase.get(); + Optional qualifiedDataSource = StorageNode.extractQualifiedDataSource(event.getKey()); + if (qualifiedDataSource.isPresent()) { + QualifiedDataSource database = qualifiedDataSource.get(); StorageNodeDataSource storageNodeDataSource = new YamlStorageNodeDataSourceSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(), YamlStorageNodeDataSource.class)); return Optional.of(new StorageNodeChangedEvent(database, storageNodeDataSource)); } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java index 7b824faa4a282..06ade7f913d3f 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java @@ -60,14 +60,14 @@ public StateChangedSubscriber(final RegistryCenter registryCenter, final Context @Subscribe public synchronized void renew(final StorageNodeChangedEvent event) { ShardingSphereMetaData metaData = contextManager.getMetaDataContexts().getMetaData(); - if (!metaData.containsDatabase(event.getQualifiedDatabase().getDatabaseName())) { + if (!metaData.containsDatabase(event.getQualifiedDataSource().getDatabaseName())) { return; } - for (StaticDataSourceRuleAttribute each : metaData.getDatabase(event.getQualifiedDatabase().getDatabaseName()).getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)) { - each.updateStatus(new StorageNodeDataSourceChangedEvent(event.getQualifiedDatabase(), event.getDataSource())); + for (StaticDataSourceRuleAttribute each : metaData.getDatabase(event.getQualifiedDataSource().getDatabaseName()).getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)) { + each.updateStatus(new StorageNodeDataSourceChangedEvent(event.getQualifiedDataSource(), event.getDataSource())); } DataSourceStateManager.getInstance().updateState( - event.getQualifiedDatabase().getDatabaseName(), event.getQualifiedDatabase().getDataSourceName(), DataSourceState.valueOf(event.getDataSource().getStatus().name())); + event.getQualifiedDataSource().getDatabaseName(), event.getQualifiedDataSource().getDataSourceName(), DataSourceState.valueOf(event.getDataSource().getStatus().name())); } /** diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageNodeTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageNodeTest.java index 79fee2733c47d..f02d05d7cde87 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageNodeTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageNodeTest.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.node; -import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.mode.storage.node.StorageNode; import org.junit.jupiter.api.Test; @@ -40,8 +40,8 @@ void assertGetStorageNodesDataSourcePath() { } @Test - void assertExtractQualifiedDatabase() { - Optional actual = StorageNode.extractQualifiedDatabase("/nodes/storage_nodes/replica_query_db.readwrite_ds.replica_ds_0"); + void assertExtractQualifiedDataSource() { + Optional actual = StorageNode.extractQualifiedDataSource("/nodes/storage_nodes/replica_query_db.readwrite_ds.replica_ds_0"); assertTrue(actual.isPresent()); assertThat(actual.get().getDatabaseName(), is("replica_query_db")); assertThat(actual.get().getGroupName(), is("readwrite_ds")); diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriberTest.java index 75d76c96c473b..91cf8aee3438a 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriberTest.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.subscriber; -import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceDeletedEvent; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; @@ -42,8 +42,8 @@ void assertDeleteStorageNodeDataSourceDataSourceState() { String databaseName = "replica_query_db"; String groupName = "readwrite_ds"; String dataSourceName = "replica_ds_0"; - StorageNodeDataSourceDeletedEvent event = new StorageNodeDataSourceDeletedEvent(new QualifiedDatabase(databaseName, groupName, dataSourceName)); + StorageNodeDataSourceDeletedEvent event = new StorageNodeDataSourceDeletedEvent(new QualifiedDataSource(databaseName, groupName, dataSourceName)); new StorageNodeStatusSubscriber(repository, eventBusContext).delete(event); - verify(repository).delete(StorageNode.getStorageNodeDataSourcePath(new QualifiedDatabase(databaseName, groupName, dataSourceName))); + verify(repository).delete(StorageNode.getStorageNodeDataSourcePath(new QualifiedDataSource(databaseName, groupName, dataSourceName))); } } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java index 4ef3da8ba2656..e1078c8af0b2f 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java @@ -40,9 +40,9 @@ void assertCreateEnabledStorageNodeChangedEvent() { new DataChangedEvent("/nodes/storage_nodes/replica_query_db.readwrite_ds.replica_ds_0", "role: MEMBER\nstatus: ENABLED\n", Type.ADDED)); assertTrue(actual.isPresent()); StorageNodeChangedEvent actualEvent = (StorageNodeChangedEvent) actual.get(); - assertThat(actualEvent.getQualifiedDatabase().getDatabaseName(), is("replica_query_db")); - assertThat(actualEvent.getQualifiedDatabase().getGroupName(), is("readwrite_ds")); - assertThat(actualEvent.getQualifiedDatabase().getDataSourceName(), is("replica_ds_0")); + assertThat(actualEvent.getQualifiedDataSource().getDatabaseName(), is("replica_query_db")); + assertThat(actualEvent.getQualifiedDataSource().getGroupName(), is("readwrite_ds")); + assertThat(actualEvent.getQualifiedDataSource().getDataSourceName(), is("replica_ds_0")); assertThat(actualEvent.getDataSource().getRole(), is(StorageNodeRole.MEMBER)); assertThat(actualEvent.getDataSource().getStatus(), is(DataSourceState.ENABLED)); } @@ -53,9 +53,9 @@ void assertCreateDisabledStorageNodeChangedEvent() { new DataChangedEvent("/nodes/storage_nodes/replica_query_db.readwrite_ds.replica_ds_0", "role: MEMBER\nstatus: DISABLED\n", Type.DELETED)); assertTrue(actual.isPresent()); StorageNodeChangedEvent actualEvent = (StorageNodeChangedEvent) actual.get(); - assertThat(actualEvent.getQualifiedDatabase().getDatabaseName(), is("replica_query_db")); - assertThat(actualEvent.getQualifiedDatabase().getGroupName(), is("readwrite_ds")); - assertThat(actualEvent.getQualifiedDatabase().getDataSourceName(), is("replica_ds_0")); + assertThat(actualEvent.getQualifiedDataSource().getDatabaseName(), is("replica_query_db")); + assertThat(actualEvent.getQualifiedDataSource().getGroupName(), is("readwrite_ds")); + assertThat(actualEvent.getQualifiedDataSource().getDataSourceName(), is("replica_ds_0")); assertThat(actualEvent.getDataSource().getRole(), is(StorageNodeRole.MEMBER)); assertThat(actualEvent.getDataSource().getStatus(), is(DataSourceState.DISABLED)); } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java index 2c58feddbc7ed..3facaf53c5362 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; @@ -116,10 +116,10 @@ private Map createDatabases() { void assertRenewForDisableStateChanged() { StaticDataSourceRuleAttribute ruleAttribute = mock(StaticDataSourceRuleAttribute.class); when(database.getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute)); - StorageNodeChangedEvent event = new StorageNodeChangedEvent(new QualifiedDatabase("db.readwrite_ds.ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED)); + StorageNodeChangedEvent event = new StorageNodeChangedEvent(new QualifiedDataSource("db.readwrite_ds.ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED)); subscriber.renew(event); verify(ruleAttribute).updateStatus(argThat( - (ArgumentMatcher) argumentEvent -> Objects.equals(event.getQualifiedDatabase(), argumentEvent.getQualifiedDatabase()) + (ArgumentMatcher) argumentEvent -> Objects.equals(event.getQualifiedDataSource(), argumentEvent.getQualifiedDataSource()) && Objects.equals(event.getDataSource(), argumentEvent.getDataSource()))); }