@Test (timeout = 180000)
public void testStoreOnlyAMContainerMetrics() throws Exception {

  Configuration conf = new Configuration();
  conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
  conf.setBoolean(
      YarnConfiguration.APPLICATION_HISTORY_SAVE_NON_AM_CONTAINER_META_INFO,
      false);
  MockRM rm1 = new MockRM(conf);
  SystemMetricsPublisher publisher = mock(SystemMetricsPublisher.class);
  rm1.getRMContext().setSystemMetricsPublisher(publisher);
  rm1.start();
  MockNM nm1 = rm1.registerNode("unknownhost:1234", 8000);
  RMApp app1 = rm1.submitApp(1024);
  MockAM am1 = MockRM.launchAndRegisterAM(app1, rm1, nm1);
  nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 1, ContainerState.RUNNING);
  // request a container.
  am1.allocate("127.0.0.1", 1024, 1, new ArrayList<ContainerId>());
  ContainerId containerId2 = ContainerId.newContainerId(
      am1.getApplicationAttemptId(), 2);
  rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED);
  am1.allocate(new ArrayList<ResourceRequest>(), new ArrayList<ContainerId>())
      .getAllocatedContainers();
  rm1.waitForState(nm1, containerId2, RMContainerState.ACQUIRED);
  nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 2, ContainerState.RUNNING);
  nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 2, ContainerState.COMPLETE);
  nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
  rm1.waitForState(nm1, containerId2, RMContainerState.COMPLETED);
  rm1.stop();
  // RMContainer should be publishing system metrics only for AM container.
  verify(publisher, times(1)).containerCreated(any(RMContainer.class), anyLong());
  verify(publisher, times(1)).containerFinished(any(RMContainer.class), anyLong());
}