Search in sources :

Example 1 with CapacityUnit

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

the class JsonCUQuotaDataProviderUtilTest method testGetFeCUCapacityFromJson.

@Test
public void testGetFeCUCapacityFromJson() throws IOException {
    CapacityUnit feCapacityUnit = JsonCUQuotaDataProviderUtil.getFeCUCapacityFromJson(DEFAULT_FRONTEND_CAPACITY_JSON);
    Assert.assertEquals(1024, (long) feCapacityUnit.getRcu());
    Assert.assertEquals(1024, (long) feCapacityUnit.getWcu());
}
Also used : CapacityUnit(com.github.ambry.quota.capacityunit.CapacityUnit) Test(org.junit.Test)

Example 2 with CapacityUnit

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

the class JsonCUQuotaDataProviderUtilTest method testGetCUQuotasFromJson.

@Test
public void testGetCUQuotasFromJson() throws IOException, AccountServiceException {
    InMemAccountService accountService = new InMemAccountService(false, false);
    ObjectMapper objectMapper = new ObjectMapper();
    Map<String, JsonCUQuotaDataProviderUtil.MapOrQuota> testQuotas = objectMapper.readValue(DEFAULT_CU_QUOTA_IN_JSON, new TypeReference<Map<String, JsonCUQuotaDataProviderUtil.MapOrQuota>>() {
    });
    for (String s : testQuotas.keySet()) {
        accountService.updateAccounts(Collections.singletonList(createAccountForQuota(testQuotas.get(s), s)));
    }
    Map<String, CapacityUnit> quotas = JsonCUQuotaDataProviderUtil.getCUQuotasFromJson(DEFAULT_CU_QUOTA_IN_JSON, accountService);
    Assert.assertEquals(4, quotas.size());
    Assert.assertEquals(1024000000, (long) quotas.get("101_1").getRcu());
    Assert.assertEquals(1024000000, (long) quotas.get("101_1").getWcu());
    Assert.assertEquals(258438456, (long) quotas.get("101_2").getRcu());
    Assert.assertEquals(258438456, (long) quotas.get("101_2").getWcu());
    Assert.assertEquals(1024000000, (long) quotas.get("102_1").getRcu());
    Assert.assertEquals(1024000000, (long) quotas.get("102_1").getWcu());
    Assert.assertEquals(10737418240L, (long) quotas.get("103").getRcu());
    Assert.assertEquals(10737418240L, (long) quotas.get("103").getWcu());
}
Also used : JsonCUQuotaDataProviderUtil(com.github.ambry.quota.capacityunit.JsonCUQuotaDataProviderUtil) InMemAccountService(com.github.ambry.account.InMemAccountService) CapacityUnit(com.github.ambry.quota.capacityunit.CapacityUnit) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with CapacityUnit

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

the class JsonCUQuotaDataProviderUtilTest method testGetFeCUCapacityFromJsonForEmptyJson.

@Test
public void testGetFeCUCapacityFromJsonForEmptyJson() throws IOException {
    CapacityUnit feCapacityUnit = JsonCUQuotaDataProviderUtil.getFeCUCapacityFromJson(EMPTY_JSON);
    Assert.assertEquals(0, (long) feCapacityUnit.getRcu());
    Assert.assertEquals(0, (long) feCapacityUnit.getWcu());
}
Also used : CapacityUnit(com.github.ambry.quota.capacityunit.CapacityUnit) Test(org.junit.Test)

Example 4 with CapacityUnit

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

the class JsonCUQuotaDataProviderUtilTest method testGetCUQuotasFromJsonForEmptyJsonString.

@Test
public void testGetCUQuotasFromJsonForEmptyJsonString() throws IOException, AccountServiceException {
    InMemAccountService accountService = new InMemAccountService(false, false);
    ObjectMapper objectMapper = new ObjectMapper();
    Map<String, JsonCUQuotaDataProviderUtil.MapOrQuota> testQuotas = objectMapper.readValue(EMPTY_JSON, new TypeReference<Map<String, JsonCUQuotaDataProviderUtil.MapOrQuota>>() {
    });
    for (String s : testQuotas.keySet()) {
        accountService.updateAccounts(Collections.singletonList(createAccountForQuota(testQuotas.get(s), s)));
    }
    Map<String, CapacityUnit> quotas = JsonCUQuotaDataProviderUtil.getCUQuotasFromJson(EMPTY_JSON, accountService);
    Assert.assertEquals(0, quotas.size());
}
Also used : JsonCUQuotaDataProviderUtil(com.github.ambry.quota.capacityunit.JsonCUQuotaDataProviderUtil) InMemAccountService(com.github.ambry.account.InMemAccountService) CapacityUnit(com.github.ambry.quota.capacityunit.CapacityUnit) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

CapacityUnit (com.github.ambry.quota.capacityunit.CapacityUnit)4 Test (org.junit.Test)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InMemAccountService (com.github.ambry.account.InMemAccountService)2 JsonCUQuotaDataProviderUtil (com.github.ambry.quota.capacityunit.JsonCUQuotaDataProviderUtil)2 Map (java.util.Map)2