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 2021/01/07 14:11:17 UTC
[shardingsphere] branch master updated: Support different Database
types for Query optimization and fixed some bugs (#8918)
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 064e486 Support different Database types for Query optimization and fixed some bugs (#8918)
064e486 is described below
commit 064e4867c8fb55da9761dc9c9784e51452c9046d
Author: Jieker <ji...@163.com>
AuthorDate: Thu Jan 7 22:10:53 2021 +0800
Support different Database types for Query optimization and fixed some bugs (#8918)
* Support different Database types for Query optimization and fix some bugs
* Support different Database types for Query optimization and fix some bugs
* fix some problem
* fixed some related problems
* fixed some related problems
* fixed some related problems
* maked more clear
* fixed some problems
* fixed some problems
* fixed some problems
---
.../metadata/MetaDataContextsBuilderTest.java | 10 +--
.../optimize/context/CalciteContextFactory.java | 94 ++++++++++++++++------
.../optimize/schema/CalciteLogicSchemaFactory.java | 9 ++-
.../context/CalciteContextFactoryTest.java | 61 ++++++++++++++
.../DatabaseCommunicationEngineFactoryTest.java | 2 +
.../DatabaseCommunicationEngineTest.java | 2 +
.../jdbc/datasource/JDBCBackendDataSourceTest.java | 2 +
.../proxy/backend/context/ProxyContextTest.java | 2 +
.../mysql/executor/ShowDatabasesExecutorTest.java | 5 +-
.../mysql/executor/ShowTablesExecutorTest.java | 2 +
.../mysql/executor/UseDatabaseExecutorTest.java | 5 +-
.../impl/BroadcastDatabaseBackendHandlerTest.java | 2 +
.../SchemaAssignedDatabaseBackendHandlerTest.java | 2 +
.../impl/UnicastDatabaseBackendHandlerTest.java | 2 +
.../hint/ShardingCTLHintBackendHandlerTest.java | 4 +-
.../frontend/mysql/MySQLFrontendEngineTest.java | 37 +++++----
16 files changed, 188 insertions(+), 53 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContextsBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContextsBuilderTest.java
index 71d3a2a..09c1d4e 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContextsBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContextsBuilderTest.java
@@ -37,7 +37,7 @@ import static org.junit.Assert.assertTrue;
@RunWith(MockitoJUnitRunner.class)
public final class MetaDataContextsBuilderTest {
-
+
@Test
public void assertBuildWithoutConfiguration() throws SQLException {
MetaDataContexts actual = new MetaDataContextsBuilder(Collections.emptyMap(), Collections.emptyMap(), null).build();
@@ -45,7 +45,7 @@ public final class MetaDataContextsBuilderTest {
assertTrue(((DefaultAuthentication) actual.getAuthentication()).getUsers().isEmpty());
assertTrue(actual.getProps().getProps().isEmpty());
}
-
+
@Test
public void assertBuildWithConfigurationsButWithoutDataSource() throws SQLException {
Properties props = new Properties();
@@ -58,7 +58,7 @@ public final class MetaDataContextsBuilderTest {
assertThat(actual.getProps().getProps().size(), is(1));
assertThat(actual.getProps().getValue(ConfigurationPropertyKey.EXECUTOR_SIZE), is(1));
}
-
+
@Test
public void assertBuildWithConfigurationsAndDataSources() throws SQLException {
Properties props = new Properties();
@@ -71,12 +71,12 @@ public final class MetaDataContextsBuilderTest {
assertThat(actual.getProps().getProps().size(), is(1));
assertThat(actual.getProps().getValue(ConfigurationPropertyKey.EXECUTOR_SIZE), is(1));
}
-
+
private void assertRules(final MetaDataContexts actual) {
assertThat(actual.getMetaData("logic_db").getRuleMetaData().getRules().size(), is(1));
assertThat(actual.getMetaData("logic_db").getRuleMetaData().getRules().iterator().next(), CoreMatchers.instanceOf(FixtureRule.class));
}
-
+
private void assertDataSources(final MetaDataContexts actual) {
assertThat(actual.getMetaData("logic_db").getResource().getDataSources().size(), is(1));
assertThat(actual.getMetaData("logic_db").getResource().getDataSources().get("ds"), CoreMatchers.instanceOf(MockedDataSource.class));
diff --git a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContextFactory.java b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContextFactory.java
index cd45e84..f0bdab8 100644
--- a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContextFactory.java
+++ b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContextFactory.java
@@ -39,6 +39,15 @@ import org.apache.calcite.sql.validate.SqlValidator;
import org.apache.calcite.sql.validate.SqlValidatorUtil;
import org.apache.calcite.sql2rel.SqlToRelConverter;
import org.apache.calcite.sql2rel.StandardConvertletTable;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.MariaDBDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.OracleDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.SQL92DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.SQLServerDatabaseType;
+import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.optimize.execute.raw.plan.PlannerInitializer;
import org.apache.shardingsphere.infra.optimize.schema.CalciteLogicSchema;
@@ -53,8 +62,12 @@ import java.util.Properties;
* Calcite context factory.
*/
public final class CalciteContextFactory {
-
- private final Properties properties;
+
+ private static final String LEX_CAMEL_NAME = CalciteConnectionProperty.LEX.camelName();
+
+ private static final String CONFORMANCE_CAMEL_NAME = CalciteConnectionProperty.CONFORMANCE.camelName();
+
+ private final Properties properties = new Properties();
private final CalciteConnectionConfig connectionConfig;
@@ -67,24 +80,60 @@ public final class CalciteContextFactory {
private final RelOptCluster cluster;
public CalciteContextFactory(final Map<String, ShardingSphereMetaData> metaDataMap) {
- properties = createProperties();
+ DatabaseType databaseType = metaDataMap.isEmpty() ? null : metaDataMap.values().iterator().next().getResource().getDatabaseType();
+ initProperties(databaseType);
+ typeFactory = new JavaTypeFactoryImpl();
+ cluster = newCluster();
+ factory = new CalciteLogicSchemaFactory(metaDataMap);
connectionConfig = new CalciteConnectionConfigImpl(properties);
parserConfig = SqlParser.config()
.withLex(connectionConfig.lex())
.withIdentifierMaxLength(SqlParser.DEFAULT_IDENTIFIER_MAX_LENGTH)
.withConformance(connectionConfig.conformance())
.withParserFactory(SqlParserImpl.FACTORY);
- typeFactory = new JavaTypeFactoryImpl();
- factory = new CalciteLogicSchemaFactory(metaDataMap);
- cluster = newCluster();
}
- private Properties createProperties() {
- // TODO Not only MySQL here.
- Properties result = new Properties();
- result.setProperty(CalciteConnectionProperty.LEX.camelName(), Lex.MYSQL.name());
- result.setProperty(CalciteConnectionProperty.CONFORMANCE.camelName(), SqlConformanceEnum.MYSQL_5.name());
- return result;
+ private void initProperties(final DatabaseType databaseType) {
+ // TODO Logic could be improved.
+ if (databaseType instanceof MySQLDatabaseType || databaseType == null) {
+ this.properties.setProperty(LEX_CAMEL_NAME, Lex.MYSQL.name());
+ this.properties.setProperty(CONFORMANCE_CAMEL_NAME, SqlConformanceEnum.MYSQL_5.name());
+ return;
+ }
+ if (databaseType instanceof H2DatabaseType) {
+ // TODO No suitable type of Lex
+ this.properties.setProperty(LEX_CAMEL_NAME, Lex.MYSQL.name());
+ this.properties.setProperty(CONFORMANCE_CAMEL_NAME, SqlConformanceEnum.DEFAULT.name());
+ return;
+ }
+ if (databaseType instanceof MariaDBDatabaseType) {
+ this.properties.setProperty(LEX_CAMEL_NAME, Lex.MYSQL.name());
+ this.properties.setProperty(CONFORMANCE_CAMEL_NAME, SqlConformanceEnum.MYSQL_5.name());
+ return;
+ }
+ if (databaseType instanceof OracleDatabaseType) {
+ this.properties.setProperty(LEX_CAMEL_NAME, Lex.ORACLE.name());
+ this.properties.setProperty(CONFORMANCE_CAMEL_NAME, SqlConformanceEnum.ORACLE_12.name());
+ return;
+ }
+ if (databaseType instanceof PostgreSQLDatabaseType) {
+ // TODO No suitable type of Lex and conformance
+ this.properties.setProperty(LEX_CAMEL_NAME, Lex.MYSQL.name());
+ this.properties.setProperty(CONFORMANCE_CAMEL_NAME, SqlConformanceEnum.DEFAULT.name());
+ return;
+ }
+ if (databaseType instanceof SQL92DatabaseType) {
+ // TODO No suitable type of Lex
+ this.properties.setProperty(LEX_CAMEL_NAME, Lex.MYSQL.name());
+ this.properties.setProperty(CONFORMANCE_CAMEL_NAME, SqlConformanceEnum.STRICT_92.name());
+ return;
+ }
+ if (databaseType instanceof SQLServerDatabaseType) {
+ this.properties.setProperty(LEX_CAMEL_NAME, Lex.SQL_SERVER.name());
+ this.properties.setProperty(CONFORMANCE_CAMEL_NAME, SqlConformanceEnum.SQL_SERVER_2008.name());
+ return;
+ }
+ throw new ShardingSphereException("No matching DatabaseType found");
}
private RelOptCluster newCluster() {
@@ -101,23 +150,20 @@ public final class CalciteContextFactory {
* @return calcite context
*/
public CalciteContext create(final String schema, final CalciteRowExecutor executor) {
- return create(connectionConfig, parserConfig, typeFactory, cluster, factory.create(schema, executor));
- }
-
- private CalciteContext create(final CalciteConnectionConfig config,
- final SqlParser.Config parserConfig, final RelDataTypeFactory typeFactory, final RelOptCluster cluster, final CalciteLogicSchema calciteLogicSchema) {
- CalciteCatalogReader catalogReader = createCalciteCatalogReader(config, typeFactory, calciteLogicSchema);
- SqlValidator validator = createSqlValidator(config, typeFactory, catalogReader);
+ CalciteLogicSchema calciteLogicSchema = factory.create(schema, executor);
+ CalciteCatalogReader catalogReader = createCalciteCatalogReader(schema, connectionConfig, typeFactory, calciteLogicSchema);
+ SqlValidator validator = createSqlValidator(connectionConfig, typeFactory, catalogReader);
SqlToRelConverter relConverter = createSqlToRelConverter(cluster, validator, catalogReader);
return new CalciteContext(properties, calciteLogicSchema, parserConfig, validator, relConverter);
}
-
- private CalciteCatalogReader createCalciteCatalogReader(final CalciteConnectionConfig config, final RelDataTypeFactory typeFactory, final CalciteLogicSchema calciteLogicSchema) {
+
+ private CalciteCatalogReader createCalciteCatalogReader(final String schema, final CalciteConnectionConfig config,
+ final RelDataTypeFactory typeFactory, final CalciteLogicSchema calciteLogicSchema) {
CalciteSchema rootSchema = CalciteSchema.createRootSchema(true);
rootSchema.add(calciteLogicSchema.getName(), calciteLogicSchema);
- return new CalciteCatalogReader(rootSchema, Collections.singletonList(config.schema()), typeFactory, config);
+ return new CalciteCatalogReader(rootSchema, Collections.singletonList(schema), typeFactory, config);
}
-
+
private SqlValidator createSqlValidator(final CalciteConnectionConfig config, final RelDataTypeFactory typeFactory, final CalciteCatalogReader catalogReader) {
return SqlValidatorUtil.newValidator(SqlStdOperatorTable.instance(), catalogReader, typeFactory, SqlValidator.Config.DEFAULT
.withLenientOperatorLookup(config.lenientOperatorLookup())
@@ -125,7 +171,7 @@ public final class CalciteContextFactory {
.withDefaultNullCollation(config.defaultNullCollation())
.withIdentifierExpansion(true));
}
-
+
private SqlToRelConverter createSqlToRelConverter(final RelOptCluster cluster, final SqlValidator validator, final CalciteCatalogReader catalogReader) {
SqlToRelConverter.Config config = SqlToRelConverter.config().withTrimUnusedFields(true);
RelOptTable.ViewExpander expander = (rowType, queryString, schemaPath, viewPath) -> null;
diff --git a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/schema/CalciteLogicSchemaFactory.java b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/schema/CalciteLogicSchemaFactory.java
index 38f706e..5b332e5 100644
--- a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/schema/CalciteLogicSchemaFactory.java
+++ b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/schema/CalciteLogicSchemaFactory.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.infra.optimize.schema;
import org.apache.commons.collections4.map.LinkedMap;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.optimize.schema.row.CalciteRowExecutor;
import org.apache.shardingsphere.infra.optimize.schema.generator.CalciteLogicSchemaGenerator;
+import org.apache.shardingsphere.infra.optimize.schema.row.CalciteRowExecutor;
import java.sql.SQLException;
import java.util.Map;
@@ -32,9 +32,9 @@ import java.util.Map.Entry;
* Calcite logic schema factory.
*/
public final class CalciteLogicSchemaFactory {
-
+
private final Map<String, CalciteLogicSchemaGenerator> schemas = new LinkedMap<>();
-
+
public CalciteLogicSchemaFactory(final Map<String, ShardingSphereMetaData> metaDataMap) {
for (Entry<String, ShardingSphereMetaData> each : metaDataMap.entrySet()) {
try {
@@ -44,7 +44,7 @@ public final class CalciteLogicSchemaFactory {
}
}
}
-
+
/**
* Create schema.
*
@@ -59,3 +59,4 @@ public final class CalciteLogicSchemaFactory {
return schemas.get(name).create(executor);
}
}
+
diff --git a/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/context/CalciteContextFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/context/CalciteContextFactoryTest.java
new file mode 100644
index 0000000..e78d940
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/context/CalciteContextFactoryTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.optimize.context;
+
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
+import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
+import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
+import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
+import org.apache.shardingsphere.infra.optimize.schema.CalciteLogicSchema;
+import org.apache.shardingsphere.infra.optimize.schema.row.CalciteRowExecutor;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+public final class CalciteContextFactoryTest {
+
+ @Test
+ public void assertCreate() {
+ ShardingSphereResource shardingSphereResource = new ShardingSphereResource(null, null, null, new H2DatabaseType());
+ ShardingSphereSchema schema = new ShardingSphereSchema();
+ schema.put("tab_user", mock(TableMetaData.class));
+ ShardingSphereRuleMetaData metaData = new ShardingSphereRuleMetaData(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
+ ShardingSphereMetaData shardingSphereMetaData = new ShardingSphereMetaData("logic_db", shardingSphereResource, metaData, schema);
+ CalciteContextFactory calciteContextFactory = new CalciteContextFactory(Collections.singletonMap("logic_db", shardingSphereMetaData));
+ assertNotNull(calciteContextFactory);
+ CalciteContext logicDb = calciteContextFactory.create("logic_db", new CalciteRowExecutor(Collections.EMPTY_LIST, 0, null, mock(JDBCExecutor.class), mock(ExecutionContext.class), null));
+ assertNotNull(logicDb);
+ Properties properties = logicDb.getConnectionProperties();
+ assertNotNull(properties);
+ assertThat(properties.getProperty("lex"), is("MYSQL"));
+ assertThat(properties.getProperty("conformance"), is("DEFAULT"));
+ CalciteLogicSchema calciteLogicSchema = logicDb.getCalciteLogicSchema();
+ assertNotNull(calciteLogicSchema);
+ assertThat(calciteLogicSchema.getName(), is("logic_db"));
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
index 0bbfae7..9b4d4eb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.proxy.backend.communication;
import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
@@ -55,6 +56,7 @@ public final class DatabaseCommunicationEngineFactoryTest {
private Map<String, ShardingSphereMetaData> getMetaDataMap() {
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
+ when(result.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
return Collections.singletonMap("schema", result);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineTest.java
index 443afb2..da03a46 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
@@ -74,6 +75,7 @@ public final class DatabaseCommunicationEngineTest {
private Map<String, ShardingSphereMetaData> getMetaDataMap() {
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
+ when(result.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
return Collections.singletonMap("schema", result);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java
index da3bc57..13ef5bb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java
@@ -22,6 +22,7 @@ import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -79,6 +80,7 @@ public final class JDBCBackendDataSourceTest {
private Map<String, ShardingSphereMetaData> createMetaDataMap() {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.getName()).thenReturn("schema");
+ when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
when(metaData.getResource().getDataSources()).thenReturn(mockDataSources(2));
return Collections.singletonMap("schema", metaData);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
index 311d597..7df16a7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -143,6 +144,7 @@ public final class ProxyContextTest {
private Map<String, ShardingSphereMetaData> mockMetaDataMap(final Map<String, DataSource> mockDataSourceMap) {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.getName()).thenReturn("schema");
+ when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
when(metaData.getResource().getDataSources()).thenReturn(mockDataSourceMap);
return Collections.singletonMap("schema", metaData);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
index f82797d..c7a0e0a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.auth.ShardingSphereUser;
import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
@@ -41,6 +42,7 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -63,7 +65,8 @@ public final class ShowDatabasesExecutorTest {
private Map<String, ShardingSphereMetaData> getMetaDataMap() {
Map<String, ShardingSphereMetaData> result = new HashMap<>(10);
for (int i = 0; i < 10; i++) {
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
+ when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
when(metaData.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()));
result.put(String.format(SCHEMA_PATTERN, i), metaData);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java
index c57006f..0df200f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.auth.ShardingSphereUser;
import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
@@ -61,6 +62,7 @@ public final class ShowTablesExecutorTest {
for (int i = 0; i < 10; i++) {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.isComplete()).thenReturn(false);
+ when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
result.put(String.format(SCHEMA_PATTERN, i), metaData);
}
return result;
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 02150c6..268aed5 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
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.auth.ShardingSphereUser;
import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
@@ -40,6 +41,7 @@ import java.util.Map;
import java.util.Properties;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -63,7 +65,8 @@ public final class UseDatabaseExecutorTest {
private Map<String, ShardingSphereMetaData> getMetaDataMap() {
Map<String, ShardingSphereMetaData> result = new HashMap<>(10, 1);
for (int i = 0; i < 10; i++) {
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
+ when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
when(metaData.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()));
result.put(String.format(SCHEMA_PATTERN, i), metaData);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java
index 1c141e8..006ce63 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -95,6 +96,7 @@ public final class BroadcastDatabaseBackendHandlerTest {
for (int i = 0; i < 10; i++) {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.isComplete()).thenReturn(true);
+ when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
result.put(String.format(SCHEMA_PATTERN, i), metaData);
}
return result;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
index d277afc..9f68b9c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -91,6 +92,7 @@ public final class SchemaAssignedDatabaseBackendHandlerTest {
for (int i = 0; i < 10; i++) {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.isComplete()).thenReturn(true);
+ when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
result.put(String.format(SCHEMA_PATTERN, i), metaData);
}
return result;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
index ff7b764..fc066ba 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.auth.ShardingSphereUser;
import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
@@ -89,6 +90,7 @@ public final class UnicastDatabaseBackendHandlerTest {
for (int i = 0; i < 10; i++) {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.isComplete()).thenReturn(true);
+ when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
result.put(String.format(SCHEMA_PATTERN, i), metaData);
}
return result;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
index a80048d..00a6250 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -197,9 +198,10 @@ public final class ShardingCTLHintBackendHandlerTest {
}
private Map<String, ShardingSphereMetaData> getMetaDataMap() {
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.getSchema()).thenReturn(new ShardingSphereSchema(ImmutableMap.of("user", mock(TableMetaData.class))));
when(metaData.isComplete()).thenReturn(true);
+ when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
when(metaData.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()));
return Collections.singletonMap("schema", metaData);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
index 83a7dd7..21c143b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
@@ -30,6 +30,7 @@ import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
@@ -59,31 +60,32 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class MySQLFrontendEngineTest {
-
+
private static final String SCHEMA_PATTERN = "schema_%s";
-
+
private MySQLFrontendEngine mysqlFrontendEngine;
-
+
@Mock
private ChannelHandlerContext context;
-
+
@Mock
private MySQLPacketPayload payload;
-
+
@Mock
private Channel channel;
-
+
@Before
public void setUp() {
resetConnectionIdGenerator();
}
-
+
@SneakyThrows(ReflectiveOperationException.class)
private void resetConnectionIdGenerator() {
Field field = ConnectionIdGenerator.class.getDeclaredField("currentId");
@@ -91,13 +93,13 @@ public final class MySQLFrontendEngineTest {
field.set(ConnectionIdGenerator.getInstance(), 0);
mysqlFrontendEngine = new MySQLFrontendEngine();
}
-
+
@Test
public void assertHandshake() {
assertTrue(mysqlFrontendEngine.getAuthEngine().handshake(context) > 0);
verify(context).writeAndFlush(isA(MySQLHandshakePacket.class));
}
-
+
@Test
public void assertAuthWhenLoginSuccess() {
setConnectionPhase(MySQLConnectionPhase.AUTH_PHASE_FAST_PATH);
@@ -110,7 +112,7 @@ public final class MySQLFrontendEngineTest {
assertTrue(actual.isFinished());
verify(context).writeAndFlush(isA(MySQLOKPacket.class));
}
-
+
@Test
public void assertAuthWhenLoginFailure() {
setConnectionPhase(MySQLConnectionPhase.AUTH_PHASE_FAST_PATH);
@@ -135,42 +137,43 @@ public final class MySQLFrontendEngineTest {
when(payload.readStringNul()).thenReturn("root");
when(payload.readStringNulByBytes()).thenReturn("root".getBytes());
when(context.channel()).thenReturn(channel);
- when(channel.remoteAddress()).thenReturn(new InetSocketAddress(InetAddress.getByAddress(new byte[] {(byte) 192, (byte) 168, (byte) 0, (byte) 102}), 3307));
+ when(channel.remoteAddress()).thenReturn(new InetSocketAddress(InetAddress.getByAddress(new byte[]{(byte) 192, (byte) 168, (byte) 0, (byte) 102}), 3307));
AuthenticationResult actual = mysqlFrontendEngine.getAuthEngine().auth(context, payload);
assertThat(actual.getUsername(), is("root"));
assertNull(actual.getDatabase());
assertTrue(actual.isFinished());
verify(context).writeAndFlush(argThat((ArgumentMatcher<MySQLErrPacket>) argument -> "Access denied for user 'root'@'192.168.0.102' (using password: YES)".equals(argument.getErrorMessage())));
}
-
+
private void setAuthentication(final ShardingSphereUser user) {
DefaultAuthentication authentication = new DefaultAuthentication();
authentication.getUsers().put("root", user);
initProxyContext(authentication);
}
-
+
@SneakyThrows(ReflectiveOperationException.class)
private void setConnectionPhase(final MySQLConnectionPhase connectionPhase) {
Field field = MySQLAuthenticationEngine.class.getDeclaredField("connectionPhase");
field.setAccessible(true);
field.set(mysqlFrontendEngine.getAuthEngine(), connectionPhase);
}
-
+
@SneakyThrows(ReflectiveOperationException.class)
private void initProxyContext(final DefaultAuthentication authentication) {
Field field = ProxyContext.getInstance().getClass().getDeclaredField("metaDataContexts");
field.setAccessible(true);
field.set(ProxyContext.getInstance(), getMetaDataContexts(authentication));
}
-
+
private MetaDataContexts getMetaDataContexts(final DefaultAuthentication authentication) {
return new StandardMetaDataContexts(getMetaDataMap(), mock(ExecutorEngine.class), authentication, new ConfigurationProperties(new Properties()));
}
-
+
private Map<String, ShardingSphereMetaData> getMetaDataMap() {
Map<String, ShardingSphereMetaData> result = new HashMap<>(10, 1);
for (int i = 0; i < 10; i++) {
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
+ when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
when(metaData.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()));
result.put(String.format(SCHEMA_PATTERN, i), metaData);
}