Search in sources :

Example 91 with VerifiableProperties

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);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) QuotaConfig(com.github.ambry.config.QuotaConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Before(org.junit.Before)

Example 92 with VerifiableProperties

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;
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) QuotaConfig(com.github.ambry.config.QuotaConfig) ArrayList(java.util.ArrayList) AmbryCUQuotaEnforcer(com.github.ambry.quota.capacityunit.AmbryCUQuotaEnforcer) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties)

Example 93 with VerifiableProperties

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;
}
Also used : JSONObject(org.json.JSONObject) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) QuotaConfig(com.github.ambry.config.QuotaConfig) JSONArray(org.json.JSONArray) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties)

Example 94 with VerifiableProperties

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);
}
Also used : RestRequest(com.github.ambry.rest.RestRequest) VerifiableProperties(com.github.ambry.config.VerifiableProperties) QuotaConfig(com.github.ambry.config.QuotaConfig) RestResponseChannel(com.github.ambry.rest.RestResponseChannel) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Test(org.junit.Test)

Example 95 with VerifiableProperties

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());
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) QuotaConfig(com.github.ambry.config.QuotaConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) AccountService(com.github.ambry.account.AccountService) Test(org.junit.Test)

Aggregations

VerifiableProperties (com.github.ambry.config.VerifiableProperties)335 Properties (java.util.Properties)219 Test (org.junit.Test)192 MetricRegistry (com.codahale.metrics.MetricRegistry)131 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)80 ArrayList (java.util.ArrayList)62 BlobProperties (com.github.ambry.messageformat.BlobProperties)61 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)52 StoreConfig (com.github.ambry.config.StoreConfig)51 IOException (java.io.IOException)47 File (java.io.File)39 RouterConfig (com.github.ambry.config.RouterConfig)37 ClusterMap (com.github.ambry.clustermap.ClusterMap)36 JSONObject (org.json.JSONObject)34 HashMap (java.util.HashMap)33 BlobId (com.github.ambry.commons.BlobId)31 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)31 CountDownLatch (java.util.concurrent.CountDownLatch)31 Map (java.util.Map)28 InMemAccountService (com.github.ambry.account.InMemAccountService)26