From 8daeaab68d03bac73109686d5c40f62a57334804 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Fri, 17 Jan 2025 23:24:09 +0800 Subject: [PATCH] Refactor ShardingSphereStatisticsFactory (#34381) * Refactor ShardingSphereStatisticsFactory --- .../impl/proxy/ProxyMetaDataInfoExporterTest.java | 2 +- .../metadata/ShardingSphereStatisticsFactory.java | 13 +++---------- .../mode/metadata/MetaDataContextsTest.java | 8 +++++++- .../connector/DatabaseConnectorFactoryTest.java | 2 +- .../ProxyDatabaseConnectionManagerTest.java | 5 +++-- .../backend/connector/ProxySQLExecutorTest.java | 5 +++-- .../jdbc/datasource/JDBCBackendDataSourceTest.java | 2 +- .../proxy/backend/context/ProxyContextTest.java | 4 ++-- .../admin/DatabaseAdminQueryBackendHandlerTest.java | 3 ++- .../DefaultDatabaseMetaDataExecutorTest.java | 2 +- .../impl/UnicastDatabaseBackendHandlerTest.java | 2 +- .../DatabaseOperateBackendHandlerFactoryTest.java | 2 +- .../ral/queryable/ExportMetaDataExecutorTest.java | 4 ++-- .../queryable/ExportStorageNodesExecutorTest.java | 2 +- .../ral/updatable/ImportMetaDataExecutorTest.java | 2 +- .../admin/MySQLAdminExecutorCreatorTest.java | 2 +- .../admin/executor/UseDatabaseExecutorTest.java | 2 +- .../proxy/frontend/state/impl/OKProxyStateTest.java | 4 +++- 18 files changed, 35 insertions(+), 31 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 24183ca7aa808..51f220a60c97a 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 @@ -82,7 +82,7 @@ private ContextManager mockContextManager() { when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); when(metaData.getAllDatabases()).thenReturn(Collections.singleton(database)); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/ShardingSphereStatisticsFactory.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/ShardingSphereStatisticsFactory.java index 970bf73ad4c08..c8429aa0bbb0b 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/ShardingSphereStatisticsFactory.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/ShardingSphereStatisticsFactory.java @@ -53,21 +53,14 @@ public static ShardingSphereStatistics create(final MetaDataPersistService persi if (metaData.getAllDatabases().isEmpty()) { return new ShardingSphereStatistics(); } - Optional dialectStatisticsAppender = DatabaseTypedSPILoader.findService(DialectStatisticsAppender.class, getDatabaseType(metaData)); - if (!dialectStatisticsAppender.isPresent()) { - return new ShardingSphereStatistics(); - } + ShardingSphereStatistics loadedStatistics = persistService.getShardingSphereDataPersistService().load(metaData).orElse(new ShardingSphereStatistics()); Collection unloadedDatabases = metaData.getAllDatabases().stream().filter(each -> !loadedStatistics.containsDatabase(each.getName())).collect(Collectors.toList()); - return create(dialectStatisticsAppender.get(), unloadedDatabases, loadedStatistics); - } - - private static ShardingSphereStatistics create(final DialectStatisticsAppender dialectStatisticsAppender, - final Collection unloadedDatabases, final ShardingSphereStatistics loadedStatistics) { ShardingSphereStatistics result = new ShardingSphereStatistics(); + Optional dialectStatisticsAppender = DatabaseTypedSPILoader.findService(DialectStatisticsAppender.class, getDatabaseType(metaData)); for (ShardingSphereDatabase each : unloadedDatabases) { ShardingSphereDatabaseData databaseData = new ShardingSphereDefaultStatisticsBuilder().build(each); - dialectStatisticsAppender.append(databaseData, each); + dialectStatisticsAppender.ifPresent(optional -> optional.append(databaseData, each)); if (!databaseData.getSchemaData().isEmpty()) { result.putDatabase(each.getName(), databaseData); } 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 cd03e7b7488f6..66471c81f4472 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 @@ -26,11 +26,15 @@ import org.junit.jupiter.api.Test; import java.util.Collections; +import java.util.Optional; import java.util.Properties; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class MetaDataContextsTest { @@ -38,6 +42,8 @@ class MetaDataContextsTest { void assertGetDefaultMetaData() { ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), mock(), mock(), Collections.emptyList()); ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), new ConfigurationProperties(new Properties())); - assertThat(new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)).getMetaData().getDatabase("foo_db"), is(database)); + MetaDataPersistService persistService = mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS); + when(persistService.getShardingSphereDataPersistService().load(any())).thenReturn(Optional.empty()); + assertThat(new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(persistService, metaData)).getMetaData().getDatabase("foo_db"), is(database)); } } 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 0697b3e8bfbd8..800b7a0288cc4 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 @@ -97,7 +97,7 @@ void assertNewDatabaseConnectorWithParameters() { private ContextManager mockContextManager(final ShardingSphereDatabase database) { ShardingSphereMetaData metaData = new ShardingSphereMetaData( Collections.singleton(database), mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties())); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); when(result.getDatabase("foo_db")).thenReturn(database); 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 069953bd5d81e..c7f20f68dba9e 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 @@ -120,6 +120,7 @@ void setUp() { private ContextManager mockContextManager() { ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); when(metaData.getDatabase("foo_db")).thenReturn(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS)); + when(metaData.getAllDatabases()).thenReturn(Collections.singleton(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS))); when(metaData.getAllDatabases().iterator().next().getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); when(metaData.getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)).thenReturn(0); TransactionRule transactionRule = mock(TransactionRule.class); @@ -127,8 +128,8 @@ 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(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)), computeNodeInstanceContext, mock(PersistRepository.class)); + return new ContextManager(new MetaDataContexts(metaData, + ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)), computeNodeInstanceContext, mock(PersistRepository.class)); } @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 b2fbf98bf0e70..7f2fffa06d105 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 @@ -103,14 +103,15 @@ void setUp() { when(databaseConnectionManager.getConnectionSession().getUsedDatabaseName()).thenReturn("foo_db"); ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); when(metaData.getDatabase("foo_db")).thenReturn(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS)); + when(metaData.getAllDatabases()).thenReturn(Collections.singleton(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS))); when(metaData.getAllDatabases().iterator().next().getProtocolType()).thenReturn(databaseType); when(metaData.getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)).thenReturn(0); when(transactionRule.getDefaultType()).thenReturn(TransactionType.XA); 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(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)), computeNodeInstanceContext, mock(PersistRepository.class)); + ContextManager contextManager = new ContextManager(new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create( + mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)), computeNodeInstanceContext, mock(PersistRepository.class, RETURNS_DEEP_STUBS)); 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 d8a777e163f20..ee1c9911a1a39 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 @@ -86,7 +86,7 @@ private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(mockDatabase()), mock(ResourceMetaData.class), new RuleMetaData(Collections.singleton(mock(TransactionRule.class, RETURNS_DEEP_STUBS))), new ConfigurationProperties(new Properties())); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); 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 57f773f332949..d656b0c06db42 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 @@ -85,7 +85,7 @@ void assertDatabaseExists() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); ShardingSphereMetaData metaData = new ShardingSphereMetaData( Collections.singleton(mockDatabase()), mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties())); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); assertTrue(ProxyContext.getInstance().databaseExists("db")); @@ -97,7 +97,7 @@ void assertGetAllDatabaseNames() { Collection databases = createDatabases(); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(), mock(), new ConfigurationProperties(new Properties())); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); assertThat(new HashSet<>(ProxyContext.getInstance().getAllDatabaseNames()), is(databases.stream().map(ShardingSphereDatabase::getName).collect(Collectors.toSet()))); 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 e22aef245cc97..744b5a4a9e6d2 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 @@ -112,6 +112,7 @@ private ContextManager mockContextManager() { when(ProxyContext.getInstance().getContextManager().getDatabase("foo_db")).thenReturn(database); ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), new ConfigurationProperties(new Properties())); ComputeNodeInstanceContext computeNodeInstanceContext = mock(ComputeNodeInstanceContext.class, RETURNS_DEEP_STUBS); - return new ContextManager(new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)), computeNodeInstanceContext, mock()); + return new ContextManager( + new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)), computeNodeInstanceContext, mock()); } } 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 57511c2ffc919..54877809caf74 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 @@ -152,7 +152,7 @@ private ContextManager mockContextManager(final ShardingSphereDatabase database) ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); ShardingSphereMetaData metaData = new ShardingSphereMetaData( Collections.singleton(database), mock(ResourceMetaData.class), new RuleMetaData(Collections.singleton(authorityRule)), new ConfigurationProperties(new Properties())); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); when(result.getDatabase("auth_db")).thenReturn(database); when(ProxyContext.getInstance().getAllDatabaseNames()).thenReturn(Collections.singleton("auth_db")); 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 84ff4aaa25831..bc282e8f78a22 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 @@ -134,7 +134,7 @@ void assertDatabaseUsingStream() throws SQLException { private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); ShardingSphereMetaData metaData = new ShardingSphereMetaData(createDatabases(), mock(), mock(), mock()); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); 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 0691b4bc681e7..2964fe3bc1965 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 @@ -81,7 +81,7 @@ void setUp() { when(connectionSession.getConnectionContext().getGrantee()).thenReturn(null); ShardingSphereMetaData metaData = new ShardingSphereMetaData( Collections.singleton(mockDatabase()), mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties())); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); when(ProxyContext.getInstance().databaseExists("foo_db")).thenReturn(true); 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 dd339d317da7c..bd05f1696a36d 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 @@ -107,7 +107,7 @@ private ContextManager mockEmptyContextManager() { ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), new ResourceMetaData(Collections.emptyMap()), new RuleMetaData(Collections.singleton(new GlobalClockRule(new DefaultGlobalClockRuleConfigurationBuilder().build()))), new ConfigurationProperties(new Properties())); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; } @@ -138,7 +138,7 @@ private ContextManager mockContextManager() { new RuleMetaData(Arrays.asList(new AuthorityRule(new DefaultAuthorityRuleConfigurationBuilder().build()), new GlobalClockRule(new DefaultGlobalClockRuleConfigurationBuilder().build()))), new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_SHOW.getKey(), "true")))); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); ComputeNodeInstanceContext computeNodeInstanceContext = new ComputeNodeInstanceContext( new ComputeNodeInstance(mock(InstanceMetaData.class)), new ModeConfiguration("Standalone", null), new EventBusContext()); computeNodeInstanceContext.init(new StandaloneWorkerIdGenerator(), mock(LockContext.class)); 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 91518ea602449..93e193827746b 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 @@ -153,7 +153,7 @@ private ContextManager mockContextManager() { new ResourceMetaData(Collections.emptyMap()), new RuleMetaData(Collections.singleton(new AuthorityRule(new DefaultAuthorityRuleConfigurationBuilder().build()))), new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_SHOW.getKey(), "true")))); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java index f3b2113e04561..6ed80dbbb6d2e 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java @@ -118,7 +118,7 @@ private ContextManager mockContextManager() { new RuleMetaData(Arrays.asList(new AuthorityRule(new DefaultAuthorityRuleConfigurationBuilder().build()), new GlobalClockRule(new DefaultGlobalClockRuleConfigurationBuilder().build()))), new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_SHOW.getKey(), "true")))); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); ComputeNodeInstanceContext computeNodeInstanceContext = new ComputeNodeInstanceContext( new ComputeNodeInstance(mock(InstanceMetaData.class)), new ModeConfiguration("Standalone", null), new EventBusContext()); computeNodeInstanceContext.init(new StandaloneWorkerIdGenerator(), mock(LockContext.class)); 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 8bf5c19856e9a..24ec681407382 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 @@ -352,7 +352,7 @@ void assertCreateWithSelectStatementFromPerformanceSchema() { private void initProxyContext(final Collection databases) { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties())); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); 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/UseDatabaseExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UseDatabaseExecutorTest.java index 412f755762e61..48c589f5527f2 100644 --- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UseDatabaseExecutorTest.java +++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UseDatabaseExecutorTest.java @@ -85,7 +85,7 @@ void assertExecuteUseStatementBackendHandlerWhenSchemaNotExist() { private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); ShardingSphereMetaData metaData = new ShardingSphereMetaData(createDatabases(), mock(), mock(), mock()); - MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; } diff --git a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java index f04bb090a2dec..2bd8219220675 100644 --- a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java +++ b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java @@ -89,6 +89,7 @@ void assertExecuteWithDistributedTransaction() { private ContextManager mockContextManager() { ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); when(metaData.getDatabase("foo_db")).thenReturn(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS)); + when(metaData.getAllDatabases()).thenReturn(Collections.singleton(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS))); when(metaData.getAllDatabases().iterator().next().getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); when(metaData.getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)).thenReturn(0); TransactionRule transactionRule = mock(TransactionRule.class); @@ -96,7 +97,8 @@ 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(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class), metaData)), computeNodeInstanceContext, mock()); + return new ContextManager( + new MetaDataContexts(metaData, ShardingSphereStatisticsFactory.create(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS), metaData)), computeNodeInstanceContext, mock()); } @SuppressWarnings({"unchecked", "SameParameterValue"})