use of com.github.ambry.config.VerifiableProperties 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.VerifiableProperties 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;
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class AmbryQuotaManagerTest method buildAmbryQuotaManagerWithNoEnforcers.
/**
* Build {@link AmbryQuotaManager} object with no enforcers.
* @return AmbryQuotaManager object.
* @throws ReflectiveOperationException in case the {@link AmbryQuotaManager} object could not be created.
*/
private AmbryQuotaManager buildAmbryQuotaManagerWithNoEnforcers() throws ReflectiveOperationException {
quotaConfig = new QuotaConfig(new VerifiableProperties(new Properties()));
quotaConfig.requestQuotaEnforcerSourcePairInfoJson = new JSONObject().put(QuotaConfig.QUOTA_ENFORCER_SOURCE_PAIR_INFO_STR, new JSONArray()).toString();
QuotaMetrics quotaMetrics = new QuotaMetrics(new MetricRegistry());
AmbryQuotaManager ambryQuotaManager = createAmbryQuotaManager(quotaConfig, quotaMetrics);
Assert.assertTrue(ambryQuotaManager.quotaEnforcers.isEmpty());
return ambryQuotaManager;
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class SimpleRequestQuotaCostPolicyTest method testCalculateRequestQuotaCharge.
@Test
public void testCalculateRequestQuotaCharge() throws Exception {
QuotaConfig quotaConfig = new QuotaConfig(new VerifiableProperties(new Properties()));
SimpleRequestQuotaCostPolicy quotaRequestCostPolicy = new SimpleRequestQuotaCostPolicy(quotaConfig);
RestResponseChannel restResponseChannel = mock(RestResponseChannel.class);
when(restResponseChannel.getHeader(anyString())).thenReturn(0);
String blobUri = "/AAYIAQSSAAgAAQAAAAAAABpFymbGwe7sRBWYa5OPlkcNHQ.bin";
// test for a 4 MB GET request.
long blobSize = 4 * MB;
RestRequest restRequest = createMockRequestWithMethod(RestMethod.GET, blobUri, -1);
Map<String, Double> costMap = quotaRequestCostPolicy.calculateRequestQuotaCharge(restRequest, blobSize);
verifyReadCost(costMap, Math.ceil(blobSize / (double) quotaConfig.quotaAccountingUnit));
// test for a small GET request (fractional CU).
blobSize = 6 * MB;
costMap = quotaRequestCostPolicy.calculateRequestQuotaCharge(restRequest, blobSize);
verifyReadCost(costMap, Math.ceil(blobSize / (double) quotaConfig.quotaAccountingUnit));
// test for a GET request of blob of size 0.
restRequest = createMockRequestWithMethod(RestMethod.GET, blobUri, -1);
costMap = quotaRequestCostPolicy.calculateRequestQuotaCharge(restRequest, 0);
verifyReadCost(costMap, 1);
// test for a GET request of blob of size 512.
blobSize = 512;
restRequest = createMockRequestWithMethod(RestMethod.GET, blobUri, -1);
costMap = quotaRequestCostPolicy.calculateRequestQuotaCharge(restRequest, blobSize);
verifyReadCost(costMap, 1);
// test for a small POST request (fractional storage cost).
blobSize = 8 * MB;
restRequest = createMockRequestWithMethod(RestMethod.POST, blobUri, blobSize);
costMap = quotaRequestCostPolicy.calculateRequestQuotaCharge(restRequest, blobSize);
verifyWriteCost(costMap, Math.ceil(blobSize / (double) quotaConfig.quotaAccountingUnit), 8 * 1024 * 1024 / (double) QuotaUtils.BYTES_IN_GB);
// test for a large POST request.
blobSize = 4 * QuotaUtils.BYTES_IN_GB;
restRequest = createMockRequestWithMethod(RestMethod.POST, blobUri, blobSize);
costMap = quotaRequestCostPolicy.calculateRequestQuotaCharge(restRequest, blobSize);
verifyWriteCost(costMap, Math.ceil(blobSize / (double) quotaConfig.quotaAccountingUnit), 4);
// test for a POST request of blob of size 0.
restRequest = createMockRequestWithMethod(RestMethod.POST, blobUri, 0);
costMap = quotaRequestCostPolicy.calculateRequestQuotaCharge(restRequest, 0);
verifyWriteCost(costMap, 1, 0);
// test for a POST request of blob of size 512.
restRequest = createMockRequestWithMethod(RestMethod.POST, blobUri, 0);
costMap = quotaRequestCostPolicy.calculateRequestQuotaCharge(restRequest, 512);
verifyWriteCost(costMap, 1, 0);
// test for a HEAD request.
restRequest = createMockRequestWithMethod(RestMethod.HEAD, blobUri, -1);
costMap = quotaRequestCostPolicy.calculateRequestQuotaCharge(restRequest, quotaConfig.quotaAccountingUnit);
verifyReadCost(costMap, 1);
// test for a DELETE request.
restRequest = createMockRequestWithMethod(RestMethod.DELETE, blobUri, -1);
costMap = quotaRequestCostPolicy.calculateRequestQuotaCharge(restRequest, quotaConfig.quotaAccountingUnit);
verifyWriteCost(costMap, 1, 0.0);
// test for a PUT request.
restRequest = createMockRequestWithMethod(RestMethod.PUT, blobUri, -1);
costMap = quotaRequestCostPolicy.calculateRequestQuotaCharge(restRequest, quotaConfig.quotaAccountingUnit);
verifyWriteCost(costMap, 1, 0.0);
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class AmbryCUQuotaSourceFactoryTest method testGetQuotaSource.
@Test
public void testGetQuotaSource() throws IOException {
QuotaConfig quotaConfig = new QuotaConfig(new VerifiableProperties(new Properties()));
AccountService mockAccountService = Mockito.mock(AccountService.class);
AmbryCUQuotaSourceFactory ambryCUQuotaSourceFactory = new AmbryCUQuotaSourceFactory(quotaConfig, mockAccountService);
Assert.assertEquals(AmbryCUQuotaSource.class, ambryCUQuotaSourceFactory.getQuotaSource().getClass());
}
Aggregations