zhuzhurk commented on a change in pull request #9950: [FLINK-14464][runtime] 
Introduce the AbstractUserClassPathJobGraphRetriever
URL: https://github.com/apache/flink/pull/9950#discussion_r339284001
 
 

 ##########
 File path: flink-core/src/test/java/org/apache/flink/util/FileUtilsTest.java
 ##########
 @@ -312,6 +381,60 @@ private static void generateRandomDirs(File dir, int 
numFiles, int numDirs, int
                }
        }
 
+       /**
+        * Generate some files in the directory {@code dir}.
+        * @param dir the directory where the files are generated
+        * @return Tuple3 holding the generated files' absolute path, relative 
to the working directory path and relative
+        * url.
+        * @throws IOException if I/O error occurs while generating the files
+        */
+       public static Tuple3<Collection<File>, Collection<File>, 
Collection<URL>> prepareTestFiles(
+               final java.nio.file.Path dir) throws IOException {
+
+               Tuple3<Collection<File>, Collection<File>, Collection<URL>> 
result = new Tuple3<>();
+
+               result.f0 = generateSomeFilesInDirectoryReturnJarFiles(dir);
+               result.f1 = toRelativeFiles(result.f0);
+               result.f2 = toRelativeURLs(result.f1);
+
+               return result;
+       }
+
+       private static Collection<File> 
generateSomeFilesInDirectoryReturnJarFiles(
+                       final java.nio.file.Path dir) throws IOException {
+
+               final java.nio.file.Path jobSubDir1 = 
Files.createDirectory(dir.resolve("_sub_dir1"));
+               final java.nio.file.Path jobSubDir2 = 
Files.createDirectory(dir.resolve("_sub_dir2"));
+               final java.nio.file.Path jarFile1 = 
Files.createFile(dir.resolve("file1.jar"));
+               final java.nio.file.Path jarFile2 = 
Files.createFile(dir.resolve("file2.jar"));
+               final java.nio.file.Path jarFile3 = 
Files.createFile(jobSubDir1.resolve("file3.jar"));
+               final java.nio.file.Path jarFile4 = 
Files.createFile(jobSubDir2.resolve("file4.jar"));
+               final Collection<File> jarFiles = new ArrayList<>();
+
+               Files.createFile(dir.resolve("file1.txt"));
+               Files.createFile(jobSubDir2.resolve("file2.txt"));
+
+               jarFiles.add(jarFile1.toFile());
+               jarFiles.add(jarFile2.toFile());
+               jarFiles.add(jarFile3.toFile());
+               jarFiles.add(jarFile4.toFile());
+               return jarFiles;
+       }
+
+       private static Collection<File> toRelativeFiles(Collection<File> files) 
{
+               final java.nio.file.Path workingDir = 
Paths.get(System.getProperty("user.dir"));
+               final Collection<File> relativeFiles = new ArrayList<>();
+               files.forEach(file -> 
relativeFiles.add(workingDir.relativize(file.toPath()).toFile()));
+               return relativeFiles;
+       }
+
+       private static Collection<URL> toRelativeURLs(Collection<File> 
relativeFiles) throws MalformedURLException {
+               final Collection<URL> relativeURLs = new ArrayList<>();
+               final URL context = new 
URL(relativeFiles.iterator().next().toURI().getScheme() + ":");
+               relativeFiles.forEach(FunctionUtils.uncheckedConsumer(file -> 
relativeURLs.add(new URL(context, file.toString()))));
 
 Review comment:
   maybe file.toString() -> file.getPath()?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to