ResourceCalculator { public abstract Set<String> getInsufficientResourceNames(Resource required, Resource available);  abstract int compare(
      Resource clusterResource, Resource lhs, Resource rhs, boolean singleType); int compare(Resource clusterResource, Resource lhs, Resource rhs); static int divideAndCeil(int a, int b); static int divideAndCeil(int a, float b); static long divideAndCeil(long a, long b); static long divideAndCeil(long a, float b); static float divideSafelyAsFloat(long lhs, long rhs); static int roundUp(int a, int b); static long roundUp(long a, long b); static long roundDown(long a, long b); static int roundDown(int a, int b); abstract long computeAvailableContainers(
      Resource available, Resource required); abstract Resource multiplyAndNormalizeUp(
      Resource r, double by, Resource stepFactor); abstract Resource multiplyAndNormalizeUp(
      Resource r, double[] by, Resource stepFactor); abstract Resource multiplyAndNormalizeDown(
      Resource r, double by, Resource stepFactor); abstract Resource normalize(Resource r, Resource minimumResource,
      Resource maximumResource, Resource stepFactor); abstract Resource roundUp(Resource r, Resource stepFactor); abstract Resource roundDown(Resource r, Resource stepFactor); abstract float divide(
      Resource clusterResource, Resource numerator, Resource denominator); abstract boolean isInvalidDivisor(Resource r); abstract float ratio(Resource a, Resource b); abstract Resource divideAndCeil(Resource numerator, int denominator); abstract Resource divideAndCeil(Resource numerator, float denominator); abstract boolean fitsIn(Resource smaller, Resource bigger); abstract boolean isAnyMajorResourceZeroOrNegative(Resource resource); abstract Resource normalizeDown(Resource r, Resource stepFactor); abstract boolean isAnyMajorResourceAboveZero(Resource resource); abstract Set<String> getInsufficientResourceNames(Resource required,
      Resource available);  }
@Test public void testFitsInDiagnosticsCollector() { if (resourceCalculator instanceof DefaultResourceCalculator) { assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 0), newResource(0, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 0), newResource(0, 1))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 0), newResource(1, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 0), newResource(1, 1))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 1), newResource(0, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 1), newResource(0, 1))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 1), newResource(1, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 1), newResource(1, 1))); assertEquals(ImmutableSet.of(ResourceInformation.MEMORY_URI), resourceCalculator.getInsufficientResourceNames(newResource(1, 0), newResource(0, 0))); assertEquals(ImmutableSet.of(ResourceInformation.MEMORY_URI), resourceCalculator.getInsufficientResourceNames(newResource(1, 0), newResource(0, 1))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(1, 0), newResource(1, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(1, 0), newResource(1, 1))); assertEquals(ImmutableSet.of(ResourceInformation.MEMORY_URI), resourceCalculator.getInsufficientResourceNames(newResource(1, 1), newResource(0, 0))); assertEquals(ImmutableSet.of(ResourceInformation.MEMORY_URI), resourceCalculator.getInsufficientResourceNames(newResource(1, 1), newResource(0, 1))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(1, 1), newResource(1, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(1, 1), newResource(1, 1))); } else if (resourceCalculator instanceof DominantResourceCalculator) { assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 0), newResource(0, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 0), newResource(0, 1))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 0), newResource(1, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 0), newResource(1, 1))); assertEquals(ImmutableSet.of(ResourceInformation.VCORES_URI), resourceCalculator.getInsufficientResourceNames(newResource(0, 1), newResource(0, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 1), newResource(0, 1))); assertEquals(ImmutableSet.of(ResourceInformation.VCORES_URI), resourceCalculator.getInsufficientResourceNames(newResource(0, 1), newResource(1, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(0, 1), newResource(1, 1))); assertEquals(ImmutableSet.of(ResourceInformation.MEMORY_URI), resourceCalculator.getInsufficientResourceNames(newResource(1, 0), newResource(0, 0))); assertEquals(ImmutableSet.of(ResourceInformation.MEMORY_URI), resourceCalculator.getInsufficientResourceNames(newResource(1, 0), newResource(0, 1))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(1, 0), newResource(1, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(1, 0), newResource(1, 1))); assertEquals(ImmutableSet.of(ResourceInformation.MEMORY_URI, ResourceInformation.VCORES_URI), resourceCalculator .getInsufficientResourceNames(newResource(1, 1), newResource(0, 0))); assertEquals(ImmutableSet.of(ResourceInformation.MEMORY_URI), resourceCalculator.getInsufficientResourceNames(newResource(1, 1), newResource(0, 1))); assertEquals(ImmutableSet.of(ResourceInformation.VCORES_URI), resourceCalculator.getInsufficientResourceNames(newResource(1, 1), newResource(1, 0))); assertEquals(ImmutableSet.of(), resourceCalculator.getInsufficientResourceNames(newResource(1, 1), newResource(1, 1))); } }