This is an automated email from the ASF dual-hosted git repository.
tuichenchuxin 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 e65da2de959 Refactor GitHubEnvironment to suit more get properties
value scenarios (#28346)
e65da2de959 is described below
commit e65da2de95953904a03ecd916235c658cb0ff675
Author: zhaojinchao <[email protected]>
AuthorDate: Mon Sep 4 09:14:03 2023 +0800
Refactor GitHubEnvironment to suit more get properties value scenarios
(#28346)
---
.../EnvironmentContext.java} | 33 +++++++++++++---------
.../impl/GitHubTestParameterLoadStrategy.java | 8 ++++--
.../env/{github-env.properties => env.properties} | 0
3 files changed, 25 insertions(+), 16 deletions(-)
diff --git
a/test/util/src/main/java/org/apache/shardingsphere/test/loader/strategy/impl/GitHubEnvironment.java
b/test/util/src/main/java/org/apache/shardingsphere/test/env/EnvironmentContext.java
similarity index 71%
rename from
test/util/src/main/java/org/apache/shardingsphere/test/loader/strategy/impl/GitHubEnvironment.java
rename to
test/util/src/main/java/org/apache/shardingsphere/test/env/EnvironmentContext.java
index 9b8ec31d3d8..28054d28bd1 100644
---
a/test/util/src/main/java/org/apache/shardingsphere/test/loader/strategy/impl/GitHubEnvironment.java
+++
b/test/util/src/main/java/org/apache/shardingsphere/test/env/EnvironmentContext.java
@@ -15,9 +15,8 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.loader.strategy.impl;
+package org.apache.shardingsphere.test.env;
-import lombok.Getter;
import lombok.SneakyThrows;
import java.io.IOException;
@@ -25,20 +24,16 @@ import java.io.InputStream;
import java.util.Properties;
/**
- * GitHub environment.
+ * environment context.
*/
-@Getter
-public final class GitHubEnvironment {
+public final class EnvironmentContext {
- private static final String TOKEN_KEY = "it.github.token";
+ private static final EnvironmentContext INSTANCE = new
EnvironmentContext();
- private static final GitHubEnvironment INSTANCE = new GitHubEnvironment();
+ private final Properties props;
- private final String githubToken;
-
- private GitHubEnvironment() {
- Properties props = loadProperties();
- githubToken = props.getProperty(TOKEN_KEY);
+ private EnvironmentContext() {
+ props = loadProperties();
}
/**
@@ -46,14 +41,24 @@ public final class GitHubEnvironment {
*
* @return got instance
*/
- public static GitHubEnvironment getInstance() {
+ public static EnvironmentContext getInstance() {
return INSTANCE;
}
+ /**
+ * Get value by key.
+ *
+ * @param key key
+ * @return value
+ */
+ public String getValue(final String key) {
+ return props.getProperty(key);
+ }
+
@SneakyThrows(IOException.class)
private Properties loadProperties() {
Properties result = new Properties();
- try (InputStream inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream("env/github-env.properties"))
{
+ try (InputStream inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream("env/env.properties"))
{
result.load(inputStream);
}
for (String each : System.getProperties().stringPropertyNames()) {
diff --git
a/test/util/src/main/java/org/apache/shardingsphere/test/loader/strategy/impl/GitHubTestParameterLoadStrategy.java
b/test/util/src/main/java/org/apache/shardingsphere/test/loader/strategy/impl/GitHubTestParameterLoadStrategy.java
index 0eb522635f8..7d96ef0948f 100644
---
a/test/util/src/main/java/org/apache/shardingsphere/test/loader/strategy/impl/GitHubTestParameterLoadStrategy.java
+++
b/test/util/src/main/java/org/apache/shardingsphere/test/loader/strategy/impl/GitHubTestParameterLoadStrategy.java
@@ -21,6 +21,7 @@ import com.google.common.base.Strings;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.test.env.EnvironmentContext;
import
org.apache.shardingsphere.test.loader.strategy.TestParameterLoadStrategy;
import org.apache.shardingsphere.test.loader.summary.FileSummary;
@@ -41,6 +42,8 @@ import java.util.stream.Collectors;
@Slf4j
public final class GitHubTestParameterLoadStrategy implements
TestParameterLoadStrategy {
+ private static final String TOKEN_KEY = "it.github.token";
+
@Override
public Collection<FileSummary> loadSQLCaseFileSummaries(final URI uri) {
if (uri.toString().isEmpty()) {
@@ -82,8 +85,9 @@ public final class GitHubTestParameterLoadStrategy implements
TestParameterLoadS
private String loadContent(final URI casesURI) {
try {
URLConnection urlConnection = casesURI.toURL().openConnection();
- if
(!Strings.isNullOrEmpty(GitHubEnvironment.getInstance().getGithubToken())) {
- urlConnection.setRequestProperty("Authorization", "Bearer " +
GitHubEnvironment.getInstance().getGithubToken());
+ String githubToken =
EnvironmentContext.getInstance().getValue(TOKEN_KEY);
+ if (!Strings.isNullOrEmpty(githubToken)) {
+ urlConnection.setRequestProperty("Authorization", "Bearer " +
githubToken);
}
try (BufferedReader reader = new BufferedReader(new
InputStreamReader(urlConnection.getInputStream()))) {
return
reader.lines().collect(Collectors.joining(System.lineSeparator()));
diff --git a/test/util/src/main/resources/env/github-env.properties
b/test/util/src/main/resources/env/env.properties
similarity index 100%
rename from test/util/src/main/resources/env/github-env.properties
rename to test/util/src/main/resources/env/env.properties