2222import java .io .FileNotFoundException ;
2323import java .io .IOException ;
2424import java .io .InputStream ;
25+ import java .net .URL ;
2526import java .util .HashMap ;
2627import java .util .Map ;
2728import java .util .UUID ;
@@ -147,13 +148,14 @@ public void testConstruct() {
147148
148149 @ Test
149150 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 );
157159 this .driver .uploadAlgorithmJar ("PageRank" , inputStream );
158160
159161 File file = new File ("/tmp/upload.txt" );
@@ -166,12 +168,13 @@ public void testUploadAlgorithmJar() throws FileNotFoundException {
166168
167169 @ Test
168170 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 );
174176
177+ InputStream inputStream = new FileInputStream (path );
175178 Assert .assertThrows (ComputerDriverException .class , () -> {
176179 this .driver .uploadAlgorithmJar ("PageRank" , inputStream );
177180 }, e -> {
@@ -315,4 +318,14 @@ public void testCheckComputerConf() {
315318 );
316319 });
317320 }
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+ }
318331}
0 commit comments