use of com.github.ambry.config.QuotaConfig 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;
}
use of com.github.ambry.config.QuotaConfig in project ambry by linkedin.
the class AmbryQuotaManagerUpdateNotificationTest method ambryQuotaManagerUpdateNotificationTest.
@Test
public void ambryQuotaManagerUpdateNotificationTest() throws Exception {
VerifiableProperties verifiableProperties = new VerifiableProperties(new Properties());
MetricRegistry metricRegistry = new MetricRegistry();
QuotaConfig quotaConfig = new QuotaConfig(verifiableProperties);
QuotaRecommendationMergePolicy quotaRecommendationMergePolicy = new SimpleQuotaRecommendationMergePolicy(quotaConfig);
AccountServiceForConsumerTest accountService = new AccountServiceForConsumerTest(new AccountServiceConfig(verifiableProperties), new AccountServiceMetrics(metricRegistry), null);
AmbryQuotaManager ambryQuotaManager = new AmbryQuotaManager(quotaConfig, quotaRecommendationMergePolicy, accountService, null, new QuotaMetrics(metricRegistry));
AmbryCUQuotaSource quotaSource = (AmbryCUQuotaSource) getQuotaSourceMember(ambryQuotaManager);
assertTrue("updated accounts should be empty", quotaSource.getAllQuota().isEmpty());
Set<Short> accountIdSet = new HashSet<>();
accountIdSet.add((short) 1);
accountIdSet.add((short) 2);
Map<Short, Account> idToRefAccountMap = new HashMap<>();
AccountTestUtils.generateRefAccounts(idToRefAccountMap, new HashMap<>(), accountIdSet, 2, 3);
accountService.notifyAccountUpdateConsumers(idToRefAccountMap.values());
assertEquals("Invalid size of updated accounts", quotaSource.getAllQuota().size(), 2);
}
use of com.github.ambry.config.QuotaConfig in project ambry by linkedin.
the class AmbryCUQuotaEnforcerFactoryTest method testGetRequestQuotaEnforcer.
@Test
public void testGetRequestQuotaEnforcer() throws IOException {
QuotaConfig quotaConfig = new QuotaConfig(new VerifiableProperties(new Properties()));
QuotaSource quotaSource = new AmbryCUQuotaSource(quotaConfig, Mockito.mock(AccountService.class));
AccountStatsStore mockAccountStatsStore = Mockito.mock(AccountStatsStore.class);
AmbryCUQuotaEnforcerFactory ambryCUQuotaEnforcerFactory = new AmbryCUQuotaEnforcerFactory(quotaConfig, quotaSource, mockAccountStatsStore);
Assert.assertEquals(AmbryCUQuotaEnforcer.class, ambryCUQuotaEnforcerFactory.getQuotaEnforcer().getClass());
}
use of com.github.ambry.config.QuotaConfig in project ambry by linkedin.
the class NonBlockingRouterQuotaCallbackTest method testRouterWithDefaultQuotaCallback.
/**
* Test default {@link QuotaChargeCallback} doesn't charge anything and doesn't error out when throttling is disabled.
*/
@Test
public void testRouterWithDefaultQuotaCallback() throws Exception {
try {
setRouter();
assertExpectedThreadCounts(2, 1);
AtomicInteger listenerCalledCount = new AtomicInteger(0);
QuotaConfig quotaConfig = new QuotaConfig(new VerifiableProperties(new Properties()));
QuotaManager quotaManager = new ChargeTesterQuotaManager(quotaConfig, new SimpleQuotaRecommendationMergePolicy(quotaConfig), accountService, null, new QuotaMetrics(new MetricRegistry()), listenerCalledCount);
QuotaChargeCallback quotaChargeCallback = QuotaUtils.buildQuotaChargeCallback(null, quotaManager, true);
int blobSize = 3000;
setOperationParams(blobSize, TTL_SECS);
String compositeBlobId = router.putBlob(putBlobProperties, putUserMetadata, putChannel, PutBlobOptions.DEFAULT, null, quotaChargeCallback).get();
assertEquals(0, listenerCalledCount.get());
RetainingAsyncWritableChannel retainingAsyncWritableChannel = new RetainingAsyncWritableChannel();
router.getBlob(compositeBlobId, new GetBlobOptionsBuilder().build(), null, quotaChargeCallback).get().getBlobDataChannel().readInto(retainingAsyncWritableChannel, null).get();
// read out all the chunks.
retainingAsyncWritableChannel.consumeContentAsInputStream().close();
assertEquals(0, listenerCalledCount.get());
} finally {
router.close();
assertExpectedThreadCounts(0, 0);
// submission after closing should return a future that is already done.
assertClosed();
}
}
Aggregations