From 31b164739ef1d95512d9fefbf57d66b417172446 Mon Sep 17 00:00:00 2001 From: Haoran Meng Date: Fri, 24 May 2024 12:47:20 +0800 Subject: [PATCH] Move init ShardingSphereStatistics to MetaDataContextsFactory --- .../proxy/ProxyMetaDataInfoExporterTest.java | 3 +- .../impl/proxy/ProxyStateExporterTest.java | 3 +- .../PrometheusPluginLifecycleServiceTest.java | 3 +- .../driver/state/DriverStateContextTest.java | 3 +- .../mode/manager/ContextManager.java | 3 +- .../context/ConfigurationContextManager.java | 3 +- .../ResourceMetaDataContextManager.java | 3 +- .../mode/metadata/MetaDataContexts.java | 57 +--------------- .../metadata/MetaDataContextsFactory.java | 68 ++++++++++++++++++- .../mode/metadata/MetaDataContextsTest.java | 2 +- .../ProcessListChangedSubscriberTest.java | 3 +- ...ResourceMetaDataChangedSubscriberTest.java | 3 +- .../StateChangedSubscriberTest.java | 3 +- .../DatabaseConnectorFactoryTest.java | 3 +- .../connector/DatabaseConnectorTest.java | 3 +- .../ProxyDatabaseConnectionManagerTest.java | 3 +- .../connector/ProxySQLExecutorTest.java | 3 +- .../datasource/JDBCBackendDataSourceTest.java | 3 +- .../context/BackendExecutorContextTest.java | 3 +- .../backend/context/ProxyContextTest.java | 7 +- .../DatabaseAdminQueryBackendHandlerTest.java | 3 +- .../DefaultDatabaseMetaDataExecutorTest.java | 3 +- .../UnicastDatabaseBackendHandlerTest.java | 3 +- ...abaseOperateBackendHandlerFactoryTest.java | 5 +- .../ral/QueryableRALBackendHandlerTest.java | 3 +- .../queryable/ExportMetaDataExecutorTest.java | 5 +- .../ExportStorageNodesExecutorTest.java | 5 +- .../SetDistVariableExecutorTest.java | 3 +- .../admin/MySQLAdminExecutorCreatorTest.java | 3 +- .../ShowCreateDatabaseExecutorTest.java | 3 +- .../executor/ShowCurrentUserExecutorTest.java | 3 +- .../executor/ShowDatabasesExecutorTest.java | 3 +- .../ShowFunctionStatusExecutorTest.java | 3 +- .../ShowProcedureStatusExecutorTest.java | 3 +- .../executor/ShowTablesExecutorTest.java | 3 +- .../executor/UseDatabaseExecutorTest.java | 3 +- ...SelectInformationSchemataExecutorTest.java | 3 +- .../FrontDatabaseProtocolTypeFactoryTest.java | 3 +- .../frontend/state/impl/OKProxyStateTest.java | 3 +- .../MySQLAuthenticationEngineTest.java | 3 +- .../OpenGaussAuthenticationEngineTest.java | 3 +- .../PostgreSQLAuthenticationEngineTest.java | 3 +- .../PostgreSQLCommandExecuteEngineTest.java | 3 +- .../core/util/PipelineContextUtils.java | 3 +- 44 files changed, 157 insertions(+), 103 deletions(-) diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java index 36d0aab30527a..7008ec312e07b 100644 --- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java +++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java @@ -30,6 +30,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -79,7 +80,7 @@ private ContextManager mockContextManager() { when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); when(metaData.getDatabases()).thenReturn(Collections.singletonMap("sharding_db", database)); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), metaData); + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java index 74ecdf388021a..30fb1fd01dfe0 100644 --- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java +++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java @@ -34,6 +34,7 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.standalone.workerid.generator.StandaloneWorkerIdGenerator; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -79,7 +80,7 @@ void assertExportWithContextManager() { } private ContextManager mockContextManager() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); ComputeNodeInstanceContext computeNodeInstanceContext = new ComputeNodeInstanceContext( new ComputeNodeInstance(mock(InstanceMetaData.class)), new StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null), mock(LockContext.class), new EventBusContext()); diff --git a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java index 36806776f008f..3dd403011943b 100644 --- a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java +++ b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java @@ -29,6 +29,7 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.standalone.workerid.generator.StandaloneWorkerIdGenerator; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -68,7 +69,7 @@ void assertStart() throws IOException { } private ContextManager mockContextManager() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); ComputeNodeInstanceContext computeNodeInstanceContext = new ComputeNodeInstanceContext( new ComputeNodeInstance(mock(InstanceMetaData.class)), new StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null), mock(LockContext.class), new EventBusContext()); diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java index a443a39a6532f..7b00dd9a8a4c2 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java @@ -30,6 +30,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.mode.state.StateContext; import org.apache.shardingsphere.traffic.rule.TrafficRule; import org.apache.shardingsphere.transaction.rule.TransactionRule; @@ -63,7 +64,7 @@ void setUp() { TransactionRule transactionRule = mock(TransactionRule.class); TrafficRule trafficRule = mock(TrafficRule.class); RuleMetaData globalRuleMetaData = new RuleMetaData(Arrays.asList(transactionRule, trafficRule)); - MetaDataContexts metaDataContexts = new MetaDataContexts( + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create( mock(MetaDataPersistService.class), new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), globalRuleMetaData, new ConfigurationProperties(new Properties()))); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); when(contextManager.getComputeNodeInstanceContext().getInstance().getState()).thenReturn(new InstanceStateContext()); diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java index 78905598a883f..8293ccd04d958 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java @@ -44,6 +44,7 @@ import org.apache.shardingsphere.mode.manager.switcher.ResourceSwitchManager; import org.apache.shardingsphere.mode.manager.switcher.SwitchingResource; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.mode.service.PersistServiceFacade; import org.apache.shardingsphere.mode.state.StateContext; @@ -180,7 +181,7 @@ private MetaDataContexts createMetaDataContexts(final ShardingSphereDatabase dat ConfigurationProperties props = new ConfigurationProperties(metaDataPersistService.getPropsService().load()); Collection globalRuleConfigs = metaDataPersistService.getGlobalRuleService().load(); RuleMetaData changedGlobalMetaData = new RuleMetaData(GlobalRulesBuilder.buildRules(globalRuleConfigs, changedDatabases, props)); - MetaDataContexts result = new MetaDataContexts(metaDataPersistService, + MetaDataContexts result = MetaDataContextsFactory.create(metaDataPersistService, new ShardingSphereMetaData(changedDatabases, metaDataContexts.get().getMetaData().getGlobalResourceMetaData(), changedGlobalMetaData, props)); switchingResource.closeStaleDataSources(); return result; diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java index 719f12fc278a1..859803b68a22e 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java @@ -41,6 +41,7 @@ import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder; import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleEntity; import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine; import org.apache.shardingsphere.metadata.factory.ExternalMetaDataFactory; @@ -413,6 +414,6 @@ public synchronized void alterProperties(final Properties props) { } private MetaDataContexts newMetaDataContexts(final ShardingSphereMetaData metaData) { - return new MetaDataContexts(metaDataContexts.get().getPersistService(), metaData); + return MetaDataContextsFactory.create(metaDataContexts.get().getPersistService(), metaData); } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ResourceMetaDataContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ResourceMetaDataContextManager.java index a7d02ddbd3bd6..1e4dbcddaf860 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ResourceMetaDataContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ResourceMetaDataContextManager.java @@ -30,6 +30,7 @@ import org.apache.shardingsphere.infra.rule.scope.GlobalRule; import org.apache.shardingsphere.infra.rule.scope.GlobalRule.GlobalRuleChangedType; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.mode.metadata.refresher.util.TableRefreshUtils; import java.util.Collections; @@ -55,7 +56,7 @@ public synchronized void addDatabase(final String databaseName) { } DatabaseType protocolType = DatabaseTypeEngine.getProtocolType(Collections.emptyMap(), metaDataContexts.get().getMetaData().getProps()); metaDataContexts.get().getMetaData().addDatabase(databaseName, protocolType, metaDataContexts.get().getMetaData().getProps()); - metaDataContexts.set(new MetaDataContexts(metaDataContexts.get().getPersistService(), metaDataContexts.get().getMetaData())); + metaDataContexts.set(MetaDataContextsFactory.create(metaDataContexts.get().getPersistService(), metaDataContexts.get().getMetaData())); } /** diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java index b9a52ce3c9e69..910a7328d80ac 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java @@ -19,24 +19,13 @@ import lombok.Getter; import lombok.SneakyThrows; -import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; -import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; -import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereDatabaseData; -import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereSchemaData; import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatistics; -import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereTableData; -import org.apache.shardingsphere.infra.metadata.statistics.builder.ShardingSphereStatisticsBuilder; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import java.util.Collection; import java.util.LinkedList; -import java.util.Map.Entry; -import java.util.Optional; /** * Meta data contexts. @@ -50,52 +39,10 @@ public final class MetaDataContexts implements AutoCloseable { private final ShardingSphereStatistics statistics; - public MetaDataContexts(final MetaDataPersistService persistService, final ShardingSphereMetaData metaData) { + public MetaDataContexts(final MetaDataPersistService persistService, final ShardingSphereMetaData metaData, final ShardingSphereStatistics statistics) { this.persistService = persistService; this.metaData = metaData; - statistics = initStatistics(metaData); - } - - private ShardingSphereStatistics initStatistics(final ShardingSphereMetaData metaData) { - if (metaData.getDatabases().isEmpty()) { - return new ShardingSphereStatistics(); - } - DatabaseType protocolType = metaData.getDatabases().values().iterator().next().getProtocolType(); - DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(protocolType).getDialectDatabaseMetaData(); - // TODO can `protocolType instanceof SchemaSupportedDatabaseType ? "PostgreSQL" : protocolType.getType()` replace to trunk database type? - DatabaseType databaseType = dialectDatabaseMetaData.getDefaultSchema().isPresent() ? TypedSPILoader.getService(DatabaseType.class, "PostgreSQL") : protocolType; - Optional statisticsBuilder = DatabaseTypedSPILoader.findService(ShardingSphereStatisticsBuilder.class, databaseType); - if (!statisticsBuilder.isPresent()) { - return new ShardingSphereStatistics(); - } - ShardingSphereStatistics result = statisticsBuilder.get().build(metaData); - Optional loadedStatistics = persistService.getShardingSphereDataPersistService().load(metaData); - loadedStatistics.ifPresent(optional -> useLoadedToReplaceInit(result, optional)); - return result; - } - - private void useLoadedToReplaceInit(final ShardingSphereStatistics initStatistics, final ShardingSphereStatistics loadedStatistics) { - for (Entry entry : initStatistics.getDatabaseData().entrySet()) { - if (loadedStatistics.getDatabaseData().containsKey(entry.getKey())) { - useLoadedToReplaceInitByDatabaseData(entry.getValue(), loadedStatistics.getDatabaseData().get(entry.getKey())); - } - } - } - - private void useLoadedToReplaceInitByDatabaseData(final ShardingSphereDatabaseData initDatabaseData, final ShardingSphereDatabaseData loadedDatabaseData) { - for (Entry entry : initDatabaseData.getSchemaData().entrySet()) { - if (loadedDatabaseData.getSchemaData().containsKey(entry.getKey())) { - useLoadedToReplaceInitBySchemaData(entry.getValue(), loadedDatabaseData.getSchemaData().get(entry.getKey())); - } - } - } - - private void useLoadedToReplaceInitBySchemaData(final ShardingSphereSchemaData initSchemaData, final ShardingSphereSchemaData loadedSchemaData) { - for (Entry entry : initSchemaData.getTableData().entrySet()) { - if (loadedSchemaData.getTableData().containsKey(entry.getKey())) { - entry.setValue(loadedSchemaData.getTableData().get(entry.getKey())); - } - } + this.statistics = statistics; } @SneakyThrows(Exception.class) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java index c46380f277bbc..b2535dcc3fad2 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java @@ -25,6 +25,10 @@ import org.apache.shardingsphere.infra.config.database.impl.DataSourceGeneratedDatabaseConfiguration; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; +import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; +import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; import org.apache.shardingsphere.infra.datasource.pool.config.DataSourceConfiguration; import org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer; import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; @@ -33,7 +37,13 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; +import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereDatabaseData; +import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereSchemaData; +import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatistics; +import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereTableData; +import org.apache.shardingsphere.infra.metadata.statistics.builder.ShardingSphereStatisticsBuilder; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; import org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager; import org.apache.shardingsphere.metadata.factory.ExternalMetaDataFactory; @@ -51,6 +61,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -99,7 +110,9 @@ public static MetaDataContexts create(final MetaDataPersistService persistServic : ExternalMetaDataFactory.create(effectiveDatabaseConfigs, props, computeNodeInstanceContext); ResourceMetaData globalResourceMetaData = new ResourceMetaData(globalDataSources); RuleMetaData globalRuleMetaData = new RuleMetaData(GlobalRulesBuilder.buildRules(globalRuleConfigs, databases, props)); - MetaDataContexts result = new MetaDataContexts(persistService, new ShardingSphereMetaData(databases, globalResourceMetaData, globalRuleMetaData, props)); + ShardingSphereMetaData shardingSphereMetaData = new ShardingSphereMetaData(databases, globalResourceMetaData, globalRuleMetaData, props); + ShardingSphereStatistics shardingSphereStatistics = initStatistics(persistService, shardingSphereMetaData); + MetaDataContexts result = new MetaDataContexts(persistService, shardingSphereMetaData, shardingSphereStatistics); if (!isDatabaseMetaDataExisted) { persistDatabaseConfigurations(result, param); persistMetaData(result); @@ -107,6 +120,17 @@ public static MetaDataContexts create(final MetaDataPersistService persistServic return result; } + /** + * Create meta data contexts. + * + * @param persistService meta data persist service + * @param metaData shardingsphere meta data + * @return meta data contexts + */ + public static MetaDataContexts create(final MetaDataPersistService persistService, final ShardingSphereMetaData metaData) { + return new MetaDataContexts(persistService, metaData, initStatistics(persistService, metaData)); + } + private static Collection getDatabaseNames(final ComputeNodeInstanceContext computeNodeInstanceContext, final Map databaseConfigs, final MetaDataPersistService persistService) { return computeNodeInstanceContext.getInstance().getMetaData() instanceof JDBCInstanceMetaData ? databaseConfigs.keySet() : persistService.getDatabaseMetaDataService().loadAllDatabaseNames(); @@ -152,6 +176,48 @@ private static Map getStorageDataSourceStates(final Map return result; } + private static ShardingSphereStatistics initStatistics(final MetaDataPersistService persistService, final ShardingSphereMetaData metaData) { + if (metaData.getDatabases().isEmpty()) { + return new ShardingSphereStatistics(); + } + DatabaseType protocolType = metaData.getDatabases().values().iterator().next().getProtocolType(); + DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(protocolType).getDialectDatabaseMetaData(); + // TODO can `protocolType instanceof SchemaSupportedDatabaseType ? "PostgreSQL" : protocolType.getType()` replace to trunk database type? + DatabaseType databaseType = dialectDatabaseMetaData.getDefaultSchema().isPresent() ? TypedSPILoader.getService(DatabaseType.class, "PostgreSQL") : protocolType; + Optional statisticsBuilder = DatabaseTypedSPILoader.findService(ShardingSphereStatisticsBuilder.class, databaseType); + if (!statisticsBuilder.isPresent()) { + return new ShardingSphereStatistics(); + } + ShardingSphereStatistics result = statisticsBuilder.get().build(metaData); + Optional loadedStatistics = persistService.getShardingSphereDataPersistService().load(metaData); + loadedStatistics.ifPresent(optional -> useLoadedToReplaceInit(result, optional)); + return result; + } + + private static void useLoadedToReplaceInit(final ShardingSphereStatistics initStatistics, final ShardingSphereStatistics loadedStatistics) { + for (Entry entry : initStatistics.getDatabaseData().entrySet()) { + if (loadedStatistics.getDatabaseData().containsKey(entry.getKey())) { + useLoadedToReplaceInitByDatabaseData(entry.getValue(), loadedStatistics.getDatabaseData().get(entry.getKey())); + } + } + } + + private static void useLoadedToReplaceInitByDatabaseData(final ShardingSphereDatabaseData initDatabaseData, final ShardingSphereDatabaseData loadedDatabaseData) { + for (Entry entry : initDatabaseData.getSchemaData().entrySet()) { + if (loadedDatabaseData.getSchemaData().containsKey(entry.getKey())) { + useLoadedToReplaceInitBySchemaData(entry.getValue(), loadedDatabaseData.getSchemaData().get(entry.getKey())); + } + } + } + + private static void useLoadedToReplaceInitBySchemaData(final ShardingSphereSchemaData initSchemaData, final ShardingSphereSchemaData loadedSchemaData) { + for (Entry entry : initSchemaData.getTableData().entrySet()) { + if (loadedSchemaData.getTableData().containsKey(entry.getKey())) { + entry.setValue(loadedSchemaData.getTableData().get(entry.getKey())); + } + } + } + private static void persistDatabaseConfigurations(final MetaDataContexts metadataContexts, final ContextManagerBuilderParameter param) { metadataContexts.getPersistService().persistGlobalRuleConfiguration(param.getGlobalRuleConfigs(), param.getProps()); for (Entry entry : param.getDatabaseConfigs().entrySet()) { diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java index b8d880c44ecfa..16d0c880bfef2 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java @@ -46,6 +46,6 @@ void assertGetDefaultMetaData() { Map databases = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database); ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties())); - assertThat(new MetaDataContexts(mock(MetaDataPersistService.class), metaData).getMetaData().getDatabase(DefaultDatabase.LOGIC_NAME), is(database)); + assertThat(MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData).getMetaData().getDatabase(DefaultDatabase.LOGIC_NAME), is(database)); } } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessListChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessListChangedSubscriberTest.java index 5d6bdeab92295..c048cd2481826 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessListChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessListChangedSubscriberTest.java @@ -39,6 +39,7 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ReportLocalProcessesCompletedEvent; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ReportLocalProcessesEvent; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration; import org.awaitility.Awaitility; @@ -83,7 +84,7 @@ class ProcessListChangedSubscriberTest { void setUp() throws SQLException { EventBusContext eventBusContext = new EventBusContext(); contextManager = new ClusterContextManagerBuilder().build(createContextManagerBuilderParameter(), eventBusContext); - contextManager.renewMetaDataContexts(new MetaDataContexts(contextManager.getMetaDataContexts().getPersistService(), new ShardingSphereMetaData(createDatabases(), + contextManager.renewMetaDataContexts(MetaDataContextsFactory.create(contextManager.getMetaDataContexts().getPersistService(), new ShardingSphereMetaData(createDatabases(), contextManager.getMetaDataContexts().getMetaData().getGlobalResourceMetaData(), contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), new ConfigurationProperties(new Properties())))); subscriber = new ProcessListChangedSubscriber(contextManager, repository); diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java index 1c7a1afa91069..0658825b98a63 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java @@ -38,6 +38,7 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaDeletedEvent; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.junit.jupiter.api.BeforeEach; @@ -80,7 +81,7 @@ class ResourceMetaDataChangedSubscriberTest { @BeforeEach void setUp() throws SQLException { contextManager = new ClusterContextManagerBuilder().build(createContextManagerBuilderParameter(), new EventBusContext()); - contextManager.renewMetaDataContexts(new MetaDataContexts(contextManager.getMetaDataContexts().getPersistService(), new ShardingSphereMetaData(createDatabases(), + contextManager.renewMetaDataContexts(MetaDataContextsFactory.create(contextManager.getMetaDataContexts().getPersistService(), new ShardingSphereMetaData(createDatabases(), contextManager.getMetaDataContexts().getMetaData().getGlobalResourceMetaData(), contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), new ConfigurationProperties(new Properties())))); subscriber = new ResourceMetaDataChangedSubscriber(contextManager); 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 c344e148831dd..6a331affa1478 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 @@ -44,6 +44,7 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.WorkerIdEvent; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration; import org.apache.shardingsphere.mode.storage.QualifiedDataSourceStatus; import org.junit.jupiter.api.BeforeEach; @@ -86,7 +87,7 @@ class StateChangedSubscriberTest { void setUp() throws SQLException { EventBusContext eventBusContext = new EventBusContext(); contextManager = new ClusterContextManagerBuilder().build(createContextManagerBuilderParameter(), eventBusContext); - contextManager.renewMetaDataContexts(new MetaDataContexts(contextManager.getMetaDataContexts().getPersistService(), new ShardingSphereMetaData(createDatabases(), + contextManager.renewMetaDataContexts(MetaDataContextsFactory.create(contextManager.getMetaDataContexts().getPersistService(), new ShardingSphereMetaData(createDatabases(), contextManager.getMetaDataContexts().getMetaData().getGlobalResourceMetaData(), contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), new ConfigurationProperties(new Properties())))); subscriber = new StateChangedSubscriber(contextManager); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java index a062877b7d22d..e2d80476f57f8 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java @@ -30,6 +30,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -83,7 +84,7 @@ void assertNewDatabaseConnectorWithParameters() { } private ContextManager mockContextManager(final ShardingSphereDatabase database) { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(Collections.singletonMap("foo_db", database), mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties()))); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorTest.java index f4e7beab42542..bdbd6cc904ad2 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorTest.java @@ -44,6 +44,7 @@ import org.apache.shardingsphere.metadata.persist.data.ShardingSphereDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration; import org.apache.shardingsphere.parser.rule.SQLParserRule; import org.apache.shardingsphere.proxy.backend.connector.jdbc.fixture.QueryHeaderBuilderFixture; @@ -122,7 +123,7 @@ private ContextManager mockContextManager() { when(shardingSphereDataPersistService.load(any())).thenReturn(Optional.empty()); when(metaDataPersistService.getShardingSphereDataPersistService()).thenReturn(shardingSphereDataPersistService); Map databases = mockDatabases(); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaDataPersistService, + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(metaDataPersistService, new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), globalRuleMetaData, new ConfigurationProperties(new Properties()))); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManagerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManagerTest.java index d646d28e20d49..335771c19d549 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManagerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManagerTest.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.connector.jdbc.connection.ConnectionPostProcessor; import org.apache.shardingsphere.proxy.backend.connector.jdbc.datasource.JDBCBackendDataSource; import org.apache.shardingsphere.proxy.backend.connector.jdbc.statement.JDBCBackendStatement; @@ -126,7 +127,7 @@ private ContextManager mockContextManager() { when(metaData.getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Collections.singletonList(transactionRule))); ComputeNodeInstanceContext computeNodeInstanceContext = mock(ComputeNodeInstanceContext.class); when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class)); - return new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext); + return new ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext); } @AfterEach diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java index ff1aca87b97d5..4cfc51b73187d 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java @@ -44,6 +44,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; @@ -111,7 +112,7 @@ void setUp() { when(metaData.getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Arrays.asList(mock(SQLFederationRule.class), transactionRule))); ComputeNodeInstanceContext computeNodeInstanceContext = mock(ComputeNodeInstanceContext.class); when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class)); - ContextManager contextManager = new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext); + ContextManager contextManager = new ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext); when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java index 377abef1650e0..f2398095694aa 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java @@ -30,6 +30,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.connector.jdbc.datasource.fixture.CallTimeRecordDataSource; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.test.mock.AutoMockExtension; @@ -84,7 +85,7 @@ void setUp() { private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData( + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData( createDatabases(), mock(ResourceMetaData.class), new RuleMetaData(Collections.singleton(mock(TransactionRule.class, RETURNS_DEEP_STUBS))), new ConfigurationProperties(new Properties()))); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/BackendExecutorContextTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/BackendExecutorContextTest.java index eac07feec0688..c7f758f4f7343 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/BackendExecutorContextTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/BackendExecutorContextTest.java @@ -21,6 +21,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; import org.junit.jupiter.api.Test; @@ -44,7 +45,7 @@ void assertGetInstance() { } private ContextManager mockContextManager() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java index c36c59fdeabec..14aed7658d945 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java @@ -29,6 +29,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -67,7 +68,7 @@ void restorePreviousContextManager() { @Test void assertInit() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); ProxyContext.init(new ContextManager(metaDataContexts, mock(ComputeNodeInstanceContext.class, RETURNS_DEEP_STUBS))); assertThat(ProxyContext.getInstance().getContextManager().getStateContext(), is(ProxyContext.getInstance().getContextManager().getStateContext())); assertThat(ProxyContext.getInstance().getContextManager().getStateContext().getCurrentClusterState(), is(ClusterState.OK)); @@ -80,7 +81,7 @@ void assertInit() { void assertDatabaseExists() { Map databases = mockDatabases(); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties()))); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); @@ -92,7 +93,7 @@ void assertDatabaseExists() { void assertGetAllDatabaseNames() { Map databases = createDatabases(); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties()))); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java index 8be713fff8195..407f68552cc2c 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor; import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeaderBuilder; @@ -117,6 +118,6 @@ private ContextManager mockContextManager() { mock(RuleMetaData.class), new ConfigurationProperties(new Properties())); ComputeNodeInstanceContext computeNodeInstanceContext = mock(ComputeNodeInstanceContext.class); when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class)); - return new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext); + return new ContextManager(MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData), computeNodeInstanceContext); } } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetaDataExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetaDataExecutorTest.java index dc4bc475c7cac..5cdb9c92b9d01 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetaDataExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetaDataExecutorTest.java @@ -31,6 +31,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; @@ -147,7 +148,7 @@ private ContextManager mockContextManager(final ShardingSphereDatabase database) AuthorityRule authorityRule = mock(AuthorityRule.class); when(authorityRule.findPrivileges(grantee)).thenReturn(Optional.of(new DatabasePermittedPrivileges(Collections.singleton("auth_db")))); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(Collections.singletonMap("auth_db", database), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(Collections.singletonMap("auth_db", database), mock(ResourceMetaData.class), new RuleMetaData(Collections.singleton(authorityRule)), new ConfigurationProperties(new Properties()))); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); when(result.getDatabase("auth_db")).thenReturn(database); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java index 0280cc6de2a91..9a0be958f7547 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java @@ -31,6 +31,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnector; import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnectorFactory; import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager; @@ -130,7 +131,7 @@ void assertDatabaseUsingStream() throws SQLException { private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(createDatabases(), mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties()))); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DatabaseOperateBackendHandlerFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DatabaseOperateBackendHandlerFactoryTest.java index 59a0670298a7f..44e15ea89d87f 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DatabaseOperateBackendHandlerFactoryTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DatabaseOperateBackendHandlerFactoryTest.java @@ -29,6 +29,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader; import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader; @@ -78,7 +79,7 @@ class DatabaseOperateBackendHandlerFactoryTest { @BeforeEach void setUp() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(getDatabases(), mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties()))); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); @@ -151,7 +152,7 @@ private Map getDatabases() { } private void setGovernanceMetaDataContexts(final boolean isGovernance) { - MetaDataContexts metaDataContexts = isGovernance ? mockMetaDataContexts() : new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + MetaDataContexts metaDataContexts = isGovernance ? mockMetaDataContexts() : MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java index be67ceb186837..316347ec114c4 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java @@ -36,6 +36,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.handler.distsql.DistSQLQueryBackendHandler; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; @@ -69,7 +70,7 @@ void assertExecuteWithNoDatabase() { @Test void assertExecuteWithUnknownDatabase() { ShardingSphereMetaData metaData = new ShardingSphereMetaData(); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), metaData); + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), metaData); ConnectionSession connectionSession = mock(ConnectionSession.class, RETURNS_DEEP_STUBS); when(connectionSession.getDatabaseName()).thenReturn("unknown"); ComputeNodeInstanceContext computeNodeInstanceContext = mock(ComputeNodeInstanceContext.class); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java index 602e04651f82e..8e181041a6f85 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java @@ -48,6 +48,7 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.standalone.workerid.generator.StandaloneWorkerIdGenerator; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyDataSourceConfiguration; import org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyDatabaseConfiguration; import org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyServerConfiguration; @@ -125,7 +126,7 @@ void assertExecuteWithEmptyMetaData() { private ContextManager mockEmptyContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(new HashMap<>(), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(new HashMap<>(), new ResourceMetaData(Collections.emptyMap()), new RuleMetaData(Collections.singletonList( new GlobalClockRule(new DefaultGlobalClockRuleConfigurationBuilder().build(), Collections.emptyMap()))), new ConfigurationProperties(new Properties()))); @@ -162,7 +163,7 @@ private Map createStorageUnits() { } private ContextManager mockContextManager() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(Collections.singletonMap(database.getName(), database), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(Collections.singletonMap(database.getName(), database), new ResourceMetaData(Collections.emptyMap()), new RuleMetaData(Arrays.asList(new AuthorityRule(new DefaultAuthorityRuleConfigurationBuilder().build()), new GlobalClockRule(new DefaultGlobalClockRuleConfigurationBuilder().build(), Collections.singletonMap(database.getName(), database)))), diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutorTest.java index c8e8ccc07912e..12b966ea91962 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutorTest.java @@ -35,6 +35,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -108,7 +109,7 @@ void assertExecuteWithEmptyMetaData() { private ContextManager mockEmptyContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(Collections.emptyMap(), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(Collections.emptyMap(), new ResourceMetaData(Collections.emptyMap()), new RuleMetaData(Collections.emptyList()), new ConfigurationProperties(new Properties()))); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; @@ -144,7 +145,7 @@ void assertExecuteWithDatabaseName() { private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(Collections.singletonMap(database.getName(), database), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(Collections.singletonMap(database.getName(), database), new ResourceMetaData(Collections.emptyMap()), new RuleMetaData(Collections.singleton(new AuthorityRule(new DefaultAuthorityRuleConfigurationBuilder().build()))), new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_SHOW.getKey(), "true"))))); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java index ed0ab2f345766..b2fd9f6871e2a 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java @@ -33,6 +33,7 @@ import org.apache.shardingsphere.metadata.persist.service.config.global.PropertiesPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.infra.exception.kernel.syntax.InvalidVariableValueException; import org.apache.shardingsphere.test.mock.AutoMockExtension; @@ -107,7 +108,7 @@ void assertExecuteWithWrongSystemLogLevel() { private ContextManager mockContextManager() { MetaDataPersistService metaDataPersistService = mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS); when(metaDataPersistService.getPropsService()).thenReturn(mock(PropertiesPersistService.class)); - ContextManager result = new ContextManager(new MetaDataContexts(metaDataPersistService, new ShardingSphereMetaData()), + ContextManager result = new ContextManager(MetaDataContextsFactory.create(metaDataPersistService, new ShardingSphereMetaData()), new ComputeNodeInstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class), new ModeConfiguration("Standalone", null), mock(LockContext.class), new EventBusContext())); return result; diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java index f73f2b24edad3..a84ec34397260 100644 --- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java +++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java @@ -28,6 +28,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor; @@ -354,7 +355,7 @@ void assertCreateWithSelectStatementFromPerformanceSchema() { private void initProxyContext(final Map databases) { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties()))); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowCreateDatabaseExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowCreateDatabaseExecutorTest.java index 2c8b650fe4004..eb560b6276b96 100644 --- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowCreateDatabaseExecutorTest.java +++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowCreateDatabaseExecutorTest.java @@ -28,6 +28,7 @@ import org.apache.shardingsphere.metadata.persist.data.ShardingSphereDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateDatabaseStatement; @@ -78,7 +79,7 @@ private ContextManager mockContextManager() { ShardingSphereDataPersistService shardingSphereDataPersistService = mock(ShardingSphereDataPersistService.class); when(shardingSphereDataPersistService.load(any())).thenReturn(Optional.empty()); when(metaDataPersistService.getShardingSphereDataPersistService()).thenReturn(shardingSphereDataPersistService); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaDataPersistService, + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(metaDataPersistService, new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties()))); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowCurrentUserExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowCurrentUserExecutorTest.java index fa5e4804bcda9..7892572ca27a9 100644 --- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowCurrentUserExecutorTest.java +++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowCurrentUserExecutorTest.java @@ -27,6 +27,7 @@ import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.test.mock.AutoMockExtension; @@ -65,7 +66,7 @@ void assertExecute() throws SQLException { private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(mock(MetaDataPersistService.class), new ShardingSphereMetaData(Collections.emptyMap(), mock(ResourceMetaData.class), mockRuleMetaData(), new ConfigurationProperties(new Properties()))); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutorTest.java index c7b09da8d7f52..ffa02896f53b4 100644 --- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutorTest.java +++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutorTest.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.metadata.persist.data.ShardingSphereDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.ShowFilterSegment; @@ -188,7 +189,7 @@ private ContextManager mockContextManager() { ShardingSphereDataPersistService shardingSphereDataPersistService = mock(ShardingSphereDataPersistService.class); when(shardingSphereDataPersistService.load(any())).thenReturn(Optional.empty()); when(metaDataPersistService.getShardingSphereDataPersistService()).thenReturn(shardingSphereDataPersistService); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaDataPersistService, new ShardingSphereMetaData(getDatabases(), + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(metaDataPersistService, new ShardingSphereMetaData(getDatabases(), mock(ResourceMetaData.class), globalRuleMetaData, new ConfigurationProperties(new Properties()))); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowFunctionStatusExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowFunctionStatusExecutorTest.java index b894c4720acd5..11d5112e3a103 100644 --- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowFunctionStatusExecutorTest.java +++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowFunctionStatusExecutorTest.java @@ -28,6 +28,7 @@ import org.apache.shardingsphere.metadata.persist.data.ShardingSphereDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowFunctionStatusStatement; @@ -70,7 +71,7 @@ private ContextManager mockContextManager() { ShardingSphereDataPersistService shardingSphereDataPersistService = mock(ShardingSphereDataPersistService.class); when(shardingSphereDataPersistService.load(any())).thenReturn(Optional.empty()); when(metaDataPersistService.getShardingSphereDataPersistService()).thenReturn(shardingSphereDataPersistService); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaDataPersistService, + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(metaDataPersistService, new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties()))); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowProcedureStatusExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowProcedureStatusExecutorTest.java index 926e2feb32efe..d5f753042c957 100644 --- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowProcedureStatusExecutorTest.java +++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowProcedureStatusExecutorTest.java @@ -28,6 +28,7 @@ import org.apache.shardingsphere.metadata.persist.data.ShardingSphereDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowProcedureStatusStatement; @@ -70,7 +71,7 @@ private ContextManager mockContextManager() { ShardingSphereDataPersistService shardingSphereDataPersistService = mock(ShardingSphereDataPersistService.class); when(shardingSphereDataPersistService.load(any())).thenReturn(Optional.empty()); when(metaDataPersistService.getShardingSphereDataPersistService()).thenReturn(shardingSphereDataPersistService); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaDataPersistService, + MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(metaDataPersistService, new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties()))); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java index 9d34ccd60c2ef..da44464a64ee2 100644 --- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java +++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.metadata.persist.data.ShardingSphereDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.FromSchemaSegment; @@ -192,7 +193,7 @@ private ContextManager mockContextManager(final Map each)), mock(ResourceMetaData.class), new RuleMetaData(Collections.singleton(authorityRule)), new ConfigurationProperties(new Properties()))); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); diff --git a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java index f022bfb3bb8e7..051917a512982 100644 --- a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java +++ b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java @@ -31,6 +31,7 @@ import org.apache.shardingsphere.metadata.persist.data.ShardingSphereDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -95,7 +96,7 @@ private ContextManager mockContextManager(final Map