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

    // 1. test that recommend returns null with not enforcers.
    Assert.assertNull(ambryQuotaManager.recommend(restRequest));

    // 2. test that enforcers are called.
    ambryQuotaManager = buildAmbryQuotaManagerWithAmbryCUEnforcer();
    testAmbryCUQuotaEnforcer.resetDefaults();
    ambryQuotaManager.init();
    ThrottlingRecommendation throttlingRecommendation = ambryQuotaManager.recommend(restRequest);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer.initCallCount);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer.recommendCallCount);
    Assert.assertEquals(throttlingRecommendation.getQuotaAction(), QuotaAction.ALLOW);
    Assert.assertEquals(2, TestCUQuotaEnforcerFactory.TestQuotaRecommendationMergePolicy.quotaRecommendationsCount);

    // 3. test that if any quota enforcer throws exception, then other quota enforcers are called nonetheless
    testAmbryCUQuotaEnforcer.resetDefaults();
    testAmbryCUQuotaEnforcer.throwException = true;
    throttlingRecommendation = ambryQuotaManager.recommend(restRequest);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer.recommendCallCount);
    Assert.assertEquals(throttlingRecommendation.getQuotaAction(), QuotaAction.ALLOW);
    Assert.assertEquals(3, TestCUQuotaEnforcerFactory.TestQuotaRecommendationMergePolicy.quotaRecommendationsCount);

    ambryQuotaManager = buildAmbryQuotaManager();
    List<QuotaEnforcer> quotaEnforcers = new ArrayList<>(ambryQuotaManager.quotaEnforcers);
    TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer testAmbryCUQuotaEnforcer1 =
        (TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer) quotaEnforcers.get(0);
    TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer testAmbryCUQuotaEnforcer2 =
        (TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer) quotaEnforcers.get(1);
    testAmbryCUQuotaEnforcer1.resetDefaults();
    testAmbryCUQuotaEnforcer2.resetDefaults();
    ambryQuotaManager.init();

    // 4. test that if any quota enforcer recommends DELAY action, then that's the recommendation
    testAmbryCUQuotaEnforcer1.resetDefaults();
    testAmbryCUQuotaEnforcer2.resetDefaults();
    testAmbryCUQuotaEnforcer1.recommendReturnVal =
        TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer.DELAY_QUOTA_RECOMMENDATION;
    testAmbryCUQuotaEnforcer2.recommendReturnVal =
        TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer.ALLOW_QUOTA_RECOMMENDATION;
    throttlingRecommendation = ambryQuotaManager.recommend(restRequest);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer1.recommendCallCount);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer2.recommendCallCount);
    Assert.assertEquals(throttlingRecommendation.getQuotaAction(), expectedDelayRecommendationQuotaExceed);
    Assert.assertEquals(5, TestCUQuotaEnforcerFactory.TestQuotaRecommendationMergePolicy.quotaRecommendationsCount);

    // 5. test that if any quota enforcer recommends REJECT action, then that's the recommendation
    testAmbryCUQuotaEnforcer1.resetDefaults();
    testAmbryCUQuotaEnforcer2.resetDefaults();
    testAmbryCUQuotaEnforcer1.recommendReturnVal =
        TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer.DELAY_QUOTA_RECOMMENDATION;
    testAmbryCUQuotaEnforcer2.recommendReturnVal =
        TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer.REJECT_QUOTA_RECOMMENDATION;
    throttlingRecommendation = ambryQuotaManager.recommend(restRequest);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer1.recommendCallCount);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer2.recommendCallCount);
    Assert.assertEquals(throttlingRecommendation.getQuotaAction(), expectedRejectRecommendationQuotaExceed);
    Assert.assertEquals(7, TestCUQuotaEnforcerFactory.TestQuotaRecommendationMergePolicy.quotaRecommendationsCount);

    // 6. test if all the enforcers throw exception.
    testAmbryCUQuotaEnforcer1.resetDefaults();
    testAmbryCUQuotaEnforcer2.resetDefaults();
    testAmbryCUQuotaEnforcer1.throwException = true;
    testAmbryCUQuotaEnforcer2.throwException = true;
    throttlingRecommendation = ambryQuotaManager.recommend(restRequest);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer1.recommendCallCount);
    Assert.assertEquals(1, testAmbryCUQuotaEnforcer2.recommendCallCount);
    Assert.assertEquals(throttlingRecommendation.getQuotaAction(), QuotaAction.ALLOW);
    Assert.assertEquals(7, TestCUQuotaEnforcerFactory.TestQuotaRecommendationMergePolicy.quotaRecommendationsCount);
  }
Running for both {@link AmbryQuotaManager} as well as {@link AtomicAmbryQuotaManager}.
@return an array container a flag that is {@code true} for {@link AtomicAmbryQuotaManager} and {@code false} for
{@link AmbryQuotaManager}.
ambry-quota/src/test/java/com/github/ambry/quota/AmbryQuotaManagerTest.java