You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/05/21 08:53:27 UTC

[shardingsphere] branch master updated: Add SchemaRegistryService (#10415)

This is an automated email from the ASF dual-hosted git repository.

menghaoran 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 1c5c10a  Add SchemaRegistryService (#10415)
1c5c10a is described below

commit 1c5c10a95921e2509cb1fa2d667f2f0b4812dc34
Author: Liang Zhang <te...@163.com>
AuthorDate: Fri May 21 16:52:47 2021 +0800

    Add SchemaRegistryService (#10415)
    
    * Add SchemaRegistryService
    
    * Refactor SchemaRegistryService
---
 .../metadata/GovernanceMetaDataContexts.java       |  10 +-
 .../governance/core/facade/GovernanceFacade.java   |   2 +-
 .../governance/core/registry/RegistryCenter.java   |  60 ++---------
 .../service/schema/SchemaRegistryService.java      |  82 +++++++++++++++
 .../core/registry/RegistryCenterTest.java          |  43 --------
 .../service/schema/SchemaRegistryServiceTest.java  | 111 +++++++++++++++++++++
 .../impl/GovernanceBootstrapInitializer.java       |   2 +-
 7 files changed, 208 insertions(+), 102 deletions(-)

diff --git a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContexts.java b/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContexts.java
index fdad7bd..48b6b40 100644
--- a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContexts.java
+++ b/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContexts.java
@@ -105,7 +105,7 @@ public final class GovernanceMetaDataContexts implements MetaDataContexts {
     }
     
     private void persistMetaData() {
-        metaDataContexts.getMetaDataMap().forEach((key, value) -> governanceFacade.getRegistryCenter().persistSchema(key, value.getSchema()));
+        metaDataContexts.getMetaDataMap().forEach((key, value) -> governanceFacade.getRegistryCenter().getSchemaService().persist(key, value.getSchema()));
     }
     
     private ShardingSphereLock createShardingSphereLock() {
@@ -181,10 +181,10 @@ public final class GovernanceMetaDataContexts implements MetaDataContexts {
         metaDataMap.put(event.getSchemaName(), buildMetaData(event));
         metaDataContexts = new StandardMetaDataContexts(
                 metaDataMap, metaDataContexts.getGlobalRuleMetaData(), metaDataContexts.getExecutorEngine(), metaDataContexts.getProps());
-        governanceFacade.getRegistryCenter().persistSchema(event.getSchemaName(), metaDataContexts.getMetaDataMap().get(event.getSchemaName()).getSchema());
+        governanceFacade.getRegistryCenter().getSchemaService().persist(event.getSchemaName(), metaDataContexts.getMetaDataMap().get(event.getSchemaName()).getSchema());
         ShardingSphereEventBus.getInstance().post(new DataSourceChangeCompletedEvent(event.getSchemaName(), 
                 metaDataContexts.getMetaDataMap().get(event.getSchemaName()).getResource().getDatabaseType(), metaDataMap.get(event.getSchemaName()).getResource().getDataSources()));
-        ShardingSphereEventBus.getInstance().post(new MetaDataChangedEvent(governanceFacade.getRegistryCenter().loadAllSchemaNames()));
+        ShardingSphereEventBus.getInstance().post(new MetaDataChangedEvent(governanceFacade.getRegistryCenter().getSchemaService().loadAllNames()));
     }
     
     /**
@@ -198,7 +198,7 @@ public final class GovernanceMetaDataContexts implements MetaDataContexts {
         metaDataMap.remove(event.getSchemaName());
         metaDataContexts = new StandardMetaDataContexts(
                 metaDataMap, metaDataContexts.getGlobalRuleMetaData(), metaDataContexts.getExecutorEngine(), metaDataContexts.getProps());
-        governanceFacade.getRegistryCenter().deleteSchema(event.getSchemaName());
+        governanceFacade.getRegistryCenter().getSchemaService().delete(event.getSchemaName());
     }
     
     /**
@@ -259,7 +259,7 @@ public final class GovernanceMetaDataContexts implements MetaDataContexts {
         newMetaDataMap.put(schemaName, getChangedMetaData(metaDataContexts.getMetaDataMap().get(schemaName), event.getRuleConfigurations()));
         metaDataContexts = new StandardMetaDataContexts(
                 newMetaDataMap, metaDataContexts.getGlobalRuleMetaData(), metaDataContexts.getExecutorEngine(), metaDataContexts.getProps());
-        governanceFacade.getRegistryCenter().persistSchema(schemaName, newMetaDataMap.get(schemaName).getSchema());
+        governanceFacade.getRegistryCenter().getSchemaService().persist(schemaName, newMetaDataMap.get(schemaName).getSchema());
     }
     
     /**
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacade.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacade.java
index d7bcdb7..c29688cb 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacade.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacade.java
@@ -56,7 +56,7 @@ public final class GovernanceFacade implements AutoCloseable {
         registryCenterRepository = RegistryCenterRepositoryFactory.newInstance(config);
         registryCenter = new RegistryCenter(registryCenterRepository);
         listenerManager = new GovernanceListenerManager(registryCenterRepository, 
-                Stream.of(registryCenter.loadAllSchemaNames(), schemaNames).flatMap(Collection::stream).distinct().collect(Collectors.toList()));
+                Stream.of(registryCenter.getSchemaService().loadAllNames(), schemaNames).flatMap(Collection::stream).distinct().collect(Collectors.toList()));
     }
     
     /**
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
index 62fd7ba..c757d4d 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
@@ -40,11 +40,10 @@ import org.apache.shardingsphere.governance.core.registry.listener.event.rule.Sw
 import org.apache.shardingsphere.governance.core.registry.listener.event.scaling.StartScalingEvent;
 import org.apache.shardingsphere.governance.core.registry.service.config.impl.DataSourceRegistryService;
 import org.apache.shardingsphere.governance.core.registry.service.config.impl.GlobalRuleRegistryService;
-import org.apache.shardingsphere.governance.core.registry.service.state.LockRegistryService;
 import org.apache.shardingsphere.governance.core.registry.service.config.impl.PropertiesRegistryService;
 import org.apache.shardingsphere.governance.core.registry.service.config.impl.SchemaRuleRegistryService;
-import org.apache.shardingsphere.governance.core.yaml.schema.pojo.YamlSchema;
-import org.apache.shardingsphere.governance.core.yaml.schema.swapper.SchemaYamlSwapper;
+import org.apache.shardingsphere.governance.core.registry.service.schema.SchemaRegistryService;
+import org.apache.shardingsphere.governance.core.registry.service.state.LockRegistryService;
 import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
@@ -56,7 +55,6 @@ import org.apache.shardingsphere.infra.executor.sql.process.model.yaml.YamlExecu
 import org.apache.shardingsphere.infra.executor.sql.process.model.yaml.YamlExecuteProcessUnit;
 import org.apache.shardingsphere.infra.metadata.mapper.event.dcl.impl.CreateUserStatementEvent;
 import org.apache.shardingsphere.infra.metadata.mapper.event.dcl.impl.GrantStatementEvent;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import org.apache.shardingsphere.infra.metadata.schema.refresher.event.SchemaAlteredEvent;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
@@ -105,6 +103,9 @@ public final class RegistryCenter {
     private final PropertiesRegistryService propsService;
     
     @Getter
+    private final SchemaRegistryService schemaService;
+    
+    @Getter
     private final LockRegistryService lockService;
     
     public RegistryCenter(final RegistryCenterRepository repository) {
@@ -116,6 +117,7 @@ public final class RegistryCenter {
         schemaRuleService = new SchemaRuleRegistryService(repository);
         globalRuleService = new GlobalRuleRegistryService(repository);
         propsService = new PropertiesRegistryService(repository);
+        schemaService = new SchemaRegistryService(repository);
         lockService = new LockRegistryService(repository);
         ShardingSphereEventBus.getInstance().register(this);
     }
@@ -181,49 +183,6 @@ public final class RegistryCenter {
     }
     
     /**
-     * Load all schema names.
-     *
-     * @return all schema names
-     */
-    public Collection<String> loadAllSchemaNames() {
-        String schemaNames = repository.get(node.getMetadataNodePath());
-        return Strings.isNullOrEmpty(schemaNames) ? new LinkedList<>() : node.splitSchemaName(schemaNames);
-    }
-    
-    /**
-     * Persist ShardingSphere schema.
-     *
-     * @param schemaName schema name
-     * @param schema ShardingSphere schema
-     */
-    public void persistSchema(final String schemaName, final ShardingSphereSchema schema) {
-        repository.persist(node.getMetadataSchemaPath(schemaName), YamlEngine.marshal(new SchemaYamlSwapper().swapToYamlConfiguration(schema)));
-    }
-    
-    /**
-     * Load ShardingSphere schema.
-     *
-     * @param schemaName schema name
-     * @return ShardingSphere schema
-     */
-    public Optional<ShardingSphereSchema> loadSchema(final String schemaName) {
-        String path = repository.get(node.getMetadataSchemaPath(schemaName));
-        if (Strings.isNullOrEmpty(path)) {
-            return Optional.empty();
-        }
-        return Optional.of(new SchemaYamlSwapper().swapToObject(YamlEngine.unmarshal(path, YamlSchema.class)));
-    }
-    
-    /**
-     * Delete schema.
-     *
-     * @param schemaName schema name
-     */
-    public void deleteSchema(final String schemaName) {
-        repository.delete(node.getSchemaNamePath(schemaName));
-    }
-    
-    /**
      * Persist data source disabled state.
      *
      * @param event data source disabled event
@@ -311,7 +270,7 @@ public final class RegistryCenter {
      */
     @Subscribe
     public synchronized void renew(final SchemaAlteredEvent event) {
-        persistSchema(event.getSchemaName(), event.getSchema());
+        schemaService.persist(event.getSchemaName(), event.getSchema());
     }
     
     /**
@@ -375,10 +334,7 @@ public final class RegistryCenter {
         Collection<ShardingSphereUser> result = new LinkedList<>(oldUsers);
         ShardingSphereUsers shardingSphereUsers = new ShardingSphereUsers(oldUsers);
         for (ShardingSphereUser each : newUsers) {
-            Optional<ShardingSphereUser> oldUser = shardingSphereUsers.findUser(each.getGrantee());
-            if (oldUser.isPresent()) {
-                result.remove(oldUser);
-            }
+            shardingSphereUsers.findUser(each.getGrantee()).ifPresent(result::remove);
             result.add(each);
         }
         return result;
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/service/schema/SchemaRegistryService.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/service/schema/SchemaRegistryService.java
new file mode 100644
index 0000000..3da5edd
--- /dev/null
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/service/schema/SchemaRegistryService.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.governance.core.registry.service.schema;
+
+import com.google.common.base.Strings;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.governance.core.registry.RegistryCenterNode;
+import org.apache.shardingsphere.governance.core.yaml.schema.pojo.YamlSchema;
+import org.apache.shardingsphere.governance.core.yaml.schema.swapper.SchemaYamlSwapper;
+import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
+import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Optional;
+
+/**
+ * Schema registry service.
+ */
+@RequiredArgsConstructor
+public final class SchemaRegistryService {
+    
+    private final RegistryCenterRepository repository;
+    
+    private final RegistryCenterNode node = new RegistryCenterNode();
+    
+    /**
+     * Persist schema.
+     *
+     * @param schemaName schema name to be persisted
+     * @param schema schema to be persisted
+     */
+    public void persist(final String schemaName, final ShardingSphereSchema schema) {
+        repository.persist(node.getMetadataSchemaPath(schemaName), YamlEngine.marshal(new SchemaYamlSwapper().swapToYamlConfiguration(schema)));
+    }
+    
+    /**
+     * Delete schema.
+     *
+     * @param schemaName schema name to be deleted
+     */
+    public void delete(final String schemaName) {
+        repository.delete(node.getSchemaNamePath(schemaName));
+    }
+    
+    /**
+     * Load schema.
+     *
+     * @param schemaName schema name to be loaded
+     * @return Loaded schema
+     */
+    public Optional<ShardingSphereSchema> load(final String schemaName) {
+        String path = repository.get(node.getMetadataSchemaPath(schemaName));
+        return Strings.isNullOrEmpty(path) ? Optional.empty() : Optional.of(new SchemaYamlSwapper().swapToObject(YamlEngine.unmarshal(path, YamlSchema.class)));
+    }
+    
+    /**
+     * Load all schema names.
+     *
+     * @return all schema names
+     */
+    public Collection<String> loadAllNames() {
+        String schemaNames = repository.get(node.getMetadataNodePath());
+        return Strings.isNullOrEmpty(schemaNames) ? new LinkedList<>() : node.splitSchemaName(schemaNames);
+    }
+}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
index 66081b7..e4489ae 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
@@ -34,7 +34,6 @@ import org.apache.shardingsphere.governance.repository.spi.RegistryCenterReposit
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
 import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import org.apache.shardingsphere.infra.metadata.schema.refresher.event.SchemaAlteredEvent;
 import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
 import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
@@ -55,14 +54,9 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 import java.util.Properties;
 import java.util.stream.Collectors;
 
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.startsWith;
@@ -199,15 +193,6 @@ public final class RegistryCenterTest {
         return result;
     }
     
-    @Test
-    public void assertLoadAllSchemaNames() {
-        when(registryCenterRepository.get("/metadata")).thenReturn("sharding_db,replica_query_db");
-        Collection<String> actual = registryCenter.loadAllSchemaNames();
-        assertThat(actual.size(), is(2));
-        assertThat(actual, hasItems("sharding_db"));
-        assertThat(actual, hasItems("replica_query_db"));
-    }
-    
     @SneakyThrows({IOException.class, URISyntaxException.class})
     private String readYAML(final String yamlFile) {
         return Files.readAllLines(Paths.get(ClassLoader.getSystemResource(yamlFile).toURI()))
@@ -268,28 +253,6 @@ public final class RegistryCenterTest {
     }
     
     @Test
-    public void assertPersistSchema() {
-        ShardingSphereSchema schema = new SchemaYamlSwapper().swapToObject(YamlEngine.unmarshal(readYAML(META_DATA_YAML), YamlSchema.class));
-        registryCenter.persistSchema("sharding_db", schema);
-        verify(registryCenterRepository).persist(eq("/metadata/sharding_db/schema"), anyString());
-    }
-    
-    @Test
-    public void assertLoadSchema() {
-        when(registryCenterRepository.get("/metadata/sharding_db/schema")).thenReturn(readYAML(META_DATA_YAML));
-        Optional<ShardingSphereSchema> schemaOptional = registryCenter.loadSchema("sharding_db");
-        assertTrue(schemaOptional.isPresent());
-        Optional<ShardingSphereSchema> empty = registryCenter.loadSchema("test");
-        assertThat(empty, is(Optional.empty()));
-        ShardingSphereSchema schema = schemaOptional.get();
-        verify(registryCenterRepository).get(eq("/metadata/sharding_db/schema"));
-        assertThat(schema.getAllTableNames(), is(Collections.singleton("t_order")));
-        assertThat(schema.get("t_order").getIndexes().keySet(), is(Collections.singleton("primary")));
-        assertThat(schema.getAllColumnNames("t_order").size(), is(1));
-        assertThat(schema.get("t_order").getColumns().keySet(), is(Collections.singleton("id")));
-    }
-    
-    @Test
     public void assertRenewSchemaAlteredEvent() {
         SchemaAlteredEvent event = new SchemaAlteredEvent("sharding_db", new SchemaYamlSwapper().swapToObject(YamlEngine.unmarshal(readYAML(META_DATA_YAML), YamlSchema.class)));
         registryCenter.renew(event);
@@ -297,12 +260,6 @@ public final class RegistryCenterTest {
     }
     
     @Test
-    public void assertDeleteSchema() {
-        registryCenter.deleteSchema("sharding_db");
-        verify(registryCenterRepository).delete(eq("/metadata/sharding_db"));
-    }
-    
-    @Test
     @SneakyThrows
     public void assertRenewSwitchRuleConfigurationEvent() {
         Field field = RegistryCenter.class.getDeclaredField("registryCacheManager");
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/service/schema/SchemaRegistryServiceTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/service/schema/SchemaRegistryServiceTest.java
new file mode 100644
index 0000000..750c3b2
--- /dev/null
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/service/schema/SchemaRegistryServiceTest.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.governance.core.registry.service.schema;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.governance.core.yaml.schema.pojo.YamlSchema;
+import org.apache.shardingsphere.governance.core.yaml.schema.swapper.SchemaYamlSwapper;
+import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
+import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class SchemaRegistryServiceTest {
+    
+    private static final String YAML_DATA = "yaml/schema.yaml";
+    
+    @Mock
+    private RegistryCenterRepository registryCenterRepository;
+    
+    private SchemaRegistryService schemaRegistryService;
+    
+    @Before
+    public void setUp() throws ReflectiveOperationException {
+        schemaRegistryService = new SchemaRegistryService(registryCenterRepository);
+        Field field = schemaRegistryService.getClass().getDeclaredField("repository");
+        field.setAccessible(true);
+        field.set(schemaRegistryService, registryCenterRepository);
+    }
+    
+    @Test
+    public void assertPersist() {
+        ShardingSphereSchema schema = new SchemaYamlSwapper().swapToObject(YamlEngine.unmarshal(readYAML(YAML_DATA), YamlSchema.class));
+        schemaRegistryService.persist("foo_db", schema);
+        verify(registryCenterRepository).persist(eq("/metadata/foo_db/schema"), anyString());
+    }
+    
+    @Test
+    public void assertDelete() {
+        schemaRegistryService.delete("foo_db");
+        verify(registryCenterRepository).delete(eq("/metadata/foo_db"));
+    }
+    
+    @Test
+    public void assertLoad() {
+        when(registryCenterRepository.get("/metadata/foo_db/schema")).thenReturn(readYAML(YAML_DATA));
+        Optional<ShardingSphereSchema> schemaOptional = schemaRegistryService.load("foo_db");
+        assertTrue(schemaOptional.isPresent());
+        Optional<ShardingSphereSchema> empty = schemaRegistryService.load("test");
+        assertThat(empty, is(Optional.empty()));
+        ShardingSphereSchema schema = schemaOptional.get();
+        verify(registryCenterRepository).get(eq("/metadata/foo_db/schema"));
+        assertThat(schema.getAllTableNames(), is(Collections.singleton("t_order")));
+        assertThat(schema.get("t_order").getIndexes().keySet(), is(Collections.singleton("primary")));
+        assertThat(schema.getAllColumnNames("t_order").size(), is(1));
+        assertThat(schema.get("t_order").getColumns().keySet(), is(Collections.singleton("id")));
+    }
+    
+    @Test
+    public void assertLoadAllNames() {
+        when(registryCenterRepository.get("/metadata")).thenReturn("foo_db,bar_db");
+        Collection<String> actual = schemaRegistryService.loadAllNames();
+        assertThat(actual.size(), is(2));
+        assertThat(actual, hasItems("foo_db"));
+        assertThat(actual, hasItems("bar_db"));
+    }
+    
+    @SneakyThrows({IOException.class, URISyntaxException.class})
+    private String readYAML(final String yamlFile) {
+        return Files.readAllLines(Paths.get(ClassLoader.getSystemResource(yamlFile).toURI()))
+                .stream().filter(each -> !each.startsWith("#")).map(each -> each + System.lineSeparator()).collect(Collectors.joining());
+    }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
index b574c52..ccd7b03 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
@@ -95,7 +95,7 @@ public final class GovernanceBootstrapInitializer extends AbstractBootstrapIniti
     }
     
     private ProxyConfiguration loadProxyConfiguration() {
-        Collection<String> schemaNames = governanceFacade.getRegistryCenter().loadAllSchemaNames();
+        Collection<String> schemaNames = governanceFacade.getRegistryCenter().getSchemaService().loadAllNames();
         Map<String, Map<String, DataSourceParameter>> schemaDataSources = loadDataSourceParametersMap(schemaNames);
         Map<String, Collection<RuleConfiguration>> schemaRules = loadSchemaRules(schemaNames);
         Properties props = governanceFacade.getRegistryCenter().getPropsService().load();