You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/10/02 10:40:13 UTC
(shardingsphere) branch master updated: Remove useless DatabaseEnvironmentManager.getDatabaseNameAndTypeMap() (#36774)
This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 890a45c654f Remove useless DatabaseEnvironmentManager.getDatabaseNameAndTypeMap() (#36774)
890a45c654f is described below
commit 890a45c654fda3f3c3d549e87bb3001f18415d89
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Oct 2 18:40:06 2025 +0800
Remove useless DatabaseEnvironmentManager.getDatabaseNameAndTypeMap() (#36774)
* Remove useless DatabaseEnvironmentManager.getDatabaseNameAndTypeMap()
* Refactor BaseDMLE2EIT
---
.../database/DatabaseEnvironmentManager.java | 28 ----------------------
.../test/e2e/sql/it/sql/dml/BaseDMLE2EIT.java | 13 +++++-----
2 files changed, 6 insertions(+), 35 deletions(-)
diff --git a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/scenario/database/DatabaseEnvironmentManager.java b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/scenario/database/DatabaseEnvironmentManager.java
index fe897f1d854..03fa2cd11e6 100644
--- a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/scenario/database/DatabaseEnvironmentManager.java
+++ b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/scenario/database/DatabaseEnvironmentManager.java
@@ -17,12 +17,9 @@
package org.apache.shardingsphere.test.e2e.env.runtime.type.scenario.database;
-import com.google.common.base.Splitter;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.e2e.env.runtime.type.scenario.path.ScenarioDataPath;
import org.apache.shardingsphere.test.e2e.env.runtime.type.scenario.path.ScenarioDataPath.Type;
@@ -31,9 +28,6 @@ import javax.xml.bind.JAXBException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
/**
* Database environment manager.
@@ -52,28 +46,6 @@ public final class DatabaseEnvironmentManager {
return unmarshal(new ScenarioDataPath(scenario, type).getDatabasesFile()).getDatabases();
}
- /**
- * Get database name and type map.
- *
- * @param scenario scenario
- * @param defaultDatabaseType default database type
- * @param type type
- * @return database name and type map
- */
- public static Map<String, DatabaseType> getDatabaseNameAndTypeMap(final String scenario, final DatabaseType defaultDatabaseType, final Type type) {
- return getDatabaseNameAndTypeMap(unmarshal(new ScenarioDataPath(scenario, type).getDatabasesFile()).getDatabases(), defaultDatabaseType);
- }
-
- private static Map<String, DatabaseType> getDatabaseNameAndTypeMap(final Collection<String> databaseNames, final DatabaseType defaultDatabaseType) {
- Map<String, DatabaseType> result = new LinkedHashMap<>(databaseNames.size(), 1F);
- for (String each : databaseNames) {
- List<String> items = Splitter.on(":").splitToList(each);
- DatabaseType databaseType = items.size() > 1 ? TypedSPILoader.getService(DatabaseType.class, items.get(1)) : defaultDatabaseType;
- result.put(items.get(0), databaseType);
- }
- return result;
- }
-
@SneakyThrows({IOException.class, JAXBException.class})
private static DatabaseNameEnvironment unmarshal(final String databasesFile) {
try (FileReader reader = new FileReader(databasesFile)) {
diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/dml/BaseDMLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/dml/BaseDMLE2EIT.java
index 0189a1147b7..34a88eb66e3 100644
--- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/dml/BaseDMLE2EIT.java
+++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/dml/BaseDMLE2EIT.java
@@ -26,7 +26,6 @@ import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.expr.entry.InlineExpressionParserFactory;
import org.apache.shardingsphere.infra.util.datetime.DateTimeFormatterFactory;
-import org.apache.shardingsphere.test.e2e.env.runtime.type.scenario.database.DatabaseEnvironmentManager;
import org.apache.shardingsphere.test.e2e.env.runtime.type.scenario.path.ScenarioDataPath;
import org.apache.shardingsphere.test.e2e.env.runtime.type.scenario.path.ScenarioDataPath.Type;
import org.apache.shardingsphere.test.e2e.sql.cases.casse.assertion.SQLE2ETestCaseAssertion;
@@ -185,14 +184,14 @@ public abstract class BaseDMLE2EIT implements SQLE2EIT {
}
private void assertDataSet(final SQLE2EITContext context, final DataSetMetaData expectedDataSetMetaData, final AssertionTestParameter testParam) throws SQLException {
- Map<String, DatabaseType> databaseTypes = DatabaseEnvironmentManager.getDatabaseNameAndTypeMap(testParam.getScenario(), testParam.getDatabaseType(), Type.ACTUAL);
for (String each : InlineExpressionParserFactory.newInstance(expectedDataSetMetaData.getDataNodes()).splitAndEvaluate()) {
DataNode dataNode = new DataNode(each);
DataSource dataSource = getEnvironmentEngine().getActualDataSourceMap().get(dataNode.getDataSourceName());
- DatabaseType databaseType = databaseTypes.get(dataNode.getDataSourceName());
+ DatabaseType databaseType = testParam.getDatabaseType();
try (
Connection connection = dataSource.getConnection();
- PreparedStatement preparedStatement = connection.prepareStatement(generateFetchActualDataSQL(getEnvironmentEngine().getActualDataSourceMap(), dataNode, databaseType))) {
+ PreparedStatement preparedStatement = connection.prepareStatement(
+ generateFetchActualDataSQL(getEnvironmentEngine().getActualDataSourceMap(), dataNode, databaseType))) {
assertDataSet(preparedStatement, expectedDataSetMetaData, context.getDataSet().findRows(dataNode), databaseType);
}
}
@@ -218,14 +217,14 @@ public abstract class BaseDMLE2EIT implements SQLE2EIT {
}
private void assertDataSet(final DataSetMetaData expectedDataSetMetaData, final CaseTestParameter testParam, final DataSet dataSet) throws SQLException {
- Map<String, DatabaseType> databaseTypes = DatabaseEnvironmentManager.getDatabaseNameAndTypeMap(testParam.getScenario(), testParam.getDatabaseType(), Type.ACTUAL);
for (String each : InlineExpressionParserFactory.newInstance(expectedDataSetMetaData.getDataNodes()).splitAndEvaluate()) {
DataNode dataNode = new DataNode(each);
- DatabaseType databaseType = databaseTypes.get(dataNode.getDataSourceName());
DataSource dataSource = getEnvironmentEngine().getActualDataSourceMap().get(dataNode.getDataSourceName());
+ DatabaseType databaseType = testParam.getDatabaseType();
try (
Connection connection = dataSource.getConnection();
- PreparedStatement preparedStatement = connection.prepareStatement(generateFetchActualDataSQL(getEnvironmentEngine().getActualDataSourceMap(), dataNode, databaseType))) {
+ PreparedStatement preparedStatement = connection.prepareStatement(
+ generateFetchActualDataSQL(getEnvironmentEngine().getActualDataSourceMap(), dataNode, databaseType))) {
assertDataSet(preparedStatement, expectedDataSetMetaData, dataSet.findRows(dataNode), databaseType);
}
}