@Test
public void testAppAttemptMetrics() throws Exception {

  // Manipulate queue 'a'
  LeafQueue a = stubLeafQueue((LeafQueue) queues.get(B));
  // Users
  final String user_0 = "user_0";
  // Submit applications
  final ApplicationAttemptId appAttemptId_0 = TestUtils
      .getMockApplicationAttemptId(0, 1);
  AppAddedSchedulerEvent addAppEvent =
      new AppAddedSchedulerEvent(appAttemptId_0.getApplicationId(),
        a.getQueueName(), user_0);
  cs.handle(addAppEvent);
  AppAttemptAddedSchedulerEvent addAttemptEvent = 
      new AppAttemptAddedSchedulerEvent(appAttemptId_0, false);
  cs.handle(addAttemptEvent);
  AppAttemptRemovedSchedulerEvent event = new AppAttemptRemovedSchedulerEvent(
      appAttemptId_0, RMAppAttemptState.FAILED, false);
  cs.handle(event);
  
  assertEquals(0, a.getMetrics().getAppsPending());
  assertEquals(0, a.getMetrics().getAppsFailed());
  // Attempt the same application again
  final ApplicationAttemptId appAttemptId_1 = TestUtils
      .getMockApplicationAttemptId(0, 2);
  FiCaSchedulerApp app_1 = new FiCaSchedulerApp(appAttemptId_1, user_0, a, null,
      spyRMContext);
  a.submitApplicationAttempt(app_1, user_0); // same user
  assertEquals(1, a.getMetrics().getAppsSubmitted());
  assertEquals(1, a.getMetrics().getAppsPending());
  
  event = new AppAttemptRemovedSchedulerEvent(appAttemptId_0,
      RMAppAttemptState.FINISHED, false);
  cs.handle(event);
  AppRemovedSchedulerEvent rEvent = new AppRemovedSchedulerEvent(
      appAttemptId_0.getApplicationId(), RMAppState.FINISHED);
  cs.handle(rEvent);
  
  assertEquals(1, a.getMetrics().getAppsSubmitted());
  assertEquals(0, a.getMetrics().getAppsPending());
  assertEquals(0, a.getMetrics().getAppsFailed());
  assertEquals(1, a.getMetrics().getAppsCompleted());
  QueueMetrics userMetrics = a.getMetrics().getUserMetrics(user_0);
  assertEquals(1, userMetrics.getAppsSubmitted());
}