@Test
public void testAppPercentages() throws Exception {

  FifoScheduler scheduler = mock(FifoScheduler.class);
  when(scheduler.getClusterResource())
      .thenReturn(Resource.newInstance(10 * 1024, 10));
  when(scheduler.getResourceCalculator())
      .thenReturn(new DefaultResourceCalculator());
  ApplicationAttemptId appAttId = createAppAttemptId(0, 0);
  RMContext rmContext = mock(RMContext.class);
  when(rmContext.getEpoch()).thenReturn(3L);
  when(rmContext.getScheduler()).thenReturn(scheduler);
  when(rmContext.getYarnConfiguration()).thenReturn(conf);
  final String user = "user1";
  Queue queue = createQueue("test", null);
  SchedulerApplicationAttempt app =
      new SchedulerApplicationAttempt(appAttId, user, queue,
          queue.getAbstractUsersManager(), rmContext);
  // Resource request
  Resource requestedResource = Resource.newInstance(1536, 2);
  app.attemptResourceUsage.incUsed(requestedResource);
  assertEquals(15.0f, app.getResourceUsageReport().getQueueUsagePercentage(),
      0.01f);
  assertEquals(15.0f,
      app.getResourceUsageReport().getClusterUsagePercentage(), 0.01f);
  queue = createQueue("test2", null, 0.5f);
  app = new SchedulerApplicationAttempt(appAttId, user, queue,
      queue.getAbstractUsersManager(), rmContext);
  app.attemptResourceUsage.incUsed(requestedResource);
  assertEquals(30.0f, app.getResourceUsageReport().getQueueUsagePercentage(),
      0.01f);
  assertEquals(15.0f,
      app.getResourceUsageReport().getClusterUsagePercentage(), 0.01f);
  app.attemptResourceUsage.incUsed(requestedResource);
  app.attemptResourceUsage.incUsed(requestedResource);
  app.attemptResourceUsage.incUsed(requestedResource);
  assertEquals(120.0f, app.getResourceUsageReport().getQueueUsagePercentage(),
      0.01f);
  assertEquals(60.0f,
      app.getResourceUsageReport().getClusterUsagePercentage(), 0.01f);
  queue = createQueue("test3", null, Float.MIN_VALUE);
  app = new SchedulerApplicationAttempt(appAttId, user, queue,
      queue.getAbstractUsersManager(), rmContext);
  // Resource request
  app.attemptResourceUsage.incUsed(requestedResource);
  assertEquals(0.0f, app.getResourceUsageReport().getQueueUsagePercentage(),
      0.01f);
  assertEquals(15.0f,
      app.getResourceUsageReport().getClusterUsagePercentage(), 0.01f);
}