@Test
public void testAllocationLatencyMetrics() throws Exception {

  oppCntxt = spy(oppCntxt);
  OpportunisticSchedulerMetrics metrics =
      mock(OpportunisticSchedulerMetrics.class);
  when(oppCntxt.getOppSchedulerMetrics()).thenReturn(metrics);
  ResourceBlacklistRequest blacklistRequest =
      ResourceBlacklistRequest.newInstance(
          Collections.emptyList(), Collections.emptyList());
  List<ResourceRequest> reqs = Arrays.asList(
      ResourceRequest.newInstance(PRIORITY_NORMAL, "*", CAPABILITY_1GB, 2,
          true, null, OPPORTUNISTIC_REQ),
      ResourceRequest.newInstance(PRIORITY_NORMAL, "h6", CAPABILITY_1GB, 2,
          true, null, OPPORTUNISTIC_REQ),
      ResourceRequest.newInstance(PRIORITY_NORMAL, "/r3", CAPABILITY_1GB, 2,
          true, null, OPPORTUNISTIC_REQ));
  ApplicationAttemptId appAttId = ApplicationAttemptId.newInstance(
      ApplicationId.newInstance(0L, 1), 1);
  oppCntxt.updateNodeList(
      Arrays.asList(
          RemoteNode.newInstance(
              NodeId.newInstance("h3", 1234), "h3:1234", "/r2"),
          RemoteNode.newInstance(
              NodeId.newInstance("h2", 1234), "h2:1234", "/r1"),
          RemoteNode.newInstance(
              NodeId.newInstance("h5", 1234), "h5:1234", "/r1"),
          RemoteNode.newInstance(
              NodeId.newInstance("h4", 1234), "h4:1234", "/r2")));
  List<Container> containers = allocator.allocateContainers(
      blacklistRequest, reqs, appAttId, oppCntxt, 1L, "luser");
  LOG.info("Containers: {}", containers);
  Assert.assertEquals(2, containers.size());
  // for each allocated container, latency should be added.
  verify(metrics, times(2)).addAllocateOLatencyEntry(anyLong());
}