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 96480da8c4c Add EnvironmentPropertiesLoader (#36712)
96480da8c4c is described below
commit 96480da8c4c3605124ac082005e53237188da5c0
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Sep 26 00:37:20 2025 +0800
Add EnvironmentPropertiesLoader (#36712)
---
.../test/e2e/env/runtime/E2ETestEnvironment.java | 30 +---------
.../env/runtime/EnvironmentPropertiesLoader.java | 64 ++++++++++++++++++++++
.../e2e/env/runtime/type/ArtifactEnvironment.java | 26 ++-------
.../transaction/env/TransactionE2EEnvironment.java | 40 ++------------
4 files changed, 78 insertions(+), 82 deletions(-)
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/E2ETestEnvironment.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/E2ETestEnvironment.java
index f133d2d5675..10cac11c319 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/E2ETestEnvironment.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/E2ETestEnvironment.java
@@ -17,20 +17,14 @@
package org.apache.shardingsphere.test.e2e.env.runtime;
-import com.google.common.base.Splitter;
import lombok.Getter;
-import lombok.SneakyThrows;
import org.apache.shardingsphere.test.e2e.env.runtime.type.ArtifactEnvironment;
import
org.apache.shardingsphere.test.e2e.env.runtime.type.NativeStorageEnvironment;
import org.apache.shardingsphere.test.e2e.env.runtime.type.RunEnvironment;
-import
org.apache.shardingsphere.test.e2e.env.runtime.type.scenario.path.ScenarioCommonPath;
-import java.io.IOException;
-import java.io.InputStream;
import java.util.Collection;
import java.util.Properties;
import java.util.TimeZone;
-import java.util.stream.Collectors;
/**
* E2E test environment.
@@ -49,34 +43,14 @@ public final class E2ETestEnvironment {
private final NativeStorageEnvironment nativeStorageEnvironment;
private E2ETestEnvironment() {
- Properties props = loadProperties();
+ Properties props = EnvironmentPropertiesLoader.loadProperties();
TimeZone.setDefault(TimeZone.getTimeZone(props.getProperty("e2e.timezone",
"UTC")));
- scenarios = getScenarios(props);
+ scenarios = EnvironmentPropertiesLoader.getListValue(props,
"e2e.scenarios");
runEnvironment = new RunEnvironment(props);
artifactEnvironment = new ArtifactEnvironment(props);
nativeStorageEnvironment = new NativeStorageEnvironment(props);
}
- @SneakyThrows(IOException.class)
- private Properties loadProperties() {
- Properties result = new Properties();
- try (InputStream inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream("env/e2e-env.properties"))
{
- result.load(inputStream);
- }
- for (String each : System.getProperties().stringPropertyNames()) {
- result.setProperty(each, System.getProperty(each));
- }
- return result;
- }
-
- private Collection<String> getScenarios(final Properties props) {
- Collection<String> result =
Splitter.on(",").trimResults().splitToList(props.getProperty("e2e.scenarios",
"")).stream().filter(each -> !each.isEmpty()).collect(Collectors.toList());
- for (String each : result) {
- new ScenarioCommonPath(each).checkFolderExist();
- }
- return result;
- }
-
/**
* Judge whether valid E2E test environment.
*
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/EnvironmentPropertiesLoader.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/EnvironmentPropertiesLoader.java
new file mode 100644
index 00000000000..bd4c366b6f1
--- /dev/null
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/EnvironmentPropertiesLoader.java
@@ -0,0 +1,64 @@
+/*
+ * 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.e2e.env.runtime;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.SneakyThrows;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
+/**
+ * Environment properties loader.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class EnvironmentPropertiesLoader {
+
+ /**
+ * Load environment properties.
+ *
+ * @return loaded properties
+ */
+ @SneakyThrows(IOException.class)
+ public static Properties loadProperties() {
+ Properties result = new Properties();
+ try (InputStream inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream("env/e2e-env.properties"))
{
+ result.load(inputStream);
+ }
+ for (String each : System.getProperties().stringPropertyNames()) {
+ result.setProperty(each, System.getProperty(each));
+ }
+ return result;
+ }
+
+ /**
+ * Get list value.
+ *
+ * @param props properties
+ * @param key key
+ * @return list value
+ */
+ public static List<String> getListValue(final Properties props, final
String key) {
+ return Arrays.stream(props.getProperty(key,
"").split(",")).map(String::trim).filter(each ->
!each.isEmpty()).collect(Collectors.toList());
+ }
+}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/ArtifactEnvironment.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/ArtifactEnvironment.java
index 3ed3afc292c..07b693a36f5 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/ArtifactEnvironment.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/ArtifactEnvironment.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.test.e2e.env.runtime.type;
-import com.google.common.base.Splitter;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import
org.apache.shardingsphere.test.e2e.env.runtime.EnvironmentPropertiesLoader;
import java.util.Collection;
import java.util.HashMap;
@@ -51,22 +51,13 @@ public final class ArtifactEnvironment {
private final List<String> proxyPortBindings;
public ArtifactEnvironment(final Properties props) {
- modes =
Splitter.on(",").trimResults().splitToList(props.getProperty("e2e.artifact.modes",
"")).stream()
- .filter(each -> !each.isEmpty()).map(each ->
Mode.valueOf(each.toUpperCase())).collect(Collectors.toList());
- adapters = getAdapters(props);
+ modes = EnvironmentPropertiesLoader.getListValue(props,
"e2e.artifact.modes").stream().map(each ->
Mode.valueOf(each.toUpperCase())).collect(Collectors.toList());
+ adapters = EnvironmentPropertiesLoader.getListValue(props,
"e2e.artifact.adapters");
regCenterType = props.getProperty("e2e.artifact.regcenter");
- databaseTypes = getDatabaseTypes(props);
+ databaseTypes = EnvironmentPropertiesLoader.getListValue(props,
"e2e.artifact.databases").stream()
+ .map(each -> TypedSPILoader.getService(DatabaseType.class,
each.trim())).collect(Collectors.toSet());
databaseImages = getDatabaseImages(props);
- proxyPortBindings = getProxyPortBindings(props);
- }
-
- private Collection<String> getAdapters(final Properties props) {
- return
Splitter.on(",").trimResults().splitToList(props.getProperty("e2e.artifact.adapters",
"")).stream().filter(each -> !each.isEmpty()).collect(Collectors.toList());
- }
-
- private Collection<DatabaseType> getDatabaseTypes(final Properties props) {
- return
Splitter.on(",").trimResults().splitToList(props.getProperty("e2e.artifact.databases",
"")).stream()
- .filter(each -> !each.isEmpty()).map(each ->
TypedSPILoader.getService(DatabaseType.class,
each.trim())).collect(Collectors.toSet());
+ proxyPortBindings = EnvironmentPropertiesLoader.getListValue(props,
"e2e.artifact.proxy.port.bindings");
}
private Map<DatabaseType, String> getDatabaseImages(final Properties
props) {
@@ -78,11 +69,6 @@ public final class ArtifactEnvironment {
return result;
}
- private List<String> getProxyPortBindings(final Properties props) {
- return Splitter.on(",").trimResults()
-
.splitToList(props.getProperty("e2e.artifact.proxy.port.bindings",
"")).stream().filter(each -> !each.isEmpty()).collect(Collectors.toList());
- }
-
public enum Mode {
STANDALONE, CLUSTER
diff --git
a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/env/TransactionE2EEnvironment.java
b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/env/TransactionE2EEnvironment.java
index 151b8600d9a..02983cfa578 100644
---
a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/env/TransactionE2EEnvironment.java
+++
b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/env/TransactionE2EEnvironment.java
@@ -17,15 +17,12 @@
package org.apache.shardingsphere.test.e2e.operation.transaction.env;
-import com.google.common.base.Strings;
import lombok.Getter;
+import
org.apache.shardingsphere.test.e2e.env.runtime.EnvironmentPropertiesLoader;
import
org.apache.shardingsphere.test.e2e.operation.transaction.env.enums.TransactionTestCaseRegistry;
-import java.io.IOException;
-import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -45,36 +42,11 @@ public final class TransactionE2EEnvironment {
private final Map<String, TransactionTestCaseRegistry>
transactionTestCaseRegistryMap;
private TransactionE2EEnvironment() {
- Properties props = loadProperties();
- cases = splitProperty(props, "e2e.cases");
- allowTransactionTypes = splitProperty(props,
"transaction.e2e.env.transtypes");
- allowXAProviders = splitProperty(props,
"transaction.e2e.env.xa.providers");
- transactionTestCaseRegistryMap = initTransactionTestCaseRegistryMap();
- }
-
- private Properties loadProperties() {
- Properties result = new Properties();
- try (InputStream inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream("env/e2e-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 List<String> splitProperty(final Properties props, final String
key) {
- return Arrays.stream(props.getOrDefault(key,
"").toString().split(",")).filter(each ->
!Strings.isNullOrEmpty(each)).map(String::trim).collect(Collectors.toList());
- }
-
- private Map<String, TransactionTestCaseRegistry>
initTransactionTestCaseRegistryMap() {
- Map<String, TransactionTestCaseRegistry> result = new
HashMap<>(TransactionTestCaseRegistry.values().length, 1F);
- for (TransactionTestCaseRegistry each :
TransactionTestCaseRegistry.values()) {
- result.put(each.getTestCaseClass().getName(), each);
- }
- return result;
+ Properties props = EnvironmentPropertiesLoader.loadProperties();
+ cases = EnvironmentPropertiesLoader.getListValue(props, "e2e.cases");
+ allowTransactionTypes =
EnvironmentPropertiesLoader.getListValue(props,
"transaction.e2e.env.transtypes");
+ allowXAProviders = EnvironmentPropertiesLoader.getListValue(props,
"transaction.e2e.env.xa.providers");
+ transactionTestCaseRegistryMap =
Arrays.stream(TransactionTestCaseRegistry.values()).collect(Collectors.toMap(each
-> each.getTestCaseClass().getName(), each -> each));
}
/**