zuston commented on a change in pull request #18220: URL: https://github.com/apache/flink/pull/18220#discussion_r779451594
########## File path: flink-yarn/src/test/java/org/apache/flink/yarn/YarnClusterClientProviderTest.java ########## @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.yarn; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.configuration.JobManagerOptions; +import org.apache.flink.configuration.RestOptions; +import org.apache.flink.yarn.configuration.YarnConfigOptions; + +import org.apache.commons.beanutils.ConvertUtils; +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ApplicationReport; +import org.apache.hadoop.yarn.api.records.YarnApplicationState; +import org.apache.hadoop.yarn.util.Records; +import org.junit.Test; + +import static org.apache.hadoop.yarn.api.records.FinalApplicationStatus.UNDEFINED; +import static org.junit.Assert.assertEquals; + +/** Test for {@link YarnClusterClientProvider}. */ +public class YarnClusterClientProviderTest { Review comment: Got it. ########## File path: flink-yarn/src/test/java/org/apache/flink/yarn/YarnClusterClientProviderTest.java ########## @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.yarn; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.configuration.JobManagerOptions; +import org.apache.flink.configuration.RestOptions; +import org.apache.flink.yarn.configuration.YarnConfigOptions; + +import org.apache.commons.beanutils.ConvertUtils; +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ApplicationReport; +import org.apache.hadoop.yarn.api.records.YarnApplicationState; +import org.apache.hadoop.yarn.util.Records; +import org.junit.Test; + +import static org.apache.hadoop.yarn.api.records.FinalApplicationStatus.UNDEFINED; +import static org.junit.Assert.assertEquals; + +/** Test for {@link YarnClusterClientProvider}. */ +public class YarnClusterClientProviderTest { + + /** Once Yarn app master has been running, it should not retrieve app report again. */ + @Test + public void testNoLongerRetrieveAppReportOnceAppRunning() { + final Configuration flinkConf = new Configuration(); + final ApplicationId applicationId = + ApplicationId.newInstance(System.currentTimeMillis(), 1); + + final ApplicationReportProvider mockAppReportProvider = + MockApplicationReportProvider.of(applicationId, "localhost", 10); + assertEquals(0, ((MockApplicationReportProvider) mockAppReportProvider).getInvokeNumber()); + + YarnClusterClientProvider provider = + YarnClusterClientProvider.of(mockAppReportProvider, flinkConf, applicationId); + + provider.getClusterClient(); + assertEquals(1, ((MockApplicationReportProvider) mockAppReportProvider).getInvokeNumber()); + + provider.getClusterClient(); + assertEquals(1, ((MockApplicationReportProvider) mockAppReportProvider).getInvokeNumber()); + } + + @Test + public void testJMHostShouldSetIntoConfig() { + final Configuration flinkConf = new Configuration(); + final ApplicationId applicationId = + ApplicationId.newInstance(System.currentTimeMillis(), 1); + final String host = "localhost"; + final int rpcPort = 10000; + final ApplicationReportProvider mockAppReportProvider = + MockApplicationReportProvider.of(applicationId, host, rpcPort); + + YarnClusterClientProvider.of(mockAppReportProvider, flinkConf, applicationId) + .getClusterClient(); + + assertEquals(flinkConf.get(JobManagerOptions.ADDRESS), host); + assertEquals(flinkConf.getInteger(JobManagerOptions.PORT), rpcPort); + assertEquals(flinkConf.get(RestOptions.ADDRESS), host); + assertEquals(flinkConf.getInteger(RestOptions.PORT), rpcPort); + assertEquals( + flinkConf.get(YarnConfigOptions.APPLICATION_ID), + ConvertUtils.convert(applicationId)); + } + + private static class MockApplicationReportProvider implements ApplicationReportProvider { + int invokeNumber = 0; + ApplicationId applicationId; + String host; + int rpcHost; Review comment: Got it. ########## File path: flink-yarn/src/test/java/org/apache/flink/yarn/ApplicationReportProviderImplTest.java ########## @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.yarn; + +import org.apache.hadoop.service.Service; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ApplicationReport; +import org.apache.hadoop.yarn.api.records.FinalApplicationStatus; +import org.apache.hadoop.yarn.api.records.YarnApplicationState; +import org.apache.hadoop.yarn.client.api.YarnClient; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.junit.Test; Review comment: Got it. ########## File path: flink-yarn/src/test/java/org/apache/flink/yarn/ApplicationReportProviderImplTest.java ########## @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.yarn; + +import org.apache.hadoop.service.Service; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ApplicationReport; +import org.apache.hadoop.yarn.api.records.FinalApplicationStatus; +import org.apache.hadoop.yarn.api.records.YarnApplicationState; +import org.apache.hadoop.yarn.client.api.YarnClient; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.junit.Test; + +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** Tests for the {@link ApplicationReportProviderImpl}. */ +public class ApplicationReportProviderImplTest extends AbstractYarnClusterTest { Review comment: Got it. ########## File path: flink-yarn/src/test/java/org/apache/flink/yarn/ApplicationReportProviderImplTest.java ########## @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.yarn; + +import org.apache.hadoop.service.Service; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ApplicationReport; +import org.apache.hadoop.yarn.api.records.FinalApplicationStatus; +import org.apache.hadoop.yarn.api.records.YarnApplicationState; +import org.apache.hadoop.yarn.client.api.YarnClient; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.junit.Test; + +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** Tests for the {@link ApplicationReportProviderImpl}. */ +public class ApplicationReportProviderImplTest extends AbstractYarnClusterTest { + + /** + * When yarnClient has been stopped and then retrieving app report from Yarn, it should fail + * fast and throw exception. + */ + @Test + public void testWhenYarnClientStoppedShouldThrowException() { + final YarnClient yarnClient = YarnClient.createYarnClient(); + initilizeYarnClient(yarnClient); + yarnClient.stop(); + assertTrue(yarnClient.isInState(Service.STATE.STOPPED)); + + try { + ApplicationReportProviderImpl.of(yarnClient, null).waitTillSubmissionFinish(); + fail(); + } catch (Exception e) { + assertEquals( + "Errors on using YarnClient to retrieve application report. Maybe it has been closed by YarnClusterDescriptor.", + e.getMessage()); + } Review comment: Got it. -- 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. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org