You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2022/02/19 15:28:18 UTC
[shardingsphere] branch master updated: Add scenario package and refactor ScenarioPath (#15521)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 6efdd23 Add scenario package and refactor ScenarioPath (#15521)
6efdd23 is described below
commit 6efdd2331c6eda026fefc655485ed1f133e3b904
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Feb 19 23:27:19 2022 +0800
Add scenario package and refactor ScenarioPath (#15521)
* Refactor IntegrationTestEnvironment
* Add scenario package
* Refactor ScenarioEnvironmentPath
* Refactor ScenarioPath
* Refactor checkFolderExist
* Refactor checkFolderExist
* Refactor ScenarioPath
* Refactor ScenarioPath
* Refactor ScenarioPath
* Refactor BaseITCase
---
.../test/integration/engine/BaseITCase.java | 2 +-
.../test/integration/engine/BatchITCase.java | 6 +-
.../test/integration/engine/dcl/BaseDCLIT.java | 6 +-
.../test/integration/engine/dml/BaseDMLIT.java | 6 +-
.../test/integration/engine/dql/BaseDQLIT.java | 6 +-
.../env/IntegrationTestEnvironment.java | 30 +++-
.../integration/env/ScenarioEnvironmentPath.java | 160 ---------------------
.../env/props/EnvironmentProperties.java | 52 -------
.../integration/env/scenario/ScenarioPath.java | 143 ++++++++++++++++++
.../authority/AuthorityEnvironment.java | 2 +-
.../authority/AuthorityEnvironmentManager.java | 2 +-
.../{ => scenario}/authority/AuthoritySQLSet.java | 2 +-
.../database/DatabaseEnvironmentManager.java | 6 +-
.../database/DatabaseNameEnvironment.java | 2 +-
.../dataset/DataSetEnvironmentManager.java | 2 +-
.../adapter/impl/ShardingSphereJDBCContainer.java | 15 +-
.../atomic/storage/DockerStorageContainer.java | 8 +-
.../atomic/storage/EmbeddedStorageContainer.java | 2 +-
.../container/atomic/storage/impl/H2Container.java | 24 ++--
19 files changed, 211 insertions(+), 265 deletions(-)
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java
index 6339200..89c95ae 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java
@@ -74,7 +74,7 @@ public abstract class BaseITCase {
databaseType = parameterizedArray.getDatabaseType();
sqlCommandType = parameterizedArray.getSqlCommandType();
integrationTestCase = parameterizedArray.getTestCaseContext().getTestCase();
- this.composedContainer = COMPOSED_CONTAINER_REGISTRY.getComposedContainer(parameterizedArray);
+ composedContainer = COMPOSED_CONTAINER_REGISTRY.getComposedContainer(parameterizedArray);
}
@Before
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchITCase.java
index aef4e18..e9ef1c9 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchITCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchITCase.java
@@ -27,8 +27,8 @@ import org.apache.shardingsphere.test.integration.cases.dataset.DataSetLoader;
import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetColumn;
import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetMetaData;
import org.apache.shardingsphere.test.integration.cases.dataset.row.DataSetRow;
-import org.apache.shardingsphere.test.integration.env.ScenarioEnvironmentPath;
-import org.apache.shardingsphere.test.integration.env.dataset.DataSetEnvironmentManager;
+import org.apache.shardingsphere.test.integration.env.scenario.ScenarioPath;
+import org.apache.shardingsphere.test.integration.env.scenario.dataset.DataSetEnvironmentManager;
import org.apache.shardingsphere.test.integration.framework.param.model.CaseParameterizedArray;
import org.junit.Before;
@@ -70,7 +70,7 @@ public abstract class BatchITCase extends BaseITCase {
for (IntegrationTestCaseAssertion each : getIntegrationTestCase().getAssertions()) {
dataSets.add(DataSetLoader.load(getParentPath(), getScenario(), getDatabaseType(), each.getExpectedDataFile()));
}
- dataSetEnvironmentManager = new DataSetEnvironmentManager(ScenarioEnvironmentPath.getDataSetFile(getScenario()), getActualDataSourceMap());
+ dataSetEnvironmentManager = new DataSetEnvironmentManager(new ScenarioPath(getScenario()).getDataSetFile(), getActualDataSourceMap());
dataSetEnvironmentManager.fillData();
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/BaseDCLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/BaseDCLIT.java
index fd928f4..605ab1d 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/BaseDCLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/BaseDCLIT.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.test.integration.engine.dcl;
import org.apache.shardingsphere.test.integration.engine.SingleITCase;
-import org.apache.shardingsphere.test.integration.env.ScenarioEnvironmentPath;
-import org.apache.shardingsphere.test.integration.env.authority.AuthorityEnvironmentManager;
+import org.apache.shardingsphere.test.integration.env.scenario.ScenarioPath;
+import org.apache.shardingsphere.test.integration.env.scenario.authority.AuthorityEnvironmentManager;
import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray;
import org.junit.Before;
@@ -33,7 +33,7 @@ public abstract class BaseDCLIT extends SingleITCase {
@Before
public final void init() throws Exception {
- authorityEnvironmentManager = new AuthorityEnvironmentManager(ScenarioEnvironmentPath.getAuthorityFile(getScenario()), getActualDataSourceMap(), getDatabaseType());
+ authorityEnvironmentManager = new AuthorityEnvironmentManager(new ScenarioPath(getScenario()).getAuthorityFile(), getActualDataSourceMap(), getDatabaseType());
authorityEnvironmentManager.initialize();
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
index 82ebfc6..e1ab3aa 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
@@ -23,8 +23,8 @@ import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSet
import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetMetaData;
import org.apache.shardingsphere.test.integration.cases.dataset.row.DataSetRow;
import org.apache.shardingsphere.test.integration.engine.SingleITCase;
-import org.apache.shardingsphere.test.integration.env.ScenarioEnvironmentPath;
-import org.apache.shardingsphere.test.integration.env.dataset.DataSetEnvironmentManager;
+import org.apache.shardingsphere.test.integration.env.scenario.ScenarioPath;
+import org.apache.shardingsphere.test.integration.env.scenario.dataset.DataSetEnvironmentManager;
import org.apache.shardingsphere.test.integration.framework.database.DatabaseAssertionMetaData;
import org.apache.shardingsphere.test.integration.framework.database.DatabaseAssertionMetaDataFactory;
import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray;
@@ -55,7 +55,7 @@ public abstract class BaseDMLIT extends SingleITCase {
@Before
public final void init() throws Exception {
- dataSetEnvironmentManager = new DataSetEnvironmentManager(ScenarioEnvironmentPath.getDataSetFile(getScenario()), getActualDataSourceMap());
+ dataSetEnvironmentManager = new DataSetEnvironmentManager(new ScenarioPath(getScenario()).getDataSetFile(), getActualDataSourceMap());
dataSetEnvironmentManager.fillData();
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
index a04d602..8c9cd23 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
@@ -21,8 +21,8 @@ import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSet
import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetMetaData;
import org.apache.shardingsphere.test.integration.cases.dataset.row.DataSetRow;
import org.apache.shardingsphere.test.integration.engine.SingleITCase;
-import org.apache.shardingsphere.test.integration.env.ScenarioEnvironmentPath;
-import org.apache.shardingsphere.test.integration.env.dataset.DataSetEnvironmentManager;
+import org.apache.shardingsphere.test.integration.env.scenario.ScenarioPath;
+import org.apache.shardingsphere.test.integration.env.scenario.dataset.DataSetEnvironmentManager;
import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray;
import org.junit.Before;
@@ -61,7 +61,7 @@ public abstract class BaseDQLIT extends SingleITCase {
if (!FILLED_SUITES.contains(key)) {
synchronized (FILLED_SUITES) {
if (!FILLED_SUITES.contains(getScenario())) {
- new DataSetEnvironmentManager(ScenarioEnvironmentPath.getDataSetFile(getScenario()), getActualDataSourceMap()).fillData();
+ new DataSetEnvironmentManager(new ScenarioPath(getScenario()).getDataSetFile(), getActualDataSourceMap()).fillData();
FILLED_SUITES.add(key);
}
}
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 65afcab..75983e2 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
@@ -20,8 +20,10 @@ package org.apache.shardingsphere.test.integration.env;
import com.google.common.base.Splitter;
import lombok.Getter;
import org.apache.shardingsphere.test.integration.env.cluster.ClusterEnvironment;
-import org.apache.shardingsphere.test.integration.env.props.EnvironmentProperties;
+import org.apache.shardingsphere.test.integration.env.scenario.ScenarioPath;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Collection;
import java.util.Properties;
@@ -42,17 +44,31 @@ public final class IntegrationTestEnvironment {
private final ClusterEnvironment clusterEnvironment;
private IntegrationTestEnvironment() {
- Properties envProps = EnvironmentProperties.loadProperties("env/it-env.properties");
- runModes = Splitter.on(",").trimResults().splitToList(envProps.getProperty("it.run.modes"));
- runAdditionalTestCases = Boolean.parseBoolean(envProps.getProperty("it.run.additional.cases"));
- scenarios = getScenarios(envProps);
- clusterEnvironment = new ClusterEnvironment(envProps);
+ Properties props = loadProperties();
+ runModes = Splitter.on(",").trimResults().splitToList(props.getProperty("it.run.modes"));
+ runAdditionalTestCases = Boolean.parseBoolean(props.getProperty("it.run.additional.cases"));
+ scenarios = getScenarios(props);
+ clusterEnvironment = new ClusterEnvironment(props);
+ }
+
+ @SuppressWarnings("AccessOfSystemProperties")
+ private Properties loadProperties() {
+ Properties result = new Properties();
+ try (InputStream inputStream = IntegrationTestEnvironment.class.getClassLoader().getResourceAsStream("env/it-env.properties")) {
+ result.load(inputStream);
+ } catch (final IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ for (String each : System.getProperties().stringPropertyNames()) {
+ result.setProperty(each, System.getProperty(each));
+ }
+ return result;
}
private Collection<String> getScenarios(final Properties envProps) {
Collection<String> result = Splitter.on(",").trimResults().splitToList(envProps.getProperty("it.scenarios"));
for (String each : result) {
- ScenarioEnvironmentPath.assertScenarioDirectoryExisted(each);
+ new ScenarioPath(each).checkFolderExist();
}
return result;
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/ScenarioEnvironmentPath.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/ScenarioEnvironmentPath.java
deleted file mode 100644
index a2bf1c5..0000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/ScenarioEnvironmentPath.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * 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.test.integration.env;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-
-import java.net.URL;
-
-import static org.junit.Assert.assertNotNull;
-
-/**
- * Scenario environment path.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ScenarioEnvironmentPath {
-
- private static final String ROOT_PATH = "env/scenario";
-
- private static final String DATABASES_FILE = "databases.xml";
-
- private static final String INIT_SQL_FILE = "init.sql";
-
- private static final String DATASET_FILE = "dataset.xml";
-
- 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 = ScenarioEnvironmentPath.class.getClassLoader().getResource(scenarioDirectory);
- assertNotNull(String.format("Scenario directory `%s` must exist.", scenarioDirectory), url);
- }
-
- /**
- * Get databases file.
- *
- * @param scenario scenario
- * @return databases file
- */
- public static String getDatabasesFile(final String scenario) {
- return getFile(scenario, DATABASES_FILE);
- }
-
- /**
- * Get init SQL resource path.
- *
- * @param databaseType database type
- * @param scenario scenario
- * @return init SQL resource path
- */
- public static String getInitSQLResourcePath(final DatabaseType databaseType, final String scenario) {
- return String.join("/", "", ROOT_PATH, scenario, "init-sql", databaseType.getName().toLowerCase());
- }
-
- /**
- * Get init SQL file.
- *
- * @param databaseType database type
- * @param scenario scenario
- * @return init SQL file
- */
- public static String getInitSQLFile(final DatabaseType databaseType, final String scenario) {
- return getFile(databaseType, scenario, INIT_SQL_FILE);
- }
-
- /**
- * Get init SQL file.
- *
- * @param databaseType database type
- * @param scenario scenario
- * @param fileName file name
- * @return init SQL file
- */
- public static String getInitSQLFile(final DatabaseType databaseType, final String scenario, final String fileName) {
- return getFile(databaseType, scenario, fileName);
- }
-
- /**
- * Get data set file.
- *
- * @param scenario scenario
- * @return data set file
- */
- public static String getDataSetFile(final String scenario) {
- return getFile(scenario, DATASET_FILE);
- }
-
- /**
- * Get rules configuration file.
- *
- * @param scenario scenario
- * @return rules configuration file
- */
- public static String getRulesConfigurationFile(final String scenario) {
- return getFile(scenario, RULES_CONFIG_FILE);
- }
-
- /**
- * Get authority file.
- *
- * @param scenario scenario
- * @return authority file
- */
- public static String getAuthorityFile(final String scenario) {
- return getFile(scenario, AUTHORITY_FILE);
- }
-
- private static String getFile(final String scenario, final String fileName) {
- String path = String.join("/", ROOT_PATH, scenario, fileName);
- URL url = ScenarioEnvironmentPath.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) {
- String path = getPath(databaseType, scenario, fileName);
- URL url = ScenarioEnvironmentPath.class.getClassLoader().getResource(path);
- assertNotNull(String.format("File `%s` must exist.", path), url);
- return url.getFile();
- }
-
- private static String getPath(final DatabaseType databaseType, final String scenario, final String fileName) {
- return String.join("/", ROOT_PATH, scenario, "init-sql", databaseType.getName().toLowerCase(), fileName);
- }
-
- /**
- * check SQL file exist.
- *
- * @param databaseType database type
- * @param scenario scenario
- * @param fileName file name
- * @return weather SQL file exist or not
- */
- public static boolean checkSQLFileExist(final DatabaseType databaseType, final String scenario, final String fileName) {
- return null != ScenarioEnvironmentPath.class.getClassLoader().getResource(getPath(databaseType, scenario, fileName));
- }
-}
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
deleted file mode 100644
index 212ba7a..0000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/EnvironmentProperties.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.test.integration.env.props;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * Environment properties.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class EnvironmentProperties {
-
- /**
- * Load properties.
- *
- * @param propsFileName properties file name
- * @return loaded properties
- */
- @SuppressWarnings("AccessOfSystemProperties")
- public static Properties loadProperties(final String propsFileName) {
- Properties result = new Properties();
- try (InputStream inputStream = EnvironmentProperties.class.getClassLoader().getResourceAsStream(propsFileName)) {
- result.load(inputStream);
- } catch (final IOException ex) {
- throw new RuntimeException(ex);
- }
- for (String each : System.getProperties().stringPropertyNames()) {
- result.setProperty(each, System.getProperty(each));
- }
- return result;
- }
-}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/ScenarioPath.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/ScenarioPath.java
new file mode 100644
index 0000000..9908336
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/ScenarioPath.java
@@ -0,0 +1,143 @@
+/*
+ * 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.test.integration.env.scenario;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.LinkedList;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Scenario path.
+ */
+@RequiredArgsConstructor
+public final class ScenarioPath {
+
+ private static final String ROOT_PATH = "env/scenario";
+
+ private static final String DATABASES_FILE = "databases.xml";
+
+ private static final String INIT_SQL_PATH = "init-sql";
+
+ private static final String INIT_SQL_FILE = "init.sql";
+
+ private static final String DATASET_FILE = "dataset.xml";
+
+ private static final String RULE_CONFIG_FILE = "rules.yaml";
+
+ private static final String AUTHORITY_FILE = "authority.xml";
+
+ private final String scenario;
+
+ /**
+ * Check folder exist.
+ */
+ public void checkFolderExist() {
+ String scenarioDirectory = String.join("/", ROOT_PATH, scenario);
+ assertNotNull(String.format("Scenario folder `%s` must exist.", scenarioDirectory), ScenarioPath.class.getClassLoader().getResource(scenarioDirectory));
+ }
+
+ /**
+ * Get databases file.
+ *
+ * @return databases file
+ */
+ public String getDatabasesFile() {
+ return getFile(DATABASES_FILE);
+ }
+
+ /**
+ * Get init SQL files.
+ *
+ * @param databaseName database name
+ * @param databaseType database type
+ * @return init SQL files
+ */
+ public Collection<String> getInitSQLFiles(final String databaseName, final DatabaseType databaseType) {
+ Collection<String> result = new LinkedList<>();
+ result.add(getInitSQLFile(databaseType, INIT_SQL_FILE));
+ String dbInitSQLFileName = "init-" + databaseName + ".sql";
+ if (isInitSQLFileExist(databaseType, dbInitSQLFileName)) {
+ result.add(getInitSQLFile(databaseType, dbInitSQLFileName));
+ }
+ return result;
+ }
+
+ private String getInitSQLFile(final DatabaseType databaseType, final String fileName) {
+ String resourceFile = getInitSQLResourceFile(databaseType, fileName);
+ URL url = ScenarioPath.class.getClassLoader().getResource(resourceFile);
+ assertNotNull(String.format("File `%s` must exist.", resourceFile), url);
+ return url.getFile();
+ }
+
+ private String getInitSQLResourceFile(final DatabaseType databaseType, final String fileName) {
+ return String.join("/", ROOT_PATH, scenario, INIT_SQL_PATH, databaseType.getName().toLowerCase(), fileName);
+ }
+
+ private boolean isInitSQLFileExist(final DatabaseType databaseType, final String fileName) {
+ return null != ScenarioPath.class.getClassLoader().getResource(getInitSQLResourceFile(databaseType, fileName));
+ }
+
+ /**
+ * Get init SQL resource path.
+ *
+ * @param databaseType database type
+ * @return init SQL resource path
+ */
+ public String getInitSQLResourcePath(final DatabaseType databaseType) {
+ return String.join("/", "", ROOT_PATH, scenario, INIT_SQL_PATH, databaseType.getName().toLowerCase());
+ }
+
+ /**
+ * Get data set file.
+ *
+ * @return data set file
+ */
+ public String getDataSetFile() {
+ return getFile(DATASET_FILE);
+ }
+
+ /**
+ * Get rule configuration file.
+ *
+ * @return rule configuration file
+ */
+ public String getRuleConfigurationFile() {
+ return getFile(RULE_CONFIG_FILE);
+ }
+
+ /**
+ * Get authority file.
+ *
+ * @return authority file
+ */
+ public String getAuthorityFile() {
+ return getFile(AUTHORITY_FILE);
+ }
+
+ private String getFile(final String fileName) {
+ String path = String.join("/", ROOT_PATH, scenario, fileName);
+ URL url = ScenarioPath.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/authority/AuthorityEnvironment.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/authority/AuthorityEnvironment.java
similarity index 96%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/authority/AuthorityEnvironment.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/authority/AuthorityEnvironment.java
index 8e0cb8c..aa59727 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/authority/AuthorityEnvironment.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/authority/AuthorityEnvironment.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.integration.env.authority;
+package org.apache.shardingsphere.test.integration.env.scenario.authority;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/authority/AuthorityEnvironmentManager.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/authority/AuthorityEnvironmentManager.java
similarity index 97%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/authority/AuthorityEnvironmentManager.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/authority/AuthorityEnvironmentManager.java
index 4d15228..87585b0 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/authority/AuthorityEnvironmentManager.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/authority/AuthorityEnvironmentManager.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.integration.env.authority;
+package org.apache.shardingsphere.test.integration.env.scenario.authority;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/authority/AuthoritySQLSet.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/authority/AuthoritySQLSet.java
similarity index 97%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/authority/AuthoritySQLSet.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/authority/AuthoritySQLSet.java
index 731c734..723b410 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/authority/AuthoritySQLSet.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/authority/AuthoritySQLSet.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.integration.env.authority;
+package org.apache.shardingsphere.test.integration.env.scenario.authority;
import com.google.common.base.Splitter;
import lombok.Setter;
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/scenario/database/DatabaseEnvironmentManager.java
similarity index 88%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironmentManager.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/database/DatabaseEnvironmentManager.java
index fa7a359..797e18a 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/scenario/database/DatabaseEnvironmentManager.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.integration.env.database;
+package org.apache.shardingsphere.test.integration.env.scenario.database;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.test.integration.env.ScenarioEnvironmentPath;
+import org.apache.shardingsphere.test.integration.env.scenario.ScenarioPath;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@@ -42,7 +42,7 @@ public final class DatabaseEnvironmentManager {
* @throws JAXBException JAXB exception
*/
public static Collection<String> getDatabaseNames(final String scenario) throws IOException, JAXBException {
- return unmarshal(ScenarioEnvironmentPath.getDatabasesFile(scenario)).getDatabases();
+ return unmarshal(new ScenarioPath(scenario).getDatabasesFile()).getDatabases();
}
private static DatabaseNameEnvironment unmarshal(final String databasesFile) throws IOException, JAXBException {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseNameEnvironment.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/database/DatabaseNameEnvironment.java
similarity index 94%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseNameEnvironment.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/database/DatabaseNameEnvironment.java
index 9f59bf3..1ea5cee 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseNameEnvironment.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/database/DatabaseNameEnvironment.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.integration.env.database;
+package org.apache.shardingsphere.test.integration.env.scenario.database;
import lombok.Getter;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/dataset/DataSetEnvironmentManager.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/dataset/DataSetEnvironmentManager.java
similarity index 99%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/dataset/DataSetEnvironmentManager.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/dataset/DataSetEnvironmentManager.java
index 969da4d..af433a4 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/dataset/DataSetEnvironmentManager.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/scenario/dataset/DataSetEnvironmentManager.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.integration.env.dataset;
+package org.apache.shardingsphere.test.integration.env.scenario.dataset;
import com.google.common.base.Joiner;
import lombok.RequiredArgsConstructor;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java
index 1469fcd..be68637 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java
@@ -18,14 +18,13 @@
package org.apache.shardingsphere.test.integration.framework.container.atomic.adapter.impl;
import com.google.common.base.Strings;
-import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
import org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlModeConfiguration;
import org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlPersistRepositoryConfiguration;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
-import org.apache.shardingsphere.test.integration.env.ScenarioEnvironmentPath;
+import org.apache.shardingsphere.test.integration.env.scenario.ScenarioPath;
import org.apache.shardingsphere.test.integration.framework.container.atomic.EmbeddedITContainer;
import org.apache.shardingsphere.test.integration.framework.container.atomic.adapter.AdapterContainer;
import org.apache.shardingsphere.test.integration.framework.container.atomic.storage.StorageContainer;
@@ -41,15 +40,19 @@ import java.util.concurrent.atomic.AtomicReference;
/**
* ShardingSphere JDBC container.
*/
-@RequiredArgsConstructor
public final class ShardingSphereJDBCContainer implements EmbeddedITContainer, AdapterContainer {
private final StorageContainer storageContainer;
- private final String scenario;
+ private final ScenarioPath scenarioPath;
private final AtomicReference<DataSource> targetDataSourceProvider = new AtomicReference<>();
+ public ShardingSphereJDBCContainer(final StorageContainer storageContainer, final String scenario) {
+ this.storageContainer = storageContainer;
+ scenarioPath = new ScenarioPath(scenario);
+ }
+
@Override
public void start() {
}
@@ -61,7 +64,7 @@ public final class ShardingSphereJDBCContainer implements EmbeddedITContainer, A
if (Strings.isNullOrEmpty(serverLists)) {
try {
targetDataSourceProvider.set(
- YamlShardingSphereDataSourceFactory.createDataSource(storageContainer.getActualDataSourceMap(), new File(ScenarioEnvironmentPath.getRulesConfigurationFile(scenario))));
+ YamlShardingSphereDataSourceFactory.createDataSource(storageContainer.getActualDataSourceMap(), new File(scenarioPath.getRuleConfigurationFile())));
} catch (final SQLException | IOException ex) {
throw new RuntimeException(ex);
}
@@ -74,7 +77,7 @@ public final class ShardingSphereJDBCContainer implements EmbeddedITContainer, A
@SneakyThrows({SQLException.class, IOException.class})
private DataSource createGovernanceClientDataSource(final String serverLists) {
- YamlRootConfiguration rootConfig = YamlEngine.unmarshal(new File(ScenarioEnvironmentPath.getRulesConfigurationFile(scenario)), YamlRootConfiguration.class);
+ YamlRootConfiguration rootConfig = YamlEngine.unmarshal(new File(scenarioPath.getRuleConfigurationFile()), YamlRootConfiguration.class);
rootConfig.setMode(createYamlModeConfiguration(serverLists));
return YamlShardingSphereDataSourceFactory.createDataSource(storageContainer.getActualDataSourceMap(), YamlEngine.marshal(rootConfig).getBytes(StandardCharsets.UTF_8));
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/DockerStorageContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/DockerStorageContainer.java
index c912fc9..fb576c8 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/DockerStorageContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/DockerStorageContainer.java
@@ -23,8 +23,8 @@ import lombok.Getter;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.env.DataSourceEnvironment;
-import org.apache.shardingsphere.test.integration.env.ScenarioEnvironmentPath;
-import org.apache.shardingsphere.test.integration.env.database.DatabaseEnvironmentManager;
+import org.apache.shardingsphere.test.integration.env.scenario.ScenarioPath;
+import org.apache.shardingsphere.test.integration.env.scenario.database.DatabaseEnvironmentManager;
import org.apache.shardingsphere.test.integration.framework.container.atomic.DockerITContainer;
import org.testcontainers.containers.BindMode;
@@ -38,9 +38,9 @@ import java.util.Map;
/**
* Docker storage container.
*/
-@Getter(AccessLevel.PROTECTED)
public abstract class DockerStorageContainer extends DockerITContainer implements StorageContainer {
+ @Getter(AccessLevel.PROTECTED)
private final DatabaseType databaseType;
private final String scenario;
@@ -55,7 +55,7 @@ public abstract class DockerStorageContainer extends DockerITContainer implement
@Override
protected void configure() {
- withClasspathResourceMapping(ScenarioEnvironmentPath.getInitSQLResourcePath(databaseType, scenario), "/docker-entrypoint-initdb.d/", BindMode.READ_ONLY);
+ withClasspathResourceMapping(new ScenarioPath(scenario).getInitSQLResourcePath(databaseType), "/docker-entrypoint-initdb.d/", BindMode.READ_ONLY);
}
@Override
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/EmbeddedStorageContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/EmbeddedStorageContainer.java
index cfb2081..896f240 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/EmbeddedStorageContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/EmbeddedStorageContainer.java
@@ -24,7 +24,7 @@ import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.env.DataSourceEnvironment;
-import org.apache.shardingsphere.test.integration.env.database.DatabaseEnvironmentManager;
+import org.apache.shardingsphere.test.integration.env.scenario.database.DatabaseEnvironmentManager;
import org.apache.shardingsphere.test.integration.framework.container.atomic.EmbeddedITContainer;
import javax.sql.DataSource;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java
index 2061dce..20086d4 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java
@@ -19,12 +19,11 @@ package org.apache.shardingsphere.test.integration.framework.container.atomic.st
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
-import org.apache.shardingsphere.test.integration.env.ScenarioEnvironmentPath;
+import org.apache.shardingsphere.test.integration.env.scenario.ScenarioPath;
import org.apache.shardingsphere.test.integration.framework.container.atomic.storage.EmbeddedStorageContainer;
import org.h2.tools.RunScript;
import javax.sql.DataSource;
-import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
@@ -36,30 +35,27 @@ import java.util.Map.Entry;
*/
public final class H2Container extends EmbeddedStorageContainer {
+ private final ScenarioPath scenarioPath;
+
public H2Container(final String scenario) {
super(DatabaseTypeRegistry.getActualDatabaseType("H2"), scenario);
+ scenarioPath = new ScenarioPath(scenario);
}
@Override
@SneakyThrows({IOException.class, SQLException.class})
public void start() {
- File initSQLFile = new File(ScenarioEnvironmentPath.getInitSQLFile(getDatabaseType(), getScenario()));
for (Entry<String, DataSource> entry : getActualDataSourceMap().entrySet()) {
- String dbInitSQLFileName = "init-" + entry.getKey() + ".sql";
- try (
- Connection connection = entry.getValue().getConnection();
- FileReader reader = new FileReader(initSQLFile)) {
- RunScript.execute(connection, reader);
- if (ScenarioEnvironmentPath.checkSQLFileExist(getDatabaseType(), getScenario(), dbInitSQLFileName)) {
- executeDataInitFile(connection, dbInitSQLFileName);
- }
+ for (String each : scenarioPath.getInitSQLFiles(entry.getKey(), getDatabaseType())) {
+ executeInitSQL(entry.getValue(), each);
}
}
}
- private void executeDataInitFile(final Connection connection, final String dataInitFileName) throws IOException, SQLException {
- File dataInitFile = new File(ScenarioEnvironmentPath.getInitSQLFile(getDatabaseType(), getScenario(), dataInitFileName));
- try (FileReader reader = new FileReader(dataInitFile)) {
+ private void executeInitSQL(final DataSource dataSource, final String initSQLFile) throws SQLException, IOException {
+ try (
+ Connection connection = dataSource.getConnection();
+ FileReader reader = new FileReader(initSQLFile)) {
RunScript.execute(connection, reader);
}
}