zentol commented on a change in pull request #7717: [FLINK-11533] [container]
Add option parse JAR manifest for jobClassName
URL: https://github.com/apache/flink/pull/7717#discussion_r260728729
##########
File path:
flink-container/src/test/java/org/apache/flink/container/entrypoint/ClassPathJobGraphRetrieverTest.java
##########
@@ -60,21 +75,111 @@ public void testJobGraphRetrieval() throws FlinkException
{
assertEquals(jobGraph.getJobID(), jobId);
}
+ @Test
+ public void testJobGraphRetrievalFromJar() throws FlinkException,
FileNotFoundException {
+ final File testJar = TestJob.getTestJobJar();
+ final ClassPathJobGraphRetriever classPathJobGraphRetriever =
new ClassPathJobGraphRetriever(
+ new JobID(),
+ SavepointRestoreSettings.none(),
+ PROGRAM_ARGUMENTS,
+ // No class name specified, but the test JAR "is" on
the class path
+ null,
+ () -> Collections.singleton(testJar));
+
+ final JobGraph jobGraph =
classPathJobGraphRetriever.retrieveJobGraph(new Configuration());
+
+ assertThat(jobGraph.getName(),
is(equalTo(TestJob.class.getCanonicalName() + "-suffix")));
+ }
+
+ @Test
+ public void
testJobGraphRetrievalJobClassNameHasPrecedenceOverClassPath() throws
FlinkException, FileNotFoundException {
+ final File testJar = new File("non-existing");
+
+ final ClassPathJobGraphRetriever classPathJobGraphRetriever =
new ClassPathJobGraphRetriever(
+ new JobID(),
+ SavepointRestoreSettings.none(),
+ PROGRAM_ARGUMENTS,
+ // Both a class name is specified and a JAR "is" on the
class path
+ // The class name should have precedence.
+ TestJob.class.getCanonicalName(),
+ () -> Collections.singleton(testJar));
+
+ final JobGraph jobGraph =
classPathJobGraphRetriever.retrieveJobGraph(new Configuration());
+
+ assertThat(jobGraph.getName(),
is(equalTo(TestJob.class.getCanonicalName() + "-suffix")));
+ }
+
@Test
public void testSavepointRestoreSettings() throws FlinkException {
final Configuration configuration = new Configuration();
final SavepointRestoreSettings savepointRestoreSettings =
SavepointRestoreSettings.forPath("foobar", true);
final JobID jobId = new JobID();
final ClassPathJobGraphRetriever classPathJobGraphRetriever =
new ClassPathJobGraphRetriever(
- TestJob.class.getCanonicalName(),
jobId,
savepointRestoreSettings,
- PROGRAM_ARGUMENTS);
+ PROGRAM_ARGUMENTS,
+ TestJob.class.getCanonicalName());
final JobGraph jobGraph =
classPathJobGraphRetriever.retrieveJobGraph(configuration);
assertThat(jobGraph.getSavepointRestoreSettings(),
is(equalTo(savepointRestoreSettings)));
assertEquals(jobGraph.getJobID(), jobId);
}
+
+ @Test
+ public void testJarFromClassPathSupplierSanityCheck() {
+ Iterable<File> jarFiles = JarsOnClassPath.INSTANCE.get();
+
+ // Junit executes this test, so it should be returned as part
of JARs on the class path
+ assertThat(jarFiles, hasItem(hasProperty("name",
containsString("junit"))));
+ }
+
+ @Test
+ public void testJarFromClassPathSupplier() throws IOException {
+ final File file1 = temporaryFolder.newFile();
+ final File file2 = temporaryFolder.newFile();
+ final File directory = temporaryFolder.newFolder();
+
+ // Mock java.class.path property. The empty strings are
important as the shell scripts
+ // that prepare the Flink class path often have such entries.
+ final String classPath = javaClassPath(
+ "",
+ "",
+ "",
+ file1.getAbsolutePath(),
+ "",
+ directory.getAbsolutePath(),
+ "",
+ file2.getAbsolutePath(),
+ "",
+ "");
+
+ Iterable<File> jarFiles =
setClassPathAndGetJarsOnClassPath(classPath);
+
+ assertThat(jarFiles, contains(file1, file2));
+ }
+
+ private static String javaClassPath(String... entries) {
+ String pathSeparator =
System.getProperty(JarsOnClassPath.PATH_SEPARATOR);
+
+ StringBuilder builder = new StringBuilder();
Review comment:
could be shortened to `return
Arrays.stream(entries).collect(Collectors.joining(pathSeparator))`;
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services