@Test
public void testDumpingSchedulerLogs() throws Exception {

  ResourceManager mockRM = mock(ResourceManager.class);
  Configuration conf = new YarnConfiguration();
  HttpServletRequest mockHsr = mockHttpServletRequestByUserName("non-admin");
  ApplicationACLsManager aclsManager = new ApplicationACLsManager(conf);
  when(mockRM.getApplicationACLsManager()).thenReturn(aclsManager);
  RMWebServices webSvc =
      new RMWebServices(mockRM, conf, mock(HttpServletResponse.class));
  // nothing should happen
  webSvc.dumpSchedulerLogs("1", mockHsr);
  waitforLogDump(50);
  checkSchedulerLogFileAndCleanup();
  conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
  conf.setStrings(YarnConfiguration.YARN_ADMIN_ACL, "admin");
  aclsManager = new ApplicationACLsManager(conf);
  when(mockRM.getApplicationACLsManager()).thenReturn(aclsManager);
  webSvc = new RMWebServices(mockRM, conf, mock(HttpServletResponse.class));
  boolean exceptionThrown = false;
  try {
    webSvc.dumpSchedulerLogs("1", mockHsr);
    fail("Dumping logs should fail");
  } catch (ForbiddenException ae) {
    exceptionThrown = true;
  }
  assertTrue("ForbiddenException expected", exceptionThrown);
  exceptionThrown = false;
  when(mockHsr.getUserPrincipal()).thenReturn(new Principal() {
    @Override
    public String getName() {
      return "testuser";
    }
  });
  try {
    webSvc.dumpSchedulerLogs("1", mockHsr);
    fail("Dumping logs should fail");
  } catch (ForbiddenException ae) {
    exceptionThrown = true;
  }
  assertTrue("ForbiddenException expected", exceptionThrown);
  when(mockHsr.getUserPrincipal()).thenReturn(new Principal() {
    @Override
    public String getName() {
      return "admin";
    }
  });
  webSvc.dumpSchedulerLogs("1", mockHsr);
  waitforLogDump(50);
  checkSchedulerLogFileAndCleanup();
}