@Test
  public void hardwareUsageTest() throws Exception {
    String hardwareThresholdsString =
        new JSONObject().put("HEAP_MEMORY", new JSONObject().put("threshold", 30).put("boundType", "UpperBound"))
            .put("DIRECT_MEMORY", new JSONObject().put("threshold", 30).put("boundType", "UpperBound"))
            .put("CPU", new JSONObject().put("threshold", 30).put("boundType", "UpperBound"))
            .toString();

    List<int[]> usages = new ArrayList<>();
    List<Boolean> expectedResult = new ArrayList<>();
    usages.add(new int[]{10, 10, 10});
    expectedResult.add(false);
    usages.add(new int[]{30, 30, 30});
    expectedResult.add(false);
    usages.add(new int[]{31, 31, 31});
    expectedResult.add(true);
    usages.add(new int[]{10, 31, 10});
    expectedResult.add(true);
    usages.add(new int[]{31, 10, 10});
    expectedResult.add(true);
    usages.add(new int[]{10, 10, 31});
    expectedResult.add(true);

    for (int i = 0; i < usages.size(); i++) {
      Map<HardwareResource, Criteria> hardwareThresholdMap =
          HostLevelThrottler.getHardwareThresholdMap(hardwareThresholdsString);
      HardwareUsageMeter mockHardwareUsageMeter = Mockito.mock(HardwareUsageMeter.class);
      HostLevelThrottler throttler =
          new HostLevelThrottler(new HashMap<>(), hardwareThresholdMap, mockHardwareUsageMeter);
      Mockito.when(mockHardwareUsageMeter.getHardwareResourcePercentage(HardwareResource.CPU))
          .thenReturn(usages.get(i)[0]);
      Mockito.when(mockHardwareUsageMeter.getHardwareResourcePercentage(HardwareResource.HEAP_MEMORY))
          .thenReturn(usages.get(i)[1]);
      Mockito.when(mockHardwareUsageMeter.getHardwareResourcePercentage(HardwareResource.DIRECT_MEMORY))
          .thenReturn(usages.get(i)[2]);
      Assert.assertEquals("Incorrect result", expectedResult.get(i),
          throttler.shouldThrottle(createRestRequest(RestMethod.GET, "https://linkedin.com")));
    }
  }
Test to make sure {@link HostLevelThrottler#shouldThrottle(RestRequest)} on hardware usage.
ambry-commons/src/test/java/com/github/ambry/commons/HostLevelThrottlerTest.java