22
22
import java .io .FileNotFoundException ;
23
23
import java .io .IOException ;
24
24
import java .io .InputStream ;
25
+ import java .net .URL ;
25
26
import java .util .HashMap ;
26
27
import java .util .Map ;
27
28
import java .util .UUID ;
@@ -147,13 +148,14 @@ public void testConstruct() {
147
148
148
149
@ Test
149
150
public void testUploadAlgorithmJar () throws FileNotFoundException {
150
- Whitebox .setInternalState (this .driver , "bashPath" ,
151
- "conf/images/docker_push_test.sh" );
152
- Whitebox .setInternalState (this .driver , "registry" ,
153
- "registry.hub.docker.com" );
154
-
155
- InputStream inputStream = new FileInputStream (
156
- "conf/images/test.jar" );
151
+ Whitebox .setInternalState (this .driver , "bashPath" , "conf/images/docker_push_test.sh" );
152
+ Whitebox .setInternalState (this .driver , "registry" , "registry.hub.docker.com" );
153
+ String url = "https://github.com/apache/hugegraph-doc/raw/" +
154
+ "binary-1.0/dist/computer/test.jar" ;
155
+ String path = "conf/images/test.jar" ;
156
+ downloadFileByUrl (url , path );
157
+
158
+ InputStream inputStream = new FileInputStream (path );
157
159
this .driver .uploadAlgorithmJar ("PageRank" , inputStream );
158
160
159
161
File file = new File ("/tmp/upload.txt" );
@@ -166,12 +168,13 @@ public void testUploadAlgorithmJar() throws FileNotFoundException {
166
168
167
169
@ Test
168
170
public void testUploadAlgorithmJarWithError () throws FileNotFoundException {
169
- Whitebox .setInternalState (this .driver , "bashPath" ,
170
- "conf/images/upload_test-x.sh" );
171
-
172
- InputStream inputStream = new FileInputStream (
173
- "conf/images/test.jar" );
171
+ Whitebox .setInternalState (this .driver , "bashPath" , "conf/images/upload_test-x.sh" );
172
+ String url = "https://github.com/apache/hugegraph-doc/raw/" +
173
+ "binary-1.0/dist/computer/test.jar" ;
174
+ String path = "conf/images/test.jar" ;
175
+ downloadFileByUrl ( url , path );
174
176
177
+ InputStream inputStream = new FileInputStream (path );
175
178
Assert .assertThrows (ComputerDriverException .class , () -> {
176
179
this .driver .uploadAlgorithmJar ("PageRank" , inputStream );
177
180
}, e -> {
@@ -315,4 +318,14 @@ public void testCheckComputerConf() {
315
318
);
316
319
});
317
320
}
321
+
322
+ public static void downloadFileByUrl (String url , String destPath ) {
323
+ int connectTimeout = 5000 ;
324
+ int readTimeout = 10000 ;
325
+ try {
326
+ FileUtils .copyURLToFile (new URL (url ), new File (destPath ), connectTimeout , readTimeout );
327
+ } catch (IOException e ) {
328
+ throw new RuntimeException (e );
329
+ }
330
+ }
318
331
}
0 commit comments