tillrohrmann commented on a change in pull request #10532: [FLINK-15053][runtime] Escape all dynamical property values for taskmanager URL: https://github.com/apache/flink/pull/10532#discussion_r362501369
########## File path: flink-tests/src/test/java/org/apache/flink/test/runtime/TaskManagerLoadingDynamicPropertiesITCase.java ########## @@ -0,0 +1,131 @@ +/* + * 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.test.runtime; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.runtime.clusterframework.BootstrapTools; +import org.apache.flink.runtime.entrypoint.FlinkParseException; +import org.apache.flink.runtime.taskexecutor.TaskManagerRunner; +import org.apache.flink.runtime.testutils.CommonTestUtils; +import org.apache.flink.test.util.ShellScript; +import org.apache.flink.util.TestLogger; + +import org.hamcrest.Matchers; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.apache.flink.configuration.GlobalConfiguration.FLINK_CONF_FILENAME; +import static org.apache.flink.runtime.testutils.CommonTestUtils.getCurrentClasspath; +import static org.apache.flink.runtime.testutils.CommonTestUtils.getJavaCommandPath; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +/** + * Tests for passing and loading dynamical properties of task manager. + * Usually(in Yarn, Kubernetes), the taskmanager java start commands are wrapped within bash. This test will generate a + * launch_container.sh script to validate the dynamical properties passing and loading. + */ +public class TaskManagerLoadingDynamicPropertiesITCase extends TestLogger { + + private static final String KEY_A = "key.a"; + private static final String VALUE_A = "#a,b&c^d*e%f(g!h"; + private static final String KEY_B = "key.b"; + private static final String VALUE_B = "'foobar"; + private static final String KEY_C = "key.c"; + private static final String VALUE_C = "foo''bar"; + private static final String KEY_D = "key.d"; + private static final String VALUE_D = "'foo' 'bar'"; + + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void testLoadingDynamicPropertiesInBash() throws Exception { + final Configuration clientConfiguration = new Configuration(); + final File root = folder.getRoot(); + final File homeDir = new File(root, "home"); + assertTrue(homeDir.mkdir()); + BootstrapTools.writeConfiguration(clientConfiguration, new File(homeDir, FLINK_CONF_FILENAME)); + + final Configuration jmUpdatedConfiguration = getJobManagerUpdatedConfiguration(); + + final File shellScriptFile = generateLaunchContainerScript( + homeDir.getAbsolutePath(), + BootstrapTools.getDynamicPropertiesAsString(clientConfiguration, jmUpdatedConfiguration)); + + Process process = new ProcessBuilder(shellScriptFile.getAbsolutePath()).start(); + try { + final StringWriter processOutput = new StringWriter(); + new CommonTestUtils.PipeForwarder(process.getErrorStream(), processOutput); + + if (!process.waitFor(10, TimeUnit.SECONDS)) { + throw new Exception("TestingTaskManagerRunner did not shutdown in time."); + } + assertEquals(processOutput.toString(), 0, process.exitValue()); + } finally { + process.destroy(); + } + } + + private Configuration getJobManagerUpdatedConfiguration() { + final Configuration updatedConfig = new Configuration(); + updatedConfig.setString(KEY_A, VALUE_A); + updatedConfig.setString(KEY_B, VALUE_B); + updatedConfig.setString(KEY_C, VALUE_C); + updatedConfig.setString(KEY_D, VALUE_D); + return updatedConfig; + } + + private File generateLaunchContainerScript(String homeDir, String dynamicProperties) throws IOException { Review comment: nit: ```suggestion private File generateLaunchContainerScript(File homeDir, String dynamicProperties) throws IOException { ``` that way we express that `homeDir` is a local file/directory. ---------------------------------------------------------------- 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] With regards, Apache Git Services
