Apps { public static void setEnvFromInputProperty(Map<String, String> env, String propName, String defaultPropValue, Configuration conf, String classPathSeparator) { String envString = conf.get(propName, defaultPropValue); Map<String, String> tmpEnv = new HashMap<String, String>(); Apps.setEnvFromInputStringNoExpand(tmpEnv, envString, classPathSeparator); Map<String, String> inputMap = conf.getPropsWithPrefix(propName + "."); tmpEnv.putAll(inputMap); setEnvFromInputStringMap(env, tmpEnv, classPathSeparator); }  static ApplicationId toAppID(String aid); static ApplicationId toAppID(String prefix, String s, Iterator<String> it); static void shouldHaveNext(String prefix, String s, Iterator<String> it); static void throwParseException(String name, String s); static void setEnvFromInputString(Map<String, String> env,
      String envString,  String classPathSeparator); static void setEnvFromInputProperty(Map<String, String> env,
      String propName, String defaultPropValue, Configuration conf,
      String classPathSeparator); static Set<String> getEnvVarsFromInputProperty(
      String propName, String defaultPropValue, Configuration conf); @Deprecated static void setEnvFromInputString(Map<String, String> env,
      String envString); @Public @Unstable static void addToEnvironment(
      Map<String, String> environment,
      String variable, String value, String classPathSeparator); @Deprecated static void addToEnvironment(
      Map<String, String> environment,
      String variable, String value); static String crossPlatformify(String var); @Private @Unstable static boolean shouldCountTowardsNodeBlacklisting(int exitStatus); static final String APP; static final String ID; }
@Test public void testSetEnvFromInputProperty() { Configuration conf = new Configuration(false); Map<String, String> env = new HashMap<>(); String propName = "mapreduce.map.env"; String defaultPropName = "mapreduce.child.env"; conf.set(propName, "env1=env1_val,env2=env2_val,env3=env3_val"); conf.set(propName + ".env4", "env4_val"); conf.set(propName + ".env2", "new_env2_val"); conf.set(defaultPropName, "env1=def1_val,env2=def2_val,env3=def3_val"); String defaultPropValue = conf.get(defaultPropName); conf.set(defaultPropName + ".env4", "def4_val"); conf.set(defaultPropName + ".env2", "new_def2_val"); Apps.setEnvFromInputProperty(env, propName, defaultPropValue, conf, File.pathSeparator); assertEquals("env1_val", env.get("env1")); assertEquals("env3_val", env.get("env3")); assertEquals("env4_val", env.get("env4")); assertEquals("new_env2_val", env.get("env2")); }
@Test public void testSetEnvFromInputPropertyDefault() { Configuration conf = new Configuration(false); Map<String, String> env = new HashMap<>(); String propName = "mapreduce.map.env"; String defaultPropName = "mapreduce.child.env"; conf.set(propName, "env1=env1_val,env2=env2_val,env3=env3_val"); conf.set(propName + ".env4", "env4_val"); conf.set(propName + ".env2", "new_env2_val"); conf.set(defaultPropName, "env1=def1_val,env2=def2_val,env3=def3_val"); String defaultPropValue = conf.get(defaultPropName); conf.set(defaultPropName + ".env4", "def4_val"); conf.set(defaultPropName + ".env2", "new_def2_val"); String bogusProp = propName + "bogus"; Apps.setEnvFromInputProperty(env, bogusProp, defaultPropValue, conf, File.pathSeparator); assertEquals("def1_val", env.get("env1")); assertEquals("def2_val", env.get("env2")); assertEquals("def3_val", env.get("env3")); assertNull(env.get("env4")); }
@Test public void testSetEnvFromInputPropertyOverrideDefault() { Configuration conf = new Configuration(false); Map<String, String> env = new HashMap<>(); String propName = "mapreduce.reduce.env"; conf.set(propName + ".env2", "new2_val"); conf.set(propName + ".env4", "new4_val"); String defaultPropName = "mapreduce.child.env"; conf.set(defaultPropName, "env1=def1_val,env2=def2_val,env3=def3_val"); String defaultPropValue = conf.get(defaultPropName); conf.set(defaultPropName + ".env4", "def4_val"); conf.set(defaultPropName + ".env2", "new_def2_val"); Apps.setEnvFromInputProperty(env, propName, defaultPropValue, conf, File.pathSeparator); assertEquals("def1_val", env.get("env1")); assertEquals("def3_val", env.get("env3")); assertEquals("new4_val", env.get("env4")); assertEquals("new2_val", env.get("env2")); }
@Test public void testSetEnvFromInputPropertyCommas() { Configuration conf = new Configuration(false); Map<String, String> env = new HashMap<>(); String propName = "mapreduce.reduce.env"; conf.set(propName, "env1=env1_val,env2=env2_val,env3=env3_val"); conf.set(propName + ".env2", "new2_val1,new2_val2,new2_val3"); conf.set(propName + ".env4", "new4_valwith=equals"); String defaultPropName = "mapreduce.child.env"; conf.set(defaultPropName, "env1=def1_val,env2=def2_val,env3=def3_val"); String defaultPropValue = conf.get(defaultPropName); Apps.setEnvFromInputProperty(env, propName, defaultPropValue, conf, File.pathSeparator); assertEquals("env1_val", env.get("env1")); assertEquals("env3_val", env.get("env3")); assertEquals("new4_valwith=equals", env.get("env4")); assertEquals("new2_val1,new2_val2,new2_val3", env.get("env2")); }
@Test public void testSetEnvFromInputPropertyNull() { Configuration conf = new Configuration(false); Map<String, String> env = new HashMap<>(); String propName = "mapreduce.map.env"; String defaultPropName = "mapreduce.child.env"; conf.set(propName, "env1=env1_val,env2=env2_val,env3=env3_val"); conf.set(propName + ".env4", "env4_val"); conf.set(propName + ".env2", "new_env2_val"); conf.set(defaultPropName, "env1=def1_val,env2=def2_val,env3=def3_val"); String defaultPropValue = conf.get(defaultPropName); conf.set(defaultPropName + ".env4", "def4_val"); conf.set(defaultPropName + ".env2", "new_def2_val"); Apps.setEnvFromInputProperty(env, "bogus1", null, conf, File.pathSeparator); assertTrue(env.isEmpty()); }