Search in sources :

Example 1 with AmbryCUQuotaEnforcer

use of com.github.ambry.quota.capacityunit.AmbryCUQuotaEnforcer in project ambry by linkedin.

the class AmbryQuotaManagerTest method buildAmbryQuotaManagerWithAmbryCUEnforcer.

/**
 * Build {@link AmbryQuotaManager} object with {@link AmbryCUQuotaEnforcer} as one of the enforcers.
 * @return AmbryQuotaManager object.
 * @throws ReflectiveOperationException in case the {@link AmbryQuotaManager} object could not be created.
 */
private AmbryQuotaManager buildAmbryQuotaManagerWithAmbryCUEnforcer() throws ReflectiveOperationException {
    Properties properties = new Properties();
    properties.setProperty(QuotaConfig.RESOURCE_CU_QUOTA_IN_JSON, String.format("{\n" + "    \"%s\": {\n" + "        \"wcu\": %d,\n" + "        \"rcu\": %d\n" + "    },\n" + "    \"%s\": {\n" + "        \"wcu\": %d,\n" + "        \"rcu\": %d\n" + "    }\n" + "}", String.valueOf(ACCOUNT.getId()), 10, 10, String.valueOf(ANOTHER_ACCOUNT.getId()), 10, 10));
    properties.setProperty(QuotaConfig.FRONTEND_CU_CAPACITY_IN_JSON, String.format("{\n" + "  \"wcu\": %d,\n" + "  \"rcu\": %d\n" + "}", 100, 100));
    quotaConfig = new QuotaConfig(new VerifiableProperties(properties));
    quotaConfig.requestQuotaEnforcerSourcePairInfoJson = buildDefaultQuotaEnforcerSourceInfoPairJson().toString();
    QuotaMetrics quotaMetrics = new QuotaMetrics(new MetricRegistry());
    AmbryQuotaManager ambryQuotaManager = createAmbryQuotaManager(quotaConfig, quotaMetrics);
    Assert.assertEquals(2, ambryQuotaManager.quotaEnforcers.size());
    List<QuotaEnforcer> quotaEnforcers = new ArrayList<>(ambryQuotaManager.quotaEnforcers);
    quotaEnforcers.sort(Comparator.comparing(o -> o.getClass().getSimpleName()));
    Assert.assertTrue(quotaEnforcers.get(0) instanceof AmbryCUQuotaEnforcer);
    Assert.assertTrue(quotaEnforcers.get(1) instanceof TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer);
    testAmbryCUQuotaEnforcer = (TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer) quotaEnforcers.get(1);
    return ambryQuotaManager;
}
Also used : Arrays(java.util.Arrays) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) RestMethod(com.github.ambry.rest.RestMethod) VerifiableProperties(com.github.ambry.config.VerifiableProperties) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) QuotaConfig(com.github.ambry.config.QuotaConfig) List(java.util.List) JSONObject(org.json.JSONObject) Map(java.util.Map) Account(com.github.ambry.account.Account) AmbryCUQuotaEnforcer(com.github.ambry.quota.capacityunit.AmbryCUQuotaEnforcer) Comparator(java.util.Comparator) Assert(org.junit.Assert) RestRequest(com.github.ambry.rest.RestRequest) Collections(java.util.Collections) InMemAccountService(com.github.ambry.account.InMemAccountService) JSONArray(org.json.JSONArray) Parameterized(org.junit.runners.Parameterized) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) ArrayList(java.util.ArrayList) AmbryCUQuotaEnforcer(com.github.ambry.quota.capacityunit.AmbryCUQuotaEnforcer) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) QuotaConfig(com.github.ambry.config.QuotaConfig) AmbryCUQuotaEnforcer(com.github.ambry.quota.capacityunit.AmbryCUQuotaEnforcer)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)1 Account (com.github.ambry.account.Account)1 InMemAccountService (com.github.ambry.account.InMemAccountService)1 QuotaConfig (com.github.ambry.config.QuotaConfig)1 VerifiableProperties (com.github.ambry.config.VerifiableProperties)1 AmbryCUQuotaEnforcer (com.github.ambry.quota.capacityunit.AmbryCUQuotaEnforcer)1 RestMethod (com.github.ambry.rest.RestMethod)1 RestRequest (com.github.ambry.rest.RestRequest)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1