public boolean canRunAppAM(Resource amResource) {
    if (Math.abs(maxAMShare - -1.0f) < 0.0001) {
      return true;
    }

    Resource maxAMResource = computeMaxAMResource();
    getMetrics().setMaxAMShare(maxAMResource);
    Resource ifRunAMResource = Resources.add(amResourceUsage, amResource);
    return Resources.fitsIn(ifRunAMResource, maxAMResource);
  }
@Test
  public void testCanRunAppAMReturnsFalse() {
    conf.set(YarnConfiguration.RESOURCE_TYPES, CUSTOM_RESOURCE);
    ResourceUtils.resetResourceTypes(conf);

    resourceManager = new MockRM(conf);
    resourceManager.start();
    scheduler = (FairScheduler) resourceManager.getResourceScheduler();

    Resource maxShare = Resource.newInstance(1024 * 8, 4,
        ImmutableMap.of(CUSTOM_RESOURCE, 10L));

    // Add a node to increase available memory and vcores in scheduler's
    // root queue metrics
    addNodeToScheduler(Resource.newInstance(4096, 10,
        ImmutableMap.of(CUSTOM_RESOURCE, 25L)));

    FSLeafQueue queue = setupQueue(maxShare);

    //Min(availableMemory, maxShareMemory (maxResourceOverridden))
    // --> Min(4096, 8192) = 4096
    //Min(availableVCores, maxShareVCores (maxResourceOverridden))
    // --> Min(10, 4) = 4
    //Min(available test1, maxShare test1 (maxResourceOverridden))
    // --> Min(25, 10) = 10
    //MaxAMResource: (4096 MB memory, 4 vcores, 10 test1) * MAX_AM_SHARE
    // --> 2048 MB memory, 2 vcores, 5 test1
    Resource expectedAMShare = Resource.newInstance(2048, 2,
        ImmutableMap.of(CUSTOM_RESOURCE, 5L));

    Resource appAMResource = Resource.newInstance(2048, 2,
        ImmutableMap.of(CUSTOM_RESOURCE, 6L));

    Map<String, Long> customResourceValues =
        verifyQueueMetricsForCustomResources(queue);

    boolean result = queue.canRunAppAM(appAMResource);
    assertFalse("AM should not have been allocated!", result);

    verifyAMShare(queue, expectedAMShare, customResourceValues);
  }