public void setAMResourceUsage(Resource resource) {
    amResourceUsageMB.set(resource.getMemorySize());
    amResourceUsageVCores.set(resource.getVirtualCores());
    if (customResources != null) {
      customResources.setAMResourceUsage(resource);
    }
  }
@Test
  public void testSetAMResourceUsage() {
    FSQueueMetrics metrics = setupMetrics(RESOURCE_NAME);

    Resource res = Resource.newInstance(2048L, 4, ImmutableMap.of(RESOURCE_NAME,
        20L));
    metrics.setAMResourceUsage(res);

    assertEquals(getErrorMessage("AMResourceUsageMB"),
        2048L, metrics.getAMResourceUsageMB());
    assertEquals(getErrorMessage("AMResourceUsageVcores"),
        4L, metrics.getAMResourceUsageVCores());

    Resource amResourceUsage = metrics.getAMResourceUsage();
    assertEquals(getErrorMessage("AMResourceUsageMB"),
        2048L, amResourceUsage.getMemorySize());
    assertEquals(getErrorMessage("AMResourceUsageVcores"),
        4L, amResourceUsage.getVirtualCores());
    assertEquals(getErrorMessage("AMResourceUsage for resource: " +
            RESOURCE_NAME),
        20L, amResourceUsage.getResourceValue(RESOURCE_NAME));

    res = Resource.newInstance(2049L, 5);
    metrics.setAMResourceUsage(res);

    assertEquals(getErrorMessage("AMResourceUsageMB"),
        2049L, metrics.getAMResourceUsageMB());
    assertEquals(getErrorMessage("AMResourceUsageVcores"),
        5L, metrics.getAMResourceUsageVCores());

    amResourceUsage = metrics.getAMResourceUsage();
    assertEquals(getErrorMessage("AMResourceUsageMB"),
        2049L, amResourceUsage.getMemorySize());
    assertEquals(getErrorMessage("AMResourceUsageVcores"),
        5L, amResourceUsage.getVirtualCores());
    assertEquals(getErrorMessage("AMResourceUsage for resource: " +
            RESOURCE_NAME),
        0, amResourceUsage.getResourceValue(RESOURCE_NAME));
  }