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;
}
Aggregations