@VisibleForTesting
  protected Map<String, String> addAMEnv() throws IOException {
    Map<String, String> env = new HashMap<>();
    ClasspathConstructor classpath = buildClasspath(
        YarnServiceConstants.SUBMITTED_CONF_DIR,
        "lib",
        fs,
        getConfig().get(YarnServiceConf.YARN_SERVICE_CLASSPATH, ""),
        getConfig().getBoolean(YarnConfiguration.IS_MINI_YARN_CLUSTER, false));
    env.put("CLASSPATH", classpath.buildClasspath());
    env.put("LANG", "en_US.UTF-8");
    env.put("LC_ALL", "en_US.UTF-8");
    env.put("LANGUAGE", "en_US.UTF-8");
    String jaas = System.getenv("HADOOP_JAAS_DEBUG");
    if (jaas != null) {
      env.put("HADOOP_JAAS_DEBUG", jaas);
    }
    if (!UserGroupInformation.isSecurityEnabled()) {
      String userName = UserGroupInformation.getCurrentUser().getUserName();
      LOG.debug("Run as user {}", userName);
      // HADOOP_USER_NAME env is used by UserGroupInformation when log in
      // This env makes AM run as this user
      env.put("HADOOP_USER_NAME", userName);
    }
    LOG.debug("AM env: \n{}", stringifyMap(env));
    return env;
  }
@Test
  public void testAMEnvCustomClasspath() throws Exception {
    Service service = createService();
    service.getComponents().forEach(comp ->
            comp.setRestartPolicy(Component.RestartPolicyEnum.NEVER));
    ServiceClient client = MockServiceClient.create(rule, service, true);
    //saving the original value of the param, for restoration purposes
    String oldParam = client.getConfig().get("yarn.service.classpath", "");
    String originalPath = client.addAMEnv().get("CLASSPATH");

    client.getConfig().set("yarn.service.classpath", "{{VAR_1}},{{VAR_2}}");
    String newPath = client.addAMEnv().get("CLASSPATH");

    Assert.assertEquals(originalPath + "<CPS>{{VAR_1}}<CPS>{{VAR_2}}", newPath);
    //restoring the original value for service classpath
    client.getConfig().set("yarn.service.classpath", oldParam);

    newPath = client.addAMEnv().get("CLASSPATH");
    Assert.assertEquals(originalPath, newPath);

    client.stop();
  }