This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 9a5cdfe69c5 TestParameterLoader support GitHub token. (#28347)
9a5cdfe69c5 is described below
commit 9a5cdfe69c5fd5bba9c3ef30980260c30777f578
Author: Cong Hu <[email protected]>
AuthorDate: Mon Sep 4 11:02:30 2023 +0800
TestParameterLoader support GitHub token. (#28347)
---
.../test/loader/TestParameterLoader.java | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git
a/test/util/src/main/java/org/apache/shardingsphere/test/loader/TestParameterLoader.java
b/test/util/src/main/java/org/apache/shardingsphere/test/loader/TestParameterLoader.java
index 46a579eed40..c3d3bebcf8b 100644
---
a/test/util/src/main/java/org/apache/shardingsphere/test/loader/TestParameterLoader.java
+++
b/test/util/src/main/java/org/apache/shardingsphere/test/loader/TestParameterLoader.java
@@ -17,10 +17,12 @@
package org.apache.shardingsphere.test.loader;
+import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
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;
@@ -28,6 +30,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
+import java.net.URLConnection;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
@@ -46,6 +49,8 @@ import java.util.stream.Collectors;
@Slf4j
public final class TestParameterLoader {
+ private static final String TOKEN_KEY = "it.github.token";
+
private static final int DEFAULT_DOWNLOAD_THREADS = 4;
private final ExecutorService executorService =
Executors.newFixedThreadPool(DEFAULT_DOWNLOAD_THREADS);
@@ -87,10 +92,15 @@ public final class TestParameterLoader {
}
private List<String> loadContent(final URI uri) {
- try (
- InputStreamReader in = new
InputStreamReader(uri.toURL().openStream());
- BufferedReader reader = new BufferedReader(in)) {
- return reader.lines().collect(Collectors.toList());
+ try {
+ URLConnection urlConnection = uri.toURL().openConnection();
+ 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.toList());
+ }
} catch (final IOException ex) {
log.warn("Load failed, reason is: ", ex);
return Lists.newArrayList();