use of com.github.ambry.config.QuotaConfig in project ambry by linkedin.
the class QuotaTestUtils method createQuotaConfig.
/**
* Create {@link QuotaConfig} object with {@link QuotaEnforcer} and corresponding {@link QuotaSource} map.
* @param enforcerSourcemap {@link Map} for {@link QuotaEnforcer} and corresponding {@link QuotaSource} object.
* @param isRequestThrottlingEnabled boolean flag indicating if request quota throttling should be enabled.
* @param quotaMode {@link QuotaMode} for quota enforcement.
* @return QuotaConfig object.
*/
public static QuotaConfig createQuotaConfig(Map<String, String> enforcerSourcemap, boolean isRequestThrottlingEnabled, QuotaMode quotaMode) {
Properties properties = new Properties();
properties.setProperty(QuotaConfig.REQUEST_THROTTLING_ENABLED, "" + isRequestThrottlingEnabled);
properties.setProperty(QuotaConfig.THROTTLING_MODE, quotaMode.name());
JSONArray jsonArray = new JSONArray();
for (String enforcerFactoryClass : enforcerSourcemap.keySet()) {
JSONObject jsonObject = new JSONObject();
jsonObject.put(QuotaConfig.ENFORCER_STR, enforcerFactoryClass);
jsonObject.put(QuotaConfig.SOURCE_STR, enforcerSourcemap.get(enforcerFactoryClass));
jsonArray.put(jsonObject);
}
properties.setProperty(QuotaConfig.REQUEST_QUOTA_ENFORCER_SOURCE_PAIR_INFO_JSON, new JSONObject().put(QuotaConfig.QUOTA_ENFORCER_SOURCE_PAIR_INFO_STR, jsonArray).toString());
return new QuotaConfig(new VerifiableProperties(properties));
}
use of com.github.ambry.config.QuotaConfig in project ambry by linkedin.
the class AmbryCUQuotaSourceTest method testInit.
public void testInit() throws Exception {
QuotaSource quotaSource = new AmbryCUQuotaSourceFactory(new QuotaConfig(new VerifiableProperties(new Properties())), inMemAccountService).getQuotaSource();
Assert.assertFalse(quotaSource.isReady());
quotaSource.init();
Assert.assertTrue(quotaSource.isReady());
quotaSource.shutdown();
Assert.assertFalse(quotaSource.isReady());
}
use of com.github.ambry.config.QuotaConfig in project ambry by linkedin.
the class AmbryCUQuotaSourceTest method setup.
/**
* Create test setup by creating the {@link AmbryCUQuotaSource} object and updating account service.
* @throws IOException
* @throws AccountServiceException
*/
@Before
public void setup() throws IOException, AccountServiceException {
Properties properties = new Properties();
properties.setProperty(QuotaConfig.RESOURCE_CU_QUOTA_IN_JSON, DEFAULT_CU_QUOTA_IN_JSON);
properties.setProperty(QuotaConfig.FRONTEND_CU_CAPACITY_IN_JSON, DEFAULT_FRONTEND_CAPACITY_JSON);
quotaConfig = new QuotaConfig(new VerifiableProperties(properties));
inMemAccountService = new InMemAccountService(false, true);
ObjectMapper objectMapper = new ObjectMapper();
testQuotas = objectMapper.readValue(quotaConfig.resourceCUQuotaInJson, new TypeReference<Map<String, JsonCUQuotaDataProviderUtil.MapOrQuota>>() {
});
for (String s : testQuotas.keySet()) {
inMemAccountService.updateAccounts(Collections.singletonList(createAccountForQuota(testQuotas.get(s), s)));
}
ambryCUQuotaSource = (AmbryCUQuotaSource) new AmbryCUQuotaSourceFactory(quotaConfig, inMemAccountService).getQuotaSource();
ambryCUQuotaSource.init();
}
use of com.github.ambry.config.QuotaConfig in project ambry by linkedin.
the class AmbryCUQuotaEnforcerTest method setup.
@Before
public void setup() throws IOException {
ACCOUNT = ACCOUNT_SERVICE.createAndAddRandomAccount(QuotaResourceType.ACCOUNT);
Properties properties = new Properties();
properties.setProperty(QuotaConfig.RESOURCE_CU_QUOTA_IN_JSON, String.format("{\n" + " \"%s\": {\n" + " \"wcu\": %d,\n" + " \"rcu\": %d\n" + " }\n" + "}", String.valueOf(ACCOUNT.getId()), WCU, RCU));
properties.setProperty(QuotaConfig.FRONTEND_CU_CAPACITY_IN_JSON, String.format("{\n" + " \"wcu\": %d,\n" + " \"rcu\": %d\n" + "}", FE_WCU, FE_RCU));
QuotaConfig quotaConfig = new QuotaConfig(new VerifiableProperties(properties));
QUOTA_SOURCE = new ExceptionQuotaSource(quotaConfig, ACCOUNT_SERVICE);
QUOTA_SOURCE.init();
AMBRY_QUOTA_ENFORCER = new AmbryCUQuotaEnforcer(QUOTA_SOURCE, quotaConfig);
}
use of com.github.ambry.config.QuotaConfig in project ambry by linkedin.
the class AmbryQuotaManagerTest method buildAmbryQuotaManager.
/**
* Build {@link AmbryQuotaManager} object with two test enforcers.
* @return AmbryQuotaManager object.
* @throws ReflectiveOperationException in case the {@link AmbryQuotaManager} object could not be created.
*/
private AmbryQuotaManager buildAmbryQuotaManager() throws ReflectiveOperationException {
quotaConfig = new QuotaConfig(new VerifiableProperties(new Properties()));
quotaConfig.requestQuotaEnforcerSourcePairInfoJson = buildTestQuotaEnforcerSourceInfoPairJson().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);
Assert.assertTrue(quotaEnforcers.get(0) instanceof TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer);
Assert.assertTrue(quotaEnforcers.get(1) instanceof TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer);
testAmbryCUQuotaEnforcer = (TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer) quotaEnforcers.get(1);
return ambryQuotaManager;
}
Aggregations