kl0u edited a comment on pull request #13024:
URL: https://github.com/apache/flink/pull/13024#issuecomment-677730660


   @wangzzu In your testing code you seem to "replicate" the code of the 
`CliFrontend.run()` method. This is pretty fragile because if someone changes 
the order of the calls in the run, the test will still pass. Can't you follow a 
similar pattern as in the `CliFrontendRunTest` where you override the 
`executeProgram(Configuration configuration, PackagedProgram program)` (see 
`RunTestingCliFrontend` at the bottom of the class)?
   
   This will also allow to avoid make methods visible just for testing. 
   
   For example, you can have a class:
   
   ```
   private static final class TestingCliFrontend extends CliFrontend {
   
                private TestingCliFrontend(
                                ClusterClientServiceLoader 
clusterClientServiceLoader,
                                CustomCommandLine cli,
                                Configuration configuration) {
                        super(
                                        configuration,
                                        clusterClientServiceLoader,
                                        Collections.singletonList(cli));
                }
   
                @Override
                protected void executeProgram(Configuration configuration, 
PackagedProgram program) {
                        Assert.assertEquals(TEST_JAR_MAIN_CLASS, 
program.getMainClassName());
                        
Assert.assertEquals(ParentFirstClassLoader.class.getName(),
                                        
program.getUserCodeClassLoader().getClass().getName());
                }
        }
   ``` 
   
   and the test becomes:
   
   ```
   @Test
        public void testDynamicPropertiesWithParentFirstClassloader() throws 
Exception {
   
                String[] args = {
                        "-e", "test-executor",
                        "-D" + CoreOptions.DEFAULT_PARALLELISM.key() + "=5",
                        "-D" + "classloader.resolve-order=parent-first",
                        getTestJarPath(), "-a", "--debug", "true", "arg1", 
"arg2"
                };
   
                frontend.run(args);
   }
   ```
   
   and of course to accommodate all the tests you have to pass as parameters to 
the test cli the expected values.


----------------------------------------------------------------
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:
[email protected]


Reply via email to