private void testChargeAndRecommendForExceeds() throws Exception {
    RestRequest restRequest =
        QuotaTestUtils.createRestRequest(ACCOUNT, ACCOUNT.getAllContainers().iterator().next(), RestMethod.GET);
    AmbryQuotaManager ambryQuotaManager = buildAmbryQuotaManagerWithNoEnforcers();
    ambryQuotaManager.init();

    // 1. test that chargeAndRecommend returns ALLOW with not enforcers.
    QuotaAction quotaAction = ambryQuotaManager.chargeAndRecommend(restRequest, null, true, false);
    Assert.assertEquals(QuotaAction.ALLOW, quotaAction);

    // 2. test that enforcers are called and usage is charged if usage is within quota limits.
    ambryQuotaManager = buildAmbryQuotaManagerWithAmbryCUEnforcer();
    testAmbryCUQuotaEnforcer.resetDefaults();
    ambryQuotaManager.init();
    Map<QuotaName, Double> costMap = Collections.singletonMap(QuotaName.READ_CAPACITY_UNIT, 11.0);
    quotaAction = ambryQuotaManager.chargeAndRecommend(restRequest, costMap, true, false);
    Assert.assertEquals(QuotaAction.ALLOW, quotaAction);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer.initCallCount);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer.recommendCallCount);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer.chargeCallCount);
    Assert.assertEquals(110, testAmbryCUQuotaEnforcer.getQuotaSource()
        .getUsage(QuotaResource.fromRestRequest(restRequest), QuotaName.READ_CAPACITY_UNIT), 0.0001);
    Assert.assertEquals(11 * routerConfig.routerGetRequestParallelism,
        testAmbryCUQuotaEnforcer.getQuotaSource().getSystemResourceUsage(QuotaName.READ_CAPACITY_UNIT), 0.0001);

    // 3. test that enforcers are called and usage is charged if usage is outside quota limits, but quota exceed is allowed.
    testAmbryCUQuotaEnforcer.resetDefaults();
    costMap = Collections.singletonMap(QuotaName.READ_CAPACITY_UNIT, 100.0);
    quotaAction = ambryQuotaManager.chargeAndRecommend(restRequest, costMap, true, false);
    Assert.assertEquals(QuotaAction.ALLOW, quotaAction);
    Assert.assertEquals(0, testAmbryCUQuotaEnforcer.initCallCount);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer.recommendCallCount);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer.chargeCallCount);
    Assert.assertEquals(1110, testAmbryCUQuotaEnforcer.getQuotaSource()
        .getUsage(QuotaResource.fromRestRequest(restRequest), QuotaName.READ_CAPACITY_UNIT), 0.0001);
    Assert.assertEquals(111 * routerConfig.routerGetRequestParallelism,
        testAmbryCUQuotaEnforcer.getQuotaSource().getSystemResourceUsage(QuotaName.READ_CAPACITY_UNIT), 0.0001);

    // 4. test that enforcers are called and usage is not charged if usage is outside quota limits and quota exceed is not allowed.
    testAmbryCUQuotaEnforcer.resetDefaults();
    costMap = Collections.singletonMap(QuotaName.READ_CAPACITY_UNIT, 100.0);
    quotaAction = ambryQuotaManager.chargeAndRecommend(restRequest, costMap, true, false);
    Assert.assertEquals(expectedDelayRecommendationQuotaExceed, quotaAction);
    Assert.assertEquals(0, testAmbryCUQuotaEnforcer.initCallCount);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer.recommendCallCount);
    Assert.assertEquals(isRequestThrottlingEnabled ? 0 : 1, testAmbryCUQuotaEnforcer.chargeCallCount);
    Assert.assertEquals(isRequestThrottlingEnabled ? 1110 : 2110, testAmbryCUQuotaEnforcer.getQuotaSource()
        .getUsage(QuotaResource.fromRestRequest(restRequest), QuotaName.READ_CAPACITY_UNIT), 0.0001);
    Assert.assertEquals(isRequestThrottlingEnabled ? 111 * routerConfig.routerGetRequestParallelism
            : 211 * routerConfig.routerGetRequestParallelism,
        testAmbryCUQuotaEnforcer.getQuotaSource().getSystemResourceUsage(QuotaName.READ_CAPACITY_UNIT), 0.0001);

    // 5. test that even if quota exceed allowed might have returned false, if a request is within its limits, the recommendation is allow
    testAmbryCUQuotaEnforcer.resetDefaults();
    costMap = Collections.singletonMap(QuotaName.READ_CAPACITY_UNIT, 100.0);
    restRequest =
        QuotaTestUtils.createRestRequest(ANOTHER_ACCOUNT, ANOTHER_ACCOUNT.getAllContainers().iterator().next(),
            RestMethod.GET);
    quotaAction = ambryQuotaManager.chargeAndRecommend(restRequest, costMap, true, false);
    Assert.assertEquals(QuotaAction.ALLOW, quotaAction);
    Assert.assertEquals(0, testAmbryCUQuotaEnforcer.initCallCount);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer.recommendCallCount);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer.chargeCallCount);
    Assert.assertEquals(1000, testAmbryCUQuotaEnforcer.getQuotaSource()
        .getUsage(QuotaResource.fromRestRequest(restRequest), QuotaName.READ_CAPACITY_UNIT), 0.0001);
    Assert.assertEquals(isRequestThrottlingEnabled ? 211 * routerConfig.routerGetRequestParallelism
            : 311 * routerConfig.routerGetRequestParallelism,
        testAmbryCUQuotaEnforcer.getQuotaSource().getSystemResourceUsage(QuotaName.READ_CAPACITY_UNIT), 0.0001);
  }
Test {@link QuotaManager#chargeAndRecommend} when quota exceed check is set to true and force charge is set to false.
@throws Exception in case of any exception.
ambry-quota/src/test/java/com/github/ambry/quota/AmbryQuotaManagerTest.java