You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/09/25 11:49:14 UTC
[shardingsphere] branch master updated: Refactor alter rule and drop resource logic (#21140)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 7744e9b870c Refactor alter rule and drop resource logic (#21140)
7744e9b870c is described below
commit 7744e9b870c4948e34157198a9bd826cdb9ad09e
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Sun Sep 25 19:49:06 2022 +0800
Refactor alter rule and drop resource logic (#21140)
* Refactor alter rule and drop resource logic
* Adjustment it
* Replace \n to System.lineSeparator()
---
.../metadata/database/schema/SchemaManager.java | 65 +++++++++++++++++-----
.../database/schema/SchemaManagerTest.java | 36 +++++++++---
.../mode/manager/ContextManager.java | 63 ++++++++-------------
.../mode/manager/ContextManagerTest.java | 2 +-
.../schema/TableMetaDataPersistServiceTest.java | 2 +-
.../ClusterContextManagerCoordinatorTest.java | 1 +
6 files changed, 107 insertions(+), 62 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/SchemaManager.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/SchemaManager.java
index 8ec3f775948..6dca5b56e3e 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/SchemaManager.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/SchemaManager.java
@@ -30,36 +30,73 @@ import java.util.stream.Collectors;
*/
public final class SchemaManager {
+
/**
- * Get to be deleted schema meta data.
+ * Get to be added tables by schemas.
*
- * @param loadedSchema loaded schema
- * @param currentSchema current schema
- * @return To be deleted schema meta data
+ * @param reloadSchemas reload schemas
+ * @param currentSchemas current schemas
+ * @return To be added table meta data
*/
- public static ShardingSphereSchema getToBeDeletedSchemaMetaData(final ShardingSphereSchema loadedSchema, final ShardingSphereSchema currentSchema) {
- return new ShardingSphereSchema(getToBeDeletedTables(loadedSchema.getTables(), currentSchema.getTables()), new LinkedHashMap<>());
+ public static Map<String, ShardingSphereSchema> getToBeAddedTablesBySchemas(final Map<String, ShardingSphereSchema> reloadSchemas, final Map<String, ShardingSphereSchema> currentSchemas) {
+ Map<String, ShardingSphereSchema> result = new LinkedHashMap<>(currentSchemas.size(), 1);
+ reloadSchemas.entrySet().stream().filter(entry -> currentSchemas.containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue))
+ .forEach((key, value) -> result.put(key, getToBeAddedTablesBySchema(value, currentSchemas.get(key))));
+ return result;
+ }
+
+ private static ShardingSphereSchema getToBeAddedTablesBySchema(final ShardingSphereSchema reloadSchema, final ShardingSphereSchema currentSchema) {
+ return new ShardingSphereSchema(getToBeAddedTables(reloadSchema.getTables(), currentSchema.getTables()), new LinkedHashMap<>());
}
/**
- * Get to be added table meta data.
+ * Get to be added tables.
*
- * @param loadedTables loaded tables
+ * @param reloadTables reload tables
* @param currentTables current tables
* @return To be added table meta data
*/
- public static Map<String, ShardingSphereTable> getToBeAddedTables(final Map<String, ShardingSphereTable> loadedTables, final Map<String, ShardingSphereTable> currentTables) {
- return loadedTables.entrySet().stream().filter(entry -> !entry.getValue().equals(currentTables.get(entry.getKey()))).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
+ public static Map<String, ShardingSphereTable> getToBeAddedTables(final Map<String, ShardingSphereTable> reloadTables, final Map<String, ShardingSphereTable> currentTables) {
+ return reloadTables.entrySet().stream().filter(entry -> !entry.getValue().equals(currentTables.get(entry.getKey()))).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}
/**
- * Get to be deleted table meta data.
+ * Get to be deleted tables by schemas.
*
- * @param loadedTables loaded tables
+ * @param reloadSchemas reload schemas
+ * @param currentSchemas current schemas
+ * @return To be deleted table meta data
+ */
+ public static Map<String, ShardingSphereSchema> getToBeDeletedTablesBySchemas(final Map<String, ShardingSphereSchema> reloadSchemas, final Map<String, ShardingSphereSchema> currentSchemas) {
+ Map<String, ShardingSphereSchema> result = new LinkedHashMap<>(currentSchemas.size(), 1);
+ currentSchemas.entrySet().stream().filter(entry -> reloadSchemas.containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue))
+ .forEach((key, value) -> result.put(key, getToBeDeletedTablesBySchema(reloadSchemas.get(key), value)));
+ return result;
+ }
+
+ private static ShardingSphereSchema getToBeDeletedTablesBySchema(final ShardingSphereSchema reloadSchema, final ShardingSphereSchema currentSchema) {
+ return new ShardingSphereSchema(getToBeDeletedTables(reloadSchema.getTables(), currentSchema.getTables()), new LinkedHashMap<>());
+ }
+
+ /**
+ * Get to be deleted tables.
+ *
+ * @param reloadTables reload tables
* @param currentTables current tables
* @return To be deleted table meta data
*/
- public static Map<String, ShardingSphereTable> getToBeDeletedTables(final Map<String, ShardingSphereTable> loadedTables, final Map<String, ShardingSphereTable> currentTables) {
- return currentTables.entrySet().stream().filter(entry -> !loadedTables.containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
+ public static Map<String, ShardingSphereTable> getToBeDeletedTables(final Map<String, ShardingSphereTable> reloadTables, final Map<String, ShardingSphereTable> currentTables) {
+ return currentTables.entrySet().stream().filter(entry -> !reloadTables.containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
+ }
+
+ /**
+ * Get to be deleted schema names.
+ *
+ * @param reloadSchemas reload schemas
+ * @param currentSchemas current schemas
+ * @return To be deleted schema names
+ */
+ public static Map<String, ShardingSphereSchema> getToBeDeletedSchemaNames(final Map<String, ShardingSphereSchema> reloadSchemas, final Map<String, ShardingSphereSchema> currentSchemas) {
+ return currentSchemas.entrySet().stream().filter(entry -> !reloadSchemas.containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/SchemaManagerTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/SchemaManagerTest.java
index 7655e002b91..de4961db3ee 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/SchemaManagerTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/SchemaManagerTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.infra.metadata.database.schema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
-import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereView;
import org.junit.Test;
import java.util.Collections;
@@ -32,12 +31,27 @@ import static org.junit.Assert.assertTrue;
public final class SchemaManagerTest {
@Test
- public void assertGetToBeDeletedSchemaMetaData() {
- ShardingSphereSchema loadedSchemas = new ShardingSphereSchema(Collections.emptyMap(), Collections.emptyMap());
- ShardingSphereSchema currentSchemas =
- new ShardingSphereSchema(Collections.singletonMap("foo_table", new ShardingSphereTable()), Collections.singletonMap("foo_view", new ShardingSphereView("", "")));
- ShardingSphereSchema actual = SchemaManager.getToBeDeletedSchemaMetaData(loadedSchemas, currentSchemas);
- assertThat(actual.getTables().size(), is(1));
+ public void assertGetToBeAddedTablesBySchemas() {
+ Map<String, ShardingSphereSchema> reloadSchemas = Collections.singletonMap("foo_schema",
+ new ShardingSphereSchema(Collections.singletonMap("foo_table", new ShardingSphereTable("foo_table",
+ Collections.emptyList(), Collections.emptyList(), Collections.emptyList())), Collections.emptyMap()));
+ Map<String, ShardingSphereSchema> currentSchemas = Collections.singletonMap("foo_schema", new ShardingSphereSchema(Collections.emptyMap(), Collections.emptyMap()));
+ Map<String, ShardingSphereSchema> actual = SchemaManager.getToBeAddedTablesBySchemas(reloadSchemas, currentSchemas);
+ assertThat(actual.size(), is(1));
+ assertThat(actual.get("foo_schema").getTables().size(), is(1));
+ assertTrue(actual.get("foo_schema").getTables().containsKey("foo_table"));
+ }
+
+ @Test
+ public void assertGetToBeDeletedTablesBySchemas() {
+ Map<String, ShardingSphereSchema> currentSchemas = Collections.singletonMap("foo_schema",
+ new ShardingSphereSchema(Collections.singletonMap("foo_table", new ShardingSphereTable("foo_table",
+ Collections.emptyList(), Collections.emptyList(), Collections.emptyList())), Collections.emptyMap()));
+ Map<String, ShardingSphereSchema> reloadSchemas = Collections.singletonMap("foo_schema", new ShardingSphereSchema(Collections.emptyMap(), Collections.emptyMap()));
+ Map<String, ShardingSphereSchema> actual = SchemaManager.getToBeDeletedTablesBySchemas(reloadSchemas, currentSchemas);
+ assertThat(actual.size(), is(1));
+ assertThat(actual.get("foo_schema").getTables().size(), is(1));
+ assertTrue(actual.get("foo_schema").getTables().containsKey("foo_table"));
}
@Test
@@ -53,4 +67,12 @@ public final class SchemaManagerTest {
assertThat(actual.size(), is(1));
assertTrue(actual.containsKey("foo_table"));
}
+
+ @Test
+ public void assertGetToBeDeletedSchemaNames() {
+ Map<String, ShardingSphereSchema> actual = SchemaManager.getToBeDeletedSchemaNames(Collections.emptyMap(), Collections.singletonMap("foo_schema", new ShardingSphereSchema()));
+ assertThat(actual.size(), is(1));
+ assertTrue(actual.containsKey("foo_schema"));
+
+ }
}
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
index b8512f1392b..9fd75bd78d1 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
@@ -257,7 +257,8 @@ public final class ContextManager implements AutoCloseable {
SwitchingResource switchingResource = new ResourceSwitchManager().create(metaDataContexts.getMetaData().getDatabase(databaseName).getResource(), toBeAddedDataSourcePropsMap);
metaDataContexts.getMetaData().getDatabases().putAll(createChangedDatabases(databaseName, switchingResource, null));
metaDataContexts.getMetaData().getGlobalRuleMetaData().findRules(ResourceHeldRule.class).forEach(each -> each.addResource(metaDataContexts.getMetaData().getDatabase(databaseName)));
- persistMetaData(databaseName);
+ metaDataContexts.getMetaData().getDatabase(databaseName).getSchemas().forEach((schemaName, schema) -> metaDataContexts.getPersistService().getDatabaseMetaDataService()
+ .persist(metaDataContexts.getMetaData().getActualDatabaseName(databaseName), schemaName, schema));
metaDataContexts.getPersistService().getDataSourceService().append(metaDataContexts.getMetaData().getActualDatabaseName(databaseName), toBeAddedDataSourcePropsMap);
switchingResource.closeStaleDataSources();
}
@@ -290,19 +291,16 @@ public final class ContextManager implements AutoCloseable {
Map<String, DataSourceProperties> dataSourcePropsMap = metaDataContexts.getPersistService().getDataSourceService().load(metaDataContexts.getMetaData().getActualDatabaseName(databaseName));
Map<String, DataSourceProperties> toBeDeletedDataSourcePropsMap = getToBeDeletedDataSourcePropsMap(dataSourcePropsMap, toBeDroppedResourceNames);
SwitchingResource switchingResource = new ResourceSwitchManager().createByDropResource(metaDataContexts.getMetaData().getDatabase(databaseName).getResource(), toBeDeletedDataSourcePropsMap);
- Map<String, ShardingSphereDatabase> reloadDatabases = createChangedDatabases(databaseName, switchingResource, null);
- deleteSchemaMetaData(databaseName, reloadDatabases.get(databaseName.toLowerCase()), metaDataContexts.getMetaData().getDatabase(databaseName));
- metaDataContexts.getMetaData().getDatabases().putAll(reloadDatabases);
metaDataContexts.getMetaData().getDatabases().putAll(renewDatabase(metaDataContexts.getMetaData().getDatabase(databaseName), switchingResource));
+ MetaDataContexts reloadMetaDataContexts = createMetaDataContexts(databaseName, switchingResource, null);
+ alterSchemaMetaData(databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.getMetaData().getDatabase(databaseName));
+ deletedSchemaNames(databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.getMetaData().getDatabase(databaseName));
+ metaDataContexts = reloadMetaDataContexts;
Map<String, DataSourceProperties> toBeReversedDataSourcePropsMap = getToBeReversedDataSourcePropsMap(dataSourcePropsMap, toBeDroppedResourceNames);
metaDataContexts.getPersistService().getDataSourceService().persist(metaDataContexts.getMetaData().getActualDatabaseName(databaseName), toBeReversedDataSourcePropsMap);
switchingResource.closeStaleDataSources();
}
- private Map<String, DataSourceProperties> getToBeDeletedDataSourcePropsMap(final Map<String, DataSourceProperties> dataSourcePropsMap, final Collection<String> toBeDroppedResourceNames) {
- return dataSourcePropsMap.entrySet().stream().filter(entry -> toBeDroppedResourceNames.contains(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
- }
-
private Map<String, ShardingSphereDatabase> renewDatabase(final ShardingSphereDatabase database, final SwitchingResource resource) {
Map<String, ShardingSphereDatabase> result = new LinkedHashMap<>(1, 1);
Map<String, DataSource> newDataSource =
@@ -314,21 +312,19 @@ public final class ContextManager implements AutoCloseable {
return result;
}
- private Map<String, DataSourceProperties> getToBeReversedDataSourcePropsMap(final Map<String, DataSourceProperties> dataSourcePropsMap, final Collection<String> toBeDroppedResourceNames) {
- return dataSourcePropsMap.entrySet().stream().filter(entry -> !toBeDroppedResourceNames.contains(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
+ private Map<String, DataSourceProperties> getToBeDeletedDataSourcePropsMap(final Map<String, DataSourceProperties> dataSourcePropsMap, final Collection<String> toBeDroppedResourceNames) {
+ return dataSourcePropsMap.entrySet().stream().filter(entry -> toBeDroppedResourceNames.contains(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}
- private synchronized void deleteSchemaMetaData(final String databaseName, final ShardingSphereDatabase reloadDatabase, final ShardingSphereDatabase currentDatabase) {
- getToBeDeletedSchemaMetaData(reloadDatabase.getSchemas(),
- currentDatabase.getSchemas()).forEach((key, value) -> metaDataContexts.getPersistService().getDatabaseMetaDataService().delete(databaseName, key, value));
- deleteSchemas(databaseName, reloadDatabase, currentDatabase);
+ private Map<String, DataSourceProperties> getToBeReversedDataSourcePropsMap(final Map<String, DataSourceProperties> dataSourcePropsMap, final Collection<String> toBeDroppedResourceNames) {
+ return dataSourcePropsMap.entrySet().stream().filter(entry -> !toBeDroppedResourceNames.contains(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}
- private Map<String, ShardingSphereSchema> getToBeDeletedSchemaMetaData(final Map<String, ShardingSphereSchema> loadedSchemas, final Map<String, ShardingSphereSchema> currentSchemas) {
- Map<String, ShardingSphereSchema> result = new LinkedHashMap<>(currentSchemas.size(), 1);
- currentSchemas.entrySet().stream().filter(entry -> loadedSchemas.containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue))
- .forEach((key, value) -> result.put(key, SchemaManager.getToBeDeletedSchemaMetaData(loadedSchemas.get(key), value)));
- return result;
+ private synchronized void alterSchemaMetaData(final String databaseName, final ShardingSphereDatabase reloadDatabase, final ShardingSphereDatabase currentDatabase) {
+ Map<String, ShardingSphereSchema> toBeDeletedTables = SchemaManager.getToBeDeletedTablesBySchemas(reloadDatabase.getSchemas(), currentDatabase.getSchemas());
+ Map<String, ShardingSphereSchema> toBeAddedTables = SchemaManager.getToBeAddedTablesBySchemas(reloadDatabase.getSchemas(), currentDatabase.getSchemas());
+ toBeAddedTables.forEach((key, value) -> metaDataContexts.getPersistService().getDatabaseMetaDataService().persist(databaseName, key, value));
+ toBeDeletedTables.forEach((key, value) -> metaDataContexts.getPersistService().getDatabaseMetaDataService().delete(databaseName, key, value));
}
/**
@@ -342,8 +338,10 @@ public final class ContextManager implements AutoCloseable {
try {
Collection<ResourceHeldRule> staleResourceHeldRules = getStaleResourceHeldRules(databaseName);
staleResourceHeldRules.forEach(ResourceHeldRule::closeStaleResource);
- metaDataContexts = createMetaDataContexts(databaseName, null, ruleConfigs);
- compareAndPersistMetaData(metaDataContexts);
+ MetaDataContexts reloadMetaDataContexts = createMetaDataContexts(databaseName, null, ruleConfigs);
+ alterSchemaMetaData(databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.getMetaData().getDatabase(databaseName));
+ metaDataContexts = reloadMetaDataContexts;
+ metaDataContexts.getMetaData().getDatabases().putAll(newShardingSphereDatabase(metaDataContexts.getMetaData().getDatabase(databaseName)));
} catch (final SQLException ex) {
log.error("Alter database: {} rule configurations failed", databaseName, ex);
}
@@ -484,33 +482,20 @@ public final class ContextManager implements AutoCloseable {
ShardingSphereResource currentResource = metaDataContexts.getMetaData().getDatabase(databaseName).getResource();
SwitchingResource switchingResource = new SwitchingResource(currentResource, currentResource.getDataSources(), Collections.emptyMap());
MetaDataContexts reloadedMetaDataContexts = createMetaDataContexts(databaseName, switchingResource, null);
- deleteSchemas(databaseName, reloadedMetaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.getMetaData().getDatabase(databaseName));
+ deletedSchemaNames(databaseName, reloadedMetaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.getMetaData().getDatabase(databaseName));
metaDataContexts = reloadedMetaDataContexts;
- compareAndPersistMetaData(reloadedMetaDataContexts);
+ metaDataContexts.getMetaData().getDatabases().values().forEach(each -> each.getSchemas().forEach((schemaName, schema) ->
+ metaDataContexts.getPersistService().getDatabaseMetaDataService().compareAndPersist(each.getName(), schemaName, schema)));
} catch (final SQLException ex) {
log.error("Reload database: {} failed", databaseName, ex);
}
}
- private synchronized void deleteSchemas(final String databaseName, final ShardingSphereDatabase reloadDatabase, final ShardingSphereDatabase currentDatabase) {
- getToBeDeletedSchemas(reloadDatabase.getSchemas(), currentDatabase.getSchemas()).keySet()
+ private void deletedSchemaNames(final String databaseName, final ShardingSphereDatabase reloadDatabase, final ShardingSphereDatabase currentDatabase) {
+ SchemaManager.getToBeDeletedSchemaNames(reloadDatabase.getSchemas(), currentDatabase.getSchemas()).keySet()
.forEach(each -> metaDataContexts.getPersistService().getDatabaseMetaDataService().dropSchema(databaseName, each));
}
- private Map<String, ShardingSphereSchema> getToBeDeletedSchemas(final Map<String, ShardingSphereSchema> loadedSchemas, final Map<String, ShardingSphereSchema> currentSchemas) {
- return currentSchemas.entrySet().stream().filter(entry -> !loadedSchemas.containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
- }
-
- private void persistMetaData(final String databaseName) {
- metaDataContexts.getMetaData().getDatabase(databaseName).getSchemas().forEach((schemaName, schema) -> metaDataContexts.getPersistService().getDatabaseMetaDataService()
- .persist(metaDataContexts.getMetaData().getActualDatabaseName(databaseName), schemaName, schema));
- }
-
- private void compareAndPersistMetaData(final MetaDataContexts metaDataContexts) {
- metaDataContexts.getMetaData().getDatabases().values().forEach(each -> each.getSchemas()
- .forEach((schemaName, schema) -> metaDataContexts.getPersistService().getDatabaseMetaDataService().compareAndPersist(each.getName(), schemaName, schema)));
- }
-
/**
* Reload schema.
*
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
index 04f3e72c328..d95b4b4e22e 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
@@ -267,7 +267,7 @@ public final class ContextManagerTest {
dataSourcePropertiesMap.put("ds_2", mock(DataSourceProperties.class));
when(metaDataContexts.getPersistService().getDataSourceService().load("foo_db")).thenReturn(dataSourcePropertiesMap);
contextManager.dropResources("foo_db", Arrays.asList("ds_1", "ds_2"));
- assertTrue(contextManager.getMetaDataContexts().getMetaData().getDatabases().get("foo_db").getResource().getDataSources().isEmpty());
+ assertTrue(metaDataContexts.getMetaData().getDatabases().get("foo_db").getResource().getDataSources().isEmpty());
}
@Test
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/config/schema/TableMetaDataPersistServiceTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/config/schema/TableMetaDataPersistServiceTest.java
index be95fdd03a7..c3c976a2e54 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/config/schema/TableMetaDataPersistServiceTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/config/schema/TableMetaDataPersistServiceTest.java
@@ -49,7 +49,7 @@ public final class TableMetaDataPersistServiceTest {
public void assertPersist() {
ShardingSphereTable table = new ShardingSphereTable("foo_table", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
new TableMetaDataPersistService(repository).persist("foo_db", "foo_schema", Collections.singletonMap("foo_table", table));
- verify(repository).persist("/metadata/foo_db/schemas/foo_schema/tables/foo_table", "name: foo_table\n");
+ verify(repository).persist("/metadata/foo_db/schemas/foo_schema/tables/foo_table", "name: foo_table" + System.lineSeparator());
}
@Test
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
index 8244025e93f..9439666937c 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
@@ -149,6 +149,7 @@ public final class ClusterContextManagerCoordinatorTest {
when(database.getName()).thenReturn("db");
when(database.getResource().getDataSources()).thenReturn(new LinkedHashMap<>());
when(database.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
+ when(database.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", new ShardingSphereSchema()));
when(database.getProtocolType()).thenReturn(new MySQLDatabaseType());
when(database.getSchema("foo_schema")).thenReturn(mock(ShardingSphereSchema.class));
when(database.getRuleMetaData().getRules()).thenReturn(new LinkedList<>());