You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/05/26 11:50:59 UTC
[shardingsphere] branch master updated: Remove MetaDataContexts.getAllDatabaseNames() (#17977)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new d7d672f4969 Remove MetaDataContexts.getAllDatabaseNames() (#17977)
d7d672f4969 is described below
commit d7d672f4969c996fdb947690683e8f7d08128eae
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu May 26 19:50:53 2022 +0800
Remove MetaDataContexts.getAllDatabaseNames() (#17977)
---
.../shardingsphere/mode/metadata/MetaDataContexts.java | 10 ----------
.../manager/cluster/ClusterContextManagerBuilder.java | 2 +-
.../ClusterContextManagerCoordinatorTest.java | 2 +-
.../executor/callback/ProxyJDBCExecutorCallback.java | 6 +++---
.../proxy/backend/context/ProxyContext.java | 10 +++++-----
.../text/TextProtocolBackendHandlerFactoryTest.java | 16 +++++++++-------
.../admin/mysql/executor/UseDatabaseExecutorTest.java | 2 +-
.../text/database/CreateDatabaseBackendHandlerTest.java | 3 ++-
.../text/database/DropDatabaseBackendHandlerTest.java | 11 +++++++++--
.../text/distsql/DistSQLBackendHandlerFactoryTest.java | 2 +-
.../ral/common/queryable/CountInstanceRulesTest.java | 7 ++++++-
.../ExportDatabaseConfigurationHandlerTest.java | 2 +-
.../common/queryable/ShowTableMetadataHandlerTest.java | 2 +-
.../ImportDatabaseConfigurationHandlerTest.java | 2 +-
.../rdl/resource/AddResourceBackendHandlerTest.java | 4 ++--
.../rdl/resource/AlterResourceBackendHandlerTest.java | 6 +++---
.../rdl/resource/DropResourceBackendHandlerTest.java | 2 +-
.../backend/text/distsql/rql/RQLBackendHandlerTest.java | 4 ++--
.../distsql/rql/RuleDefinitionBackendHandlerTest.java | 3 ++-
.../proxy/version/ShardingSphereProxyVersion.java | 3 +--
.../protocol/FrontDatabaseProtocolTypeFactoryTest.java | 4 ++--
.../describe/PostgreSQLComDescribeExecutorTest.java | 14 ++++++++------
22 files changed, 62 insertions(+), 55 deletions(-)
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java
index 1632806cf0d..5c301f47d94 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java
@@ -26,7 +26,6 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Optional;
@@ -57,15 +56,6 @@ public final class MetaDataContexts implements AutoCloseable {
return Optional.ofNullable(persistService);
}
- /**
- * Get all database names.
- *
- * @return all database names
- */
- public Collection<String> getAllDatabaseNames() {
- return metaData.getDatabases().keySet();
- }
-
/**
* Get database.
*
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 1548d35f33d..722a6fcc4fe 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -97,7 +97,7 @@ public final class ClusterContextManagerBuilder implements ContextManagerBuilder
}
private Properties getTransactionProperties(final MetaDataContexts metaDataContexts) {
- Optional<String> databaseName = metaDataContexts.getAllDatabaseNames().stream().findFirst();
+ Optional<String> databaseName = metaDataContexts.getMetaData().getDatabases().keySet().stream().findFirst();
Optional<TransactionRule> transactionRule =
metaDataContexts.getMetaData().getGlobalRuleMetaData().getRules().stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
Optional<TransactionConfigurationFileGenerator> fileGenerator = transactionRule.isPresent()
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
index d33a6af361c..443b675ec23 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
@@ -205,7 +205,7 @@ public final class ClusterContextManagerCoordinatorTest {
TableMetaData changedTableMetaData = new TableMetaData("t_order", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
SchemaChangedEvent event = new SchemaChangedEvent("db", "db", changedTableMetaData, null);
coordinator.renew(event);
- assertTrue(contextManager.getMetaDataContexts().getAllDatabaseNames().contains("db"));
+ assertTrue(contextManager.getMetaDataContexts().getMetaData().getDatabases().containsKey("db"));
verify(contextManager.getMetaDataContexts().getDatabase("db").getSchemas().get("db")).put("t_order", event.getChangedTableMetaData());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
index 5667642f4e4..8d0ed39dd99 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
@@ -110,11 +110,11 @@ public abstract class ProxyJDBCExecutorCallback extends JDBCExecutorCallback<Exe
if (configuredDatabaseType.isPresent()) {
return configuredDatabaseType.get();
}
- if (ProxyContext.getInstance().getContextManager().getMetaDataContexts().getAllDatabaseNames().isEmpty()) {
+ if (ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases().isEmpty()) {
return DatabaseTypeEngine.getTrunkDatabaseType("MySQL");
}
- String schemaName = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getAllDatabaseNames().iterator().next();
- return ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabase(schemaName).getResource().getDatabaseType();
+ String databaseName = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases().keySet().iterator().next();
+ return ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabase(databaseName).getResource().getDatabaseType();
}
private static Optional<DatabaseType> findConfiguredDatabaseType() {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
index 450f68429df..a1d5180c3f6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
@@ -66,11 +66,11 @@ public final class ProxyContext {
/**
* Check database exists.
*
- * @param databaseName database name
+ * @param name database name
* @return database exists or not
*/
- public boolean databaseExists(final String databaseName) {
- return contextManager.getMetaDataContexts().getAllDatabaseNames().contains(databaseName);
+ public boolean databaseExists(final String name) {
+ return contextManager.getMetaDataContexts().getMetaData().getDatabases().containsKey(name);
}
/**
@@ -80,7 +80,7 @@ public final class ProxyContext {
* @return got database
*/
public ShardingSphereDatabase getDatabase(final String name) {
- if (Strings.isNullOrEmpty(name) || !contextManager.getMetaDataContexts().getAllDatabaseNames().contains(name)) {
+ if (Strings.isNullOrEmpty(name) || !contextManager.getMetaDataContexts().getMetaData().getDatabases().containsKey(name)) {
throw new NoDatabaseSelectedException();
}
return contextManager.getMetaDataContexts().getDatabase(name);
@@ -92,7 +92,7 @@ public final class ProxyContext {
* @return all database names
*/
public Collection<String> getAllDatabaseNames() {
- return contextManager.getMetaDataContexts().getAllDatabaseNames();
+ return contextManager.getMetaDataContexts().getMetaData().getDatabases().keySet();
}
/**
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
index c26d1be4b06..696577c0abb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
@@ -57,6 +57,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.sql.SQLException;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Optional;
import java.util.Properties;
@@ -86,7 +87,7 @@ public final class TextProtocolBackendHandlerFactoryTest extends ProxyContextRes
MetaDataContexts metaDataContexts = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS);
mockGlobalRuleMetaData(metaDataContexts);
ShardingSphereDatabase database = mockDatabase();
- when(metaDataContexts.getAllDatabaseNames().contains("db")).thenReturn(true);
+ when(metaDataContexts.getMetaData().getDatabases().containsKey("db")).thenReturn(true);
when(metaDataContexts.getMetaData().getDatabases().get("db")).thenReturn(database);
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
@@ -193,9 +194,10 @@ public final class TextProtocolBackendHandlerFactoryTest extends ProxyContextRes
@Test
public void assertNewInstanceWithSet() throws SQLException {
String sql = "set @num=1";
- ProxyContext instance = ProxyContext.getInstance();
- when(instance.getAllDatabaseNames()).thenReturn(Collections.singletonList("schema"));
- when(instance.getDatabase("schema").hasDataSource()).thenReturn(true);
+ ProxyContext proxyContext = ProxyContext.getInstance();
+ when(proxyContext.getAllDatabaseNames()).thenReturn(new HashSet<>(Collections.singletonList("schema")));
+ when(proxyContext.getContextManager().getMetaDataContexts().getMetaData().getDatabases().containsKey("schema")).thenReturn(true);
+ when(proxyContext.getDatabase("schema").hasDataSource()).thenReturn(true);
TextProtocolBackendHandler actual = TextProtocolBackendHandlerFactory.newInstance(databaseType, sql, Optional::empty, connectionSession);
assertThat(actual, instanceOf(BroadcastDatabaseBackendHandler.class));
}
@@ -226,9 +228,9 @@ public final class TextProtocolBackendHandlerFactoryTest extends ProxyContextRes
@Test
public void assertNewInstanceWithQuery() throws SQLException {
String sql = "select * from t_order limit 1";
- ProxyContext instance = ProxyContext.getInstance();
- when(instance.getAllDatabaseNames()).thenReturn(Collections.singletonList("db"));
- when(instance.getDatabase("db").hasDataSource()).thenReturn(true);
+ ProxyContext proxyContext = ProxyContext.getInstance();
+ when(proxyContext.getAllDatabaseNames()).thenReturn(new HashSet<>(Collections.singletonList("db")));
+ when(proxyContext.getDatabase("db").hasDataSource()).thenReturn(true);
TextProtocolBackendHandler actual = TextProtocolBackendHandlerFactory.newInstance(databaseType, sql, Optional::empty, connectionSession);
assertThat(actual, instanceOf(SchemaAssignedDatabaseBackendHandler.class));
sql = "select * from information_schema.schemata limit 1";
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java
index fdfbce7d7a7..85177535d39 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java
@@ -82,7 +82,7 @@ public final class UseDatabaseExecutorTest extends ProxyContextRestorer {
MySQLUseStatement useStatement = mock(MySQLUseStatement.class);
when(useStatement.getSchema()).thenReturn(String.format(DATABASE_PATTERN, 0));
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts().getAllDatabaseNames().contains(anyString())).thenReturn(true);
+ when(contextManager.getMetaDataContexts().getMetaData().getDatabases().containsKey(anyString())).thenReturn(true);
when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getRules()).thenReturn(Collections.emptyList());
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getRuleMetaData().getRules()).thenReturn(new LinkedList<>());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java
index a6472853c7e..f228230552a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.proxy.backend.text.database;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -54,7 +55,7 @@ public final class CreateDatabaseBackendHandlerTest extends ProxyContextRestorer
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.init(contextManager);
handler = new CreateDatabaseBackendHandler(statement);
- when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getMetaData().getDatabases()).thenReturn(Collections.singletonMap("test_db", mock(ShardingSphereDatabase.class)));
}
@SneakyThrows
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java
index 7ad3efc2fec..9ded773dde8 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.proxy.backend.text.database;
+import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -33,8 +34,9 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
@@ -65,7 +67,12 @@ public final class DropDatabaseBackendHandlerTest extends ProxyContextRestorer {
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.init(contextManager);
handler = new DropDatabaseBackendHandler(sqlStatement, connectionSession);
- when(metaDataContexts.getAllDatabaseNames()).thenReturn(Arrays.asList("test_db", "other_db"));
+ Map<String, ShardingSphereDatabase> databases = new HashMap<>(2, 1);
+ ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
+ when(database.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
+ databases.put("test_db", database);
+ databases.put("other_db", database);
+ when(metaDataContexts.getMetaData().getDatabases()).thenReturn(databases);
when(metaDataContexts.getMetaData().getGlobalRuleMetaData().getRules()).thenReturn(Collections.emptyList());
when(metaDataContexts.getDatabase(any()).getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
index 681d870a678..cb152a9fda0 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
@@ -271,7 +271,7 @@ public final class DistSQLBackendHandlerFactoryTest extends ProxyContextRestorer
private MetaDataContexts mockMetaDataContexts() {
MetaDataContexts result = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS);
- when(result.getAllDatabaseNames()).thenReturn(Collections.singletonList("db"));
+ when(result.getMetaData().getDatabases()).thenReturn(Collections.singletonMap("db", mock(ShardingSphereDatabase.class)));
when(result.getDatabase("db").getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
when(result.getDatabase("db").getResource().getDataSources()).thenReturn(Collections.emptyMap());
when(result.getDatabase("db").getResource().getNotExistedResources(any())).thenReturn(Collections.emptyList());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesTest.java
index d41bf01c25c..537e14a9ca4 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesTest.java
@@ -45,8 +45,10 @@ import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.Map;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
@@ -80,7 +82,10 @@ public final class CountInstanceRulesTest extends ProxyContextRestorer {
when(ruleMetaData.getConfigurations()).thenReturn(ruleConfigs);
when(database1.getRuleMetaData()).thenReturn(ruleMetaData);
when(database2.getRuleMetaData()).thenReturn(ruleMetaData);
- when(contextManager.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Arrays.asList("db_1", "db_2"));
+ Map<String, ShardingSphereDatabase> databases = new HashMap<>(2, 1);
+ databases.put("db_1", database1);
+ databases.put("db_2", database2);
+ when(contextManager.getMetaDataContexts().getMetaData().getDatabases()).thenReturn(databases);
when(contextManager.getMetaDataContexts().getDatabase("db_1")).thenReturn(database1);
when(contextManager.getMetaDataContexts().getDatabase("db_2")).thenReturn(database2);
ProxyContext.init(contextManager);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandlerTest.java
index ed8d8a43f9d..37c3698ed12 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandlerTest.java
@@ -61,11 +61,11 @@ public final class ExportDatabaseConfigurationHandlerTest extends ProxyContextRe
@Before
public void init() {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Collections.singletonList("sharding_db"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchemas().get("sharding_db")).thenReturn(new ShardingSphereSchema(createTableMap()));
when(database.getResource().getDataSources()).thenReturn(createDataSourceMap());
when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.singletonList(createShardingRuleConfiguration()));
+ when(contextManager.getMetaDataContexts().getMetaData().getDatabases()).thenReturn(Collections.singletonMap("sharding_db", database));
when(contextManager.getMetaDataContexts().getDatabase("sharding_db")).thenReturn(database);
ProxyContext.init(contextManager);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandlerTest.java
index 877022c91c6..0310ec2a811 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandlerTest.java
@@ -51,9 +51,9 @@ public final class ShowTableMetadataHandlerTest extends ProxyContextRestorer {
@Test
public void assertExecutor() throws SQLException {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Collections.singletonList("db_name"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchemas().get("db_name")).thenReturn(new ShardingSphereSchema(createTableMap()));
+ when(contextManager.getMetaDataContexts().getMetaData().getDatabases()).thenReturn(Collections.singletonMap("db_name", database));
when(contextManager.getMetaDataContexts().getDatabase("db_name")).thenReturn(database);
ProxyContext.init(contextManager);
ConnectionSession connectionSession = mock(ConnectionSession.class, RETURNS_DEEP_STUBS);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandlerTest.java
index e0a93cb6ec8..3e490315969 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandlerTest.java
@@ -135,10 +135,10 @@ public final class ImportDatabaseConfigurationHandlerTest extends ProxyContextRe
validatorField.setAccessible(true);
validatorField.set(importDatabaseConfigurationHandler, validator);
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Collections.singletonList(feature));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchemas().get(DefaultDatabase.LOGIC_NAME)).thenReturn(new ShardingSphereSchema(createTableMap()));
when(database.getResource().getDataSources()).thenReturn(createDataSourceMap());
+ when(contextManager.getMetaDataContexts().getMetaData().getDatabases()).thenReturn(Collections.singletonMap(feature, database));
when(contextManager.getMetaDataContexts().getDatabase(feature)).thenReturn(database);
ProxyContext.init(contextManager);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
index 817e169b693..74d07edcf6b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
@@ -88,7 +88,7 @@ public final class AddResourceBackendHandlerTest extends ProxyContextRestorer {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.init(contextManager);
- when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getMetaData().getDatabases()).thenReturn(Collections.singletonMap("test_db", database));
when(metaDataContexts.getDatabase("test_db")).thenReturn(database);
when(database.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.emptyMap());
@@ -101,7 +101,7 @@ public final class AddResourceBackendHandlerTest extends ProxyContextRestorer {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.init(contextManager);
- when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getMetaData().getDatabases()).thenReturn(Collections.singletonMap("test_db", database));
when(metaDataContexts.getDatabase("test_db")).thenReturn(database);
when(database.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.emptyMap());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
index e2ebb81233d..1227192b058 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
@@ -95,7 +95,7 @@ public final class AlterResourceBackendHandlerTest extends ProxyContextRestorer
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.init(contextManager);
- when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getMetaData().getDatabases()).thenReturn(Collections.singletonMap("test_db", database));
when(metaDataContexts.getDatabase("test_db")).thenReturn(database);
when(database.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.singletonMap("ds_0", mockHikariDataSource("ds_0")));
@@ -112,7 +112,7 @@ public final class AlterResourceBackendHandlerTest extends ProxyContextRestorer
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.init(contextManager);
- when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getMetaData().getDatabases()).thenReturn(Collections.singletonMap("test_db", database));
when(metaDataContexts.getDatabase("test_db")).thenReturn(database);
when(database.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.singletonMap("ds_0", dataSource));
@@ -124,7 +124,7 @@ public final class AlterResourceBackendHandlerTest extends ProxyContextRestorer
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.init(contextManager);
- when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getMetaData().getDatabases()).thenReturn(Collections.singletonMap("test_db", database));
when(metaDataContexts.getDatabase("test_db")).thenReturn(database);
when(database.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.singletonMap("ds_0", mockHikariDataSource("ds_1")));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
index 90eb98a0d0f..1a810e57a66 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
@@ -83,7 +83,7 @@ public final class DropResourceBackendHandlerTest extends ProxyContextRestorer {
@Before
public void setUp() throws Exception {
MetaDataContexts metaDataContexts = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS);
- when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test"));
+ when(metaDataContexts.getMetaData().getDatabases()).thenReturn(Collections.singletonMap("test", database));
when(metaDataContexts.getDatabase("test")).thenReturn(database);
when(database.getRuleMetaData()).thenReturn(ruleMetaData);
when(database.getResource()).thenReturn(resource);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java
index 1b4d85597b0..e3212a70296 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java
@@ -49,11 +49,11 @@ public final class RQLBackendHandlerTest extends ProxyContextRestorer {
@Before
public void setUp() {
- MetaDataContexts metaDataContexts = mock(MetaDataContexts.class);
- when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test"));
+ MetaDataContexts metaDataContexts = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS);
ShardingSphereRuleMetaData ruleMetaData = mock(ShardingSphereRuleMetaData.class);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
when(database.getRuleMetaData()).thenReturn(ruleMetaData);
+ when(metaDataContexts.getMetaData().getDatabases()).thenReturn(Collections.singletonMap("test", database));
when(metaDataContexts.getDatabase("test")).thenReturn(database);
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java
index ace3e0c0da7..a8baceb750e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.rql;
import io.netty.util.DefaultAttributeMap;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -51,7 +52,7 @@ public final class RuleDefinitionBackendHandlerTest extends ProxyContextRestorer
private ContextManager mockContextManager() {
ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(result.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Collections.singleton("test"));
+ when(result.getMetaDataContexts().getMetaData().getDatabases()).thenReturn(Collections.singletonMap("test", mock(ShardingSphereDatabase.class)));
when(result.getMetaDataContexts().getDatabase("test").getRuleMetaData()).thenReturn(mock(ShardingSphereRuleMetaData.class));
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java
index 2e37bc93639..388bcf9f087 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java
@@ -44,8 +44,7 @@ public final class ShardingSphereProxyVersion {
*/
public static void setVersion(final ContextManager contextManager) {
CommonConstants.PROXY_VERSION.set(ShardingSphereProxyVersion.getProxyVersion());
- contextManager.getMetaDataContexts().getAllDatabaseNames()
- .forEach(each -> setDatabaseVersion(each, contextManager.getDataSourceMap(each)));
+ contextManager.getMetaDataContexts().getMetaData().getDatabases().keySet().forEach(each -> setDatabaseVersion(each, contextManager.getDataSourceMap(each)));
}
private static String getProxyVersion() {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java
index 6d2348c7a1a..c0b248fc746 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java
@@ -67,7 +67,7 @@ public final class FrontDatabaseProtocolTypeFactoryTest extends ProxyContextRest
assertFalse(metaDataContexts.getMetaData().getDatabases().isEmpty());
String configuredDatabaseType = metaDataContexts.getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE);
assertTrue(configuredDatabaseType.isEmpty());
- assertTrue(metaDataContexts.getAllDatabaseNames().contains(DefaultDatabase.LOGIC_NAME));
+ assertTrue(metaDataContexts.getMetaData().getDatabases().containsKey(DefaultDatabase.LOGIC_NAME));
DatabaseType databaseType = FrontDatabaseProtocolTypeFactory.getDatabaseType();
assertThat(databaseType, instanceOf(DatabaseType.class));
assertThat(databaseType.getType(), is("MySQL"));
@@ -81,7 +81,7 @@ public final class FrontDatabaseProtocolTypeFactoryTest extends ProxyContextRest
assertFalse(metaDataContexts.getMetaData().getDatabases().isEmpty());
String configuredDatabaseType = metaDataContexts.getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE);
assertThat(configuredDatabaseType, is("PostgreSQL"));
- assertTrue(metaDataContexts.getAllDatabaseNames().contains(DefaultDatabase.LOGIC_NAME));
+ assertTrue(metaDataContexts.getMetaData().getDatabases().containsKey(DefaultDatabase.LOGIC_NAME));
DatabaseType databaseType = FrontDatabaseProtocolTypeFactory.getDatabaseType();
assertThat(databaseType, instanceOf(DatabaseType.class));
assertThat(databaseType.getType(), is("PostgreSQL"));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
index 7b95873ba5b..179a44b7b26 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
@@ -31,6 +31,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
+import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine;
@@ -89,7 +90,7 @@ public final class PostgreSQLComDescribeExecutorTest extends ProxyContextRestore
private static final ShardingSphereSQLParserEngine SQL_PARSER_ENGINE = new ShardingSphereSQLParserEngine("PostgreSQL", new CacheOption(2000, 65535L), new CacheOption(128, 1024L), false);
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ContextManager mockContextManager;
+ private ContextManager contextManager;
@Mock
private PostgreSQLConnectionContext connectionContext;
@@ -105,11 +106,12 @@ public final class PostgreSQLComDescribeExecutorTest extends ProxyContextRestore
@Before
public void setup() {
- ProxyContext.init(mockContextManager);
+ ProxyContext.init(contextManager);
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.SQL_SHOW)).thenReturn(false);
when(connectionSession.getDatabaseName()).thenReturn(DATABASE_NAME);
- when(mockContextManager.getMetaDataContexts().getAllDatabaseNames().contains(DATABASE_NAME)).thenReturn(true);
- when(mockContextManager.getMetaDataContexts().getDatabase(any(String.class)).getRuleMetaData().findSingleRule(SQLTranslatorRule.class))
+ when(contextManager.getMetaDataContexts().getMetaData().getDatabases().containsKey(DATABASE_NAME)).thenReturn(true);
+ when(contextManager.getMetaDataContexts().getMetaData().getDatabases().get(DATABASE_NAME)).thenReturn(mock(ShardingSphereDatabase.class));
+ when(contextManager.getMetaDataContexts().getDatabase(any(String.class)).getRuleMetaData().findSingleRule(SQLTranslatorRule.class))
.thenReturn(Optional.of(new SQLTranslatorRule(new SQLTranslatorRuleConfiguration())));
prepareTableMetaData();
}
@@ -121,8 +123,8 @@ public final class PostgreSQLComDescribeExecutorTest extends ProxyContextRestore
new ColumnMetaData("c", Types.CHAR, true, false, false),
new ColumnMetaData("pad", Types.CHAR, true, false, false));
TableMetaData tableMetaData = new TableMetaData(TABLE_NAME, columnMetaData, Collections.emptyList(), Collections.emptyList());
- when(mockContextManager.getMetaDataContexts().getDatabase(DATABASE_NAME).getSchemas().get("public").get(TABLE_NAME)).thenReturn(tableMetaData);
- when(mockContextManager.getMetaDataContexts().getDatabase(DATABASE_NAME).getResource().getDatabaseType()).thenReturn(new PostgreSQLDatabaseType());
+ when(contextManager.getMetaDataContexts().getDatabase(DATABASE_NAME).getSchemas().get("public").get(TABLE_NAME)).thenReturn(tableMetaData);
+ when(contextManager.getMetaDataContexts().getDatabase(DATABASE_NAME).getResource().getDatabaseType()).thenReturn(new PostgreSQLDatabaseType());
}
@Test