You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/01/14 16:11:42 UTC
[shardingsphere] branch master updated: Add scenario directory
check when IT startup (#9038)
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 5af0da6 Add scenario directory check when IT startup (#9038)
5af0da6 is described below
commit 5af0da6c7d51fb2c4781d223a7e0c87ce17a1751
Author: Liang Zhang <te...@163.com>
AuthorDate: Fri Jan 15 00:11:15 2021 +0800
Add scenario directory check when IT startup (#9038)
---
.../integration/engine/it/dcl/GeneralDCLIT.java | 2 +-
.../test/integration/env/EnvironmentPath.java | 21 +++++++++++++++++----
.../integration/env/IntegrationTestEnvironment.java | 12 ++++++++++--
.../env/props/EnvironmentProperties.java | 6 +++---
4 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dcl/GeneralDCLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dcl/GeneralDCLIT.java
index 9c6b6bb..14bbf11 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dcl/GeneralDCLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dcl/GeneralDCLIT.java
@@ -38,7 +38,7 @@ public final class GeneralDCLIT extends BaseDCLIT {
final String databaseType, final SQLExecuteType sqlExecuteType, final String sql) throws IOException, JAXBException, SQLException, ParseException {
super(parentPath, assertion, adapter, scenario, DatabaseTypeRegistry.getActualDatabaseType(databaseType), sqlExecuteType, sql);
}
-
+
@Parameters(name = "{2}: {3} -> {4} -> {5} -> {6}")
public static Collection<Object[]> getParameters() {
return ParameterizedArrayFactory.getAssertionParameterizedArray(SQLCommandType.DCL);
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/EnvironmentPath.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/EnvironmentPath.java
index 56628f6..01d8670 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/EnvironmentPath.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/EnvironmentPath.java
@@ -42,6 +42,17 @@ public final class EnvironmentPath {
private static final String RULES_CONFIG_FILE = "rules.yaml";
private static final String AUTHORITY_FILE = "authority.xml";
+
+ /**
+ * Assert scenario directory existed.
+ *
+ * @param scenario scenario
+ */
+ public static void assertScenarioDirectoryExisted(final String scenario) {
+ String scenarioDirectory = String.join("/", ROOT_PATH, scenario);
+ URL url = EnvironmentPath.class.getClassLoader().getResource(scenarioDirectory);
+ assertNotNull(String.format("Scenario directory `%s` must exist.", scenarioDirectory), url);
+ }
/**
* Get databases file.
@@ -95,14 +106,16 @@ public final class EnvironmentPath {
}
private static String getFile(final String scenario, final String fileName) {
- URL url = EnvironmentPath.class.getClassLoader().getResource(String.join("/", ROOT_PATH, scenario, fileName));
- assertNotNull(url);
+ String path = String.join("/", ROOT_PATH, scenario, fileName);
+ URL url = EnvironmentPath.class.getClassLoader().getResource(path);
+ assertNotNull(String.format("File `%s` must exist.", path), url);
return url.getFile();
}
private static String getFile(final DatabaseType databaseType, final String scenario, final String fileName) {
- URL url = EnvironmentPath.class.getClassLoader().getResource(String.join("/", ROOT_PATH, scenario, databaseType.getName().toLowerCase(), fileName));
- assertNotNull(url);
+ String path = String.join("/", ROOT_PATH, scenario, databaseType.getName().toLowerCase(), fileName);
+ URL url = EnvironmentPath.class.getClassLoader().getResource(path);
+ assertNotNull(String.format("File `%s` must exist.", path), url);
return url.getFile();
}
}
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 c01edac..7e7c981 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
@@ -63,12 +63,20 @@ public final class IntegrationTestEnvironment {
isEnvironmentPrepared = "docker".equals(engineEnvProps.getProperty("it.env.type"));
adapters = Splitter.on(",").trimResults().splitToList(engineEnvProps.getProperty("it.adapters"));
runAdditionalTestCases = Boolean.parseBoolean(engineEnvProps.getProperty("it.run.additional.cases"));
- scenarios = Splitter.on(",").trimResults().splitToList(engineEnvProps.getProperty("it.scenarios"));
+ scenarios = getScenarios(engineEnvProps);
Map<String, DatabaseScenarioProperties> databaseProps = getDatabaseScenarioProperties();
databaseEnvironments = createDatabaseEnvironments(getDatabaseTypes(engineEnvProps), databaseProps);
proxyEnvironments = createProxyEnvironments(databaseProps);
}
+ private Collection<String> getScenarios(final Properties engineEnvProps) {
+ Collection<String> result = Splitter.on(",").trimResults().splitToList(engineEnvProps.getProperty("it.scenarios"));
+ for (String each : result) {
+ EnvironmentPath.assertScenarioDirectoryExisted(each);
+ }
+ return result;
+ }
+
private Map<String, DatabaseScenarioProperties> getDatabaseScenarioProperties() {
Map<String, DatabaseScenarioProperties> result = new HashMap<>(scenarios.size(), 1);
for (String each : scenarios) {
@@ -80,7 +88,7 @@ public final class IntegrationTestEnvironment {
private Collection<DatabaseType> getDatabaseTypes(final Properties engineEnvProps) {
return Arrays.stream(engineEnvProps.getProperty("it.databases", "H2").split(",")).map(each -> DatabaseTypeRegistry.getActualDatabaseType(each.trim())).collect(Collectors.toList());
}
-
+
private Map<DatabaseType, Map<String, DatabaseEnvironment>> createDatabaseEnvironments(final Collection<DatabaseType> databaseTypes, final Map<String, DatabaseScenarioProperties> databaseProps) {
Map<DatabaseType, Map<String, DatabaseEnvironment>> result = new LinkedHashMap<>(databaseTypes.size(), 1);
for (DatabaseType each : databaseTypes) {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/EnvironmentProperties.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/EnvironmentProperties.java
index e2cf282..8ac1a66 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/EnvironmentProperties.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/EnvironmentProperties.java
@@ -19,9 +19,9 @@ package org.apache.shardingsphere.test.integration.env.props;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.test.integration.env.IntegrationTestEnvironment;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Properties;
/**
@@ -39,8 +39,8 @@ public final class EnvironmentProperties {
@SuppressWarnings("AccessOfSystemProperties")
public static Properties loadProperties(final String propsFileName) {
Properties result = new Properties();
- try {
- result.load(IntegrationTestEnvironment.class.getClassLoader().getResourceAsStream(propsFileName));
+ try (InputStream inputStream = EnvironmentProperties.class.getClassLoader().getResourceAsStream(propsFileName)) {
+ result.load(inputStream);
} catch (final IOException ex) {
throw new RuntimeException(ex);
}