### Question:
MRAppMaster extends CompositeService { protected static void initAndStartAppMaster(final MRAppMaster appMaster, final JobConf conf, String jobUserName) throws IOException, InterruptedException { UserGroupInformation.setConfiguration(conf); Credentials credentials = UserGroupInformation.getCurrentUser().getCredentials(); UserGroupInformation appMasterUgi = UserGroupInformation .createRemoteUser(jobUserName); appMasterUgi.addCredentials(credentials); conf.getCredentials().addAll(credentials); appMasterUgi.doAs(new PrivilegedExceptionAction<Object>() { @Override public Object run() throws Exception { appMaster.init(conf); appMaster.start(); return null; } }); } MRAppMaster(ApplicationAttemptId applicationAttemptId,
      ContainerId containerId, String nmHost, int nmPort, int nmHttpPort,
      long appSubmitTime);  MRAppMaster(ApplicationAttemptId applicationAttemptId,
      ContainerId containerId, String nmHost, int nmPort, int nmHttpPort,
      Clock clock, long appSubmitTime); @Override void init(final Configuration conf); void cleanupStagingDir(); @VisibleForTesting void shutDownJob(); ApplicationId getAppID(); ApplicationAttemptId getAttemptID(); JobId getJobId(); OutputCommitter getCommitter(); boolean isNewApiCommitter(); int getStartCount(); AppContext getContext(); Dispatcher getDispatcher(); Map<TaskId, TaskInfo> getCompletedTaskFromPreviousRun(); List<AMInfo> getAllAMInfos(); ContainerAllocator getContainerAllocator(); ContainerLauncher getContainerLauncher(); TaskAttemptListener getTaskAttemptListener(); @SuppressWarnings("unchecked") @Override void start(); static void main(String[] args); static final int SHUTDOWN_HOOK_PRIORITY; }### Answer:
@Test public void testMRAppMasterForDifferentUser() throws IOException, InterruptedException { String applicationAttemptIdStr = "appattempt_1317529182569_0004_000001"; String containerIdStr = "container_1317529182569_0004_000001_1"; String stagingDir = "/tmp/staging"; String userName = "TestAppMasterUser"; ApplicationAttemptId applicationAttemptId = ConverterUtils .toApplicationAttemptId(applicationAttemptIdStr); ContainerId containerId = ConverterUtils.toContainerId(containerIdStr); MRAppMasterTest appMaster = new MRAppMasterTest(applicationAttemptId, containerId, "host", -1, -1, System.currentTimeMillis()); JobConf conf = new JobConf(new YarnConfiguration()); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); MRAppMaster.initAndStartAppMaster(appMaster, conf, userName); Assert.assertEquals(stagingDir + Path.SEPARATOR + userName + Path.SEPARATOR + ".staging", appMaster.stagingDirPath.toString()); }