This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 b27e245 Revise #9227 (#9231)
b27e245 is described below
commit b27e2452b60214b6d4db8170cc840c2a507eabfb
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jan 31 01:00:15 2021 +0800
Revise #9227 (#9231)
---
pom.xml | 4 +--
.../shardingsphere-integration-test-suite/pom.xml | 1 -
.../test/integration/engine/it/BaseIT.java | 23 ++++++++---------
.../env/IntegrationTestEnvironment.java | 23 ++++++++++-------
.../env/database/DatabaseEnvironmentManager.java | 29 +++++++++++-----------
...vironment.java => DatabaseNameEnvironment.java} | 4 +--
.../env/database/EmbeddedDatabaseResource.java | 8 +++---
.../database/MySQLEmbeddedDatabaseResource.java | 16 ++++++------
.../env/datasource/DatabaseEnvironment.java | 4 +--
.../env/datasource/builder/DataSourceCacheKey.java | 4 +--
.../env/props/DatabaseScenarioProperties.java | 10 ++++----
11 files changed, 64 insertions(+), 62 deletions(-)
diff --git a/pom.xml b/pom.xml
index 2952b2f..443a5c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,6 +67,7 @@
<commons-codec.version>1.10</commons-codec.version>
<commons-cli.version>1.4</commons-cli.version>
<commons-collections4.version>4.2</commons-collections4.version>
+ <commons-io.version>2.8.0</commons-io.version>
<javax.transaction.version>1.1</javax.transaction.version>
<atomikos.version>4.0.6</atomikos.version>
@@ -104,9 +105,8 @@
<elasticjob.version>3.0.0-beta</elasticjob.version>
<calcite.version>1.26.0</calcite.version>
- <commons-io.version>2.8.0</commons-io.version>
<embedded-mysql.version>4.6.1</embedded-mysql.version>
-
+
<!-- Plugin versions -->
<apache-rat-plugin.version>0.12</apache-rat-plugin.version>
<takari-maven-plugin.version>0.6.1</takari-maven-plugin.version>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml
index ea128b1..9c74ce5 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml
@@ -73,7 +73,6 @@
<dependency>
<groupId>com.wix</groupId>
<artifactId>wix-embedded-mysql</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BaseIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BaseIT.java
index 6b2f0d9..9196c00 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BaseIT.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BaseIT.java
@@ -66,7 +66,6 @@ public abstract class BaseIT {
this.databaseType = databaseType;
actualDataSources =
ActualDataSourceBuilder.createActualDataSources(scenario, databaseType);
targetDataSource = createTargetDataSource();
-
// TODO maybe use @AfterClass, but targetDataSource should be static
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (targetDataSource instanceof ShardingSphereDataSource) {
@@ -86,6 +85,17 @@ public abstract class BaseIT {
targetDataSource = createTargetDataSource();
}
+ private void closeTargetDataSource() {
+ ((ShardingSphereDataSource)
targetDataSource).getDataSourceMap().values().forEach(dataSource -> {
+ try {
+ ((AutoCloseable) dataSource).close();
+ //CHECKSTYLE:OFF
+ } catch (final Exception ignored) {
+ }
+ //CHECKSTYLE:ON
+ });
+ }
+
@BeforeClass
public static void executeInitSQLs() throws IOException, JAXBException,
SQLException {
if (!IntegrationTestEnvironment.getInstance().isEnvironmentPrepared())
{
@@ -99,15 +109,4 @@ public abstract class BaseIT {
((ShardingSphereDataSource)
targetDataSource).getMetaDataContexts().getExecutorEngine().close();
}
}
-
- private void closeTargetDataSource() {
- ((ShardingSphereDataSource)
targetDataSource).getDataSourceMap().values().forEach(dataSource -> {
- try {
- ((AutoCloseable) dataSource).close();
- //CHECKSTYLE:OFF
- } catch (Exception ignore) {
- }
- //CHECKSTYLE:ON
- });
- }
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/IntegrationTestEnvironment.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/IntegrationTestEnvironment.java
index ceeb070..efd9d26 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/IntegrationTestEnvironment.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/IntegrationTestEnvironment.java
@@ -37,6 +37,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import java.util.stream.Collectors;
@@ -59,7 +60,7 @@ public final class IntegrationTestEnvironment {
private final Map<DatabaseType, Map<String, DatabaseEnvironment>>
databaseEnvironments;
private final Map<String, DatabaseEnvironment> proxyEnvironments;
-
+
private final boolean isDatabasesEmbedded;
private IntegrationTestEnvironment() {
@@ -72,7 +73,7 @@ public final class IntegrationTestEnvironment {
Map<String, DatabaseScenarioProperties> databaseProps =
getDatabaseScenarioProperties();
databaseEnvironments =
createDatabaseEnvironments(getDatabaseTypes(engineEnvProps), databaseProps);
if (isDatabasesEmbedded) {
- initEmbeddedDatabaseResources();
+ createEmbeddedDatabaseResources();
}
proxyEnvironments = createProxyEnvironments(databaseProps);
if (isEnvironmentPrepared) {
@@ -122,17 +123,21 @@ public final class IntegrationTestEnvironment {
databaseProps.getDatabaseUsername(databaseType),
databaseProps.getDatabasePassword(databaseType),
databaseProps.getDatabaseDistributionUrl(databaseType),
databaseProps.getDatabaseDistributionVersion(databaseType));
}
-
- private void initEmbeddedDatabaseResources() {
- if (!isEnvironmentPrepared()) {
- for (Map.Entry<DatabaseType, Map<String, DatabaseEnvironment>>
each : getDatabaseEnvironments().entrySet()) {
- for (Map.Entry<String, DatabaseEnvironment>
databaseEnvironmentEntry : each.getValue().entrySet()) {
-
DatabaseEnvironmentManager.createEmbeddedDatabaseResource(each.getKey(),
databaseEnvironmentEntry.getKey(), databaseEnvironmentEntry.getValue());
- }
+
+ private void createEmbeddedDatabaseResources() {
+ if (!isEnvironmentPrepared) {
+ for (Entry<DatabaseType, Map<String, DatabaseEnvironment>> entry :
databaseEnvironments.entrySet()) {
+ createEmbeddedDatabaseResources(entry.getKey(),
entry.getValue());
}
}
}
+ private void createEmbeddedDatabaseResources(final DatabaseType
databaseType, final Map<String, DatabaseEnvironment> databaseEnvs) {
+ for (Entry<String, DatabaseEnvironment> databaseEnvironmentEntry :
databaseEnvs.entrySet()) {
+
DatabaseEnvironmentManager.createEmbeddedDatabaseResource(databaseType,
databaseEnvironmentEntry.getKey(), databaseEnvironmentEntry.getValue());
+ }
+ }
+
private Map<String, DatabaseEnvironment> createProxyEnvironments(final
Map<String, DatabaseScenarioProperties> databaseProps) {
Map<String, DatabaseEnvironment> result = new
HashMap<>(scenarios.size(), 1);
for (String each : scenarios) {
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironmentManager.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironmentManager.java
index c9155a4..5f22404 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironmentManager.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironmentManager.java
@@ -24,6 +24,7 @@ import
org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
import
org.apache.shardingsphere.test.integration.env.IntegrationTestEnvironment;
+import
org.apache.shardingsphere.test.integration.env.datasource.DatabaseEnvironment;
import
org.apache.shardingsphere.test.integration.env.datasource.builder.ActualDataSourceBuilder;
import org.h2.tools.RunScript;
@@ -46,9 +47,9 @@ import java.util.concurrent.locks.ReentrantLock;
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DatabaseEnvironmentManager {
-
+
private static final ConcurrentMap<String, EmbeddedDatabaseResource>
DATABASE_RESOURCE_CACHE = new ConcurrentHashMap<>();
-
+
private static final Lock DATABASE_RESOURCE_LOCK = new ReentrantLock();
/**
@@ -63,9 +64,9 @@ public final class DatabaseEnvironmentManager {
return
unmarshal(EnvironmentPath.getDatabasesFile(scenario)).getDatabases();
}
- private static DatabaseEnvironment unmarshal(final String databasesFile)
throws IOException, JAXBException {
+ private static DatabaseNameEnvironment unmarshal(final String
databasesFile) throws IOException, JAXBException {
try (FileReader reader = new FileReader(databasesFile)) {
- return (DatabaseEnvironment)
JAXBContext.newInstance(DatabaseEnvironment.class).createUnmarshaller().unmarshal(reader);
+ return (DatabaseNameEnvironment)
JAXBContext.newInstance(DatabaseNameEnvironment.class).createUnmarshaller().unmarshal(reader);
}
}
@@ -111,22 +112,20 @@ public final class DatabaseEnvironmentManager {
RunScript.execute(connection, reader);
}
}
-
+
/**
- * create embedded database resource by database type and environment.
+ * Create embedded database resource.
*
* @param databaseType database type
* @param scenario scenario
- * @param databaseEnvironment database props
+ * @param databaseEnvironment database environment
*/
- public static void createEmbeddedDatabaseResource(final DatabaseType
databaseType,
- final String scenario,
- final
org.apache.shardingsphere.test.integration.env.datasource.DatabaseEnvironment
databaseEnvironment) {
+ public static void createEmbeddedDatabaseResource(final DatabaseType
databaseType, final String scenario, final DatabaseEnvironment
databaseEnvironment) {
if (null == databaseType) {
return;
}
String databaseTypeName = databaseType.getName();
- String embeddedDatabaseResourceKey = databaseTypeName + "_" + scenario;
+ String embeddedDatabaseResourceKey = String.join("_",
databaseTypeName, scenario);
EmbeddedDatabaseResource embeddedDatabaseResource =
DATABASE_RESOURCE_CACHE.get(embeddedDatabaseResourceKey);
if (null != embeddedDatabaseResource) {
return;
@@ -142,11 +141,11 @@ public final class DatabaseEnvironmentManager {
} else {
// TODO return default database resource
embeddedDatabaseResource = new EmbeddedDatabaseResource() {
-
+
@Override
public void start() {
}
-
+
@Override
public void stop() {
}
@@ -158,9 +157,9 @@ public final class DatabaseEnvironmentManager {
DATABASE_RESOURCE_LOCK.unlock();
}
}
-
+
/**
- * drop embedded database resource.
+ * Drop embedded database resource.
*/
public static void dropEmbeddedDatabaseResource() {
DATABASE_RESOURCE_CACHE.values().forEach(EmbeddedDatabaseResource::stop);
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironment.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseNameEnvironment.java
similarity index 92%
rename from
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironment.java
rename to
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseNameEnvironment.java
index 8c0e7cd..9f59bf3 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironment.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseNameEnvironment.java
@@ -25,11 +25,11 @@ import java.util.Collection;
import java.util.LinkedList;
/**
- * XML definition of database environment.
+ * XML definition of database name environment.
*/
@Getter
@XmlRootElement(name = "databases")
-public final class DatabaseEnvironment {
+public final class DatabaseNameEnvironment {
@XmlElement(name = "database")
private final Collection<String> databases = new LinkedList<>();
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/EmbeddedDatabaseResource.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/EmbeddedDatabaseResource.java
index 251f0c9..e01cfb7 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/EmbeddedDatabaseResource.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/EmbeddedDatabaseResource.java
@@ -21,14 +21,14 @@ package
org.apache.shardingsphere.test.integration.env.database;
* Embedded database resource.
*/
public interface EmbeddedDatabaseResource {
-
+
/**
- * start embedded database resource.
+ * Start embedded database resource.
*/
void start();
-
+
/**
- * stop embedded database resource.
+ * Stop embedded database resource.
*/
void stop();
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/MySQLEmbeddedDatabaseResource.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/MySQLEmbeddedDatabaseResource.java
index 7bfe2d6..659c02e 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/MySQLEmbeddedDatabaseResource.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/MySQLEmbeddedDatabaseResource.java
@@ -27,19 +27,19 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.test.integration.env.datasource.DatabaseEnvironment;
/**
- * MySQL database resource.
+ * Embedded database resource for MySQL.
*/
-@Slf4j
@RequiredArgsConstructor
+@Slf4j
public final class MySQLEmbeddedDatabaseResource implements
EmbeddedDatabaseResource {
-
+
private final DatabaseEnvironment databaseEnvironment;
-
+
private EmbeddedMysql embeddedMySQL;
-
+
@Override
public void start() {
- final long t = System.currentTimeMillis();
+ long startTime = System.currentTimeMillis();
log.info("Test embedded database resources MySQL prepare.");
DownloadConfig downloadConfig = DownloadConfig.aDownloadConfig()
.withBaseUrl(databaseEnvironment.getDistributionUrl())
@@ -52,9 +52,9 @@ public final class MySQLEmbeddedDatabaseResource implements
EmbeddedDatabaseReso
.withServerVariable("innodb_flush_log_at_trx_commit", 2)
.build();
embeddedMySQL = EmbeddedMysql.anEmbeddedMysql(mysqldConfig,
downloadConfig).start();
- log.info("Test embedded database resources MySQL start mysqld elapsed
time {}s", (System.currentTimeMillis() - t) / 1000);
+ log.info("Test embedded database resources MySQL start mysqld elapsed
time {}s", (System.currentTimeMillis() - startTime) / 1000);
}
-
+
@Override
public void stop() {
if (null != embeddedMySQL) {
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/DatabaseEnvironment.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/DatabaseEnvironment.java
index 394a248..0da308f 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/DatabaseEnvironment.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/DatabaseEnvironment.java
@@ -37,9 +37,9 @@ public final class DatabaseEnvironment {
private final String username;
private final String password;
-
+
private final String distributionUrl;
-
+
private final String distributionVersion;
/**
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/DataSourceCacheKey.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/DataSourceCacheKey.java
index cbdc803..ca99687 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/DataSourceCacheKey.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/DataSourceCacheKey.java
@@ -27,9 +27,9 @@ import
org.apache.shardingsphere.infra.database.type.DatabaseType;
@RequiredArgsConstructor
@EqualsAndHashCode
public final class DataSourceCacheKey {
-
+
private final String scenario;
-
+
private final String dataSourceName;
private final DatabaseType databaseType;
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/DatabaseScenarioProperties.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/DatabaseScenarioProperties.java
index c219e90..0da0833 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/DatabaseScenarioProperties.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/DatabaseScenarioProperties.java
@@ -27,7 +27,7 @@ import java.util.Properties;
*/
@RequiredArgsConstructor
public final class DatabaseScenarioProperties {
-
+
private final String scenario;
private final Properties props;
@@ -107,17 +107,17 @@ public final class DatabaseScenarioProperties {
public String getProxyPassword() {
return props.getProperty(String.format("it.%s.proxy.password",
scenario));
}
-
+
/**
- * Get database distribution url.
+ * Get database distribution URL.
*
* @param databaseType database type
- * @return database distribution url
+ * @return database distribution URL
*/
public String getDatabaseDistributionUrl(final DatabaseType databaseType) {
return props.getProperty(String.format("it.%s.%s.distribution.url",
scenario, databaseType.getName().toLowerCase()));
}
-
+
/**
* Get database distribution version.
*