31
31
import org .apache .flink .configuration .CoreOptions ;
32
32
import org .apache .flink .configuration .PipelineOptions ;
33
33
import org .apache .flink .configuration .PipelineOptionsInternal ;
34
+ import org .apache .flink .runtime .execution .librarycache .FlinkUserCodeClassLoaders ;
34
35
import org .apache .flink .runtime .jobgraph .JobGraph ;
35
36
import org .apache .flink .runtime .jobgraph .SavepointRestoreSettings ;
37
+ import org .apache .flink .util .ChildFirstClassLoader ;
36
38
import org .apache .flink .util .ExceptionUtils ;
37
39
import org .apache .flink .util .FileUtils ;
38
40
import org .apache .flink .util .FlinkException ;
39
41
import org .apache .flink .util .TestLogger ;
40
42
import org .apache .flink .util .function .FunctionUtils ;
41
43
44
+ import org .hamcrest .core .IsInstanceOf ;
42
45
import org .junit .Assert ;
43
46
import org .junit .BeforeClass ;
44
47
import org .junit .ClassRule ;
65
68
import static org .hamcrest .Matchers .hasItem ;
66
69
import static org .hamcrest .Matchers .hasProperty ;
67
70
import static org .hamcrest .Matchers .is ;
71
+ import static org .hamcrest .Matchers .not ;
68
72
import static org .junit .Assert .assertEquals ;
69
73
import static org .junit .Assert .assertThat ;
70
74
import static org .junit .Assert .assertTrue ;
@@ -142,7 +146,7 @@ public void testJobGraphRetrieval()
142
146
configuration .set (PipelineOptionsInternal .PIPELINE_FIXED_JOB_ID , jobId .toHexString ());
143
147
144
148
final ClassPathPackagedProgramRetriever retrieverUnderTest =
145
- ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS )
149
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , new Configuration () )
146
150
.setJobClassName (TestJob .class .getCanonicalName ())
147
151
.build ();
148
152
@@ -161,7 +165,7 @@ public void testJobGraphRetrievalFromJar()
161
165
throws IOException , FlinkException , ProgramInvocationException {
162
166
final File testJar = TestJob .getTestJobJar ();
163
167
final ClassPathPackagedProgramRetriever retrieverUnderTest =
164
- ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS )
168
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , new Configuration () )
165
169
.setJarsOnClassPath (() -> Collections .singleton (testJar ))
166
170
.build ();
167
171
@@ -176,7 +180,7 @@ public void testJobGraphRetrievalJobClassNameHasPrecedenceOverClassPath()
176
180
final File testJar = new File ("non-existing" );
177
181
178
182
final ClassPathPackagedProgramRetriever retrieverUnderTest =
179
- ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS )
183
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , new Configuration () )
180
184
// Both a class name is specified and a JAR "is" on the class path
181
185
// The class name should have precedence.
182
186
.setJobClassName (TestJob .class .getCanonicalName ())
@@ -200,7 +204,7 @@ public void testSavepointRestoreSettings()
200
204
SavepointRestoreSettings .toConfiguration (savepointRestoreSettings , configuration );
201
205
202
206
final ClassPathPackagedProgramRetriever retrieverUnderTest =
203
- ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS )
207
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , new Configuration () )
204
208
.setJobClassName (TestJob .class .getCanonicalName ())
205
209
.build ();
206
210
@@ -249,7 +253,7 @@ public void testJobGraphRetrievalFailIfJobDirDoesNotHaveEntryClass()
249
253
throws IOException , ProgramInvocationException {
250
254
final File testJar = TestJob .getTestJobJar ();
251
255
final ClassPathPackagedProgramRetriever retrieverUnderTest =
252
- ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS )
256
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , new Configuration () )
253
257
.setJarsOnClassPath (() -> Collections .singleton (testJar ))
254
258
.setUserLibDirectory (userDirHasNotEntryClass )
255
259
.build ();
@@ -268,7 +272,7 @@ public void testJobGraphRetrievalFailIfJobDirDoesNotHaveEntryClass()
268
272
public void testJobGraphRetrievalFailIfDoesNotFindTheEntryClassInTheJobDir ()
269
273
throws IOException , ProgramInvocationException {
270
274
final ClassPathPackagedProgramRetriever retrieverUnderTest =
271
- ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS )
275
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , new Configuration () )
272
276
.setJobClassName (TestJobInfo .JOB_CLASS )
273
277
.setJarsOnClassPath (Collections ::emptyList )
274
278
.setUserLibDirectory (userDirHasNotEntryClass )
@@ -288,7 +292,7 @@ public void testJobGraphRetrievalFailIfDoesNotFindTheEntryClassInTheJobDir()
288
292
public void testRetrieveCorrectUserClasspathsWithoutSpecifiedEntryClass ()
289
293
throws IOException , FlinkException , ProgramInvocationException {
290
294
final ClassPathPackagedProgramRetriever retrieverUnderTest =
291
- ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS )
295
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , new Configuration () )
292
296
.setJarsOnClassPath (Collections ::emptyList )
293
297
.setUserLibDirectory (userDirHasEntryClass )
294
298
.build ();
@@ -303,7 +307,7 @@ public void testRetrieveCorrectUserClasspathsWithoutSpecifiedEntryClass()
303
307
public void testRetrieveCorrectUserClasspathsWithSpecifiedEntryClass ()
304
308
throws IOException , FlinkException , ProgramInvocationException {
305
309
final ClassPathPackagedProgramRetriever retrieverUnderTest =
306
- ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS )
310
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , new Configuration () )
307
311
.setJobClassName (TestJobInfo .JOB_CLASS )
308
312
.setJarsOnClassPath (Collections ::emptyList )
309
313
.setUserLibDirectory (userDirHasEntryClass )
@@ -320,7 +324,7 @@ public void testRetrieveFromJarFileWithoutUserLib()
320
324
throws IOException , FlinkException , ProgramInvocationException {
321
325
final File testJar = TestJob .getTestJobJar ();
322
326
final ClassPathPackagedProgramRetriever retrieverUnderTest =
323
- ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS )
327
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , new Configuration () )
324
328
.setJarFile (testJar )
325
329
.build ();
326
330
final JobGraph jobGraph = retrieveJobGraph (retrieverUnderTest , new Configuration ());
@@ -336,7 +340,7 @@ public void testRetrieveFromJarFileWithUserLib()
336
340
throws IOException , FlinkException , ProgramInvocationException {
337
341
final File testJar = TestJob .getTestJobJar ();
338
342
final ClassPathPackagedProgramRetriever retrieverUnderTest =
339
- ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS )
343
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , new Configuration () )
340
344
.setJarFile (testJar )
341
345
.setUserLibDirectory (userDirHasEntryClass )
342
346
.build ();
@@ -350,6 +354,50 @@ public void testRetrieveFromJarFileWithUserLib()
350
354
containsInAnyOrder (expectedURLs .stream ().map (URL ::toString ).toArray ()));
351
355
}
352
356
357
+ @ Test
358
+ public void testChildFirstDefaultConfiguration () throws FlinkException , IOException {
359
+ // this is a sanity check to backup testConfigurationIsConsidered
360
+ final Configuration configuration = new Configuration ();
361
+ // CHECK_LEAKED_CLASSLOADER has to be disabled to enable the instanceof check later on in
362
+ // this test. Otherwise, the actual instance would be hidden by a wrapper
363
+ configuration .set (CoreOptions .CHECK_LEAKED_CLASSLOADER , false );
364
+
365
+ final ClassPathPackagedProgramRetriever retriever =
366
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , configuration )
367
+ .setUserLibDirectory (userDirHasEntryClass )
368
+ .setJobClassName (TestJobInfo .JOB_CLASS )
369
+ .build ();
370
+
371
+ assertThat (
372
+ retriever .getPackagedProgram ().getUserCodeClassLoader (),
373
+ IsInstanceOf .instanceOf (ChildFirstClassLoader .class ));
374
+ }
375
+
376
+ @ Test
377
+ public void testConfigurationIsConsidered () throws FlinkException , IOException {
378
+ final String parentFirstConfigValue = "parent-first" ;
379
+ // we want to make sure that parent-first is not set as a default
380
+ assertThat (
381
+ CoreOptions .CLASSLOADER_RESOLVE_ORDER .defaultValue (),
382
+ not (is (parentFirstConfigValue )));
383
+
384
+ final Configuration configuration = new Configuration ();
385
+ configuration .set (CoreOptions .CLASSLOADER_RESOLVE_ORDER , parentFirstConfigValue );
386
+ // CHECK_LEAKED_CLASSLOADER has to be disabled to enable the instanceof check later on in
387
+ // this test. Otherwise, the actual instance would be hidden by a wrapper
388
+ configuration .set (CoreOptions .CHECK_LEAKED_CLASSLOADER , false );
389
+
390
+ final ClassPathPackagedProgramRetriever retriever =
391
+ ClassPathPackagedProgramRetriever .newBuilder (PROGRAM_ARGUMENTS , configuration )
392
+ .setUserLibDirectory (userDirHasEntryClass )
393
+ .setJobClassName (TestJobInfo .JOB_CLASS )
394
+ .build ();
395
+
396
+ assertThat (
397
+ retriever .getPackagedProgram ().getUserCodeClassLoader (),
398
+ IsInstanceOf .instanceOf (FlinkUserCodeClassLoaders .ParentFirstClassLoader .class ));
399
+ }
400
+
353
401
private JobGraph retrieveJobGraph (
354
402
ClassPathPackagedProgramRetriever retrieverUnderTest , Configuration configuration )
355
403
throws FlinkException , ProgramInvocationException , MalformedURLException {
0 commit comments