Skip to content

Commit e400e4d

Browse files
authored
refact(test): download binary file for https test (#126)
1 parent 0239a1e commit e400e4d

File tree

7 files changed

+30
-8
lines changed

7 files changed

+30
-8
lines changed

hugegraph-common/src/test/java/org/apache/hugegraph/unit/BaseUnitTest.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919

2020
package org.apache.hugegraph.unit;
2121

22+
import java.io.File;
23+
import java.io.IOException;
24+
import java.net.URL;
2225
import java.util.ArrayList;
2326
import java.util.List;
2427
import java.util.concurrent.ExecutionException;
2528
import java.util.concurrent.ExecutorService;
2629
import java.util.concurrent.Executors;
2730
import java.util.concurrent.Future;
2831

32+
import org.apache.commons.io.FileUtils;
2933
import org.apache.hugegraph.util.TimeUtil;
3034
import org.junit.AfterClass;
3135
import org.junit.BeforeClass;
@@ -42,7 +46,7 @@ public static void clear() throws Exception {
4246
// pass
4347
}
4448

45-
protected static final void runWithThreads(int threads, Runnable task) {
49+
protected static void runWithThreads(int threads, Runnable task) {
4650
ExecutorService executor = Executors.newFixedThreadPool(threads);
4751
List<Future<?>> futures = new ArrayList<>();
4852
for (int i = 0; i < threads; i++) {
@@ -57,7 +61,17 @@ protected static final void runWithThreads(int threads, Runnable task) {
5761
}
5862
}
5963

60-
protected static final void waitTillNext(long seconds) {
64+
protected static void waitTillNext(long seconds) {
6165
TimeUtil.tillNextMillis(TimeUtil.timeGen() + seconds * 1000);
6266
}
67+
68+
public static void downloadFileByUrl(String url, String destPath) {
69+
int connectTimeout = 5000;
70+
int readTimeout = 5000;
71+
try {
72+
FileUtils.copyURLToFile(new URL(url), new File(destPath), connectTimeout, readTimeout);
73+
} catch (IOException e) {
74+
throw new RuntimeException(e);
75+
}
76+
}
6377
}

hugegraph-common/src/test/java/org/apache/hugegraph/unit/concurrent/KeyLockTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.hugegraph.unit.concurrent;
2121

2222
import java.util.Arrays;
23+
import java.util.Collections;
2324
import java.util.List;
2425
import java.util.concurrent.locks.Lock;
2526

@@ -103,7 +104,7 @@ public void testLockUnlockAll() {
103104
});
104105

105106
Assert.assertThrows(IllegalArgumentException.class, () -> {
106-
locks.lockAll(Arrays.asList().toArray());
107+
locks.lockAll(Collections.emptyList().toArray());
107108
}, e -> {
108109
Assert.assertContains("Lock keys can't be null or empty",
109110
e.getMessage());

hugegraph-common/src/test/java/org/apache/hugegraph/unit/license/LicenseCreateParamTest.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,18 @@
2020
package org.apache.hugegraph.unit.license;
2121

2222
import java.io.IOException;
23-
import java.text.ParseException;
2423

2524
import org.apache.hugegraph.date.SafeDateFormat;
26-
import org.junit.Test;
27-
2825
import org.apache.hugegraph.license.LicenseCreateParam;
2926
import org.apache.hugegraph.testutil.Assert;
27+
import org.junit.Test;
28+
3029
import com.fasterxml.jackson.databind.ObjectMapper;
3130

3231
public class LicenseCreateParamTest {
3332

3433
@Test
35-
public void testDeserializeLicenseCreateParam()
36-
throws IOException, ParseException {
34+
public void testDeserializeLicenseCreateParam() throws IOException {
3735
String json = "{"
3836
+ "\"subject\":\"hugegraph-evaluation\","
3937
+ "\"private_alias\":\"privatekey\","

hugegraph-common/src/test/java/org/apache/hugegraph/unit/rest/RestClientTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import jakarta.ws.rs.core.MultivaluedMap;
4040
import jakarta.ws.rs.core.Response;
4141

42+
import org.apache.hugegraph.unit.BaseUnitTest;
4243
import org.junit.Test;
4344
import org.mockito.Mockito;
4445

@@ -271,7 +272,11 @@ public void testPostWithTokenAndAllParams() {
271272

272273
@Test
273274
public void testPostHttpsWithAllParams() {
275+
String url = "https://github.com/apache/incubator-hugegraph-doc/" +
276+
"raw/master/dist/commons/cacerts.jks";
274277
String trustStoreFile = "src/test/resources/cacerts.jks";
278+
BaseUnitTest.downloadFileByUrl(url, trustStoreFile);
279+
275280
String trustStorePassword = "changeit";
276281
RestClient client = new RestClientImpl("/test", "user", "", 1000,
277282
10, 5, trustStoreFile,
@@ -282,7 +287,11 @@ public void testPostHttpsWithAllParams() {
282287

283288
@Test
284289
public void testPostHttpsWithTokenAndAllParams() {
290+
String url = "https://github.com/apache/incubator-hugegraph-doc/" +
291+
"raw/master/dist/commons/cacerts.jks";
285292
String trustStoreFile = "src/test/resources/cacerts.jks";
293+
BaseUnitTest.downloadFileByUrl(url, trustStoreFile);
294+
286295
String trustStorePassword = "changeit";
287296
RestClient client = new RestClientImpl("/test", "token", 1000,
288297
10, 5, trustStoreFile,
-939 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)